refactor(cli): restructure cmd packages into subdirectories
- Move CLI commands into subdirectories matching command hierarchy:
dev/, go/, php/, build/, ci/, sdk/, pkg/, vm/, docs/, setup/, doctor/, test/, ai/
- Create shared/ package for common styles and utilities
- Add new `core ai` root command with claude subcommand
- Update package declarations and imports across all files
- Create commands.go entry points for each package
- Remove GUI-related files (moved to core-gui repo)
This makes the filesystem structure match the CLI command structure,
improving context capture and code organization.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-29 18:02:43 +00:00
|
|
|
package dev
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"os"
|
|
|
|
|
|
2026-01-30 00:22:47 +00:00
|
|
|
"github.com/host-uk/core/cmd/shared"
|
2026-01-28 15:29:42 +00:00
|
|
|
"github.com/host-uk/core/pkg/git"
|
|
|
|
|
"github.com/host-uk/core/pkg/repos"
|
2026-01-30 00:47:54 +00:00
|
|
|
"github.com/spf13/cobra"
|
2026-01-27 21:08:51 +00:00
|
|
|
)
|
|
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
// Commit command flags
|
|
|
|
|
var (
|
|
|
|
|
commitRegistryPath string
|
|
|
|
|
commitAll bool
|
|
|
|
|
)
|
2026-01-27 21:08:51 +00:00
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
// addCommitCommand adds the 'commit' command to the given parent command.
|
|
|
|
|
func addCommitCommand(parent *cobra.Command) {
|
|
|
|
|
commitCmd := &cobra.Command{
|
|
|
|
|
Use: "commit",
|
|
|
|
|
Short: "Claude-assisted commits across repos",
|
|
|
|
|
Long: `Uses Claude to create commits for dirty repos.
|
|
|
|
|
Shows uncommitted changes and invokes Claude to generate commit messages.`,
|
|
|
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
|
|
|
return runCommit(commitRegistryPath, commitAll)
|
|
|
|
|
},
|
|
|
|
|
}
|
2026-01-27 21:08:51 +00:00
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
commitCmd.Flags().StringVar(&commitRegistryPath, "registry", "", "Path to repos.yaml (auto-detected if not specified)")
|
|
|
|
|
commitCmd.Flags().BoolVar(&commitAll, "all", false, "Commit all dirty repos without prompting")
|
2026-01-27 21:08:51 +00:00
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
parent.AddCommand(commitCmd)
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runCommit(registryPath string, all bool) error {
|
|
|
|
|
ctx := context.Background()
|
|
|
|
|
|
|
|
|
|
// Find or use provided registry, fall back to directory scan
|
|
|
|
|
var reg *repos.Registry
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
|
|
if registryPath != "" {
|
|
|
|
|
reg, err = repos.LoadRegistry(registryPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to load registry: %w", err)
|
|
|
|
|
}
|
2026-01-28 14:23:11 +00:00
|
|
|
fmt.Printf("%s %s\n", dimStyle.Render("Registry:"), registryPath)
|
2026-01-27 21:08:51 +00:00
|
|
|
} else {
|
|
|
|
|
registryPath, err = repos.FindRegistry()
|
|
|
|
|
if err == nil {
|
|
|
|
|
reg, err = repos.LoadRegistry(registryPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to load registry: %w", err)
|
|
|
|
|
}
|
2026-01-28 14:23:11 +00:00
|
|
|
fmt.Printf("%s %s\n", dimStyle.Render("Registry:"), registryPath)
|
2026-01-27 21:08:51 +00:00
|
|
|
} else {
|
|
|
|
|
// Fallback: scan current directory
|
|
|
|
|
cwd, _ := os.Getwd()
|
|
|
|
|
reg, err = repos.ScanDirectory(cwd)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to scan directory: %w", err)
|
|
|
|
|
}
|
2026-01-28 14:23:11 +00:00
|
|
|
fmt.Printf("%s %s\n", dimStyle.Render("Scanning:"), cwd)
|
2026-01-27 21:08:51 +00:00
|
|
|
registryPath = cwd
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build paths and names for git operations
|
|
|
|
|
var paths []string
|
|
|
|
|
names := make(map[string]string)
|
|
|
|
|
|
|
|
|
|
for _, repo := range reg.List() {
|
|
|
|
|
if repo.IsGitRepo() {
|
|
|
|
|
paths = append(paths, repo.Path)
|
|
|
|
|
names[repo.Path] = repo.Name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(paths) == 0 {
|
|
|
|
|
fmt.Println("No git repositories found.")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get status for all repos
|
|
|
|
|
statuses := git.Status(ctx, git.StatusOptions{
|
|
|
|
|
Paths: paths,
|
|
|
|
|
Names: names,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Find dirty repos
|
|
|
|
|
var dirtyRepos []git.RepoStatus
|
|
|
|
|
for _, s := range statuses {
|
|
|
|
|
if s.Error == nil && s.IsDirty() {
|
|
|
|
|
dirtyRepos = append(dirtyRepos, s)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(dirtyRepos) == 0 {
|
|
|
|
|
fmt.Println("No uncommitted changes found.")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Show dirty repos
|
|
|
|
|
fmt.Printf("\n%d repo(s) with uncommitted changes:\n\n", len(dirtyRepos))
|
|
|
|
|
for _, s := range dirtyRepos {
|
|
|
|
|
fmt.Printf(" %s: ", repoNameStyle.Render(s.Name))
|
|
|
|
|
if s.Modified > 0 {
|
|
|
|
|
fmt.Printf("%s ", dirtyStyle.Render(fmt.Sprintf("%d modified", s.Modified)))
|
|
|
|
|
}
|
|
|
|
|
if s.Untracked > 0 {
|
|
|
|
|
fmt.Printf("%s ", dirtyStyle.Render(fmt.Sprintf("%d untracked", s.Untracked)))
|
|
|
|
|
}
|
|
|
|
|
if s.Staged > 0 {
|
|
|
|
|
fmt.Printf("%s ", aheadStyle.Render(fmt.Sprintf("%d staged", s.Staged)))
|
|
|
|
|
}
|
|
|
|
|
fmt.Println()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Confirm unless --all
|
|
|
|
|
if !all {
|
|
|
|
|
fmt.Println()
|
2026-01-30 00:22:47 +00:00
|
|
|
if !shared.Confirm("Have Claude commit these repos?") {
|
2026-01-27 21:08:51 +00:00
|
|
|
fmt.Println("Aborted.")
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
|
|
// Commit each dirty repo
|
|
|
|
|
var succeeded, failed int
|
|
|
|
|
for _, s := range dirtyRepos {
|
|
|
|
|
fmt.Printf("%s %s\n", dimStyle.Render("Committing"), s.Name)
|
|
|
|
|
|
|
|
|
|
if err := claudeCommit(ctx, s.Path, s.Name, registryPath); err != nil {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Printf(" %s %s\n", errorStyle.Render("x"), err)
|
2026-01-27 21:08:51 +00:00
|
|
|
failed++
|
|
|
|
|
} else {
|
2026-01-30 00:22:47 +00:00
|
|
|
fmt.Printf(" %s committed\n", successStyle.Render("v"))
|
2026-01-27 21:08:51 +00:00
|
|
|
succeeded++
|
|
|
|
|
}
|
|
|
|
|
fmt.Println()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Summary
|
|
|
|
|
fmt.Printf("%s %d succeeded", successStyle.Render("Done:"), succeeded)
|
|
|
|
|
if failed > 0 {
|
|
|
|
|
fmt.Printf(", %s", errorStyle.Render(fmt.Sprintf("%d failed", failed)))
|
|
|
|
|
}
|
|
|
|
|
fmt.Println()
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|