feat: bubbletea dashboard, skill picker and update review
Bare skm opens a dashboard with live upstream status per source; add uses a filterable picker and update a side-by-side diff review when run in a terminal. Non-interactive paths are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
65a96ada8e
commit
6f4d6f5609
12 files changed
+1262
-55
No files matched your search
+36
-3
@@ -14,9 +14,12 @@ import (
|
||||
"skill-manager/internal/fetch"
|
||||
"skill-manager/internal/jsonfile"
|
||||
"skill-manager/internal/manifest"
|
||||
"skill-manager/internal/tui"
|
||||
)
|
||||
|
||||
const usage = `usage: skm [--dir DIR] <command> [args]
|
||||
const usage = `usage: skm [--dir DIR] [command] [args]
|
||||
|
||||
Without a command, skm opens the dashboard.
|
||||
|
||||
commands:
|
||||
add <url> [--ref R] [--name N] (--skill a,b=alias,dir/c | --all)
|
||||
@@ -53,9 +56,9 @@ func run(ctx context.Context, args []string) error {
|
||||
return err
|
||||
}
|
||||
args = global.Args()
|
||||
if len(args) == 0 {
|
||||
if len(args) == 0 && !tui.Interactive() {
|
||||
global.Usage()
|
||||
return errors.New("no command")
|
||||
return errors.New("no command (the dashboard needs a terminal)")
|
||||
}
|
||||
|
||||
cfg, err := loadConfig(*dir)
|
||||
@@ -64,6 +67,20 @@ func run(ctx context.Context, args []string) error {
|
||||
}
|
||||
store := core.Store{Dir: cfg.ManifestDir, Fetcher: fetch.Nix{}}
|
||||
|
||||
if len(args) == 0 {
|
||||
summary, err := tui.Dashboard(ctx, store)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, line := range summary {
|
||||
fmt.Println(line)
|
||||
}
|
||||
if len(summary) > 0 {
|
||||
return rebuild(cfg, false)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
switch cmd, rest := args[0], args[1:]; cmd {
|
||||
case "add":
|
||||
return add(ctx, store, rest)
|
||||
@@ -150,6 +167,22 @@ func add(ctx context.Context, store core.Store, args []string) error {
|
||||
req.Skills = append(req.Skills, k)
|
||||
}
|
||||
|
||||
if !req.All && len(req.Skills) == 0 && tui.Interactive() {
|
||||
found, installed, err := store.Available(ctx, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
chosen, err := tui.Pick(ctx, "add from "+req.URL, found, installed)
|
||||
if errors.Is(err, tui.ErrCanceled) {
|
||||
fmt.Println("nothing added")
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Skills = core.Select(found, chosen)
|
||||
}
|
||||
|
||||
key, err := store.Add(ctx, req)
|
||||
if sel, ok := errors.AsType[*core.NoSelectionError](err); ok {
|
||||
fmt.Fprintf(os.Stderr, "skills in %s:\n", sel.Source)
|
||||
|
||||
+50
-22
@@ -12,6 +12,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"skill-manager/internal/core"
|
||||
"skill-manager/internal/tui"
|
||||
)
|
||||
|
||||
func outdated(ctx context.Context, store core.Store, args []string) error {
|
||||
@@ -53,36 +54,39 @@ func update(ctx context.Context, store core.Store, cfg config, args []string) er
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
in := bufio.NewReader(os.Stdin)
|
||||
var accepted []core.SourceStatus
|
||||
var outdated []core.SourceStatus
|
||||
failed := 0
|
||||
for _, st := range statuses {
|
||||
if st.Err != nil {
|
||||
fmt.Fprintf(os.Stderr, "%s: %v\n", st.Source, st.Err)
|
||||
failed++
|
||||
continue
|
||||
} else if st.Outdated() {
|
||||
outdated = append(outdated, st)
|
||||
}
|
||||
if !st.Outdated() {
|
||||
continue
|
||||
}
|
||||
|
||||
var accepted []core.SourceStatus
|
||||
switch {
|
||||
case len(outdated) == 0:
|
||||
case *yes:
|
||||
accepted = outdated
|
||||
case tui.Interactive():
|
||||
accepted, err = tui.Review(ctx, outdated)
|
||||
if errors.Is(err, tui.ErrCanceled) {
|
||||
fmt.Println("aborted, nothing changed")
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
accepted, err = reviewText(ctx, outdated)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, st := range accepted {
|
||||
printStatus(os.Stdout, st)
|
||||
if !*yes {
|
||||
for _, ch := range st.Changes {
|
||||
d, err := core.Diff(ctx, ch)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Print(d)
|
||||
}
|
||||
ok, err := confirm(in, fmt.Sprintf("apply %s? [y/N] ", st.Source))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
}
|
||||
accepted = append(accepted, st)
|
||||
}
|
||||
|
||||
if len(accepted) > 0 {
|
||||
@@ -102,6 +106,30 @@ func update(ctx context.Context, store core.Store, cfg config, args []string) er
|
||||
return nil
|
||||
}
|
||||
|
||||
// reviewText prints each outdated source's diff and asks on stdin; used without a terminal.
|
||||
func reviewText(ctx context.Context, outdated []core.SourceStatus) ([]core.SourceStatus, error) {
|
||||
in := bufio.NewReader(os.Stdin)
|
||||
var accepted []core.SourceStatus
|
||||
for _, st := range outdated {
|
||||
printStatus(os.Stdout, st)
|
||||
for _, ch := range st.Changes {
|
||||
d, err := core.Diff(ctx, ch)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
fmt.Print(d)
|
||||
}
|
||||
ok, err := confirm(in, fmt.Sprintf("apply %s? [y/N] ", st.Source))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ok {
|
||||
accepted = append(accepted, st)
|
||||
}
|
||||
}
|
||||
return accepted, nil
|
||||
}
|
||||
|
||||
func printStatus(w io.Writer, st core.SourceStatus) {
|
||||
switch {
|
||||
case st.OldRev == "":
|
||||
|
||||
Reference in new issue
Block a user