Files
pipelines/internal/cli/skills.go
T
alan a37a6e0934 First run: friendly empty lists, actionable unreachable server, clearer installer
- CLI: empty list/runs/drafts/skills say so on stderr with the next command
  (stdout and --json unchanged); empty stats skip the zero table; connection
  shows ntfy not configured.
- CLI: a refused or unresolvable server says where it dialled and how to
  start it (pipelines start/doctor, or pipelines serve), redacting the URL.
- skills list/show/import dial the saved client.json address like every
  other server command instead of always 127.0.0.1:8080.
- Status: an unreachable server says how to start it; unconfigured ntfy reads
  as optional phone notifications rather than a Docker misconfiguration.
- Installer: missing tools name where to get them; Docker missing vs not
  running are told apart; the summary ends with numbered next steps (open
  the URL, sign in with the password just chosen, set up harnesses, start a
  chat or example pipeline).
- README: prerequisites, password and a short First steps; install docs
  updated (password rule was stale).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 22:41:02 +00:00

141 lines
4.1 KiB
Go

package cli
import (
"context"
"flag"
"fmt"
"os"
"git.a-wan.net/alan/pipelines/internal/client"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/skills"
)
func (a App) skillsCommand(ctx context.Context, args []string) error {
if len(args) < 1 {
return fmt.Errorf("usage: pipelines skills import|list|show")
}
if args[0] == "help" || args[0] == "--help" || args[0] == "-h" {
_, err := fmt.Fprintln(a.Out, "Usage: pipelines skills import <folder> [--yes] | skills list | skills show <name> [--version N]")
return err
}
// Accept flags after the folder, matching the rest of the Pipelines CLI.
var flags, positionals []string
for i := 1; i < len(args); i++ {
if args[i] == "--yes" || args[i] == "--json" || args[i] == "-json" {
flags = append(flags, args[i])
continue
}
if args[i] == "--url" || args[i] == "--version" {
if i+1 >= len(args) {
return fmt.Errorf("%s needs a value", args[i])
}
flags = append(flags, args[i], args[i+1])
i++
continue
}
positionals = append(positionals, args[i])
}
args = append([]string{args[0]}, append(flags, positionals...)...)
sub := args[0]
fs := flag.NewFlagSet("skills "+sub, flag.ContinueOnError)
fs.SetOutput(a.Err)
url := envOr("PIPELINES_URL", "ws://127.0.0.1:8080/connect")
if os.Getenv("PIPELINES_URL") == "" {
// Like every other server command, dial the installation's saved
// address unless --url or PIPELINES_URL chooses another.
if configured, err := client.ConfiguredURL(); err != nil {
return err
} else if configured != "" {
url = configured
}
}
yes := false
version := 0
jsonMode := false
fs.StringVar(&url, "url", url, "Pipeline server WebSocket URL")
fs.BoolVar(&yes, "yes", false, "Confirm import without prompting")
fs.BoolVar(&jsonMode, "json", false, "Machine-readable JSON")
fs.IntVar(&version, "version", 0, "Immutable version (0 = latest)")
if err := fs.Parse(args[1:]); err != nil {
return err
}
pos := fs.Args()
if sub == "import" {
if len(pos) != 1 {
return fmt.Errorf("skills import requires a folder")
}
b, e := skills.Validate(pos[0])
if e != nil {
return e
}
if !yes {
if e = a.confirmAction(fmt.Sprintf("Import skill %s (%d files, %d bytes, digest %s)?", b.Name, len(b.Files), b.TotalBytes, b.Digest), false); e != nil {
return e
}
}
c, e := client.Open(ctx, url)
if e != nil {
return serverUnreachable(e, url, a.Install != nil)
}
defer c.Close()
files := make([]protocol.SkillFile, len(b.Files))
for i, f := range b.Files {
files[i] = protocol.SkillFile{Path: f.Path, Bytes: f.Bytes}
}
r, e := c.Call(ctx, protocol.Message{Type: protocol.ImportSkill, Name: b.Name, Description: b.Description, Digest: b.Digest, SourcePath: pos[0], SkillFiles: files})
if e != nil {
return e
}
if r.SkillVersion == nil {
return fmt.Errorf("server returned no skill version")
}
return a.outputSkill(r.SkillVersion, jsonMode)
}
if sub != "list" && sub != "show" {
return fmt.Errorf("unknown skills command %q", sub)
}
c, e := client.Open(ctx, url)
if e != nil {
return serverUnreachable(e, url, a.Install != nil)
}
defer c.Close()
if sub == "list" {
if len(pos) != 0 {
return fmt.Errorf("skills list takes no arguments")
}
r, e := c.Call(ctx, protocol.Message{Type: protocol.ListSkills})
if e != nil {
return e
}
if jsonMode {
return a.output(r)
}
for _, s := range r.SkillSummaries {
fmt.Fprintf(a.Out, "%s\tv%d\t%s\n", s.Name, s.LatestVersion, s.Digest)
}
if len(r.SkillSummaries) == 0 {
a.notice("No library skills yet. Add one with: pipelines skills import <folder>")
}
return nil
}
if len(pos) != 1 {
return fmt.Errorf("skills show requires a name")
}
r, e := c.Call(ctx, protocol.Message{Type: protocol.ShowSkill, Name: pos[0], Version: version})
if e != nil {
return e
}
if r.SkillVersion == nil {
return fmt.Errorf("server returned no skill")
}
return a.outputSkill(r.SkillVersion, jsonMode)
}
func (a App) outputSkill(s *protocol.SkillVersion, jsonMode bool) error {
if jsonMode {
return a.output(s)
}
fmt.Fprintf(a.Out, "%s v%d\t%s\n%s\n", s.Name, s.Version, s.Digest, s.SkillMD)
return nil
}