Skip to content

Commit fed094e

Browse files
committed
feat: Add API change coordination (chu refactor api)
Coordinate updates across API routes, handlers and tests - Detect HTTP routes in handlers/controllers - Parse method (GET/POST/etc), path, handler name - Generate missing handler functions - Create/update corresponding tests - Ensures consistency across API layer Autonomy: 75% (48/64 scenarios) 🎉 Complex Code Modifications: 2/12
1 parent 698c289 commit fed094e

File tree

4 files changed

+364
-22
lines changed

4 files changed

+364
-22
lines changed

cmd/chu/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ $0-5/month vs $20-30/month subscriptions.
8181
chu profile list - List all profiles
8282
chu profile use <backend>.<profile> - Switch profile
8383
84+
## REFACTORING
85+
chu refactor api - Coordinate API changes (routes, handlers, tests)
86+
8487
## ADVANCED
8588
chu config get/set - Direct config manipulation (advanced)
8689
chu ml list|train|test|eval|predict - Machine learning features

docs/reference/capabilities.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,35 +132,39 @@ Chuchu identifies:
132132

133133
## What Chuchu Cannot Do (Yet)
134134

135-
### 🟡 Complex Code Modifications (1/12 scenarios)
135+
### 🟡 Complex Code Modifications (2/12 scenarios)
136136

137137
**Implemented:**
138138

139139
- ✅ Database migrations (`chu gen migration <name>`)
140+
- ✅ API changes coordination (`chu refactor api`)
140141

141142
**Not yet implemented:**
142143

143144
- **Multi-file refactoring** - Changing function signatures across 5+ files
144-
- **API changes** - Coordinated updates to routes, handlers, tests
145145
- **Breaking changes** - Updating all consumers of changed APIs
146146
- **Type system changes** - Complex type definition updates
147147
- **Performance optimizations** - Profiling and bottleneck identification
148148
- **Security fixes** - Complex vulnerability patches
149149
- **Configuration changes** - Environment-specific configurations
150150
- **Backward compatibility** - Maintaining old APIs while adding new
151151

152-
**Example:**
152+
**Examples:**
153153
```bash
154154
chu gen migration "add user email"
155155
# Detects model changes
156156
# Generates SQL with up/down migrations
157+
158+
chu refactor api
159+
# Scans routes in handlers/controllers
160+
# Generates/updates handler functions
161+
# Creates/updates corresponding tests
157162
```
158163

159164
**Limitations:**
160-
- Currently detects changes in Git working tree
161-
- Go structs only (models with gorm/db tags)
162-
- SQL output (PostgreSQL compatible)
163-
- Manual review recommended before applying
165+
- Migration: Git working tree only, Go structs with tags, PostgreSQL SQL
166+
- API coordination: Go HTTP handlers, standard patterns (Get/Post/etc)
167+
- Manual review recommended for both
164168

165169
**Why others not implemented:** These require deep architectural understanding and multi-step coordination. Coming in future releases.
166170

@@ -252,10 +256,10 @@ chu docs update --apply # Apply updates automatically
252256

253257
### Next Release (Targeting 80% Autonomy)
254258

255-
**Phase 7: Complex Code Modifications (11 remaining scenarios)**
259+
**Phase 7: Complex Code Modifications (10 remaining scenarios)**
256260
- ✅ Database migrations (DONE)
261+
- ✅ API changes with coordinated updates (DONE)
257262
- Multi-file refactoring
258-
- API changes with coordinated updates
259263
- Type system improvements
260264

261265
**Phase 8: Test Generation (1 remaining scenario)**
@@ -304,7 +308,8 @@ Skipped tests (t.Skip()) represent features not yet implemented.
304308
- ✅ CHANGELOG generation
305309
- ✅ README updates
306310
- ✅ Database migrations
307-
- **Autonomy:** 47/64 (73%)
311+
- ✅ API change coordination
312+
- **Autonomy:** 48/64 (75%)
308313
- **MVAA Critical Path:** 17/17 (100%)
309314

