- Add `vendor rename <source> [upstream-id=name ...] [--reset ids]` to change deployed names after `vendor add`, without moving the pinned rev or selection - Persist renames in the lockfile so they survive `vendor update` and `vendor select` - Rewrite SKILL.md frontmatter `name:` to the folder name so OpenCode loads renamed skills - Validate rename targets: single path segment, no leading dot, and OpenCode skill naming rules for skills - Re-run collision checks before writing; failed renames leave lockfile and external area untouched - Add unit tests for frontmatter rewrite and name validation, plus e2e rename coverage - Document renames in README; sync beads issue export
162 lines
6.8 KiB
Go
162 lines
6.8 KiB
Go
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/m3tam3re/agent-lib/internal/vendor"
|
|
)
|
|
|
|
func newVendorCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "vendor",
|
|
Short: "Curate external sources into this work repository",
|
|
}
|
|
cmd.AddCommand(newVendorAddCmd())
|
|
cmd.AddCommand(newVendorSelectCmd())
|
|
cmd.AddCommand(newVendorRenameCmd())
|
|
cmd.AddCommand(newVendorListCmd())
|
|
cmd.AddCommand(newVendorInspectCmd())
|
|
cmd.AddCommand(newVendorUpdateCmd())
|
|
cmd.AddCommand(newVendorDiffCmd())
|
|
cmd.AddCommand(newVendorRemoveCmd())
|
|
return cmd
|
|
}
|
|
|
|
func newVendorAddCmd() *cobra.Command {
|
|
var ref string
|
|
var include, exclude, onlyTypes, excludeTypes []string
|
|
var renames []string
|
|
cmd := &cobra.Command{
|
|
Use: "add <name> <url>",
|
|
Short: "Vendor a new external git source",
|
|
Long: "Clones the source (in-process, via go-git), discovers skills, commands,\n" +
|
|
"agents and MCP fragments, materializes the selection under external/<name>/\n" +
|
|
"and pins URL, ref, revision, selection and renames in the lockfile.\n" +
|
|
"Default selection is everything; --include switches to an explicit list,\n" +
|
|
"--exclude keeps everything except the listed ids. --types (allow-list) and\n" +
|
|
"--exclude-types (deny-list) filter whole content types and survive updates:\n" +
|
|
"new upstream items of an excluded type never enter the work repository.\n" +
|
|
"Collisions abort with a hard error; resolve them with --rename upstream=deployed.",
|
|
Args: cobra.ExactArgs(2),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
renameMap, err := vendor.ParseRenames(renames)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
opts := vendor.AddOptions{
|
|
Name: args[0],
|
|
URL: args[1],
|
|
Ref: ref,
|
|
Include: splitList(include),
|
|
Exclude: splitList(exclude),
|
|
OnlyTypes: splitList(onlyTypes),
|
|
ExcludeTypes: splitList(excludeTypes),
|
|
Renames: renameMap,
|
|
}
|
|
if err := vendor.Add(".", opts, cmd.OutOrStdout()); err != nil {
|
|
return fmt.Errorf("vendor add: %w", err)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
cmd.Flags().StringVar(&ref, "ref", "", "branch or tag to track (default: the source's default branch)")
|
|
cmd.Flags().StringSliceVar(&include, "include", nil, "comma-separated item ids to vendor (switches selection to include mode)")
|
|
cmd.Flags().StringSliceVar(&exclude, "exclude", nil, "comma-separated item ids to skip (keeps all mode, drops these ids)")
|
|
cmd.Flags().StringSliceVar(&onlyTypes, "types", nil, "comma-separated content types to take: skills, commands, agents, mcp (allow-list)")
|
|
cmd.Flags().StringSliceVar(&excludeTypes, "exclude-types", nil, "comma-separated content types to skip: skills, commands, agents, mcp (deny-list)")
|
|
cmd.Flags().StringSliceVar(&renames, "rename", nil, "deployed-name override upstream-id=deployed-name (repeatable)")
|
|
return cmd
|
|
}
|
|
|
|
func newVendorRenameCmd() *cobra.Command {
|
|
var reset []string
|
|
cmd := &cobra.Command{
|
|
Use: "rename <name> [upstream-id=deployed-name ...]",
|
|
Short: "Give vendored items user-friendly deployed names",
|
|
Long: "Sets or resets deployed-name overrides for a vendored source after\n" +
|
|
"vendor add. The rename map is pinned in the lockfile and survives\n" +
|
|
"vendor update and vendor select. Renamed skills get their SKILL.md\n" +
|
|
"frontmatter name rewritten to the new folder name, so OpenCode lists\n" +
|
|
"them under the new name. Skill names must be lowercase letters, digits\n" +
|
|
"and single hyphens (e.g. code-review). The pinned revision and the\n" +
|
|
"selection never change; collisions re-run before anything is written.\n" +
|
|
"Without arguments the current renames are listed.\n\n" +
|
|
"Examples:\n" +
|
|
" agent-lib vendor rename superpowers brainstorming=ideen-sammeln\n" +
|
|
" agent-lib vendor rename superpowers --reset brainstorming\n" +
|
|
" agent-lib vendor rename superpowers",
|
|
Args: cobra.MinimumNArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
set, err := vendor.ParseRenames(args[1:])
|
|
if err != nil {
|
|
return err
|
|
}
|
|
opts := vendor.RenameOptions{Set: set, Reset: splitList(reset)}
|
|
if err := vendor.Rename(".", args[0], opts, cmd.OutOrStdout()); err != nil {
|
|
return fmt.Errorf("vendor rename: %w", err)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
cmd.Flags().StringSliceVar(&reset, "reset", nil, "comma-separated upstream ids whose rename is dropped (deploy under the upstream id again)")
|
|
return cmd
|
|
}
|
|
|
|
func splitList(in []string) []string {
|
|
var out []string
|
|
for _, s := range in {
|
|
for _, part := range strings.Split(s, ",") {
|
|
if t := strings.TrimSpace(part); t != "" {
|
|
out = append(out, t)
|
|
}
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
func newVendorSelectCmd() *cobra.Command {
|
|
var add, remove []string
|
|
var onlyTypes, excludeTypes []string
|
|
var mode string
|
|
cmd := &cobra.Command{
|
|
Use: "select <name>",
|
|
Short: "Change a source's selection without advancing the pinned revision",
|
|
Long: "Manages include/exclude selection after the initial vendor add.\n" +
|
|
"Include mode: --add appends ids (validated against the pinned upstream),\n" +
|
|
"--remove drops ids and deletes their folders. All mode: --remove moves ids\n" +
|
|
"onto the exclude list; --add is an error (everything is selected already).\n" +
|
|
"--types/--exclude-types replace the content-type filter (skills, commands,\n" +
|
|
"agents, mcp); absent flags keep it as-is. --mode all resets to everything:\n" +
|
|
"include/exclude lists and the type filter are cleared and the full pinned\n" +
|
|
"upstream is re-materialized. Collisions re-run on every change; renames\n" +
|
|
"from the lockfile are honored. The revision never moves — that is\n" +
|
|
"vendor update's job.",
|
|
Args: cobra.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if mode != "" && mode != "all" {
|
|
return fmt.Errorf("--mode accepts only \"all\" (got %q)", mode)
|
|
}
|
|
opts := vendor.SelectOptions{
|
|
Add: splitList(add),
|
|
Remove: splitList(remove),
|
|
ModeAll: mode == "all",
|
|
OnlyTypes: splitList(onlyTypes),
|
|
ExcludeTypes: splitList(excludeTypes),
|
|
}
|
|
if _, err := vendor.Select(".", args[0], opts, cmd.OutOrStdout()); err != nil {
|
|
return fmt.Errorf("vendor select: %w", err)
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
cmd.Flags().StringSliceVar(&add, "add", nil, "comma-separated upstream ids to add to the selection")
|
|
cmd.Flags().StringSliceVar(&remove, "remove", nil, "comma-separated upstream ids to remove from the selection")
|
|
cmd.Flags().StringSliceVar(&onlyTypes, "types", nil, "content types to take: skills, commands, agents, mcp (allow-list; replaces the type filter)")
|
|
cmd.Flags().StringSliceVar(&excludeTypes, "exclude-types", nil, "content types to skip: skills, commands, agents, mcp (deny-list; replaces the type filter)")
|
|
cmd.Flags().StringVar(&mode, "mode", "", "switch selection mode (only \"all\": clear include/exclude and the type filter, take everything)")
|
|
return cmd
|
|
}
|