mindsystem-cc 3.12.0 → 3.13.1
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/agents/ms-consolidator.md +4 -4
- package/agents/ms-executor.md +19 -351
- package/agents/ms-flutter-code-quality.md +7 -6
- package/agents/ms-mock-generator.md +51 -138
- package/agents/ms-plan-checker.md +170 -175
- package/agents/ms-plan-writer.md +120 -115
- package/agents/ms-verifier.md +22 -18
- package/commands/ms/check-phase.md +3 -3
- package/commands/ms/execute-phase.md +8 -6
- package/commands/ms/plan-phase.md +4 -3
- package/commands/ms/verify-work.md +7 -7
- package/mindsystem/references/goal-backward.md +10 -25
- package/mindsystem/references/mock-patterns.md +149 -240
- package/mindsystem/references/plan-format.md +326 -247
- package/mindsystem/references/scope-estimation.md +29 -24
- package/mindsystem/references/tdd-execution.md +70 -0
- package/mindsystem/references/tdd.md +53 -194
- package/mindsystem/templates/UAT.md +16 -16
- package/mindsystem/templates/phase-prompt.md +51 -367
- package/mindsystem/templates/roadmap.md +1 -1
- package/mindsystem/templates/verification-report.md +2 -2
- package/mindsystem/workflows/adhoc.md +16 -21
- package/mindsystem/workflows/execute-phase.md +71 -49
- package/mindsystem/workflows/execute-plan.md +183 -1054
- package/mindsystem/workflows/plan-phase.md +47 -38
- package/mindsystem/workflows/verify-phase.md +16 -20
- package/mindsystem/workflows/verify-work.md +54 -67
- package/package.json +1 -1
- package/scripts/update-state.sh +59 -0
- package/scripts/validate-execution-order.sh +102 -0
- package/skills/flutter-code-quality/SKILL.md +4 -3
- package/mindsystem/templates/summary.md +0 -293
- package/mindsystem/workflows/generate-mocks.md +0 -261
|
@@ -1,309 +1,395 @@
|
|
|
1
|
-
<
|
|
2
|
-
Claude-executable plans have a specific format that enables Claude to implement without interpretation. This reference defines what makes a plan executable vs. vague.
|
|
1
|
+
<plan_format>
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
</overview>
|
|
3
|
+
Plans are executable prompts for a single intelligent reader. ~90% actionable content, ~10% structure. Pure markdown — no XML containers, no YAML frontmatter.
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
A plan is Claude-executable when Claude can read the PLAN.md and immediately start implementing without asking clarifying questions.
|
|
5
|
+
A plan is Claude-executable when Claude can read the PLAN.md and start implementing without asking clarifying questions. If Claude has to guess, interpret, or make assumptions — the plan is too vague.
|
|
9
6
|
|
|
10
|
-
|
|
11
|
-
</core_principle>
|
|
7
|
+
## Plan Anatomy
|
|
12
8
|
|
|
13
|
-
|
|
14
|
-
Every PLAN.md starts with YAML frontmatter:
|
|
9
|
+
Every plan follows this structure:
|
|
15
10
|
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
11
|
+
```markdown
|
|
12
|
+
# Plan NN: Descriptive Title
|
|
13
|
+
|
|
14
|
+
**Subsystem:** auth | **Type:** tdd
|
|
15
|
+
|
|
16
|
+
## Context
|
|
17
|
+
Why this work exists. Approach chosen and why.
|
|
18
|
+
|
|
19
|
+
## Changes
|
|
20
|
+
|
|
21
|
+
### 1. Change title
|
|
22
|
+
**Files:** `src/path/to/file.ts`
|
|
23
|
+
|
|
24
|
+
Implementation details with inline code blocks where needed.
|
|
25
|
+
|
|
26
|
+
### 2. Another change
|
|
27
|
+
**Files:** `src/path/to/other.ts`, `src/path/to/related.ts`
|
|
28
|
+
|
|
29
|
+
Details referencing existing utilities: "Use `comparePassword` in `src/lib/crypto.ts`".
|
|
30
|
+
|
|
31
|
+
## Verification
|
|
32
|
+
- `npm test -- --grep auth` passes
|
|
33
|
+
- `curl -X POST localhost:3000/api/auth/login` returns 200 with Set-Cookie
|
|
34
|
+
|
|
35
|
+
## Must-Haves
|
|
36
|
+
- [ ] Valid credentials return 200 with Set-Cookie header
|
|
37
|
+
- [ ] Invalid credentials return 401
|
|
38
|
+
- [ ] Passwords compared with bcrypt, never plaintext
|
|
25
39
|
```
|
|
26
40
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
|
30
|
-
|
|
31
|
-
| `
|
|
32
|
-
|
|
|
33
|
-
| `
|
|
34
|
-
| `
|
|
35
|
-
| `
|
|
41
|
+
### Section Reference
|
|
42
|
+
|
|
43
|
+
| Section | Purpose | Required |
|
|
44
|
+
|---------|---------|----------|
|
|
45
|
+
| `# Plan NN: Title` | H1 with plan number and descriptive title | Yes |
|
|
46
|
+
| `**Subsystem:** X \| **Type:** Y` | Inline metadata (replaces YAML frontmatter) | Yes (type defaults to `execute`) |
|
|
47
|
+
| `## Context` | Why this work exists, why this approach | Yes |
|
|
48
|
+
| `## Changes` | Numbered subsections with files and implementation details | Yes |
|
|
49
|
+
| `## Verification` | Bash commands and observable checks | Yes |
|
|
50
|
+
| `## Must-Haves` | Markdown checklist of user-observable truths | Yes |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## Context Section Guidance
|
|
55
|
+
|
|
56
|
+
The `## Context` section bridges the gap between plan-writer and executor. The executor starts with zero context beyond the plan — approach rationale compensates for this boundary.
|
|
36
57
|
|
|
37
|
-
**
|
|
38
|
-
|
|
58
|
+
**Include:**
|
|
59
|
+
- Problem being solved
|
|
60
|
+
- Approach chosen and WHY (constraints, trade-offs, rejected alternatives)
|
|
61
|
+
- Key dependencies or prior work referenced
|
|
62
|
+
- Technical context the executor needs to make correct decisions
|
|
39
63
|
|
|
40
|
-
|
|
41
|
-
|
|
64
|
+
**Exclude:**
|
|
65
|
+
- Rehash of the roadmap or project vision
|
|
66
|
+
- Generic background information
|
|
67
|
+
- Anything not specific to this plan's implementation decisions
|
|
68
|
+
|
|
69
|
+
**Example:**
|
|
42
70
|
|
|
43
71
|
```markdown
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
72
|
+
## Context
|
|
73
|
+
User authentication requires JWT tokens for the API layer. Using jose library
|
|
74
|
+
(not jsonwebtoken) because jsonwebtoken uses CommonJS which causes issues with
|
|
75
|
+
Next.js Edge runtime. Refresh token rotation prevents token theft — a single-use
|
|
76
|
+
refresh token invalidates on use and issues a new pair.
|
|
77
|
+
|
|
78
|
+
Prior plan 01 created the User model with `passwordHash` field in Prisma schema.
|
|
79
|
+
```
|
|
80
|
+
|
|
51
81
|
---
|
|
52
82
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
<files>[paths]</files>
|
|
77
|
-
<action>[what to do, what to avoid and WHY]</action>
|
|
78
|
-
<verify>[command/check]</verify>
|
|
79
|
-
<done>[criteria]</done>
|
|
80
|
-
</task>
|
|
81
|
-
|
|
82
|
-
</tasks>
|
|
83
|
-
|
|
84
|
-
<verification>
|
|
85
|
-
[Overall phase checks]
|
|
86
|
-
</verification>
|
|
87
|
-
|
|
88
|
-
<success_criteria>
|
|
89
|
-
[Measurable completion]
|
|
90
|
-
</success_criteria>
|
|
91
|
-
|
|
92
|
-
<output>
|
|
93
|
-
[SUMMARY.md specification]
|
|
94
|
-
</output>
|
|
83
|
+
## Changes Section Guidance
|
|
84
|
+
|
|
85
|
+
Each `### N. Title` subsection is a coherent unit of work — a file group, a logical change, or a feature slice.
|
|
86
|
+
|
|
87
|
+
**Structure each subsection with:**
|
|
88
|
+
- `**Files:**` line listing exact paths
|
|
89
|
+
- Implementation details in prose with inline code blocks for critical snippets
|
|
90
|
+
- References to existing utilities with file paths: "Use `hashPassword` in `src/lib/crypto.ts`"
|
|
91
|
+
- Tables for configuration, mappings, or data structures
|
|
92
|
+
- Line number references when modifying existing files: "After the import block (~line 15)"
|
|
93
|
+
|
|
94
|
+
**Sizing:** Each subsection represents 15-60 minutes of Claude work. If a subsection takes multiple sessions, split it. If it's trivial, combine with a related subsection.
|
|
95
|
+
|
|
96
|
+
**Example:**
|
|
97
|
+
|
|
98
|
+
```markdown
|
|
99
|
+
### 2. Add password comparison utility
|
|
100
|
+
**Files:** `src/lib/crypto.ts`
|
|
101
|
+
|
|
102
|
+
Export `comparePassword(plain: string, hash: string): Promise<boolean>` using
|
|
103
|
+
bcrypt.compare. Import `bcrypt` from the existing dependency in package.json.
|
|
104
|
+
|
|
105
|
+
Follow the pattern of `hashPassword` already in this file (~line 8).
|
|
95
106
|
```
|
|
96
107
|
|
|
97
|
-
|
|
108
|
+
---
|
|
98
109
|
|
|
99
|
-
|
|
100
|
-
Every task has four required fields:
|
|
110
|
+
## Inline Metadata Specification
|
|
101
111
|
|
|
102
|
-
|
|
103
|
-
**What it is**: Exact file paths that will be created or modified.
|
|
112
|
+
The metadata line sits directly below the H1 title:
|
|
104
113
|
|
|
105
|
-
|
|
106
|
-
|
|
114
|
+
```markdown
|
|
115
|
+
# Plan 03: Create login endpoint with JWT
|
|
107
116
|
|
|
108
|
-
|
|
109
|
-
|
|
117
|
+
**Subsystem:** auth | **Type:** tdd
|
|
118
|
+
```
|
|
110
119
|
|
|
111
|
-
|
|
112
|
-
**What it is**: Specific implementation instructions, including what to avoid and WHY.
|
|
120
|
+
### Subsystem
|
|
113
121
|
|
|
114
|
-
|
|
122
|
+
Matches vocabulary from the project's `config.json`. Used by the executor when generating SUMMARY.md after plan completion.
|
|
115
123
|
|
|
116
|
-
|
|
124
|
+
### Type
|
|
117
125
|
|
|
118
|
-
|
|
119
|
-
|
|
126
|
+
| Value | Behavior |
|
|
127
|
+
|-------|----------|
|
|
128
|
+
| `execute` | Default. Standard plan execution. Can be omitted. |
|
|
129
|
+
| `tdd` | Triggers lazy-load of `tdd-execution.md` reference during execution. Plan uses RED/GREEN/REFACTOR structure. |
|
|
120
130
|
|
|
121
|
-
|
|
122
|
-
**What it is**: How to prove the task is complete.
|
|
131
|
+
When `**Type:**` is omitted, the plan defaults to `execute`.
|
|
123
132
|
|
|
124
|
-
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## Must-Haves Specification
|
|
125
136
|
|
|
126
|
-
|
|
127
|
-
- `curl -X POST /api/auth/login` returns 200 with Set-Cookie header
|
|
128
|
-
- Build completes without errors
|
|
137
|
+
The `## Must-Haves` section is a markdown checklist consumed by ms-verifier. Each item is a user-observable truth — not an implementation detail.
|
|
129
138
|
|
|
130
|
-
**
|
|
139
|
+
**Good (observable truths):**
|
|
140
|
+
- `- [ ] Valid credentials return 200 with Set-Cookie header`
|
|
141
|
+
- `- [ ] Passwords are hashed, never stored plaintext`
|
|
142
|
+
- `- [ ] Unauthenticated requests to /api/protected return 401`
|
|
131
143
|
|
|
132
|
-
|
|
133
|
-
|
|
144
|
+
**Bad (implementation details):**
|
|
145
|
+
- `- [ ] bcrypt library installed`
|
|
146
|
+
- `- [ ] JWT_SECRET in .env file`
|
|
147
|
+
- `- [ ] Auth middleware created`
|
|
134
148
|
|
|
135
|
-
|
|
136
|
-
**What it is**: Acceptance criteria - the measurable state of completion.
|
|
149
|
+
The verifier derives artifacts and key_links from the `## Changes` section. Must-haves focus on what the user can observe or verify.
|
|
137
150
|
|
|
138
|
-
|
|
151
|
+
---
|
|
139
152
|
|
|
140
|
-
|
|
153
|
+
## EXECUTION-ORDER.md Specification
|
|
141
154
|
|
|
142
|
-
|
|
143
|
-
</field>
|
|
144
|
-
</task_anatomy>
|
|
155
|
+
Execution order lives in a single `EXECUTION-ORDER.md` file alongside the plans. Individual plans carry no wave numbers or dependency declarations.
|
|
145
156
|
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
**Format:**
|
|
158
|
+
|
|
159
|
+
```markdown
|
|
160
|
+
# Execution Order
|
|
148
161
|
|
|
149
|
-
|
|
150
|
-
|
|
162
|
+
## Wave 1 (parallel)
|
|
163
|
+
- 01-PLAN.md — Database schema and Prisma client
|
|
164
|
+
- 02-PLAN.md — Environment configuration
|
|
151
165
|
|
|
152
|
-
|
|
166
|
+
## Wave 2 (parallel)
|
|
167
|
+
- 03-PLAN.md — Auth endpoints (depends on schema from 01)
|
|
168
|
+
- 04-PLAN.md — User profile CRUD (depends on schema from 01)
|
|
153
169
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
<name>Task 3: Create login endpoint with JWT</name>
|
|
157
|
-
<files>src/app/api/auth/login/route.ts</files>
|
|
158
|
-
<action>POST endpoint accepting {email, password}. Query User by email, compare password with bcrypt. On match, create JWT with jose library, set as httpOnly cookie (15-min expiry). Return 200. On mismatch, return 401.</action>
|
|
159
|
-
<verify>curl -X POST localhost:3000/api/auth/login returns 200 with Set-Cookie header</verify>
|
|
160
|
-
<done>Valid credentials → 200 + cookie. Invalid → 401.</done>
|
|
161
|
-
</task>
|
|
170
|
+
## Wave 3
|
|
171
|
+
- 05-PLAN.md — Protected route middleware (depends on auth from 03)
|
|
162
172
|
```
|
|
163
173
|
|
|
164
|
-
|
|
165
|
-
|
|
174
|
+
**Rules:**
|
|
175
|
+
- Generated by plan-writer alongside plans
|
|
176
|
+
- Read by execute-phase orchestrator for wave grouping
|
|
177
|
+
- Plans within a wave execute in parallel
|
|
178
|
+
- Single source of truth for execution structure
|
|
179
|
+
- Human-readable, easy to override by editing directly
|
|
166
180
|
|
|
167
|
-
|
|
181
|
+
---
|
|
168
182
|
|
|
169
|
-
|
|
170
|
-
</task_types>
|
|
183
|
+
## Cross-Reference Table
|
|
171
184
|
|
|
172
|
-
|
|
173
|
-
|
|
185
|
+
| Question | Answer |
|
|
186
|
+
|----------|--------|
|
|
187
|
+
| How does the verifier find must-haves? | Reads `## Must-Haves` section |
|
|
188
|
+
| How does the executor know the subsystem? | Reads inline metadata (`**Subsystem:**`) |
|
|
189
|
+
| How does the plan-checker validate plans? | Reads EXECUTION-ORDER.md + plan structure |
|
|
190
|
+
| What triggers TDD lazy-loading? | `**Type:** tdd` in inline metadata |
|
|
191
|
+
| How does the executor know why an approach was chosen? | Reads `## Context` section |
|
|
192
|
+
| How does the executor find existing utilities? | Reads `**Files:**` lines and inline references in `## Changes` |
|
|
174
193
|
|
|
175
|
-
|
|
194
|
+
---
|
|
176
195
|
|
|
177
|
-
|
|
178
|
-
- Business logic with defined inputs/outputs
|
|
179
|
-
- API endpoints with request/response contracts
|
|
180
|
-
- Data transformations and parsing
|
|
181
|
-
- Validation rules
|
|
182
|
-
- Algorithms with testable behavior
|
|
196
|
+
## What Plans Do NOT Contain
|
|
183
197
|
|
|
184
|
-
**
|
|
185
|
-
-
|
|
186
|
-
-
|
|
187
|
-
-
|
|
188
|
-
-
|
|
198
|
+
- **No YAML frontmatter** — metadata is inline markdown
|
|
199
|
+
- **No XML containers** — pure markdown throughout
|
|
200
|
+
- **No wave numbers or dependency declarations** — centralized in EXECUTION-ORDER.md
|
|
201
|
+
- **No file ownership lists** — centralized in EXECUTION-ORDER.md
|
|
202
|
+
- **No `<output>` or `<execution_context>` sections** — executor handles these inline
|
|
203
|
+
- **No summary template references** — executor loads templates as needed
|
|
189
204
|
|
|
190
|
-
|
|
191
|
-
→ Yes: Create a TDD plan (one feature per plan)
|
|
192
|
-
→ No: Use standard plan, add tests after if needed
|
|
205
|
+
---
|
|
193
206
|
|
|
194
|
-
|
|
195
|
-
</tdd_plans>
|
|
207
|
+
## Examples
|
|
196
208
|
|
|
197
|
-
|
|
198
|
-
Use @file references to load context for the prompt:
|
|
209
|
+
### Simple Plan: CRUD Endpoint
|
|
199
210
|
|
|
200
211
|
```markdown
|
|
201
|
-
|
|
202
|
-
@.planning/PROJECT.md # Project vision
|
|
203
|
-
@.planning/ROADMAP.md # Phase structure
|
|
204
|
-
@.planning/STATE.md # Current position
|
|
205
|
-
|
|
206
|
-
# Only include prior SUMMARY if genuinely needed:
|
|
207
|
-
# - This plan imports types from prior plan
|
|
208
|
-
# - Prior plan made decision affecting this plan
|
|
209
|
-
# Independent plans need NO prior SUMMARY references.
|
|
210
|
-
|
|
211
|
-
@src/lib/db.ts # Existing database setup
|
|
212
|
-
@src/types/user.ts # Existing type definitions
|
|
213
|
-
</context>
|
|
214
|
-
```
|
|
212
|
+
# Plan 01: Create user profile CRUD endpoints
|
|
215
213
|
|
|
216
|
-
|
|
214
|
+
**Subsystem:** api
|
|
217
215
|
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
## Context
|
|
217
|
+
The API needs basic user profile management. Using Next.js route handlers with
|
|
218
|
+
Prisma ORM. The User model already exists in the schema (created during project
|
|
219
|
+
init).
|
|
220
220
|
|
|
221
|
-
|
|
222
|
-
Overall phase verification (beyond individual task verification):
|
|
221
|
+
## Changes
|
|
223
222
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
Before declaring phase complete:
|
|
227
|
-
- [ ] `npm run build` succeeds without errors
|
|
228
|
-
- [ ] `npm test` passes all tests
|
|
229
|
-
- [ ] No TypeScript errors
|
|
230
|
-
- [ ] Feature works end-to-end manually
|
|
231
|
-
</verification>
|
|
232
|
-
```
|
|
223
|
+
### 1. Create GET /api/users/[id] endpoint
|
|
224
|
+
**Files:** `src/app/api/users/[id]/route.ts`
|
|
233
225
|
|
|
234
|
-
|
|
226
|
+
Route handler accepting `id` param. Query User by ID with Prisma. Return 200
|
|
227
|
+
with user JSON (exclude passwordHash). Return 404 if not found.
|
|
235
228
|
|
|
236
|
-
|
|
237
|
-
|
|
229
|
+
### 2. Create PATCH /api/users/[id] endpoint
|
|
230
|
+
**Files:** `src/app/api/users/[id]/route.ts`
|
|
238
231
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
-
|
|
245
|
-
-
|
|
246
|
-
-
|
|
247
|
-
|
|
232
|
+
Accept JSON body with optional `name` and `email` fields. Validate email format
|
|
233
|
+
with regex. Update User with Prisma. Return 200 with updated user. Return 404
|
|
234
|
+
if not found, 400 if validation fails.
|
|
235
|
+
|
|
236
|
+
## Verification
|
|
237
|
+
- `curl localhost:3000/api/users/1` returns 200 with user JSON
|
|
238
|
+
- `curl -X PATCH localhost:3000/api/users/1 -d '{"name":"New"}' -H 'Content-Type: application/json'` returns 200
|
|
239
|
+
- `curl localhost:3000/api/users/999` returns 404
|
|
240
|
+
|
|
241
|
+
## Must-Haves
|
|
242
|
+
- [ ] GET /api/users/:id returns user profile without password hash
|
|
243
|
+
- [ ] PATCH /api/users/:id updates name and email
|
|
244
|
+
- [ ] Invalid user ID returns 404
|
|
245
|
+
- [ ] Invalid email format returns 400
|
|
248
246
|
```
|
|
249
247
|
|
|
250
|
-
|
|
248
|
+
### Complex Plan: Auth with Approach Rationale
|
|
249
|
+
|
|
250
|
+
```markdown
|
|
251
|
+
# Plan 03: Create login endpoint with JWT
|
|
252
|
+
|
|
253
|
+
**Subsystem:** auth | **Type:** execute
|
|
254
|
+
|
|
255
|
+
## Context
|
|
256
|
+
User authentication for the API layer. Using jose library instead of
|
|
257
|
+
jsonwebtoken — jsonwebtoken uses CommonJS which causes issues with Next.js Edge
|
|
258
|
+
runtime. Tokens use httpOnly cookies (not Authorization headers) to prevent XSS
|
|
259
|
+
token theft.
|
|
260
|
+
|
|
261
|
+
Refresh token rotation: each refresh token is single-use. On refresh, the old
|
|
262
|
+
token is invalidated and a new access/refresh pair is issued. This limits the
|
|
263
|
+
window of a stolen refresh token.
|
|
264
|
+
|
|
265
|
+
Prior plan 01 created the User model with `passwordHash` field in Prisma schema.
|
|
266
|
+
|
|
267
|
+
## Changes
|
|
251
268
|
|
|
252
|
-
|
|
253
|
-
|
|
269
|
+
### 1. Create POST /api/auth/login endpoint
|
|
270
|
+
**Files:** `src/app/api/auth/login/route.ts`
|
|
271
|
+
|
|
272
|
+
POST endpoint accepting `{email, password}`. Query User by email with Prisma.
|
|
273
|
+
Compare password using `comparePassword` in `src/lib/crypto.ts` (created in
|
|
274
|
+
plan 02). On match, create access JWT (15-min expiry) and refresh JWT (7-day
|
|
275
|
+
expiry) with jose. Set both as httpOnly cookies. Return 200 with user profile.
|
|
276
|
+
On mismatch, return 401 with generic "Invalid credentials" message.
|
|
277
|
+
|
|
278
|
+
### 2. Create POST /api/auth/refresh endpoint
|
|
279
|
+
**Files:** `src/app/api/auth/refresh/route.ts`
|
|
280
|
+
|
|
281
|
+
Read refresh token from cookie. Verify with jose. Look up token in
|
|
282
|
+
RefreshToken table — if not found or already used, return 401. Mark current
|
|
283
|
+
token as used. Issue new access + refresh pair. Set cookies. Return 200.
|
|
284
|
+
|
|
285
|
+
### 3. Add RefreshToken model to schema
|
|
286
|
+
**Files:** `prisma/schema.prisma`
|
|
287
|
+
|
|
288
|
+
Add RefreshToken model with fields: `id`, `token` (unique), `userId` (relation
|
|
289
|
+
to User), `used` (boolean, default false), `expiresAt` (DateTime), `createdAt`.
|
|
290
|
+
Run `npx prisma db push` after schema change.
|
|
291
|
+
|
|
292
|
+
## Verification
|
|
293
|
+
- `curl -X POST localhost:3000/api/auth/login -H 'Content-Type: application/json' -d '{"email":"test@test.com","password":"test123"}'` returns 200 with Set-Cookie headers
|
|
294
|
+
- Login with wrong password returns 401
|
|
295
|
+
- Refresh endpoint with valid cookie returns new tokens
|
|
296
|
+
- Refresh endpoint with used token returns 401
|
|
297
|
+
|
|
298
|
+
## Must-Haves
|
|
299
|
+
- [ ] Valid credentials return 200 with httpOnly cookie containing JWT
|
|
300
|
+
- [ ] Invalid credentials return 401 with generic error message
|
|
301
|
+
- [ ] Refresh token rotation invalidates used tokens
|
|
302
|
+
- [ ] Passwords compared with bcrypt, never plaintext
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
### TDD Plan: Pure Markdown RED/GREEN/REFACTOR
|
|
254
306
|
|
|
255
307
|
```markdown
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
308
|
+
# Plan 04: Email validation utility
|
|
309
|
+
|
|
310
|
+
**Subsystem:** validation | **Type:** tdd
|
|
311
|
+
|
|
312
|
+
## Context
|
|
313
|
+
Multiple endpoints need email validation (registration, profile update, invite).
|
|
314
|
+
Centralizing in a utility prevents inconsistent validation rules. Using TDD
|
|
315
|
+
because the function has clear inputs/outputs and edge cases that benefit from
|
|
316
|
+
test-first design.
|
|
317
|
+
|
|
318
|
+
## Changes
|
|
319
|
+
|
|
320
|
+
### 1. RED — Write failing tests
|
|
321
|
+
**Files:** `src/lib/__tests__/validate-email.test.ts`
|
|
322
|
+
|
|
323
|
+
Test cases:
|
|
324
|
+
- Valid: `user@example.com`, `name+tag@domain.co.uk` → returns true
|
|
325
|
+
- Invalid: `@domain.com`, `user@`, `user@.com`, empty string, `null` → returns false
|
|
326
|
+
- Edge: very long local part (>64 chars), very long domain (>255 chars) → returns false
|
|
327
|
+
|
|
328
|
+
Import `validateEmail` from `src/lib/validate-email.ts` (does not exist yet).
|
|
329
|
+
Run tests — all must fail with import/function error.
|
|
330
|
+
|
|
331
|
+
### 2. GREEN — Implement minimal validation
|
|
332
|
+
**Files:** `src/lib/validate-email.ts`
|
|
333
|
+
|
|
334
|
+
Export `validateEmail(email: string): boolean`. Use regex matching RFC 5322
|
|
335
|
+
simplified pattern. Handle null/undefined input by returning false. No
|
|
336
|
+
optimization — just make tests pass.
|
|
337
|
+
|
|
338
|
+
### 3. REFACTOR — Extract regex constant
|
|
339
|
+
**Files:** `src/lib/validate-email.ts`
|
|
340
|
+
|
|
341
|
+
Extract regex to `EMAIL_REGEX` constant at module level. Add JSDoc with
|
|
342
|
+
examples. Run tests — all must still pass. Only commit if changes improve
|
|
343
|
+
readability.
|
|
344
|
+
|
|
345
|
+
## Verification
|
|
346
|
+
- `npm test -- --grep "validate-email"` passes all cases
|
|
347
|
+
- Import works from other modules without errors
|
|
348
|
+
|
|
349
|
+
## Must-Haves
|
|
350
|
+
- [ ] Valid email addresses return true
|
|
351
|
+
- [ ] Invalid email addresses return false
|
|
352
|
+
- [ ] Edge cases (length limits, null input) handled correctly
|
|
259
353
|
```
|
|
260
354
|
|
|
261
|
-
|
|
355
|
+
---
|
|
356
|
+
|
|
357
|
+
## Specificity Guidelines
|
|
262
358
|
|
|
263
|
-
|
|
264
|
-
<too_vague>
|
|
359
|
+
### Too Vague
|
|
265
360
|
|
|
266
|
-
```
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
<verify>???</verify>
|
|
272
|
-
<done>Users can authenticate</done>
|
|
273
|
-
</task>
|
|
361
|
+
```markdown
|
|
362
|
+
### 1. Add authentication
|
|
363
|
+
**Files:** ???
|
|
364
|
+
|
|
365
|
+
Implement auth.
|
|
274
366
|
```
|
|
275
367
|
|
|
276
368
|
Claude: "How? What type? What library? Where?"
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
</task>
|
|
369
|
+
|
|
370
|
+
### Just Right
|
|
371
|
+
|
|
372
|
+
```markdown
|
|
373
|
+
### 1. Create login endpoint with JWT
|
|
374
|
+
**Files:** `src/app/api/auth/login/route.ts`
|
|
375
|
+
|
|
376
|
+
POST endpoint accepting {email, password}. Query User by email, compare
|
|
377
|
+
password with bcrypt. On match, create JWT with jose library, set as httpOnly
|
|
378
|
+
cookie (15-min expiry). Return 200. On mismatch, return 401. Use jose instead
|
|
379
|
+
of jsonwebtoken (CommonJS issues with Edge).
|
|
289
380
|
```
|
|
290
381
|
|
|
291
382
|
Claude can implement this immediately.
|
|
292
|
-
</just_right>
|
|
293
383
|
|
|
294
|
-
|
|
295
|
-
**TDD candidates get dedicated plans.**
|
|
384
|
+
### Too Detailed
|
|
296
385
|
|
|
297
|
-
|
|
298
|
-
|
|
386
|
+
Writing the actual code in the plan. Trust Claude to implement from clear instructions — specify WHAT and WHY, not the exact lines of code.
|
|
387
|
+
|
|
388
|
+
---
|
|
299
389
|
|
|
300
|
-
|
|
301
|
-
Writing the actual code in the plan. Trust Claude to implement from clear instructions.
|
|
302
|
-
</too_detailed>
|
|
303
|
-
</specificity_levels>
|
|
390
|
+
## Anti-Patterns
|
|
304
391
|
|
|
305
|
-
|
|
306
|
-
<vague_actions>
|
|
392
|
+
### Vague Actions
|
|
307
393
|
|
|
308
394
|
- "Set up the infrastructure"
|
|
309
395
|
- "Handle edge cases"
|
|
@@ -311,9 +397,8 @@ Writing the actual code in the plan. Trust Claude to implement from clear instru
|
|
|
311
397
|
- "Add proper error handling"
|
|
312
398
|
|
|
313
399
|
These require Claude to decide WHAT to do. Specify it.
|
|
314
|
-
</vague_actions>
|
|
315
400
|
|
|
316
|
-
|
|
401
|
+
### Unverifiable Completion
|
|
317
402
|
|
|
318
403
|
- "It works correctly"
|
|
319
404
|
- "User experience is good"
|
|
@@ -321,27 +406,21 @@ These require Claude to decide WHAT to do. Specify it.
|
|
|
321
406
|
- "Tests pass" (which tests? do they exist?)
|
|
322
407
|
|
|
323
408
|
These require subjective judgment. Make it objective.
|
|
324
|
-
</unverifiable_completion>
|
|
325
409
|
|
|
326
|
-
|
|
410
|
+
### Missing Context
|
|
327
411
|
|
|
328
412
|
- "Use the standard approach"
|
|
329
413
|
- "Follow best practices"
|
|
330
414
|
- "Like the other endpoints"
|
|
331
415
|
|
|
332
|
-
Claude
|
|
333
|
-
</missing_context>
|
|
334
|
-
</anti_patterns>
|
|
416
|
+
Claude has no memory of your standards across contexts. Be explicit.
|
|
335
417
|
|
|
336
|
-
|
|
337
|
-
Good task size: 15-60 minutes of Claude work.
|
|
418
|
+
### Implementation-Detail Must-Haves
|
|
338
419
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
420
|
+
- "bcrypt library installed"
|
|
421
|
+
- "Middleware file created"
|
|
422
|
+
- "ENV variable added"
|
|
342
423
|
|
|
343
|
-
|
|
344
|
-
If a task is trivial, combine with related tasks.
|
|
424
|
+
Must-haves are user-observable truths. The verifier checks outcomes, not internals.
|
|
345
425
|
|
|
346
|
-
|
|
347
|
-
</sizing_tasks>
|
|
426
|
+
</plan_format>
|