@fermindi/pwn-cli 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +251 -0
- package/cli/batch.js +333 -0
- package/cli/codespaces.js +303 -0
- package/cli/index.js +91 -0
- package/cli/inject.js +53 -0
- package/cli/knowledge.js +531 -0
- package/cli/notify.js +135 -0
- package/cli/patterns.js +665 -0
- package/cli/status.js +91 -0
- package/cli/validate.js +61 -0
- package/package.json +70 -0
- package/src/core/inject.js +128 -0
- package/src/core/state.js +91 -0
- package/src/core/validate.js +202 -0
- package/src/core/workspace.js +176 -0
- package/src/index.js +20 -0
- package/src/knowledge/gc.js +308 -0
- package/src/knowledge/lifecycle.js +401 -0
- package/src/knowledge/promote.js +364 -0
- package/src/knowledge/references.js +342 -0
- package/src/patterns/matcher.js +218 -0
- package/src/patterns/registry.js +375 -0
- package/src/patterns/triggers.js +423 -0
- package/src/services/batch-service.js +849 -0
- package/src/services/notification-service.js +342 -0
- package/templates/codespaces/devcontainer.json +52 -0
- package/templates/codespaces/setup.sh +70 -0
- package/templates/workspace/.ai/README.md +164 -0
- package/templates/workspace/.ai/agents/README.md +204 -0
- package/templates/workspace/.ai/agents/claude.md +625 -0
- package/templates/workspace/.ai/config/.gitkeep +0 -0
- package/templates/workspace/.ai/config/README.md +79 -0
- package/templates/workspace/.ai/config/notifications.template.json +20 -0
- package/templates/workspace/.ai/memory/deadends.md +79 -0
- package/templates/workspace/.ai/memory/decisions.md +58 -0
- package/templates/workspace/.ai/memory/patterns.md +65 -0
- package/templates/workspace/.ai/patterns/backend/README.md +126 -0
- package/templates/workspace/.ai/patterns/frontend/README.md +103 -0
- package/templates/workspace/.ai/patterns/index.md +256 -0
- package/templates/workspace/.ai/patterns/triggers.json +1087 -0
- package/templates/workspace/.ai/patterns/universal/README.md +141 -0
- package/templates/workspace/.ai/state.template.json +8 -0
- package/templates/workspace/.ai/tasks/active.md +77 -0
- package/templates/workspace/.ai/tasks/backlog.md +95 -0
- package/templates/workspace/.ai/workflows/batch-task.md +356 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Failed Approaches & Dead Ends
|
|
2
|
+
|
|
3
|
+
This file documents approaches that failed, to avoid repeating mistakes.
|
|
4
|
+
|
|
5
|
+
## Format
|
|
6
|
+
|
|
7
|
+
Each dead end follows this structure:
|
|
8
|
+
|
|
9
|
+
```markdown
|
|
10
|
+
## DE-XXX: Failed Approach Title
|
|
11
|
+
**Date:** YYYY-MM-DD
|
|
12
|
+
**Attempted:** What we tried
|
|
13
|
+
**Problem:** Why it failed
|
|
14
|
+
**Solution:** What worked instead
|
|
15
|
+
**Time Spent:** Approximate hours
|
|
16
|
+
**Reference:** Related decision or issue
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Adding New Dead Ends
|
|
22
|
+
|
|
23
|
+
When an approach fails:
|
|
24
|
+
|
|
25
|
+
1. Assign next DE number (DE-001, DE-002, etc.)
|
|
26
|
+
2. Fill in all sections while fresh in memory
|
|
27
|
+
3. Commit with message: `docs: add DE-XXX dead end`
|
|
28
|
+
4. Reference in code: `// See DE-XXX - why we don't use X`
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Categories
|
|
33
|
+
|
|
34
|
+
- **Architecture:** Structural decisions that didn't work
|
|
35
|
+
- **Performance:** Optimization attempts that backfired
|
|
36
|
+
- **Dependencies:** Library choices that caused problems
|
|
37
|
+
- **Testing:** Test strategies that were too brittle
|
|
38
|
+
- **Integration:** External service integrations that failed
|
|
39
|
+
- **Data Modeling:** Schema or object structure issues
|
|
40
|
+
- **DevOps:** Deployment/infrastructure approaches
|
|
41
|
+
|
|
42
|
+
---
|
|
43
|
+
|
|
44
|
+
## Template for New Dead End
|
|
45
|
+
|
|
46
|
+
```markdown
|
|
47
|
+
## DE-XXX: [Title]
|
|
48
|
+
**Date:** YYYY-MM-DD
|
|
49
|
+
**Attempted:** (What we tried and why we thought it would work)
|
|
50
|
+
**Problem:** (Why it failed - specific errors, limitations, etc.)
|
|
51
|
+
**Solution:** (What we did instead - working approach)
|
|
52
|
+
**Time Spent:** X hours
|
|
53
|
+
**Reference:** (Link to related DEC, issue, or PR)
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Tips for Recording Dead Ends
|
|
59
|
+
|
|
60
|
+
- Be honest about what failed
|
|
61
|
+
- Include error messages and specific blockers
|
|
62
|
+
- Document the solution for future reference
|
|
63
|
+
- Note if this is a category-wide dead end or specific case
|
|
64
|
+
- Update if you discover new info about why it failed
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Archiving
|
|
69
|
+
|
|
70
|
+
Dead ends are archived to `/context/dead-ends/archive/` after:
|
|
71
|
+
- 90 days with no new references
|
|
72
|
+
- Superseded by later approaches
|
|
73
|
+
- External changes (library update) invalidate the issue
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Current Backlog
|
|
78
|
+
|
|
79
|
+
Document new dead ends as they occur. Keep the most recent 5-10 active.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Architectural Decisions
|
|
2
|
+
|
|
3
|
+
This file tracks major architectural decisions made for this project.
|
|
4
|
+
|
|
5
|
+
## Format
|
|
6
|
+
|
|
7
|
+
Each decision follows this structure:
|
|
8
|
+
|
|
9
|
+
```markdown
|
|
10
|
+
## DEC-XXX: Decision Title
|
|
11
|
+
**Date:** YYYY-MM-DD
|
|
12
|
+
**Status:** Active | Superseded | Deprecated
|
|
13
|
+
**Context:** Why this decision was needed
|
|
14
|
+
**Decision:** What was decided
|
|
15
|
+
**Rationale:** Why this is the best choice
|
|
16
|
+
**Impact:** What this affects
|
|
17
|
+
**Alternatives Considered:** Other options we evaluated
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## DEC-001: Example Decision
|
|
23
|
+
**Date:** 2026-01-21
|
|
24
|
+
**Status:** Active
|
|
25
|
+
**Context:** (Describe the situation that required this decision)
|
|
26
|
+
**Decision:** (State what was decided)
|
|
27
|
+
**Rationale:** (Explain why this is the right choice)
|
|
28
|
+
**Impact:** (List what this affects - files, patterns, dependencies)
|
|
29
|
+
**Alternatives Considered:**
|
|
30
|
+
- Option A: (why rejected)
|
|
31
|
+
- Option B: (why rejected)
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## Adding New Decisions
|
|
36
|
+
|
|
37
|
+
When making significant architectural choices:
|
|
38
|
+
1. Assign next DEC number (DEC-002, DEC-003, etc.)
|
|
39
|
+
2. Fill in all sections
|
|
40
|
+
3. Commit with message: `docs: add DEC-XXX decision`
|
|
41
|
+
4. Reference in code comments: `// See DEC-XXX`
|
|
42
|
+
|
|
43
|
+
## Decision Categories
|
|
44
|
+
|
|
45
|
+
- **Technology Choices:** Frameworks, libraries, tools
|
|
46
|
+
- **Architecture Patterns:** How systems interact
|
|
47
|
+
- **Data Models:** Database schemas, API contracts
|
|
48
|
+
- **Security:** Authentication, authorization, encryption
|
|
49
|
+
- **Performance:** Caching, optimization strategies
|
|
50
|
+
- **DevOps:** Deployment, CI/CD, monitoring
|
|
51
|
+
|
|
52
|
+
## Superseding Decisions
|
|
53
|
+
|
|
54
|
+
When a decision changes:
|
|
55
|
+
1. Update status to "Superseded"
|
|
56
|
+
2. Link to new decision: "Superseded by DEC-XXX"
|
|
57
|
+
3. Don't delete - keep for historical context
|
|
58
|
+
4. Move to `.ai/memory/archive/` after 90 days unused
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# Codebase Patterns
|
|
2
|
+
|
|
3
|
+
This file documents recurring patterns discovered during development.
|
|
4
|
+
|
|
5
|
+
## Format
|
|
6
|
+
|
|
7
|
+
Each pattern follows this structure:
|
|
8
|
+
|
|
9
|
+
```markdown
|
|
10
|
+
## Pattern Category
|
|
11
|
+
|
|
12
|
+
### Pattern Name
|
|
13
|
+
**Context:** When this pattern applies
|
|
14
|
+
**Pattern:** Code example or description
|
|
15
|
+
**Rationale:** Why this is the better approach
|
|
16
|
+
**Example Location:** Where to find real examples
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Add New Patterns
|
|
22
|
+
|
|
23
|
+
When you discover a useful pattern:
|
|
24
|
+
|
|
25
|
+
1. Identify the category (Frontend, Backend, Testing, etc.)
|
|
26
|
+
2. Fill in all sections
|
|
27
|
+
3. Add code example if possible
|
|
28
|
+
4. Commit with message: `docs: add pattern - [name]`
|
|
29
|
+
5. Update `patterns/index.md` if this should be auto-applied
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Pattern Categories
|
|
34
|
+
|
|
35
|
+
- **Frontend:** React, TypeScript, styling, component patterns
|
|
36
|
+
- **Backend:** API design, database queries, middleware
|
|
37
|
+
- **Testing:** Unit tests, integration tests, fixtures
|
|
38
|
+
- **Performance:** Caching, memoization, optimization
|
|
39
|
+
- **Security:** Input validation, authentication, authorization
|
|
40
|
+
- **Error Handling:** Exception patterns, recovery strategies
|
|
41
|
+
- **Data Structures:** Modeling domain objects effectively
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Template for New Pattern
|
|
46
|
+
|
|
47
|
+
```markdown
|
|
48
|
+
## [Category]
|
|
49
|
+
|
|
50
|
+
### [Pattern Name]
|
|
51
|
+
**Context:** (When to use this pattern)
|
|
52
|
+
**Pattern:** (Description or code example)
|
|
53
|
+
**Rationale:** (Why this is better)
|
|
54
|
+
**Example Location:** (Where in codebase)
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Notes
|
|
60
|
+
|
|
61
|
+
- Patterns should be language-agnostic when possible
|
|
62
|
+
- Prioritize patterns that prevent common bugs
|
|
63
|
+
- Link related patterns together
|
|
64
|
+
- Update this file as team learns new approaches
|
|
65
|
+
- Archive rarely-used patterns after 3 months of no references
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# Backend Patterns
|
|
2
|
+
|
|
3
|
+
This directory contains design patterns and best practices for backend development.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Backend patterns cover:
|
|
8
|
+
- Express.js route structure
|
|
9
|
+
- REST API design
|
|
10
|
+
- Database queries and migrations
|
|
11
|
+
- Error handling and logging
|
|
12
|
+
- Authentication and authorization
|
|
13
|
+
- Data validation
|
|
14
|
+
- Performance optimization
|
|
15
|
+
- Middleware patterns
|
|
16
|
+
- Integration patterns
|
|
17
|
+
|
|
18
|
+
## Structure
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
backend/
|
|
22
|
+
├── README.md # This file
|
|
23
|
+
├── express/ # Express.js patterns
|
|
24
|
+
│ └── README.md # Express routing and middleware
|
|
25
|
+
├── database/ # Database patterns
|
|
26
|
+
│ └── README.md # Query and ORM patterns
|
|
27
|
+
├── api-design/ # REST API patterns
|
|
28
|
+
│ └── README.md # API structure and conventions
|
|
29
|
+
├── security/ # Security patterns
|
|
30
|
+
│ └── README.md # Auth, validation, sanitization
|
|
31
|
+
└── integration/ # Integration patterns
|
|
32
|
+
└── README.md # Working with external services
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Auto-Apply Triggers
|
|
36
|
+
|
|
37
|
+
These patterns are automatically loaded when:
|
|
38
|
+
|
|
39
|
+
- **File:** `*.routes.ts`, `routes/*.ts` (Express routes)
|
|
40
|
+
- **Import:** `from.*express`, `import.*Router`
|
|
41
|
+
- **Path:** `src/routes/`, `src/api/`
|
|
42
|
+
- **Keyword:** `app.get`, `app.post`, `router.use`
|
|
43
|
+
|
|
44
|
+
See `patterns/index.md` for trigger configuration.
|
|
45
|
+
|
|
46
|
+
## Common Patterns
|
|
47
|
+
|
|
48
|
+
### Route Structure
|
|
49
|
+
```typescript
|
|
50
|
+
// Group related routes together
|
|
51
|
+
// Use middleware for common operations (auth, logging)
|
|
52
|
+
// Keep route handlers thin, logic in services
|
|
53
|
+
// Consistent error handling
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### Express Middleware
|
|
57
|
+
- Authentication middleware early in chain
|
|
58
|
+
- Error handling middleware last
|
|
59
|
+
- Logging middleware for all requests
|
|
60
|
+
- Request validation middleware
|
|
61
|
+
- CORS middleware appropriately configured
|
|
62
|
+
|
|
63
|
+
### API Design
|
|
64
|
+
- RESTful conventions (GET, POST, PUT, DELETE)
|
|
65
|
+
- Consistent response format
|
|
66
|
+
- Proper HTTP status codes
|
|
67
|
+
- Pagination for list endpoints
|
|
68
|
+
- Filtering and sorting support
|
|
69
|
+
|
|
70
|
+
### Database Queries
|
|
71
|
+
- Use ORM/query builder (not raw SQL)
|
|
72
|
+
- Eager load relationships when needed
|
|
73
|
+
- Avoid N+1 query problems
|
|
74
|
+
- Index frequently-queried columns
|
|
75
|
+
- Use transactions for multi-step operations
|
|
76
|
+
|
|
77
|
+
### Error Handling
|
|
78
|
+
- Custom error classes for different error types
|
|
79
|
+
- Consistent error response format
|
|
80
|
+
- Log errors with full context
|
|
81
|
+
- Don't expose internal errors to clients
|
|
82
|
+
- Use HTTP status codes correctly
|
|
83
|
+
|
|
84
|
+
### Validation
|
|
85
|
+
- Validate all user input
|
|
86
|
+
- Use schema validation (Zod, Joi, etc.)
|
|
87
|
+
- Sanitize input to prevent injection
|
|
88
|
+
- Custom validation rules for domain logic
|
|
89
|
+
- Clear error messages for users
|
|
90
|
+
|
|
91
|
+
### Authentication
|
|
92
|
+
- Use industry-standard auth (JWT, OAuth, etc.)
|
|
93
|
+
- Secure token storage
|
|
94
|
+
- Token expiration and refresh strategy
|
|
95
|
+
- Role-based access control (RBAC)
|
|
96
|
+
- Audit logging of auth events
|
|
97
|
+
|
|
98
|
+
## Usage
|
|
99
|
+
|
|
100
|
+
1. Read the relevant sub-directory README for your task
|
|
101
|
+
2. Check code examples for reference implementations
|
|
102
|
+
3. Follow patterns in new routes and services
|
|
103
|
+
4. Update patterns if you discover improvements
|
|
104
|
+
|
|
105
|
+
## Contributing
|
|
106
|
+
|
|
107
|
+
Found a better pattern?
|
|
108
|
+
|
|
109
|
+
1. Document it with examples
|
|
110
|
+
2. Add to appropriate subdirectory
|
|
111
|
+
3. Update this README
|
|
112
|
+
4. Commit with message: `docs: add [pattern name] pattern`
|
|
113
|
+
5. Update triggers in `patterns/index.md` if widely applicable
|
|
114
|
+
|
|
115
|
+
## Links
|
|
116
|
+
|
|
117
|
+
- [Express Patterns](express/README.md)
|
|
118
|
+
- [Database Patterns](database/README.md)
|
|
119
|
+
- [API Design](api-design/README.md)
|
|
120
|
+
- [Security Patterns](security/README.md)
|
|
121
|
+
- [Integration Patterns](integration/README.md)
|
|
122
|
+
|
|
123
|
+
## Version
|
|
124
|
+
|
|
125
|
+
**Last Updated:** (Set on template injection)
|
|
126
|
+
**Maintained By:** Development Team
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Frontend Patterns
|
|
2
|
+
|
|
3
|
+
This directory contains design patterns and best practices for frontend development.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Frontend patterns cover:
|
|
8
|
+
- React component architecture
|
|
9
|
+
- TypeScript type definitions
|
|
10
|
+
- Styling and CSS strategies
|
|
11
|
+
- State management
|
|
12
|
+
- Performance optimization
|
|
13
|
+
- Accessibility (a11y)
|
|
14
|
+
- Component composition
|
|
15
|
+
- Hook patterns
|
|
16
|
+
|
|
17
|
+
## Structure
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
frontend/
|
|
21
|
+
├── README.md # This file
|
|
22
|
+
├── react/ # React-specific patterns
|
|
23
|
+
│ └── README.md # React component patterns
|
|
24
|
+
├── styling/ # CSS and styling patterns
|
|
25
|
+
│ └── README.md # Styling strategies
|
|
26
|
+
├── component-libs/ # UI component library patterns
|
|
27
|
+
│ └── README.md # Working with component libraries
|
|
28
|
+
└── accessibility/ # A11y patterns
|
|
29
|
+
└── README.md # Accessibility patterns
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Auto-Apply Triggers
|
|
33
|
+
|
|
34
|
+
These patterns are automatically loaded when:
|
|
35
|
+
|
|
36
|
+
- **File:** `*.tsx`, `*.jsx` (React components)
|
|
37
|
+
- **Import:** `import.*React`, `from.*react`
|
|
38
|
+
- **Path:** `src/components/`
|
|
39
|
+
- **Keyword:** `function Component`, `export default`
|
|
40
|
+
|
|
41
|
+
See `patterns/index.md` for trigger configuration.
|
|
42
|
+
|
|
43
|
+
## Common Patterns
|
|
44
|
+
|
|
45
|
+
### Component Architecture
|
|
46
|
+
- Functional components with hooks (not class components)
|
|
47
|
+
- One component per file
|
|
48
|
+
- Props interfaces at top of file
|
|
49
|
+
- Hooks (useState, useEffect, useContext)
|
|
50
|
+
- Custom hooks for reusable logic
|
|
51
|
+
|
|
52
|
+
### TypeScript
|
|
53
|
+
- Define interfaces for component props
|
|
54
|
+
- Use `React.FC<Props>` for component type
|
|
55
|
+
- Strict null checks enabled
|
|
56
|
+
- Export types alongside components
|
|
57
|
+
|
|
58
|
+
### State Management
|
|
59
|
+
- Local state with `useState` for component-only state
|
|
60
|
+
- Context API for shared state
|
|
61
|
+
- Consider Redux/Zustand for complex state
|
|
62
|
+
- Avoid prop drilling (use Context instead)
|
|
63
|
+
|
|
64
|
+
### Performance
|
|
65
|
+
- Memoize expensive components with `React.memo`
|
|
66
|
+
- Use `useCallback` for stable function references
|
|
67
|
+
- Use `useMemo` for expensive computations
|
|
68
|
+
- Lazy load routes with `React.lazy`
|
|
69
|
+
|
|
70
|
+
### Styling
|
|
71
|
+
- TailwindCSS for utility-first styling
|
|
72
|
+
- CSS modules for scoped styles
|
|
73
|
+
- Avoid inline styles except for dynamic values
|
|
74
|
+
- Use design tokens for consistency
|
|
75
|
+
|
|
76
|
+
## Usage
|
|
77
|
+
|
|
78
|
+
1. Read the relevant sub-directory README for your task
|
|
79
|
+
2. Check code examples for reference implementations
|
|
80
|
+
3. Follow patterns in new components
|
|
81
|
+
4. Update patterns if you discover improvements
|
|
82
|
+
|
|
83
|
+
## Contributing
|
|
84
|
+
|
|
85
|
+
Found a better pattern?
|
|
86
|
+
|
|
87
|
+
1. Document it with examples
|
|
88
|
+
2. Add to appropriate subdirectory
|
|
89
|
+
3. Update this README
|
|
90
|
+
4. Commit with message: `docs: add [pattern name] pattern`
|
|
91
|
+
5. Update triggers in `patterns/index.md` if widely applicable
|
|
92
|
+
|
|
93
|
+
## Links
|
|
94
|
+
|
|
95
|
+
- [React Component Patterns](react/README.md)
|
|
96
|
+
- [Styling Strategies](styling/README.md)
|
|
97
|
+
- [Component Libraries](component-libs/README.md)
|
|
98
|
+
- [Accessibility Patterns](accessibility/README.md)
|
|
99
|
+
|
|
100
|
+
## Version
|
|
101
|
+
|
|
102
|
+
**Last Updated:** (Set on template injection)
|
|
103
|
+
**Maintained By:** Development Team
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# Pattern Auto-Apply Trigger Map
|
|
2
|
+
|
|
3
|
+
This file defines triggers that automatically load relevant patterns during AI sessions.
|
|
4
|
+
|
|
5
|
+
## How It Works
|
|
6
|
+
|
|
7
|
+
1. AI agent starts session
|
|
8
|
+
2. Reads this file to register triggers
|
|
9
|
+
3. Monitors file changes, imports, and commands
|
|
10
|
+
4. When trigger matches, loads relevant patterns from `patterns/` subdirectories
|
|
11
|
+
5. Applies patterns to current work
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## Trigger Types
|
|
16
|
+
|
|
17
|
+
- **`fileExt`** - File extension patterns (e.g., `*.tsx`, `*.py`)
|
|
18
|
+
- **`import`** - Import statements (e.g., `from react import`)
|
|
19
|
+
- **`command`** - CLI commands (e.g., `pnpm dev`, `npm test`)
|
|
20
|
+
- **`path`** - Directory path patterns (e.g., `src/components/`)
|
|
21
|
+
- **`keyword`** - Code keywords (e.g., `interface`, `class`)
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Trigger Format
|
|
26
|
+
|
|
27
|
+
```yaml
|
|
28
|
+
triggers:
|
|
29
|
+
- name: "Pattern Name"
|
|
30
|
+
type: "fileExt | import | command | path | keyword"
|
|
31
|
+
value: "*.tsx"
|
|
32
|
+
patterns:
|
|
33
|
+
- "frontend/react"
|
|
34
|
+
- "universal/typescript"
|
|
35
|
+
description: "Loads when working with React components"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Trigger Registry
|
|
41
|
+
|
|
42
|
+
### Frontend Triggers
|
|
43
|
+
|
|
44
|
+
```yaml
|
|
45
|
+
triggers:
|
|
46
|
+
- name: "React Components"
|
|
47
|
+
type: "fileExt"
|
|
48
|
+
value: "*.tsx"
|
|
49
|
+
patterns:
|
|
50
|
+
- "frontend/react"
|
|
51
|
+
- "universal/typescript"
|
|
52
|
+
description: "Auto-loads React component patterns"
|
|
53
|
+
|
|
54
|
+
- name: "React Hooks"
|
|
55
|
+
type: "import"
|
|
56
|
+
value: "import.*useEffect|useState|useContext"
|
|
57
|
+
patterns:
|
|
58
|
+
- "frontend/react/hooks"
|
|
59
|
+
description: "Loads when using React hooks"
|
|
60
|
+
|
|
61
|
+
- name: "Styling"
|
|
62
|
+
type: "fileExt"
|
|
63
|
+
value: "*.css,*.scss,*.tailwind"
|
|
64
|
+
patterns:
|
|
65
|
+
- "frontend/styling"
|
|
66
|
+
description: "CSS/styling patterns"
|
|
67
|
+
|
|
68
|
+
- name: "Component Library"
|
|
69
|
+
type: "import"
|
|
70
|
+
value: "from.*@shadcn|from.*@mui"
|
|
71
|
+
patterns:
|
|
72
|
+
- "frontend/component-libs"
|
|
73
|
+
description: "Component library patterns"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Backend Triggers
|
|
77
|
+
|
|
78
|
+
```yaml
|
|
79
|
+
triggers:
|
|
80
|
+
- name: "Express Routes"
|
|
81
|
+
type: "fileExt"
|
|
82
|
+
value: "*.routes.ts,routes/*.ts"
|
|
83
|
+
patterns:
|
|
84
|
+
- "backend/express"
|
|
85
|
+
- "universal/rest-api"
|
|
86
|
+
description: "Express route patterns"
|
|
87
|
+
|
|
88
|
+
- name: "Database Queries"
|
|
89
|
+
type: "import"
|
|
90
|
+
value: "from.*prisma|from.*knex|from.*typeorm"
|
|
91
|
+
patterns:
|
|
92
|
+
- "backend/database"
|
|
93
|
+
description: "Database query patterns"
|
|
94
|
+
|
|
95
|
+
- name: "API Endpoints"
|
|
96
|
+
type: "keyword"
|
|
97
|
+
value: "app.get|app.post|router.put"
|
|
98
|
+
patterns:
|
|
99
|
+
- "backend/express"
|
|
100
|
+
- "universal/rest-api"
|
|
101
|
+
description: "REST API patterns"
|
|
102
|
+
|
|
103
|
+
- name: "Error Handling"
|
|
104
|
+
type: "keyword"
|
|
105
|
+
value: "try|catch|throw|Error"
|
|
106
|
+
patterns:
|
|
107
|
+
- "universal/error-handling"
|
|
108
|
+
description: "Error handling patterns"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Testing Triggers
|
|
112
|
+
|
|
113
|
+
```yaml
|
|
114
|
+
triggers:
|
|
115
|
+
- name: "Unit Tests"
|
|
116
|
+
type: "import"
|
|
117
|
+
value: "from.*jest|from.*vitest|describe|it"
|
|
118
|
+
patterns:
|
|
119
|
+
- "universal/testing/unit"
|
|
120
|
+
description: "Unit test patterns"
|
|
121
|
+
|
|
122
|
+
- name: "Integration Tests"
|
|
123
|
+
type: "path"
|
|
124
|
+
value: "**/*.integration.test.ts"
|
|
125
|
+
patterns:
|
|
126
|
+
- "universal/testing/integration"
|
|
127
|
+
description: "Integration test patterns"
|
|
128
|
+
|
|
129
|
+
- name: "E2E Tests"
|
|
130
|
+
type: "path"
|
|
131
|
+
value: "**/*.e2e.test.ts,cypress/**/*,playwright/**/*"
|
|
132
|
+
patterns:
|
|
133
|
+
- "universal/testing/e2e"
|
|
134
|
+
description: "End-to-end test patterns"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### Universal Triggers
|
|
138
|
+
|
|
139
|
+
```yaml
|
|
140
|
+
triggers:
|
|
141
|
+
- name: "TypeScript"
|
|
142
|
+
type: "fileExt"
|
|
143
|
+
value: "*.ts,*.tsx"
|
|
144
|
+
patterns:
|
|
145
|
+
- "universal/typescript"
|
|
146
|
+
description: "TypeScript patterns"
|
|
147
|
+
|
|
148
|
+
- name: "Git Workflow"
|
|
149
|
+
type: "command"
|
|
150
|
+
value: "git commit|git push|git pull"
|
|
151
|
+
patterns:
|
|
152
|
+
- "universal/git"
|
|
153
|
+
description: "Git workflow patterns"
|
|
154
|
+
|
|
155
|
+
- name: "Build Tools"
|
|
156
|
+
type: "command"
|
|
157
|
+
value: "npm|pnpm|yarn|webpack|vite"
|
|
158
|
+
patterns:
|
|
159
|
+
- "universal/build-tools"
|
|
160
|
+
description: "Build and package patterns"
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Priority Order
|
|
166
|
+
|
|
167
|
+
Triggers are applied in priority order:
|
|
168
|
+
1. **Highest:** `fileExt` (most specific)
|
|
169
|
+
2. **High:** `path` (directory context)
|
|
170
|
+
3. **Medium:** `import` (code context)
|
|
171
|
+
4. **Low:** `keyword` (broad matches)
|
|
172
|
+
5. **Lowest:** `command` (least specific)
|
|
173
|
+
|
|
174
|
+
If multiple triggers match, load all associated patterns.
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Adding New Triggers
|
|
179
|
+
|
|
180
|
+
1. Identify the pattern category
|
|
181
|
+
2. Determine trigger type
|
|
182
|
+
3. Define pattern value
|
|
183
|
+
4. Link to pattern files in `patterns/` subdirectories
|
|
184
|
+
5. Add entry to appropriate section
|
|
185
|
+
6. Commit with message: `docs: add trigger for [pattern]`
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## Pattern Directory Structure
|
|
190
|
+
|
|
191
|
+
Patterns are organized in subdirectories matching triggers:
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
patterns/
|
|
195
|
+
├── frontend/
|
|
196
|
+
│ ├── react/
|
|
197
|
+
│ ├── styling/
|
|
198
|
+
│ └── component-libs/
|
|
199
|
+
├── backend/
|
|
200
|
+
│ ├── express/
|
|
201
|
+
│ └── database/
|
|
202
|
+
└── universal/
|
|
203
|
+
├── typescript/
|
|
204
|
+
├── testing/
|
|
205
|
+
├── error-handling/
|
|
206
|
+
├── git/
|
|
207
|
+
└── build-tools/
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Each directory contains:
|
|
211
|
+
- `README.md` - Pattern documentation
|
|
212
|
+
- `*.example.ts` - Code examples (optional)
|
|
213
|
+
- `checklist.md` - Verification checklist (optional)
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## Examples
|
|
218
|
+
|
|
219
|
+
### Example 1: React Component Trigger
|
|
220
|
+
|
|
221
|
+
**Condition:** User edits `src/components/Button.tsx`
|
|
222
|
+
**Triggers:** `*.tsx` matches
|
|
223
|
+
**Load:** `patterns/frontend/react/README.md`
|
|
224
|
+
**Apply:** React component best practices to Button component
|
|
225
|
+
|
|
226
|
+
### Example 2: API Endpoint Trigger
|
|
227
|
+
|
|
228
|
+
**Condition:** User imports `from 'express'`
|
|
229
|
+
**Triggers:** `import.*express` matches
|
|
230
|
+
**Load:** `patterns/backend/express/README.md` + `patterns/universal/rest-api/README.md`
|
|
231
|
+
**Apply:** Express + REST API patterns to new route
|
|
232
|
+
|
|
233
|
+
### Example 3: Test File Trigger
|
|
234
|
+
|
|
235
|
+
**Condition:** User creates `src/__tests__/utils.test.ts`
|
|
236
|
+
**Triggers:** `*.test.ts` matches + `import jest` matches
|
|
237
|
+
**Load:** `patterns/universal/testing/unit/README.md`
|
|
238
|
+
**Apply:** Unit test patterns and Jest best practices
|
|
239
|
+
|
|
240
|
+
---
|
|
241
|
+
|
|
242
|
+
## Disabling Triggers
|
|
243
|
+
|
|
244
|
+
To temporarily disable pattern auto-apply:
|
|
245
|
+
|
|
246
|
+
1. Add to `state.json`: `"auto_patterns_enabled": false`
|
|
247
|
+
2. Manually import patterns as needed
|
|
248
|
+
3. Re-enable: `"auto_patterns_enabled": true`
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
## Feedback
|
|
253
|
+
|
|
254
|
+
- If pattern is irrelevant, note in `state.json` to refine triggers
|
|
255
|
+
- Patterns that save time: commit and document
|
|
256
|
+
- Patterns that cause friction: update or disable
|