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 (
|
|
|
|
|
"encoding/json"
|
refactor(cli): move commands from cmd/ to pkg/ with self-registration
Implements defence in depth through build variants - only compiled code
exists in the binary. Commands now self-register via cli.RegisterCommands()
in their init() functions, mirroring the i18n.RegisterLocales() pattern.
Structure changes:
- cmd/{ai,build,ci,dev,docs,doctor,go,php,pkg,sdk,setup,test,vm}/ → pkg/*/cmd_*.go
- cmd/core_dev.go, cmd/core_ci.go → cmd/variants/{full,ci,php,minimal}.go
- Added pkg/cli/commands.go with RegisterCommands API
- Updated pkg/cli/runtime.go to attach registered commands
Build variants:
- go build → full (21MB, all 13 command groups)
- go build -tags ci → ci (18MB, build/ci/sdk/doctor)
- go build -tags php → php (14MB, php/doctor)
- go build -tags minimal → minimal (11MB, doctor only)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 21:55:55 +00:00
|
|
|
"errors"
|
2026-01-27 21:08:51 +00:00
|
|
|
"os/exec"
|
|
|
|
|
"sort"
|
|
|
|
|
"strings"
|
|
|
|
|
"time"
|
|
|
|
|
|
2026-02-16 14:24:37 +00:00
|
|
|
"forge.lthn.ai/core/go/pkg/cli"
|
|
|
|
|
"forge.lthn.ai/core/go/pkg/i18n"
|
2026-01-27 21:08:51 +00:00
|
|
|
)
|
|
|
|
|
|
2026-01-30 01:28:39 +00:00
|
|
|
// PR-specific styles (aliases to shared)
|
2026-01-27 21:08:51 +00:00
|
|
|
var (
|
2026-01-31 23:36:43 +00:00
|
|
|
prNumberStyle = cli.NumberStyle
|
2026-01-30 10:32:05 +00:00
|
|
|
prTitleStyle = cli.ValueStyle
|
|
|
|
|
prAuthorStyle = cli.InfoStyle
|
|
|
|
|
prApprovedStyle = cli.SuccessStyle
|
|
|
|
|
prChangesStyle = cli.WarningStyle
|
|
|
|
|
prPendingStyle = cli.DimStyle
|
|
|
|
|
prDraftStyle = cli.DimStyle
|
2026-01-27 21:08:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// GitHubPR represents a GitHub pull request.
|
|
|
|
|
type GitHubPR struct {
|
|
|
|
|
Number int `json:"number"`
|
|
|
|
|
Title string `json:"title"`
|
|
|
|
|
State string `json:"state"`
|
|
|
|
|
IsDraft bool `json:"isDraft"`
|
|
|
|
|
CreatedAt time.Time `json:"createdAt"`
|
|
|
|
|
Author struct {
|
|
|
|
|
Login string `json:"login"`
|
|
|
|
|
} `json:"author"`
|
|
|
|
|
ReviewDecision string `json:"reviewDecision"`
|
|
|
|
|
Reviews struct {
|
|
|
|
|
Nodes []struct {
|
|
|
|
|
State string `json:"state"`
|
|
|
|
|
Author struct {
|
|
|
|
|
Login string `json:"login"`
|
|
|
|
|
} `json:"author"`
|
|
|
|
|
} `json:"nodes"`
|
|
|
|
|
} `json:"reviews"`
|
|
|
|
|
URL string `json:"url"`
|
|
|
|
|
|
|
|
|
|
// Added by us
|
|
|
|
|
RepoName string `json:"-"`
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-30 00:47:54 +00:00
|
|
|
// Reviews command flags
|
|
|
|
|
var (
|
|
|
|
|
reviewsRegistryPath string
|
|
|
|
|
reviewsAuthor string
|
|
|
|
|
reviewsShowAll bool
|
|
|
|
|
)
|
|
|
|
|
|
2026-01-30 00:22:47 +00:00
|
|
|
// addReviewsCommand adds the 'reviews' command to the given parent command.
|
2026-01-31 11:39:19 +00:00
|
|
|
func addReviewsCommand(parent *cli.Command) {
|
|
|
|
|
reviewsCmd := &cli.Command{
|
2026-01-30 00:47:54 +00:00
|
|
|
Use: "reviews",
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
Short: i18n.T("cmd.dev.reviews.short"),
|
|
|
|
|
Long: i18n.T("cmd.dev.reviews.long"),
|
2026-01-31 11:39:19 +00:00
|
|
|
RunE: func(cmd *cli.Command, args []string) error {
|
2026-01-30 00:47:54 +00:00
|
|
|
return runReviews(reviewsRegistryPath, reviewsAuthor, reviewsShowAll)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
refactor(i18n): consolidate duplicate translation keys into common section
Add common.* keys for reusable translations:
- common.label.* - UI labels (error, done, status, version, etc.)
- common.status.* - status words (running, stopped, dirty, synced)
- common.error.* - error messages (failed, not_found, working_dir)
- common.flag.* - CLI flag descriptions (registry, verbose, etc.)
- common.count.* - count templates (failed, passed, skipped)
- common.result.* - result messages (all_passed, no_issues)
- common.progress.* - progress messages (running, checking)
- common.hint.* - help hints (install_with, fix_deps)
Update all cmd/* files to use common keys instead of duplicated
command-specific keys. Reduces translation maintenance burden
and ensures consistency across the CLI.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 11:32:25 +00:00
|
|
|
reviewsCmd.Flags().StringVar(&reviewsRegistryPath, "registry", "", i18n.T("common.flag.registry"))
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
reviewsCmd.Flags().StringVar(&reviewsAuthor, "author", "", i18n.T("cmd.dev.reviews.flag.author"))
|
|
|
|
|
reviewsCmd.Flags().BoolVar(&reviewsShowAll, "all", false, i18n.T("cmd.dev.reviews.flag.all"))
|
2026-01-30 00:47:54 +00:00
|
|
|
|
|
|
|
|
parent.AddCommand(reviewsCmd)
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func runReviews(registryPath string, author string, showAll bool) error {
|
|
|
|
|
// Check gh is available
|
|
|
|
|
if _, err := exec.LookPath("gh"); err != nil {
|
refactor(cli): move commands from cmd/ to pkg/ with self-registration
Implements defence in depth through build variants - only compiled code
exists in the binary. Commands now self-register via cli.RegisterCommands()
in their init() functions, mirroring the i18n.RegisterLocales() pattern.
Structure changes:
- cmd/{ai,build,ci,dev,docs,doctor,go,php,pkg,sdk,setup,test,vm}/ → pkg/*/cmd_*.go
- cmd/core_dev.go, cmd/core_ci.go → cmd/variants/{full,ci,php,minimal}.go
- Added pkg/cli/commands.go with RegisterCommands API
- Updated pkg/cli/runtime.go to attach registered commands
Build variants:
- go build → full (21MB, all 13 command groups)
- go build -tags ci → ci (18MB, build/ci/sdk/doctor)
- go build -tags php → php (14MB, php/doctor)
- go build -tags minimal → minimal (11MB, doctor only)
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 21:55:55 +00:00
|
|
|
return errors.New(i18n.T("error.gh_not_found"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
2026-02-01 02:07:26 +00:00
|
|
|
// Find or use provided registry
|
|
|
|
|
reg, _, err := loadRegistryWithConfig(registryPath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Fetch PRs sequentially (avoid GitHub rate limits)
|
|
|
|
|
var allPRs []GitHubPR
|
|
|
|
|
var fetchErrors []error
|
|
|
|
|
|
|
|
|
|
repoList := reg.List()
|
|
|
|
|
for i, repo := range repoList {
|
2026-01-31 11:39:19 +00:00
|
|
|
repoFullName := cli.Sprintf("%s/%s", reg.Org, repo.Name)
|
|
|
|
|
cli.Print("\033[2K\r%s %d/%d %s", dimStyle.Render(i18n.T("i18n.progress.fetch")), i+1, len(repoList), repo.Name)
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
prs, err := fetchPRs(repoFullName, repo.Name, author)
|
|
|
|
|
if err != nil {
|
2026-01-31 11:39:19 +00:00
|
|
|
fetchErrors = append(fetchErrors, cli.Wrap(err, repo.Name))
|
2026-01-27 21:08:51 +00:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for _, pr := range prs {
|
|
|
|
|
// Filter drafts unless --all
|
|
|
|
|
if !showAll && pr.IsDraft {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
allPRs = append(allPRs, pr)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-01-31 11:39:19 +00:00
|
|
|
cli.Print("\033[2K\r") // Clear progress line
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
// Sort: pending review first, then by date
|
|
|
|
|
sort.Slice(allPRs, func(i, j int) bool {
|
|
|
|
|
// Pending reviews come first
|
|
|
|
|
iPending := allPRs[i].ReviewDecision == "" || allPRs[i].ReviewDecision == "REVIEW_REQUIRED"
|
|
|
|
|
jPending := allPRs[j].ReviewDecision == "" || allPRs[j].ReviewDecision == "REVIEW_REQUIRED"
|
|
|
|
|
if iPending != jPending {
|
|
|
|
|
return iPending
|
|
|
|
|
}
|
|
|
|
|
return allPRs[i].CreatedAt.After(allPRs[j].CreatedAt)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
// Print PRs
|
|
|
|
|
if len(allPRs) == 0 {
|
2026-01-31 11:39:19 +00:00
|
|
|
cli.Text(i18n.T("cmd.dev.reviews.no_prs"))
|
2026-01-27 21:08:51 +00:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Count by status
|
|
|
|
|
var pending, approved, changesRequested int
|
|
|
|
|
for _, pr := range allPRs {
|
|
|
|
|
switch pr.ReviewDecision {
|
|
|
|
|
case "APPROVED":
|
|
|
|
|
approved++
|
|
|
|
|
case "CHANGES_REQUESTED":
|
|
|
|
|
changesRequested++
|
|
|
|
|
default:
|
|
|
|
|
pending++
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-31 23:36:43 +00:00
|
|
|
cli.Blank()
|
2026-01-31 11:39:19 +00:00
|
|
|
cli.Print("%s", i18n.T("cmd.dev.reviews.open_prs", map[string]interface{}{"Count": len(allPRs)}))
|
2026-01-27 21:08:51 +00:00
|
|
|
if pending > 0 {
|
2026-01-31 11:39:19 +00:00
|
|
|
cli.Print(" * %s", prPendingStyle.Render(i18n.T("common.count.pending", map[string]interface{}{"Count": pending})))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
if approved > 0 {
|
2026-01-31 11:39:19 +00:00
|
|
|
cli.Print(" * %s", prApprovedStyle.Render(i18n.T("cmd.dev.reviews.approved", map[string]interface{}{"Count": approved})))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
if changesRequested > 0 {
|
2026-01-31 11:39:19 +00:00
|
|
|
cli.Print(" * %s", prChangesStyle.Render(i18n.T("cmd.dev.reviews.changes_requested", map[string]interface{}{"Count": changesRequested})))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
2026-01-31 23:36:43 +00:00
|
|
|
cli.Blank()
|
|
|
|
|
cli.Blank()
|
2026-01-27 21:08:51 +00:00
|
|
|
|
|
|
|
|
for _, pr := range allPRs {
|
|
|
|
|
printPR(pr)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Print any errors
|
|
|
|
|
if len(fetchErrors) > 0 {
|
2026-01-31 23:36:43 +00:00
|
|
|
cli.Blank()
|
2026-01-27 21:08:51 +00:00
|
|
|
for _, err := range fetchErrors {
|
2026-01-31 11:39:19 +00:00
|
|
|
cli.Print("%s %s\n", errorStyle.Render(i18n.Label("error")), err)
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func fetchPRs(repoFullName, repoName string, author string) ([]GitHubPR, error) {
|
|
|
|
|
args := []string{
|
|
|
|
|
"pr", "list",
|
|
|
|
|
"--repo", repoFullName,
|
|
|
|
|
"--state", "open",
|
|
|
|
|
"--json", "number,title,state,isDraft,createdAt,author,reviewDecision,reviews,url",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if author != "" {
|
|
|
|
|
args = append(args, "--author", author)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmd := exec.Command("gh", args...)
|
|
|
|
|
output, err := cmd.Output()
|
|
|
|
|
if err != nil {
|
|
|
|
|
if exitErr, ok := err.(*exec.ExitError); ok {
|
|
|
|
|
stderr := string(exitErr.Stderr)
|
|
|
|
|
if strings.Contains(stderr, "no pull requests") || strings.Contains(stderr, "Could not resolve") {
|
|
|
|
|
return nil, nil
|
|
|
|
|
}
|
2026-01-31 11:39:19 +00:00
|
|
|
return nil, cli.Err("%s", stderr)
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var prs []GitHubPR
|
|
|
|
|
if err := json.Unmarshal(output, &prs); err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Tag with repo name
|
|
|
|
|
for i := range prs {
|
|
|
|
|
prs[i].RepoName = repoName
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return prs, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func printPR(pr GitHubPR) {
|
|
|
|
|
// #12 [core-php] Webhook validation
|
2026-01-31 11:39:19 +00:00
|
|
|
num := prNumberStyle.Render(cli.Sprintf("#%d", pr.Number))
|
|
|
|
|
repo := issueRepoStyle.Render(cli.Sprintf("[%s]", pr.RepoName))
|
2026-01-30 10:32:05 +00:00
|
|
|
title := prTitleStyle.Render(cli.Truncate(pr.Title, 50))
|
2026-01-27 21:08:51 +00:00
|
|
|
author := prAuthorStyle.Render("@" + pr.Author.Login)
|
|
|
|
|
|
|
|
|
|
// Review status
|
|
|
|
|
var status string
|
|
|
|
|
switch pr.ReviewDecision {
|
|
|
|
|
case "APPROVED":
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
status = prApprovedStyle.Render(i18n.T("cmd.dev.reviews.status_approved"))
|
2026-01-27 21:08:51 +00:00
|
|
|
case "CHANGES_REQUESTED":
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
status = prChangesStyle.Render(i18n.T("cmd.dev.reviews.status_changes"))
|
2026-01-27 21:08:51 +00:00
|
|
|
default:
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
status = prPendingStyle.Render(i18n.T("cmd.dev.reviews.status_pending"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draft indicator
|
|
|
|
|
draft := ""
|
|
|
|
|
if pr.IsDraft {
|
feat(i18n): add translation keys to all CLI commands
Replace hardcoded strings with i18n.T() calls across all cmd/* packages:
- ai, build, ci, dev, docs, doctor, go, php, pkg, sdk, setup, test, vm
Adds 500+ translation keys to en.json for command descriptions,
flag descriptions, labels, messages, and error strings.
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 02:37:57 +00:00
|
|
|
draft = prDraftStyle.Render(" " + i18n.T("cmd.dev.reviews.draft"))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|
|
|
|
|
|
2026-01-30 10:32:05 +00:00
|
|
|
age := cli.FormatAge(pr.CreatedAt)
|
2026-01-27 21:08:51 +00:00
|
|
|
|
2026-01-31 11:39:19 +00:00
|
|
|
cli.Print(" %s %s %s%s %s %s %s\n", num, repo, title, draft, author, status, issueAgeStyle.Render(age))
|
2026-01-27 21:08:51 +00:00
|
|
|
}
|