Skip to content

Commit 5ce6853

Browse files
Refactor: Split bug commands and add --prompt flag
Co-authored-by: benji <benji@codepros.org>
1 parent b9e96c5 commit 5ce6853

File tree

24 files changed

+912
-443
lines changed

24 files changed

+912
-443
lines changed

CLI_REFACTOR_SUMMARY.md

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# CLI Refactor Summary
2+
3+
## Overview
4+
Refactored the Canary CLI to improve structure and add `--prompt` argument support to all subcommands.
5+
6+
## Changes Made
7+
8+
### 1. Split Bug Command Subcommands
9+
- **Created separate files** for each bug subcommand:
10+
- `cli/bug/list.go` - List bug tokens with filtering
11+
- `cli/bug/create.go` - Create new bug tokens
12+
- `cli/bug/update.go` - Update existing bug tokens
13+
- `cli/bug/show.go` - Display bug token details
14+
- `cli/bug/bug.go` - Main command and helper functions
15+
16+
- **Benefits**:
17+
- Better code organization
18+
- Easier to maintain and test
19+
- Follows single responsibility principle
20+
- Each subcommand is self-contained with its own init()
21+
22+
### 2. Added --prompt Flag to All Commands
23+
Added `--prompt` flag (stubbed for future use) to all CLI commands:
24+
25+
#### Commands with --prompt added:
26+
- `create` - Generate CANARY token template
27+
- `list` - List tokens with filtering
28+
- `show` - Display token details
29+
- `status` - Show implementation progress
30+
- `specify` - Create requirement specification
31+
- `plan` - Generate implementation plan
32+
- `scan` - Scan for CANARY tokens
33+
- `search` - Search tokens by keywords
34+
- `index` - Build token database
35+
- `files` - List implementation files
36+
- `grep` - Search tokens by pattern
37+
- `implement` - Generate implementation guidance (uses --prompt-arg)
38+
- `next` - Identify next priority (uses --prompt-arg)
39+
- `prioritize` - Update token priority
40+
- `checkpoint` - Create state snapshot
41+
- `gap` (all subcommands) - Manage gap analysis
42+
43+
#### Commands with subcommands:
44+
- `bug list` - Added --prompt flag
45+
- `bug create` - Added --prompt flag
46+
- `bug update` - Added --prompt flag
47+
- `bug show` - Added --prompt flag
48+
- `gap mark`, `gap query`, etc. - Added --prompt as persistent flag
49+
50+
### 3. Moved Flag Registrations to init()
51+
- Moved flag registrations from `cmd/canary/main.go` to individual command `init()` functions
52+
- Reduces duplication and centralizes command configuration
53+
- Makes commands more self-contained
54+
55+
**Removed from main.go:**
56+
- create command flags (aspect, status, owner, test, bench)
57+
- list command flags (db, status, aspect, phase, owner, etc.)
58+
- search command flags (db, json)
59+
- scan command flags (root, out, csv, verify, etc.)
60+
- specify command flags (aspect)
61+
- plan command flags (aspect)
62+
- index command flags (db, root)
63+
- prioritize command flags (db)
64+
- checkpoint command flags (db)
65+
66+
**Kept in main.go:**
67+
- init command flags (local, agents, key, etc.)
68+
- migrate/rollback command flags
69+
- legacy command flags
70+
- next command flags (db, prompt, json, dry-run, status, aspect)
71+
72+
### 4. Created Prompt Helper Utility
73+
Created `cli/internal/utils/prompt.go` with:
74+
75+
#### Functions:
76+
- `LoadPrompt(promptArg string)` - Load custom prompts from file or embedded FS
77+
- `loadPromptFromFile(path string)` - Load from filesystem
78+
- `loadEmbeddedPrompt(name string)` - Load from embedded prompts (stub)
79+
- `ValidatePromptArg(promptArg string)` - Validate prompt argument format
80+
- `GetAvailablePrompts()` - List available embedded prompts (stub)
81+
82+
#### Future Implementation:
83+
The helper functions are stubbed and ready for:
84+
- Loading prompts from embedded FS (`prompts/sys/*.md`, `prompts/commands/*.md`)
85+
- Loading custom project prompts from `.canary/templates/*.md`
86+
- Template variable substitution
87+
- Prompt validation and caching
88+
89+
## File Structure Changes
90+
91+
### Before:
92+
```
93+
cli/bug/bug.go (single file with all subcommands)
94+
cmd/canary/main.go (all flag registrations)
95+
```
96+
97+
### After:
98+
```
99+
cli/bug/
100+
??? bug.go # Main command + helpers
101+
??? list.go # List subcommand
102+
??? create.go # Create subcommand
103+
??? update.go # Update subcommand
104+
??? show.go # Show subcommand
105+
106+
cli/internal/utils/
107+
??? prompt.go # Prompt helper utilities
108+
109+
cmd/canary/main.go # Reduced flag registrations
110+
```
111+
112+
## Usage Examples
113+
114+
### Using --prompt flag:
115+
```bash
116+
# Will be used to load custom prompts in the future
117+
canary create CBIN-200 "Feature" --prompt /path/to/custom/prompt.md
118+
canary list --prompt embedded:list-detailed
119+
canary bug create "Issue" --prompt .canary/templates/bug-prompt.md
120+
```
121+
122+
### Bug command subcommands:
123+
```bash
124+
# List all bugs
125+
canary bug list
126+
127+
# Create new bug
128+
canary bug create "Login fails" --aspect API --severity S1
129+
130+
# Update bug status
131+
canary bug update BUG-API-001 --status FIXED
132+
133+
# Show bug details
134+
canary bug show BUG-API-001
135+
```
136+
137+
## Testing
138+
139+
All changes have been tested:
140+
- Binary builds successfully: ?
141+
- Bug command and subcommands work: ?
142+
- --prompt flag appears in all command help: ?
143+
- Existing tests pass: ?
144+
- No duplicate flag registrations: ?
145+
146+
## Implementation Notes
147+
148+
### TODO Comments
149+
All --prompt flag usage includes TODO comments:
150+
```go
151+
// TODO: Implement --prompt flag to load custom prompts
152+
prompt, _ := cmd.Flags().GetString("prompt")
153+
_ = prompt // Stubbed for future use
154+
```
155+
156+
### Flag Pattern
157+
Consistent pattern across all commands:
158+
```go
159+
func init() {
160+
Cmd.Flags().String("prompt", "", "Custom prompt file or embedded prompt name (future use)")
161+
// ... other flags
162+
}
163+
```
164+
165+
### Gap Command
166+
Uses PersistentFlags for all subcommands:
167+
```go
168+
GapCmd.PersistentFlags().String("prompt", "", "Custom prompt file or embedded prompt name (future use)")
169+
GapCmd.PersistentFlags().String("db", ".canary/canary.db", "path to database file")
170+
```
171+
172+
## Next Steps
173+
174+
To fully implement the --prompt functionality:
175+
176+
1. **Embed Prompts**: Add prompt templates to embedded FS
177+
2. **Implement Loaders**: Complete `loadEmbeddedPrompt()` function
178+
3. **Add Templates**: Create command-specific prompt templates
179+
4. **Variable Substitution**: Add template variable support
180+
5. **Caching**: Implement prompt caching for performance
181+
6. **Validation**: Add prompt format validation
182+
7. **Documentation**: Document available prompts and usage
183+
184+
## Benefits
185+
186+
1. **Better Organization**: Subcommands in separate files
187+
2. **Easier Maintenance**: Self-contained command definitions
188+
3. **Future-Ready**: --prompt flag stub ready for implementation
189+
4. **Consistency**: All commands follow same pattern
190+
5. **Reduced Duplication**: Flags defined once per command
191+
6. **Testability**: Each subcommand can be tested independently
192+
193+
## Compatibility
194+
195+
All changes are backward compatible:
196+
- No breaking changes to command syntax
197+
- All existing flags preserved
198+
- New --prompt flag is optional
199+
- Tests continue to pass

0 commit comments

Comments
 (0)