Files
wehub-resource-sync a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:33:42 +08:00

73 lines
2.1 KiB
Go

package main
import (
"fmt"
"github.com/spf13/cobra"
"github.com/zzet/gortex/internal/daemon"
)
var enrichChurnBranch string
var enrichChurnCmd = &cobra.Command{
Use: "churn [path]",
Short: "Pre-compute per-symbol git churn from a fixed branch (default: origin/main)",
Long: `Walks the daemon's graph and stamps meta.churn on every file and
function/method with the commit_count / age_days / churn_rate /
last_author / last_commit_at metrics the get_churn_rate MCP tool reads.
The signal is computed against a single branch — typically the
repository's default branch — so feature-branch work-in-progress
doesn't pollute the persisted data. Pass --branch to override.
The enrichment is forwarded to the running daemon, which runs it against
its in-process graph and persists the result (avoiding the on-disk store
write-lock collision a direct CLI write would cause). A daemon must be
running; if none is, the command exits with an error — start one with
` + "`gortex daemon start`" + `.`,
Args: cobra.MaximumNArgs(1),
RunE: runEnrichChurn,
}
func init() {
enrichChurnCmd.Flags().StringVar(&enrichChurnBranch, "branch", "",
"branch / tag / SHA to compute churn against (default: origin/main, falls back to local main/master)")
enrichCmd.AddCommand(enrichChurnCmd)
}
func runEnrichChurn(cmd *cobra.Command, args []string) error {
abs, err := enrichAbsPath(args)
if err != nil {
return err
}
if !daemon.IsRunning() {
return errNoDaemon
}
c, err := dialEnrichDaemon("cli-enrich-churn")
if err != nil {
return err
}
defer c.Close()
var out daemon.EnrichChurnResult
if err := controlEnrich(c, daemon.ControlEnrichChurn, daemon.EnrichChurnParams{
Path: abs,
Branch: enrichChurnBranch,
}, &out); err != nil {
return err
}
sp := newCLISpinner(cmd, "Enriched via daemon")
sp.Set("", fmt.Sprintf("%d files · %d symbols · %s", out.Files, out.Symbols, out.Branch))
sp.Done()
return printEnrichResult(map[string]any{
"files": out.Files,
"symbols": out.Symbols,
"branch": out.Branch,
"head_sha": out.HeadSHA,
"duration_ms": out.DurationMS,
"path": abs,
"mode": "daemon",
})
}