planflow-ai 1.0.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/.claude/commands/create-contract.md +468 -0
- package/.claude/commands/create-plan.md +512 -0
- package/.claude/commands/discovery-plan.md +561 -0
- package/.claude/commands/execute-plan.md +682 -0
- package/.claude/commands/review-code.md +459 -0
- package/.claude/commands/review-pr.md +651 -0
- package/.claude/commands/setup.md +1609 -0
- package/.claude/commands/write-tests.md +543 -0
- package/.claude/rules/core/allowed-patterns.md +175 -0
- package/.claude/rules/core/complexity-scoring.md +225 -0
- package/.claude/rules/core/forbidden-patterns.md +253 -0
- package/.claude/rules/core/project-ledger.md +150 -0
- package/.claude/rules/languages/python-patterns.md +6 -0
- package/.claude/rules/languages/typescript-patterns.md +7 -0
- package/.claude/rules/patterns/contract-patterns.md +332 -0
- package/.claude/rules/patterns/discovery-patterns.md +342 -0
- package/.claude/rules/patterns/discovery-templates.md +319 -0
- package/.claude/rules/patterns/jest-patterns.md +482 -0
- package/.claude/rules/patterns/plans-patterns.md +225 -0
- package/.claude/rules/patterns/plans-templates.md +227 -0
- package/.claude/rules/patterns/pytest-patterns.md +457 -0
- package/.claude/rules/patterns/review-code-templates.md +305 -0
- package/.claude/rules/patterns/review-pr-patterns.md +360 -0
- package/.claude/rules/tools/auth-pr-tool.md +30 -0
- package/.claude/rules/tools/interactive-questions-tool.md +235 -0
- package/.claude/rules/tools/jest-testing-tool.md +73 -0
- package/.claude/rules/tools/plan-mode-tool.md +164 -0
- package/.claude/rules/tools/pytest-testing-tool.md +121 -0
- package/.claude/rules/tools/reference-expansion-tool.md +326 -0
- package/LICENSE +21 -0
- package/README.md +167 -0
- package/dist/cli/commands/init.d.ts +6 -0
- package/dist/cli/commands/init.d.ts.map +1 -0
- package/dist/cli/commands/init.js +141 -0
- package/dist/cli/commands/init.js.map +1 -0
- package/dist/cli/handlers/claude.d.ts +9 -0
- package/dist/cli/handlers/claude.d.ts.map +1 -0
- package/dist/cli/handlers/claude.js +119 -0
- package/dist/cli/handlers/claude.js.map +1 -0
- package/dist/cli/handlers/codex.d.ts +9 -0
- package/dist/cli/handlers/codex.d.ts.map +1 -0
- package/dist/cli/handlers/codex.js +100 -0
- package/dist/cli/handlers/codex.js.map +1 -0
- package/dist/cli/handlers/cursor.d.ts +9 -0
- package/dist/cli/handlers/cursor.d.ts.map +1 -0
- package/dist/cli/handlers/cursor.js +60 -0
- package/dist/cli/handlers/cursor.js.map +1 -0
- package/dist/cli/handlers/openclaw.d.ts +8 -0
- package/dist/cli/handlers/openclaw.d.ts.map +1 -0
- package/dist/cli/handlers/openclaw.js +34 -0
- package/dist/cli/handlers/openclaw.js.map +1 -0
- package/dist/cli/handlers/shared.d.ts +9 -0
- package/dist/cli/handlers/shared.d.ts.map +1 -0
- package/dist/cli/handlers/shared.js +126 -0
- package/dist/cli/handlers/shared.js.map +1 -0
- package/dist/cli/index.d.ts +8 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +43 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/types.d.ts +26 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +5 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/utils/files.d.ts +37 -0
- package/dist/cli/utils/files.d.ts.map +1 -0
- package/dist/cli/utils/files.js +115 -0
- package/dist/cli/utils/files.js.map +1 -0
- package/dist/cli/utils/logger.d.ts +11 -0
- package/dist/cli/utils/logger.d.ts.map +1 -0
- package/dist/cli/utils/logger.js +34 -0
- package/dist/cli/utils/logger.js.map +1 -0
- package/dist/cli/utils/prompts.d.ts +10 -0
- package/dist/cli/utils/prompts.d.ts.map +1 -0
- package/dist/cli/utils/prompts.js +65 -0
- package/dist/cli/utils/prompts.js.map +1 -0
- package/dist/test/setup.d.ts +5 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/dist/test/setup.js +7 -0
- package/dist/test/setup.js.map +1 -0
- package/package.json +63 -0
- package/rules/core/_index.mdc +99 -0
- package/rules/core/allowed-patterns.mdc +185 -0
- package/rules/core/complexity-scoring.mdc +235 -0
- package/rules/core/forbidden-patterns.mdc +263 -0
- package/rules/core/project-ledger.mdc +155 -0
- package/rules/languages/_index.mdc +80 -0
- package/rules/languages/python-patterns.mdc +188 -0
- package/rules/languages/typescript-patterns.mdc +128 -0
- package/rules/patterns/_index.mdc +185 -0
- package/rules/patterns/contract-patterns.mdc +344 -0
- package/rules/patterns/discovery-patterns.mdc +354 -0
- package/rules/patterns/discovery-templates.mdc +329 -0
- package/rules/patterns/jest-patterns.mdc +492 -0
- package/rules/patterns/plans-patterns.mdc +237 -0
- package/rules/patterns/plans-templates.mdc +237 -0
- package/rules/patterns/pytest-patterns.mdc +467 -0
- package/rules/patterns/review-code-templates.mdc +315 -0
- package/rules/patterns/review-pr-patterns.mdc +370 -0
- package/rules/skills/_index.mdc +174 -0
- package/rules/skills/create-contract-skill.mdc +239 -0
- package/rules/skills/create-plan-skill.mdc +271 -0
- package/rules/skills/discovery-skill.mdc +295 -0
- package/rules/skills/execute-plan-skill.mdc +388 -0
- package/rules/skills/review-code-skill.mdc +308 -0
- package/rules/skills/review-pr-skill.mdc +496 -0
- package/rules/skills/setup-skill.mdc +923 -0
- package/rules/skills/write-tests-skill.mdc +294 -0
- package/rules/templates/index-template.mdc +126 -0
- package/rules/tools/_index.mdc +114 -0
- package/rules/tools/auth-pr-tool.mdc +362 -0
- package/rules/tools/interactive-questions-tool.mdc +337 -0
- package/rules/tools/jest-testing-tool.mdc +96 -0
- package/rules/tools/plan-mode-tool.mdc +229 -0
- package/rules/tools/pytest-testing-tool.mdc +144 -0
- package/rules/tools/reference-expansion-tool.mdc +338 -0
- package/skills/plan-flow/SKILL.md +116 -0
- package/skills/plan-flow/create-contract/SKILL.md +139 -0
- package/skills/plan-flow/create-plan/SKILL.md +93 -0
- package/skills/plan-flow/discovery/SKILL.md +85 -0
- package/skills/plan-flow/execute-plan/SKILL.md +89 -0
- package/skills/plan-flow/ledger/SKILL.md +70 -0
- package/skills/plan-flow/review-code/SKILL.md +100 -0
- package/skills/plan-flow/review-pr/SKILL.md +122 -0
- package/skills/plan-flow/setup/SKILL.md +73 -0
- package/skills/plan-flow/write-tests/SKILL.md +115 -0
- package/templates/shared/AGENTS.md.template +65 -0
- package/templates/shared/CLAUDE.md.template +67 -0
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Core pattern for calculating task complexity scores for implementation planning and code review"
|
|
3
|
+
alwaysApply: false
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Complexity Scoring
|
|
7
|
+
|
|
8
|
+
This document defines the scoring system for plan phases. These scores determine execution strategy and help estimate implementation effort.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Complexity Scale
|
|
13
|
+
|
|
14
|
+
| Score | Level | Description | Examples |
|
|
15
|
+
| ----- | --------- | ------------------------------------------ | ---------------------------------------------------------------------- |
|
|
16
|
+
| 0-2 | Trivial | Simple, mechanical changes | Adding a type alias, renaming a variable, adding an import |
|
|
17
|
+
| 3-4 | Low | Straightforward implementation | Creating a simple Zod schema, adding a basic utility function |
|
|
18
|
+
| 5-6 | Medium | Moderate complexity, some decisions | Creating a new component with logic hook, adding a store action |
|
|
19
|
+
| 7-8 | High | Complex implementation, multiple concerns | API route with command pattern, complex state management |
|
|
20
|
+
| 9-10 | Very High | Highly complex, requires careful attention | Streaming implementation, complex algorithms, multi-system integration |
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## Scoring Criteria
|
|
25
|
+
|
|
26
|
+
Use these modifiers to calculate the complexity score for each phase:
|
|
27
|
+
|
|
28
|
+
### Positive Modifiers (Add Points)
|
|
29
|
+
|
|
30
|
+
| Modifier | Points |
|
|
31
|
+
| ------------------------------------ | ------ |
|
|
32
|
+
| Each new file to create | +1 |
|
|
33
|
+
| External API integration | +1 |
|
|
34
|
+
| Database operations | +1 |
|
|
35
|
+
| Complex state management | +1 |
|
|
36
|
+
| View/logic separation pattern | +1 |
|
|
37
|
+
| Streaming or real-time features | +2 |
|
|
38
|
+
| Complex business logic or algorithms | +2 |
|
|
39
|
+
| Multi-system integration | +2 |
|
|
40
|
+
| Authentication/authorization logic | +1 |
|
|
41
|
+
| Error handling with recovery | +1 |
|
|
42
|
+
|
|
43
|
+
### Negative Modifiers (Subtract Points)
|
|
44
|
+
|
|
45
|
+
| Modifier | Points |
|
|
46
|
+
| ------------------------------------ | ------ |
|
|
47
|
+
| Purely mechanical/repetitive tasks | -1 |
|
|
48
|
+
| Small modifications to existing code | -1 |
|
|
49
|
+
| Following existing patterns exactly | -1 |
|
|
50
|
+
| Copy/paste with minor changes | -1 |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Execution Strategy Based on Scores
|
|
55
|
+
|
|
56
|
+
| Total Adjacent Score | Execution Strategy |
|
|
57
|
+
| -------------------- | ------------------------------------------------------------------ |
|
|
58
|
+
| ≤ 6 | **Aggregate**: Execute multiple phases together in one pass |
|
|
59
|
+
| 7-10 | **Cautious**: Execute 1-2 phases, then verify |
|
|
60
|
+
| > 10 | **Sequential**: Execute one phase at a time with full verification |
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Aggregation Rules
|
|
65
|
+
|
|
66
|
+
1. **Can aggregate** phases when their combined complexity ≤ 6
|
|
67
|
+
2. **Never aggregate** across a phase with complexity ≥ 8
|
|
68
|
+
3. **Always execute separately**: Tests phase (regardless of score)
|
|
69
|
+
4. **Prefer aggregation** for trivial consecutive phases (0-2 each)
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
## Examples
|
|
74
|
+
|
|
75
|
+
### Example 1: Aggregatable Phases (Combined ≤ 6)
|
|
76
|
+
|
|
77
|
+
```markdown
|
|
78
|
+
### Phase 1: Types and Schemas
|
|
79
|
+
|
|
80
|
+
**Complexity**: 3/10
|
|
81
|
+
|
|
82
|
+
- [ ] Create WorkflowStep type
|
|
83
|
+
- [ ] Create Zod schema
|
|
84
|
+
|
|
85
|
+
### Phase 2: Utility Functions
|
|
86
|
+
|
|
87
|
+
**Complexity**: 2/10
|
|
88
|
+
|
|
89
|
+
- [ ] Create transformation helper
|
|
90
|
+
|
|
91
|
+
<!-- Combined complexity: 5 → Execute together -->
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Example 2: Must Execute Separately (Phase ≥ 8)
|
|
95
|
+
|
|
96
|
+
```markdown
|
|
97
|
+
### Phase 3: API Route with Streaming
|
|
98
|
+
|
|
99
|
+
**Complexity**: 9/10
|
|
100
|
+
|
|
101
|
+
- [ ] Create streaming endpoint
|
|
102
|
+
- [ ] Handle SSE events
|
|
103
|
+
- [ ] Implement error recovery
|
|
104
|
+
|
|
105
|
+
### Phase 4: UI Components
|
|
106
|
+
|
|
107
|
+
**Complexity**: 6/10
|
|
108
|
+
|
|
109
|
+
- [ ] Create component with view/logic separation
|
|
110
|
+
- [ ] Integrate with store
|
|
111
|
+
|
|
112
|
+
<!-- Phase 3 is ≥ 8, execute separately. Phase 4 starts fresh. -->
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Example 3: Sequential Execution (Total > 10)
|
|
116
|
+
|
|
117
|
+
```markdown
|
|
118
|
+
### Phase 1: Database Schema
|
|
119
|
+
|
|
120
|
+
**Complexity**: 5/10
|
|
121
|
+
|
|
122
|
+
### Phase 2: Backend API
|
|
123
|
+
|
|
124
|
+
**Complexity**: 7/10
|
|
125
|
+
|
|
126
|
+
### Phase 3: Frontend Components
|
|
127
|
+
|
|
128
|
+
**Complexity**: 6/10
|
|
129
|
+
|
|
130
|
+
<!-- Adjacent totals exceed 10, execute one at a time -->
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Phase Format with Complexity
|
|
136
|
+
|
|
137
|
+
Every phase in a plan must include a complexity score:
|
|
138
|
+
|
|
139
|
+
```markdown
|
|
140
|
+
### Phase 1: [Phase Name]
|
|
141
|
+
|
|
142
|
+
**Scope**: [What this phase covers]
|
|
143
|
+
**Complexity**: X/10
|
|
144
|
+
|
|
145
|
+
- [ ] Task 1
|
|
146
|
+
- [ ] Task 2
|
|
147
|
+
|
|
148
|
+
**Build Verification**: Run `npm run build`
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Scoring Guidelines
|
|
154
|
+
|
|
155
|
+
### When in Doubt, Score Higher
|
|
156
|
+
|
|
157
|
+
If uncertain about complexity, err on the side of a higher score. It's better to execute cautiously than to rush through a complex phase.
|
|
158
|
+
|
|
159
|
+
### Re-evaluate During Execution
|
|
160
|
+
|
|
161
|
+
If a phase turns out to be more complex than estimated:
|
|
162
|
+
|
|
163
|
+
1. Stop execution
|
|
164
|
+
2. Update the complexity score in the plan
|
|
165
|
+
3. Adjust execution strategy accordingly
|
|
166
|
+
|
|
167
|
+
### Common Complexity Patterns
|
|
168
|
+
|
|
169
|
+
| Task Type | Typical Score |
|
|
170
|
+
| ------------------------------- | ------------- |
|
|
171
|
+
| Type definitions only | 2-3 |
|
|
172
|
+
| Simple utility function | 2-3 |
|
|
173
|
+
| Zod schema creation | 3-4 |
|
|
174
|
+
| Basic React component | 4-5 |
|
|
175
|
+
| Component with view/logic split | 5-6 |
|
|
176
|
+
| Zustand store actions | 4-5 |
|
|
177
|
+
| REST API route | 5-6 |
|
|
178
|
+
| API route with command pattern | 6-7 |
|
|
179
|
+
| Database operations | 5-7 |
|
|
180
|
+
| Streaming/SSE implementation | 8-9 |
|
|
181
|
+
| Complex algorithm | 7-9 |
|
|
182
|
+
| Multi-service integration | 8-10 |
|
|
183
|
+
| Unit tests | 3-5 |
|
|
184
|
+
| Integration tests | 5-6 |
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Real-World Scoring Examples
|
|
189
|
+
|
|
190
|
+
### Example A: Add a New Form Field
|
|
191
|
+
|
|
192
|
+
**Scenario**: Add an email field to the user registration form.
|
|
193
|
+
|
|
194
|
+
| Modifier | Points | Reason |
|
|
195
|
+
|----------|--------|--------|
|
|
196
|
+
| Modify existing component | -1 | Small modification |
|
|
197
|
+
| Following existing patterns | -1 | Other fields already exist |
|
|
198
|
+
| Add Zod validation | +1 | Schema update |
|
|
199
|
+
| **Total** | **2/10** | Trivial |
|
|
200
|
+
|
|
201
|
+
**Execution**: Can be aggregated with other trivial phases.
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
### Example B: Create User Dashboard API
|
|
206
|
+
|
|
207
|
+
**Scenario**: Create an API endpoint that fetches user data with analytics.
|
|
208
|
+
|
|
209
|
+
| Modifier | Points | Reason |
|
|
210
|
+
|----------|--------|--------|
|
|
211
|
+
| New file (route.ts) | +1 | Creating API route |
|
|
212
|
+
| Database operations | +1 | Fetch user data |
|
|
213
|
+
| External API integration | +1 | Analytics service |
|
|
214
|
+
| Error handling with recovery | +1 | Handle service failures |
|
|
215
|
+
| Complex business logic | +2 | Aggregate multiple data sources |
|
|
216
|
+
| **Total** | **6/10** | Medium |
|
|
217
|
+
|
|
218
|
+
**Execution**: Can be aggregated if adjacent phase is ≤ 0.
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
### Example C: Implement Real-time Chat Feature
|
|
223
|
+
|
|
224
|
+
**Scenario**: Add WebSocket-based chat with message persistence.
|
|
225
|
+
|
|
226
|
+
| Modifier | Points | Reason |
|
|
227
|
+
|----------|--------|--------|
|
|
228
|
+
| New files (3 files) | +3 | Route, hook, component |
|
|
229
|
+
| Streaming/real-time | +2 | WebSocket handling |
|
|
230
|
+
| Database operations | +1 | Message persistence |
|
|
231
|
+
| Complex state management | +1 | Chat state with optimistic updates |
|
|
232
|
+
| Multi-system integration | +2 | WebSocket + DB + Auth |
|
|
233
|
+
| **Total** | **9/10** | Very High |
|
|
234
|
+
|
|
235
|
+
**Execution**: Must execute separately. Never aggregate with other phases.
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Anti-patterns and practices to avoid in all code"
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Forbidden Patterns
|
|
7
|
+
|
|
8
|
+
This file defines **anti-patterns and practices to avoid** in your project. Add patterns that your team has identified as problematic and wants the AI to avoid during code generation.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## How to Use This File
|
|
13
|
+
|
|
14
|
+
1. **Add anti-patterns** that cause problems in your codebase
|
|
15
|
+
2. **Show examples** of the problematic code
|
|
16
|
+
3. **Explain why** each pattern is harmful
|
|
17
|
+
4. **Reference the fix** in `.cursor/rules/core/allowed-patterns.mdc` when applicable
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Example Pattern Structure
|
|
22
|
+
|
|
23
|
+
### DON'T: Pattern Name
|
|
24
|
+
|
|
25
|
+
**Problem**: Brief description of why this is problematic.
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
// BAD - Example of the anti-pattern
|
|
29
|
+
const badExample = doThingWrong()
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Why This is Wrong**:
|
|
33
|
+
|
|
34
|
+
- Reason 1
|
|
35
|
+
- Reason 2
|
|
36
|
+
|
|
37
|
+
**Fix**: Description of the correct approach or link to `.cursor/rules/core/allowed-patterns.mdc`.
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## Example Anti-Patterns
|
|
42
|
+
|
|
43
|
+
### 1. DON'T Use Magic Numbers
|
|
44
|
+
|
|
45
|
+
**Problem**: Hardcoded numbers without context make code hard to understand and maintain.
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// BAD - What does 86400000 mean?
|
|
49
|
+
setTimeout(cleanup, 86400000)
|
|
50
|
+
|
|
51
|
+
// BAD - Why 5? What if it needs to change?
|
|
52
|
+
if (retryCount > 5) {
|
|
53
|
+
throw new Error('Too many retries')
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Why This is Wrong**:
|
|
58
|
+
|
|
59
|
+
- No context for what the number represents
|
|
60
|
+
- Hard to find and update when requirements change
|
|
61
|
+
- Easy to introduce bugs with typos
|
|
62
|
+
|
|
63
|
+
**Fix**: Use named constants with descriptive names.
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
// GOOD
|
|
67
|
+
const ONE_DAY_MS = 24 * 60 * 60 * 1000
|
|
68
|
+
setTimeout(cleanup, ONE_DAY_MS)
|
|
69
|
+
|
|
70
|
+
const MAX_RETRY_ATTEMPTS = 5
|
|
71
|
+
if (retryCount > MAX_RETRY_ATTEMPTS) {
|
|
72
|
+
throw new Error('Too many retries')
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
### 2. DON'T Swallow Errors Silently
|
|
79
|
+
|
|
80
|
+
**Problem**: Catching errors without handling them hides bugs and makes debugging impossible.
|
|
81
|
+
|
|
82
|
+
```typescript
|
|
83
|
+
// BAD - Error is completely ignored
|
|
84
|
+
try {
|
|
85
|
+
await saveData(data)
|
|
86
|
+
} catch (error) {
|
|
87
|
+
// Silent failure - no one knows something went wrong
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// BAD - Generic catch that hides the real issue
|
|
91
|
+
try {
|
|
92
|
+
await complexOperation()
|
|
93
|
+
} catch {
|
|
94
|
+
return null
|
|
95
|
+
}
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
**Why This is Wrong**:
|
|
99
|
+
|
|
100
|
+
- Bugs go unnoticed until they cause bigger problems
|
|
101
|
+
- Impossible to debug issues in production
|
|
102
|
+
- Users don't know their action failed
|
|
103
|
+
|
|
104
|
+
**Fix**: Always log errors and provide appropriate user feedback.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
// GOOD
|
|
108
|
+
try {
|
|
109
|
+
await saveData(data)
|
|
110
|
+
} catch (error) {
|
|
111
|
+
logger.error('Failed to save data', { error, data })
|
|
112
|
+
throw new UserFacingError('Unable to save. Please try again.')
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
### 3. DON'T Use Nested Ternaries
|
|
119
|
+
|
|
120
|
+
**Problem**: Deeply nested ternary operators are hard to read and maintain.
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// BAD - Unreadable nested ternaries
|
|
124
|
+
const status = isLoading ? 'loading' : hasError ? 'error' : isComplete ? 'complete' : 'idle'
|
|
125
|
+
|
|
126
|
+
// BAD - Even worse with more nesting
|
|
127
|
+
const message = !user ? 'Not logged in' : !user.verified ? 'Please verify' : user.isPremium ? 'Welcome back, premium user!' : 'Welcome back!'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
**Why This is Wrong**:
|
|
131
|
+
|
|
132
|
+
- Extremely hard to read and understand
|
|
133
|
+
- Easy to introduce bugs when modifying
|
|
134
|
+
- Difficult to add new conditions
|
|
135
|
+
|
|
136
|
+
**Fix**: Use if/else statements, switch statements, or lookup objects.
|
|
137
|
+
|
|
138
|
+
```typescript
|
|
139
|
+
// GOOD - Clear and maintainable
|
|
140
|
+
function getStatus(isLoading: boolean, hasError: boolean, isComplete: boolean) {
|
|
141
|
+
if (isLoading) return 'loading'
|
|
142
|
+
if (hasError) return 'error'
|
|
143
|
+
if (isComplete) return 'complete'
|
|
144
|
+
return 'idle'
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
### 4. DON'T Mutate Function Parameters
|
|
151
|
+
|
|
152
|
+
**Problem**: Mutating parameters causes unexpected side effects and makes code unpredictable.
|
|
153
|
+
|
|
154
|
+
```typescript
|
|
155
|
+
// BAD - Mutating the input array
|
|
156
|
+
function addItem(items: string[], newItem: string) {
|
|
157
|
+
items.push(newItem) // Modifies the original array!
|
|
158
|
+
return items
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// BAD - Mutating object properties
|
|
162
|
+
function updateUser(user: User) {
|
|
163
|
+
user.lastUpdated = new Date() // Modifies the original object!
|
|
164
|
+
return user
|
|
165
|
+
}
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
**Why This is Wrong**:
|
|
169
|
+
|
|
170
|
+
- Caller doesn't expect their data to change
|
|
171
|
+
- Causes bugs that are hard to track down
|
|
172
|
+
- Breaks immutability expectations in React/Redux
|
|
173
|
+
|
|
174
|
+
**Fix**: Return new objects/arrays instead of mutating.
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// GOOD - Returns new array
|
|
178
|
+
function addItem(items: string[], newItem: string) {
|
|
179
|
+
return [...items, newItem]
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// GOOD - Returns new object
|
|
183
|
+
function updateUser(user: User) {
|
|
184
|
+
return { ...user, lastUpdated: new Date() }
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
---
|
|
189
|
+
|
|
190
|
+
### 5. DON'T Mix Async Patterns
|
|
191
|
+
|
|
192
|
+
**Problem**: Mixing callbacks, promises, and async/await makes code confusing and error-prone.
|
|
193
|
+
|
|
194
|
+
```typescript
|
|
195
|
+
// BAD - Mixing callbacks and promises
|
|
196
|
+
function fetchData(callback) {
|
|
197
|
+
fetch('/api/data')
|
|
198
|
+
.then(res => res.json())
|
|
199
|
+
.then(data => callback(null, data))
|
|
200
|
+
.catch(err => callback(err))
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// BAD - Mixing .then() with async/await
|
|
204
|
+
async function processData() {
|
|
205
|
+
const result = await fetchData()
|
|
206
|
+
return result.then(data => transform(data)) // Mixing patterns!
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Why This is Wrong**:
|
|
211
|
+
|
|
212
|
+
- Confusing control flow
|
|
213
|
+
- Error handling becomes inconsistent
|
|
214
|
+
- Harder to debug and maintain
|
|
215
|
+
|
|
216
|
+
**Fix**: Use async/await consistently throughout.
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
// GOOD - Consistent async/await
|
|
220
|
+
async function fetchData() {
|
|
221
|
+
const response = await fetch('/api/data')
|
|
222
|
+
return response.json()
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
async function processData() {
|
|
226
|
+
const data = await fetchData()
|
|
227
|
+
return transform(data)
|
|
228
|
+
}
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Adding Your Anti-Patterns
|
|
234
|
+
|
|
235
|
+
When adding new anti-patterns to this file:
|
|
236
|
+
|
|
237
|
+
1. **Start with "DON'T"** followed by the pattern name
|
|
238
|
+
2. **Describe the problem** briefly
|
|
239
|
+
3. **Provide BAD examples** showing the anti-pattern
|
|
240
|
+
4. **Explain why it's wrong** with a bullet list
|
|
241
|
+
5. **Show the fix** or reference `.cursor/rules/core/allowed-patterns.mdc`
|
|
242
|
+
|
|
243
|
+
---
|
|
244
|
+
|
|
245
|
+
## Template for New Anti-Patterns
|
|
246
|
+
|
|
247
|
+
```markdown
|
|
248
|
+
### DON'T: Pattern Name
|
|
249
|
+
|
|
250
|
+
**Problem**: Brief description of why this is problematic.
|
|
251
|
+
|
|
252
|
+
\`\`\`typescript
|
|
253
|
+
// BAD - Example of the anti-pattern
|
|
254
|
+
const badExample = problematicCode()
|
|
255
|
+
\`\`\`
|
|
256
|
+
|
|
257
|
+
**Why This is Wrong**:
|
|
258
|
+
|
|
259
|
+
- Reason 1
|
|
260
|
+
- Reason 2
|
|
261
|
+
|
|
262
|
+
**Fix**: Description or link to `.cursor/rules/core/allowed-patterns.mdc`.
|
|
263
|
+
```
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: "Persistent project learning journal - always active to maintain institutional memory across sessions"
|
|
3
|
+
alwaysApply: true
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Project Ledger
|
|
7
|
+
|
|
8
|
+
## Purpose
|
|
9
|
+
|
|
10
|
+
A persistent, project-specific learning journal maintained across sessions. The ledger captures mistakes, corrections, discovered patterns, and hard-won knowledge about a specific codebase - building institutional memory that compounds over time.
|
|
11
|
+
|
|
12
|
+
**Location**: `flow/ledger.md`
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Behavior
|
|
17
|
+
|
|
18
|
+
### On Session Start
|
|
19
|
+
|
|
20
|
+
1. Check if `flow/ledger.md` exists
|
|
21
|
+
2. If it exists, read it and internalize the learnings silently
|
|
22
|
+
3. If it doesn't exist and the `flow/` directory exists, create it using the template below
|
|
23
|
+
4. Apply all recorded learnings naturally - never announce "I read the ledger" or reference it unless asked
|
|
24
|
+
|
|
25
|
+
### During Work
|
|
26
|
+
|
|
27
|
+
Record entries as soon as you learn something worth remembering. Don't batch updates for the end of a session - write them while the context is fresh.
|
|
28
|
+
|
|
29
|
+
**Update the ledger when you:**
|
|
30
|
+
|
|
31
|
+
- Get corrected by the user on something project-specific
|
|
32
|
+
- Discover an undocumented project quirk or constraint
|
|
33
|
+
- Find that an approach doesn't work in this codebase (and why)
|
|
34
|
+
- Learn a user preference for how they like things done
|
|
35
|
+
- Successfully navigate a tricky problem unique to this project
|
|
36
|
+
- Notice a gap between documented patterns and actual codebase behavior
|
|
37
|
+
- Encounter environment-specific gotchas (build issues, tool configs, etc.)
|
|
38
|
+
- Learn domain-specific terminology or business rules
|
|
39
|
+
|
|
40
|
+
### What NOT to Record
|
|
41
|
+
|
|
42
|
+
- Generic programming knowledge (that's what rules files are for)
|
|
43
|
+
- Patterns already documented in rules files
|
|
44
|
+
- Temporary issues that won't recur
|
|
45
|
+
- Information that belongs in a discovery document or plan
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## Entry Format
|
|
50
|
+
|
|
51
|
+
Each entry should be concise and actionable. Write entries as lessons, not as narratives.
|
|
52
|
+
|
|
53
|
+
**Good entries:**
|
|
54
|
+
- "The `buildWidgets` script requires Node 18+ - fails silently on Node 16"
|
|
55
|
+
- "User prefers explicit error types over generic Error class"
|
|
56
|
+
- "API responses from /legacy/* endpoints use snake_case despite the rest being camelCase"
|
|
57
|
+
- "Tests for streaming endpoints need a 3s timeout override - default 5s causes CI flakiness"
|
|
58
|
+
|
|
59
|
+
**Bad entries:**
|
|
60
|
+
- "Had a good session today" (not actionable)
|
|
61
|
+
- "JavaScript uses === for strict equality" (generic knowledge)
|
|
62
|
+
- "Fixed a bug in user service" (too vague, no lesson)
|
|
63
|
+
|
|
64
|
+
---
|
|
65
|
+
|
|
66
|
+
## Ledger Sections
|
|
67
|
+
|
|
68
|
+
### Project Quirks
|
|
69
|
+
|
|
70
|
+
Things that are unique or surprising about this specific project. Build config gotchas, undocumented dependencies between modules, services that behave differently than expected.
|
|
71
|
+
|
|
72
|
+
### What Works
|
|
73
|
+
|
|
74
|
+
Approaches and solutions that proved effective in this project. Patterns that solved recurring problems. Techniques the user approved of.
|
|
75
|
+
|
|
76
|
+
### What Didn't Work
|
|
77
|
+
|
|
78
|
+
Approaches that were tried and failed, with brief explanation of why. This prevents repeating the same mistakes across sessions.
|
|
79
|
+
|
|
80
|
+
### User Preferences
|
|
81
|
+
|
|
82
|
+
How the user likes things done. Communication style, code style preferences beyond what's in rules files, workflow preferences, conventions they care about.
|
|
83
|
+
|
|
84
|
+
### Domain Context
|
|
85
|
+
|
|
86
|
+
Business logic, domain terminology, and project-specific concepts that affect technical decisions. Things that aren't obvious from reading the code alone.
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Template
|
|
91
|
+
|
|
92
|
+
When creating `flow/ledger.md` for the first time, use this structure:
|
|
93
|
+
|
|
94
|
+
```markdown
|
|
95
|
+
# Project Ledger
|
|
96
|
+
|
|
97
|
+
> Persistent learning journal - updated automatically across sessions.
|
|
98
|
+
> Last updated: {date}
|
|
99
|
+
|
|
100
|
+
## Project Quirks
|
|
101
|
+
|
|
102
|
+
<!-- Unexpected behaviors, environment gotchas, undocumented constraints -->
|
|
103
|
+
|
|
104
|
+
## What Works
|
|
105
|
+
|
|
106
|
+
<!-- Proven approaches and solutions for this project -->
|
|
107
|
+
|
|
108
|
+
## What Didn't Work
|
|
109
|
+
|
|
110
|
+
<!-- Failed approaches with brief "why" so we don't repeat them -->
|
|
111
|
+
|
|
112
|
+
## User Preferences
|
|
113
|
+
|
|
114
|
+
<!-- How the user likes things done beyond what rules files capture -->
|
|
115
|
+
|
|
116
|
+
## Domain Context
|
|
117
|
+
|
|
118
|
+
<!-- Business logic, terminology, and concepts that affect decisions -->
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Maintenance Rules
|
|
124
|
+
|
|
125
|
+
1. **Keep it under 150 lines** of high-signal content
|
|
126
|
+
2. **Consolidate periodically**: After every 8-10 sessions, merge similar entries, remove outdated ones, and promote recurring corrections to standing guidelines
|
|
127
|
+
3. **Remove stale entries**: If a quirk gets fixed or a constraint is lifted, remove the entry
|
|
128
|
+
4. **Promote to rules**: If a preference or pattern becomes well-established, move it to the appropriate rules file and remove from the ledger
|
|
129
|
+
5. **No duplicates**: Before adding an entry, scan existing entries to avoid redundancy
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Integration with Plan-Flow Workflow
|
|
134
|
+
|
|
135
|
+
The ledger naturally captures learnings from plan-flow activities:
|
|
136
|
+
|
|
137
|
+
| Activity | What Gets Captured |
|
|
138
|
+
|----------|-------------------|
|
|
139
|
+
| `/setup` | Environment surprises, toolchain quirks |
|
|
140
|
+
| `/discovery-plan` | Domain context, business rules learned from user |
|
|
141
|
+
| `/execute-plan` | What worked/didn't during implementation |
|
|
142
|
+
| `/review-code` | Pattern conflicts discovered, user feedback on style |
|
|
143
|
+
| `/review-pr` | Recurring review issues, team conventions |
|
|
144
|
+
|
|
145
|
+
The ledger is **not** a replacement for plan-flow artifacts. Discovery documents, plans, and reviews remain in their respective folders. The ledger captures the meta-learnings that span across activities.
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## Rules
|
|
150
|
+
|
|
151
|
+
1. **Silent by default**: Never tell the user "I updated the ledger" unless they ask about it
|
|
152
|
+
2. **Immediate writes**: Record learnings as they happen, don't wait
|
|
153
|
+
3. **Lessons over logs**: Write what you learned, not what you did
|
|
154
|
+
4. **Project-specific only**: Only record things unique to this project
|
|
155
|
+
5. **Honest self-correction**: Record your own mistakes, not just user corrections
|