Skip to content

Commit c6cf607

Browse files
feat: Implement fixed prefixes for REQ, TASK, and BUG IDs
Co-authored-by: benji <benji@codepros.org>
1 parent 02184a9 commit c6cf607

File tree

5 files changed

+1041
-13
lines changed

5 files changed

+1041
-13
lines changed

FIXED_PREFIXES_MIGRATION.md

Lines changed: 353 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,353 @@
1+
# Fixed Prefixes Migration Guide
2+
3+
## Overview
4+
5+
Canary is migrating from variable prefixes (e.g., `CBIN-001`, `PROJ-042`) to **fixed prefixes** for improved consistency and clarity.
6+
7+
### New ID System
8+
9+
| Type | Prefix | Purpose | Example |
10+
|------|--------|---------|---------|
11+
| **REQ** | `REQ` | Requirement specifications | `REQ-1`, `REQ-123` |
12+
| **TASK** | `TASK` | Tasks within requirement plans | `TASK-1`, `TASK-456` |
13+
| **BUG** | `BUG` | Bugs related to requirements/tasks | `BUG-1`, `BUG-789` |
14+
15+
## Key Changes
16+
17+
### 1. ID Format
18+
19+
**Before:**
20+
```
21+
// CANARY: REQ=CBIN-001; FEATURE="UserAuth"; ASPECT=API; STATUS=IMPL; UPDATED=2025-10-15
22+
// CANARY: REQ=PROJ-042; FEATURE="DataSync"; ASPECT=Storage; STATUS=TESTED; UPDATED=2025-10-20
23+
```
24+
25+
**After:**
26+
```
27+
// CANARY: REQ-1; FEATURE="UserAuth"; ASPECT=API; STATUS=IMPL; UPDATED=2025-10-15
28+
// CANARY: TASK-1; FEATURE="SetupAuth"; ASPECT=API; STATUS=IMPL; PARENT=REQ-1; UPDATED=2025-10-16
29+
// CANARY: BUG-1; FEATURE="AuthTimeout"; ASPECT=API; STATUS=OPEN; PARENT=REQ-1; UPDATED=2025-10-17
30+
```
31+
32+
### 2. Hierarchical Relationships
33+
34+
#### REQ (Requirements)
35+
- Top-level specifications
36+
- Contains overall feature description
37+
- Can have multiple TASKs
38+
- Can have related BUGs
39+
40+
#### TASK (Tasks)
41+
- Implementation tasks for a REQ
42+
- Part of a requirement's implementation plan
43+
- References parent REQ with `PARENT=REQ-###`
44+
- Can have sub-TASKs (PARENT=TASK-###)
45+
- Can have related BUGs
46+
47+
#### BUG (Bugs)
48+
- Issues related to REQ or TASK
49+
- References parent with `PARENT=REQ-###` or `PARENT=TASK-###`
50+
- Tracks bug lifecycle independently
51+
52+
### 3. Token Format Updates
53+
54+
#### Full Format
55+
```
56+
// CANARY: <ID>; FEATURE="<name>"; ASPECT=<aspect>; STATUS=<status>; [PARENT=<parent-id>]; [TEST=<test>]; [BENCH=<bench>]; [OWNER=<owner>]; UPDATED=<date>
57+
```
58+
59+
#### Examples
60+
61+
**Requirement:**
62+
```
63+
// CANARY: REQ-1; FEATURE="UserAuthentication"; ASPECT=API; STATUS=TESTED; TEST=TestREQ_1_Login; OWNER=backend; UPDATED=2025-11-01
64+
```
65+
66+
**Task:**
67+
```
68+
// CANARY: TASK-1; FEATURE="ImplementPasswordHashing"; ASPECT=API; STATUS=IMPL; PARENT=REQ-1; OWNER=backend; UPDATED=2025-11-01
69+
```
70+
71+
**Bug:**
72+
```
73+
// CANARY: BUG-1; FEATURE="SessionTimeout"; ASPECT=API; STATUS=OPEN; PARENT=REQ-1; SEVERITY=HIGH; OWNER=backend; UPDATED=2025-11-01
74+
```
75+
76+
## Migration Steps
77+
78+
### For Existing Projects
79+
80+
#### 1. Backup Your Database
81+
```bash
82+
cp .canary/canary.db .canary/canary.db.backup
83+
```
84+
85+
#### 2. Run Migration Tool
86+
```bash
87+
canary migrate up
88+
```
89+
90+
This will:
91+
- Convert all `CBIN-###`, `PROJ-###`, etc. to `REQ-###`
92+
- Maintain numeric IDs where possible
93+
- Create mapping for reference
94+
95+
#### 3. Update Token Comments
96+
Use the provided migration script:
97+
```bash
98+
canary migrate tokens --dry-run # Preview changes
99+
canary migrate tokens # Apply changes
100+
```
101+
102+
#### 4. Update Documentation
103+
- Update `GAP_ANALYSIS.md` references
104+
- Update specification files
105+
- Update README references
106+
107+
### For New Projects
108+
109+
Simply use the new format from the start:
110+
```bash
111+
canary init myproject
112+
canary create REQ-1 "MyFeature" --aspect API
113+
```
114+
115+
## Benefits
116+
117+
### 1. Clarity
118+
- **REQ-1** immediately identifies as a requirement
119+
- **TASK-42** clearly indicates a task
120+
- **BUG-7** obviously represents a bug
121+
122+
### 2. Hierarchy
123+
- Clear parent-child relationships
124+
- `PARENT=REQ-1` links task to requirement
125+
- Better dependency tracking
126+
127+
### 3. Simplicity
128+
- No project-specific prefixes to remember
129+
- Universal understanding across all Canary projects
130+
- Easier for AI assistants to parse
131+
132+
### 4. Scalability
133+
- Unlimited numeric space (REQ-1 to REQ-999999+)
134+
- Clear categorization
135+
- Better for large projects
136+
137+
## API Changes
138+
139+
### reqid Package
140+
141+
**Old API:**
142+
```go
143+
// Parse with variable prefix
144+
id, err := reqid.ParseRequirementID("CBIN-001") // RequirementID{Key: "CBIN", ID: "001"}
145+
```
146+
147+
**New API:**
148+
```go
149+
// Parse with fixed prefix
150+
id, err := reqid.Parse("REQ-1") // ID{Type: "REQ", Number: 1}
151+
id, err := reqid.Parse("TASK-42") // ID{Type: "TASK", Number: 42}
152+
id, err := reqid.Parse("BUG-7") // ID{Type: "BUG", Number: 7}
153+
154+
// Type checking
155+
if id.IsREQ() { ... }
156+
if id.IsTASK() { ... }
157+
if id.IsBUG() { ... }
158+
159+
// Create new IDs
160+
req := reqid.NewREQ(1)
161+
task := reqid.NewTASK(42)
162+
bug := reqid.NewBUG(7)
163+
```
164+
165+
### Storage Layer
166+
167+
**Token struct updated:**
168+
```go
169+
type Token struct {
170+
// ... existing fields ...
171+
ReqID string // Now stores "REQ-1", "TASK-42", or "BUG-7"
172+
ParentID string // NEW: Parent REQ or TASK
173+
// ... existing fields ...
174+
}
175+
```
176+
177+
### CLI Commands
178+
179+
All commands now accept the new format:
180+
181+
```bash
182+
# List requirements
183+
canary list REQ
184+
185+
# List tasks
186+
canary list TASK
187+
188+
# List bugs
189+
canary list BUG
190+
191+
# Show specific item
192+
canary show REQ-1
193+
canary show TASK-42
194+
canary show BUG-7
195+
196+
# Create new items
197+
canary create REQ "FeatureName" --aspect API
198+
canary create TASK "TaskName" --aspect API --parent REQ-1
199+
canary create BUG "BugTitle" --parent REQ-1 --severity HIGH
200+
```
201+
202+
## Compatibility
203+
204+
### Backward Compatibility
205+
206+
The migration includes a compatibility layer:
207+
208+
1. **Reading Old Format**: Scanner can still read old `CBIN-###` format
209+
2. **Automatic Conversion**: Old IDs automatically mapped to new format
210+
3. **Warning Mode**: Shows deprecation warnings for old format
211+
4. **Migration Reports**: Generates report of all conversions
212+
213+
### Breaking Changes
214+
215+
- **Project Configuration**: `project.yaml` no longer needs `key:` field
216+
- **Gap Analysis**: Must use new format (`REQ-1` instead of `CBIN-001`)
217+
- **Spec Directories**: Now named `.canary/specs/REQ-001-feature/` instead of `.canary/specs/CBIN-001-feature/`
218+
219+
## Test Naming
220+
221+
### Before
222+
```go
223+
func TestCANARY_CBIN_001_UserAuth(t *testing.T) { ... }
224+
func BenchmarkCANARY_CBIN_001_UserAuth(b *testing.B) { ... }
225+
```
226+
227+
### After
228+
```go
229+
func TestREQ_1_UserAuth(t *testing.T) { ... }
230+
func TestTASK_42_PasswordHash(t *testing.T) { ... }
231+
func BenchmarkREQ_1_UserAuth(b *testing.B) { ... }
232+
```
233+
234+
## Example Workflow
235+
236+
### 1. Create Requirement
237+
```bash
238+
canary specify "Add user authentication with OAuth2"
239+
```
240+
Creates: `REQ-1` with specification in `.canary/specs/REQ-001-user-auth/spec.md`
241+
242+
### 2. Create Implementation Plan
243+
```bash
244+
canary plan REQ-1
245+
```
246+
Creates: `.canary/specs/REQ-001-user-auth/plan.md` with tasks:
247+
- `TASK-1`: Setup OAuth2 library
248+
- `TASK-2`: Implement login endpoint
249+
- `TASK-3`: Add session management
250+
251+
### 3. Implement Tasks
252+
```go
253+
// CANARY: TASK-1; FEATURE="OAuth2Setup"; ASPECT=API; STATUS=IMPL; PARENT=REQ-1; UPDATED=2025-11-01
254+
func setupOAuth2() { ... }
255+
256+
// CANARY: TASK-2; FEATURE="LoginEndpoint"; ASPECT=API; STATUS=TESTED; PARENT=REQ-1; TEST=TestTASK_2_Login; UPDATED=2025-11-01
257+
func handleLogin() { ... }
258+
```
259+
260+
### 4. Track Bugs
261+
```bash
262+
canary bug create "Session timeout too short" --parent REQ-1 --severity MEDIUM
263+
```
264+
Creates: `BUG-1` linked to `REQ-1`
265+
266+
```go
267+
// CANARY: BUG-1; FEATURE="SessionTimeout"; ASPECT=API; STATUS=FIXED; PARENT=REQ-1; UPDATED=2025-11-02
268+
const sessionTimeout = 30 * time.Minute
269+
```
270+
271+
## File Structure
272+
273+
### Spec Directories
274+
```
275+
.canary/specs/
276+
??? REQ-001-user-auth/
277+
? ??? spec.md
278+
? ??? plan.md
279+
??? REQ-002-data-sync/
280+
? ??? spec.md
281+
? ??? plan.md
282+
??? REQ-003-reporting/
283+
??? spec.md
284+
```
285+
286+
### Task Tracking
287+
Tasks are tracked in `plan.md` within the requirement directory:
288+
289+
```markdown
290+
# Implementation Plan: REQ-1
291+
292+
## Tasks
293+
- [ ] TASK-1: Setup OAuth2 library (STATUS=IMPL)
294+
- [ ] TASK-2: Implement login endpoint (STATUS=TESTED)
295+
- [ ] TASK-3: Add session management (STATUS=STUB)
296+
```
297+
298+
## Migration Timeline
299+
300+
### Phase 1: Compatibility (Current)
301+
- Both old and new formats supported
302+
- Warnings for old format usage
303+
- Migration tools available
304+
305+
### Phase 2: New Format Preferred (3 months)
306+
- New format is default
307+
- Old format deprecated but still works
308+
- Documentation updated
309+
310+
### Phase 3: Old Format Removed (6 months)
311+
- Only new format supported
312+
- Old format generates errors
313+
- All tooling updated
314+
315+
## FAQ
316+
317+
### Q: Can I still use my old CBIN-### IDs?
318+
A: During the migration period, yes. The migration tool will convert them to REQ-###.
319+
320+
### Q: What happens to my existing spec directories?
321+
A: They're renamed during migration: `CBIN-001-feature/` ? `REQ-001-feature/`
322+
323+
### Q: How do I link a TASK to a REQ?
324+
A: Use the `PARENT=` field: `CANARY: TASK-1; ...; PARENT=REQ-1; ...`
325+
326+
### Q: Can a TASK have sub-TASKs?
327+
A: Yes! Use `PARENT=TASK-1` to create a hierarchy.
328+
329+
### Q: What if I have a large codebase?
330+
A: Use the migration tool with `--dry-run` first to preview changes, then apply incrementally.
331+
332+
### Q: Will this break my CI?
333+
A: No, the compatibility layer ensures old IDs still work during migration.
334+
335+
## Support
336+
337+
For migration issues:
338+
1. Check `.canary/migration.log` for detailed logs
339+
2. Run `canary migrate status` to see migration state
340+
3. Use `canary migrate rollback` if needed
341+
4. File an issue on GitHub with migration log
342+
343+
## Summary
344+
345+
The fixed prefix system (`REQ`, `TASK`, `BUG`) provides:
346+
- ? Clearer identification
347+
- ? Better hierarchy
348+
- ? Simpler mental model
349+
- ? Universal understanding
350+
- ? Easier AI integration
351+
- ? Scalable to any project size
352+
353+
**Migration is straightforward and well-supported!**

0 commit comments

Comments
 (0)