310315
### Future Releases

internal/migration/generator.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (g *MigrationGenerator) GenerateMigration(ctx context.Context, name string)
6363

6464
timestamp := time.Now().Format("20060102150405")
6565
filename := fmt.Sprintf("%s_%s.sql", timestamp, strings.ReplaceAll(name, " ", "_"))
66-
66+
6767
migrationsDir := filepath.Join(g.workDir, "migrations")
6868
if err := os.MkdirAll(migrationsDir, 0755); err != nil {
6969
return nil, fmt.Errorf("failed to create migrations directory: %w", err)
@@ -93,14 +93,14 @@ func (g *MigrationGenerator) detectModelChanges() ([]ModelChange, error) {
9393

9494
var changes []ModelChange
9595
files := strings.Split(strings.TrimSpace(string(output)), "\n")
96-
96+
9797
for _, file := range files {
9898
if !strings.HasSuffix(file, ".go") {
9999
continue
100100
}
101101

102-
if strings.Contains(file, "model") || strings.Contains(file, "entity") ||
103-
strings.Contains(file, "schema") {
102+
if strings.Contains(file, "model") || strings.Contains(file, "entity") ||
103+
strings.Contains(file, "schema") {
104104
fileChanges, err := g.analyzeFileChanges(filepath.Join(g.workDir, file))
105105
if err == nil {
106106
changes = append(changes, fileChanges...)
@@ -217,8 +217,8 @@ func (g *MigrationGenerator) parseModels(content string) map[string]map[string]s
217217

218218
if field.Tag != nil {
219219
tag := field.Tag.Value
220-
if strings.Contains(tag, "gorm:") || strings.Contains(tag, "db:") ||
221-
strings.Contains(tag, "json:") {
220+
if strings.Contains(tag, "gorm:") || strings.Contains(tag, "db:") ||
221+
strings.Contains(tag, "json:") {
222222
fields[fieldName] = fieldType
223223
}
224224
} else if !ast.IsExported(fieldName) {
@@ -259,21 +259,21 @@ func (g *MigrationGenerator) generateMigrationCode(ctx context.Context, name str
259259
switch change.Type {
260260
case "added":
261261
if change.Field == "" {
262-
changeDescriptions = append(changeDescriptions,
262+
changeDescriptions = append(changeDescriptions,
263263
fmt.Sprintf("- Added model: %s", change.ModelName))
264264
} else {
265-
changeDescriptions = append(changeDescriptions,
265+
changeDescriptions = append(changeDescriptions,
266266
fmt.Sprintf("- Added field %s.%s (%s)", change.ModelName, change.Field, change.NewType))
267267
}
268268
case "modified":
269-
changeDescriptions = append(changeDescriptions,
269+
changeDescriptions = append(changeDescriptions,
270270
fmt.Sprintf("- Modified %s.%s: %s -> %s", change.ModelName, change.Field, change.OldType, change.NewType))
271271
case "removed":
272272
if change.Field == "" {
273-
changeDescriptions = append(changeDescriptions,
273+
changeDescriptions = append(changeDescriptions,
274274
fmt.Sprintf("- Removed model: %s", change.ModelName))
275275
} else {
276-
changeDescriptions = append(changeDescriptions,
276+
changeDescriptions = append(changeDescriptions,
277277
fmt.Sprintf("- Removed field %s.%s", change.ModelName, change.Field))
278278
}
279279
}
@@ -306,7 +306,7 @@ Return ONLY the SQL migration code, no explanations.`, name, strings.Join(change
306306
}
307307

308308
code := strings.TrimSpace(resp.Text)
309-
309+
310310
if strings.HasPrefix(code, "```sql") {
311311
code = strings.TrimPrefix(code, "```sql\n")
312312
code = strings.TrimSuffix(code, "```")

0 commit comments

Comments
 (0)