From 4af34fe6951205ab518ab65cc708c1a98788311e Mon Sep 17 00:00:00 2001 From: Willie Hung Date: Fri, 16 Jan 2026 22:12:03 +0800 Subject: [PATCH] feat: rename update to upgrade with CLI self-update support - Rename `update` command to `upgrade` - Add CLI binary self-update from GitHub releases - Add `--cli` and `--skill` flags to upgrade specific components - Detect Homebrew installation and use `brew install` instead - Refactor SKILL.md with progressive disclosure pattern - Split references into separate files (status, sync, install, etc.) - Move run.sh to skills/skillshare/scripts/ - Fix --update flag to auto-reinstall when git pull not possible BREAKING CHANGE: `skillshare update` is now `skillshare upgrade` --- README.md | 30 +- cmd/skillshare/init.go | 177 ++++++++- cmd/skillshare/install.go | 47 ++- cmd/skillshare/main.go | 6 +- cmd/skillshare/update.go | 82 ----- cmd/skillshare/upgrade.go | 345 ++++++++++++++++++ internal/install/install.go | 8 +- internal/testutil/testutil.go | 13 +- skills/skillshare/SKILL.md | 311 ++++------------ .../skillshare/references/TROUBLESHOOTING.md | 143 ++++++++ skills/skillshare/references/backup.md | 23 ++ skills/skillshare/references/init.md | 49 +++ skills/skillshare/references/install.md | 36 ++ skills/skillshare/references/status.md | 44 +++ skills/skillshare/references/sync.md | 41 +++ skills/skillshare/references/targets.md | 33 ++ run.sh => skills/skillshare/scripts/run.sh | 2 +- tests/integration/init_test.go | 269 ++++++++++++++ tests/integration/install_test.go | 156 +++++++- .../{update_test.go => upgrade_test.go} | 28 +- 20 files changed, 1465 insertions(+), 378 deletions(-) delete mode 100644 cmd/skillshare/update.go create mode 100644 cmd/skillshare/upgrade.go create mode 100644 skills/skillshare/references/TROUBLESHOOTING.md create mode 100644 skills/skillshare/references/backup.md create mode 100644 skills/skillshare/references/init.md create mode 100644 skills/skillshare/references/install.md create mode 100644 skills/skillshare/references/status.md create mode 100644 skills/skillshare/references/sync.md create mode 100644 skills/skillshare/references/targets.md rename run.sh => skills/skillshare/scripts/run.sh (97%) rename tests/integration/{update_test.go => upgrade_test.go} (74%) diff --git a/README.md b/README.md index 2c952a6e0..7dfe815de 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ skillshare pull claude && skillshare sync # Pull from Claude → sync to all ## AI-Native Execution -The built-in [`skillshare` skill](https://github.com/runkids/skillshare/tree/main/skills/skillshare) enables your AI CLI to manage skills directly — **no manual installation required**. +The built-in [`skillshare` skill](https://github.com/runkids/skillshare/tree/main/skills/skillshare) enables your AI CLI to manage skills directly. Just download the skill folder into your AI CLI's skills directory — the binary is auto-downloaded on first use. ```text ┌─────────────────────────────────────────────────────────────┐ @@ -69,7 +69,7 @@ The built-in [`skillshare` skill](https://github.com/runkids/skillshare/tree/mai ``` > [!TIP] -> The skill automatically downloads the binary on first use — just say: +> Once installed, just say: > - *"Show my skillshare status"* > - *"Sync my skills to all targets"* > - *"Pull skills from Claude and sync everywhere"* @@ -173,7 +173,7 @@ Done! Your skills are now synced across all AI CLI tools. | `backup` | Manually backup targets | | `restore` | Restore from backup | | `doctor` | Diagnose configuration issues | -| `update` | Update built-in skillshare skill from GitHub | +| `upgrade` | Upgrade CLI and built-in skillshare skill | ### Target Management @@ -195,7 +195,7 @@ Jump to a section: - [Install Skills](#install-skills) - [Uninstall Skills](#uninstall-skills) - [List Skills](#list-skills) -- [Update Built-in Skill](#update-built-in-skill) +- [Upgrade](#upgrade) - [Dry Run](#dry-run) - [Sync Modes](#sync-modes) - [Backup & Restore](#backup--restore) @@ -299,7 +299,7 @@ skillshare install git@github.com:user/repo.git |--------|-------------| | `--name ` | Override the skill name (direct install only) | | `--force, -f` | Overwrite if skill already exists | -| `--update, -u` | Update existing installation (git pull) | +| `--update, -u` | Update existing (git pull if possible, else reinstall) | | `--dry-run, -n` | Preview discovered skills without installing | ### Examples @@ -350,21 +350,19 @@ Installed skills composio-skills github.com/ComposioHQ/awesome-claude-skills ``` -## Update Built-in Skill +## Upgrade -> **Note:** Available since v0.3.1 - -Update the built-in `skillshare` skill to the latest version from GitHub. This skill enables AI-driven management of your skills. +Upgrade the CLI binary and built-in `skillshare` skill to the latest version. ```bash -skillshare update # Update skillshare skill -skillshare update --force # Skip confirmation -skillshare update --dry-run # Preview without updating +skillshare upgrade # Upgrade CLI + skill +skillshare upgrade --skill # Upgrade skill only +skillshare upgrade --cli # Upgrade CLI only +skillshare upgrade --force # Skip confirmation +skillshare upgrade --dry-run # Preview without upgrading ``` -The skill is downloaded from the [skillshare repository](https://github.com/runkids/skillshare/tree/main/skills/skillshare) and includes AI behavior guides, command references, and troubleshooting tips. - -After updating, run `skillshare sync` to distribute to all targets. +After upgrading the skill, run `skillshare sync` to distribute to all targets. ## Dry Run @@ -394,7 +392,7 @@ skillshare restore claude --from 2026-01-14_21-22-18 -n # Preview restore from skillshare target remove claude -n # Preview unlink skillshare target remove --all -n # Preview unlink all -skillshare update -n # Preview skill update +skillshare upgrade -n # Preview upgrade ``` ## Sync Modes diff --git a/cmd/skillshare/init.go b/cmd/skillshare/init.go index a6545a06d..27506e69c 100644 --- a/cmd/skillshare/init.go +++ b/cmd/skillshare/init.go @@ -25,6 +25,16 @@ func cmdInit(args []string) error { remoteURL := "" dryRun := false + // Non-interactive flags + copyFrom := "" // --copy-from: copy from specified name or path + noCopy := false // --no-copy: start fresh + targetsArg := "" // --targets: comma-separated list + allTargets := false // --all-targets: add all detected + noTargets := false // --no-targets: skip targets + initGit := false // --git: initialize git (set by flag) + noGit := false // --no-git: skip git + gitFlagSet := false // track if --git was explicitly set + // Parse args for i := 0; i < len(args); i++ { switch args[i] { @@ -42,9 +52,58 @@ func cmdInit(args []string) error { i++ case "--dry-run", "-n": dryRun = true + case "--copy-from", "-c": + if i+1 >= len(args) { + return fmt.Errorf("--copy-from requires a name or path argument") + } + copyFrom = args[i+1] + i++ + case "--no-copy": + noCopy = true + case "--targets", "-t": + if i+1 >= len(args) { + return fmt.Errorf("--targets requires a comma-separated list") + } + targetsArg = args[i+1] + i++ + case "--all-targets": + allTargets = true + case "--no-targets": + noTargets = true + case "--git": + initGit = true + gitFlagSet = true + case "--no-git": + noGit = true } } + // Validate mutual exclusions + if copyFrom != "" && noCopy { + return fmt.Errorf("--copy-from and --no-copy are mutually exclusive") + } + exclusiveCount := 0 + if targetsArg != "" { + exclusiveCount++ + } + if allTargets { + exclusiveCount++ + } + if noTargets { + exclusiveCount++ + } + if exclusiveCount > 1 { + return fmt.Errorf("--targets, --all-targets, and --no-targets are mutually exclusive") + } + if gitFlagSet && noGit { + return fmt.Errorf("--git and --no-git are mutually exclusive") + } + + // --remote implies --git + if remoteURL != "" && !noGit { + initGit = true + } + // Expand ~ in path if utils.HasTildePrefix(sourcePath) { sourcePath = filepath.Join(home, sourcePath[1:]) @@ -80,8 +139,8 @@ func cmdInit(args []string) error { } } - // Ask user if they want to initialize from existing skills - copyFrom, copyFromName := promptCopyFrom(withSkills) + // Determine copy source (non-interactive or prompt) + copyFromPath, copyFromName := promptCopyFrom(withSkills, copyFrom, noCopy, home) if dryRun { ui.Warning("Dry run mode - no changes will be made") @@ -99,12 +158,12 @@ func cmdInit(args []string) error { } // Copy skills from selected directory - if copyFrom != "" { - copySkillsToSource(copyFrom, sourcePath, dryRun) + if copyFromPath != "" { + copySkillsToSource(copyFromPath, sourcePath, dryRun) } // Build targets list - targets := buildTargetsList(detected, copyFrom, copyFromName) + targets := buildTargetsList(detected, copyFromPath, copyFromName, targetsArg, allTargets, noTargets) // Create config cfg := &config.Config{ @@ -124,7 +183,7 @@ func cmdInit(args []string) error { } // Initialize git in source directory for safety - initGitIfNeeded(sourcePath, dryRun) + initGitIfNeeded(sourcePath, dryRun, initGit, noGit) // Set up git remote for cross-machine sync setupGitRemote(sourcePath, remoteURL, dryRun) @@ -207,7 +266,40 @@ func detectCLIDirectories(home string) []detectedDir { return detected } -func promptCopyFrom(withSkills []detectedDir) (copyFrom, copyFromName string) { +func promptCopyFrom(withSkills []detectedDir, copyFromArg string, noCopy bool, home string) (copyFrom, copyFromName string) { + // Non-interactive: --no-copy + if noCopy { + ui.Info("Starting with empty source (--no-copy)") + return "", "" + } + + // Non-interactive: --copy-from + if copyFromArg != "" { + // First, try to match by name (e.g., "claude", "cursor") + for _, d := range withSkills { + if strings.EqualFold(d.name, copyFromArg) { + ui.Success("Will copy skills from %s (matched by name)", d.name) + return d.path, d.name + } + } + + // Treat as path + path := copyFromArg + if utils.HasTildePrefix(path) { + path = filepath.Join(home, path[1:]) + } + + // Verify path exists + if info, err := os.Stat(path); err == nil && info.IsDir() { + ui.Success("Will copy skills from %s", path) + return path, "" + } + + ui.Warning("Copy source not found: %s", copyFromArg) + return "", "" + } + + // Interactive mode if len(withSkills) == 0 { return "", "" } @@ -284,11 +376,54 @@ func copySkillsToSource(copyFrom, sourcePath string, dryRun bool) { ui.Success("Copied %d skills to source", copied) } -func buildTargetsList(detected []detectedDir, copyFrom, copyFromName string) map[string]config.TargetConfig { +func buildTargetsList(detected []detectedDir, copyFrom, copyFromName, targetsArg string, allTargets, noTargets bool) map[string]config.TargetConfig { defaultTargets := config.DefaultTargets() targets := make(map[string]config.TargetConfig) - // Add the directory user chose to copy from + // Non-interactive: --no-targets + if noTargets { + ui.Info("Skipping targets (--no-targets)") + return targets + } + + // Non-interactive: --all-targets + if allTargets { + for _, d := range detected { + targets[d.name] = defaultTargets[d.name] + } + if len(targets) > 0 { + ui.Success("Added all %d detected targets (--all-targets)", len(targets)) + } else { + ui.Warning("No CLI skills directories detected") + } + return targets + } + + // Non-interactive: --targets (comma-separated list) + if targetsArg != "" { + names := strings.Split(targetsArg, ",") + added := 0 + for _, name := range names { + name = strings.TrimSpace(name) + if name == "" { + continue + } + + // Check if it's a known target name + if target, ok := defaultTargets[name]; ok { + targets[name] = target + added++ + } else { + ui.Warning("Unknown target: %s (skipped)", name) + } + } + if added > 0 { + ui.Success("Added %d targets from --targets", added) + } + return targets + } + + // Interactive mode: Add the directory user chose to copy from if copyFromName != "" { targets[copyFromName] = config.TargetConfig{Path: copyFrom} } @@ -354,13 +489,31 @@ func summarizeInitConfig(cfg *config.Config) { } } -func initGitIfNeeded(sourcePath string, dryRun bool) { +func initGitIfNeeded(sourcePath string, dryRun, initGit, noGit bool) { + // Non-interactive: --no-git + if noGit { + ui.Info("Skipped git initialization (--no-git)") + ui.Warning("Without git, deleted skills cannot be recovered!") + return + } + gitDir := filepath.Join(sourcePath, ".git") if _, err := os.Stat(gitDir); err == nil { ui.Info("Git already initialized in source directory") return } + // Non-interactive: --git flag was set, proceed without prompting + if initGit { + if dryRun { + ui.Info("Dry run - would initialize git in %s (--git)", sourcePath) + return + } + doGitInit(sourcePath) + return + } + + // Interactive mode ui.Header("Git version control") fmt.Println(" Git helps protect your skills from accidental deletion.") fmt.Println() @@ -384,6 +537,10 @@ func initGitIfNeeded(sourcePath string, dryRun bool) { return } + doGitInit(sourcePath) +} + +func doGitInit(sourcePath string) { // Run git init cmd := exec.Command("git", "init") cmd.Dir = sourcePath diff --git a/cmd/skillshare/install.go b/cmd/skillshare/install.go index f81b82939..90fe90361 100644 --- a/cmd/skillshare/install.go +++ b/cmd/skillshare/install.go @@ -13,6 +13,26 @@ import ( "skillshare/internal/validate" ) +func resolveSkillFromName(skillName string, cfg *config.Config) (*install.Source, error) { + skillPath := filepath.Join(cfg.Source, skillName) + + meta, err := install.ReadMeta(skillPath) + if err != nil { + return nil, fmt.Errorf("skill '%s' not found or has no metadata", skillName) + } + if meta == nil { + return nil, fmt.Errorf("skill '%s' has no metadata, cannot update", skillName) + } + + source, err := install.ParseSource(meta.Source) + if err != nil { + return nil, fmt.Errorf("invalid source in metadata: %w", err) + } + + source.Name = skillName + return source, nil +} + func cmdInstall(args []string) error { opts := install.InstallOptions{} var sourceArg string @@ -62,7 +82,20 @@ func cmdInstall(args []string) error { // Parse the source source, err := install.ParseSource(sourceArg) if err != nil { - return fmt.Errorf("invalid source: %w", err) + if opts.Update || opts.Force { + resolvedSource, resolveErr := resolveSkillFromName(sourceArg, cfg) + if resolveErr != nil { + return fmt.Errorf("invalid source: %w", err) + } + source = resolvedSource + ui.Info("Resolved '%s' from installed skill metadata", sourceArg) + } else { + return fmt.Errorf("invalid source: %w", err) + } + } + + if (opts.Update || opts.Force) && source.Raw != sourceArg { + return handleDirectInstall(source, cfg, opts) } // If git source without subdir, discover skills and let user choose @@ -233,9 +266,10 @@ func handleDirectInstall(source *install.Source, cfg *config.Config, opts instal } func printInstallHelp() { - fmt.Println(`Usage: skillshare install [options] + fmt.Println(`Usage: skillshare install [options] Install a skill from a local path or git repository. +When using --update or --force with a skill name, skillshare uses stored metadata to resolve the source. Sources: user/repo GitHub shorthand (expands to github.com/user/repo) @@ -249,7 +283,7 @@ Sources: Options: --name Override the skill name (only for direct install) --force, -f Overwrite if skill already exists - --update, -u Update existing installation (git pull for git sources) + --update, -u Update existing (git pull if possible, else reinstall) --dry-run, -n Preview the installation without making changes --help, -h Show this help @@ -258,5 +292,10 @@ Examples: skillshare install anthropics/skills/skills/pdf skillshare install ComposioHQ/awesome-claude-skills skillshare install ~/my-skill - skillshare install github.com/user/repo --force`) + skillshare install github.com/user/repo --force + +Update existing skills: + skillshare install my-skill --update # Update using stored source + skillshare install my-skill --force # Reinstall using stored source + skillshare install my-skill --update -n # Preview update`) } diff --git a/cmd/skillshare/main.go b/cmd/skillshare/main.go index 9937eb385..e9cad1127 100644 --- a/cmd/skillshare/main.go +++ b/cmd/skillshare/main.go @@ -46,8 +46,8 @@ func main() { err = cmdDoctor(args) case "target": err = cmdTarget(args) - case "update": - err = cmdUpdate(args) + case "upgrade": + err = cmdUpgrade(args) case "version", "-v", "--version": fmt.Printf("skillshare %s\n", version) case "help", "-h", "--help": @@ -94,7 +94,7 @@ Commands: target remove [--dry-run] Unlink target and restore skills target remove --all [--dry-run] Unlink all targets target list List all targets - update [--force] [--dry-run] Update built-in skillshare skill from GitHub + upgrade [--skill|--cli] [--force] Upgrade CLI and/or skillshare skill version Show version help Show this help diff --git a/cmd/skillshare/update.go b/cmd/skillshare/update.go deleted file mode 100644 index 5567e94b6..000000000 --- a/cmd/skillshare/update.go +++ /dev/null @@ -1,82 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - - "skillshare/internal/config" - "skillshare/internal/ui" -) - -func cmdUpdate(args []string) error { - dryRun := false - force := false - - // Parse args - for _, arg := range args { - switch arg { - case "--dry-run", "-n": - dryRun = true - case "--force", "-f": - force = true - } - } - - cfg, err := config.Load() - if err != nil { - return fmt.Errorf("config not found: run 'skillshare init' first") - } - - skillshareSkillDir := filepath.Join(cfg.Source, "skillshare") - skillshareSkillFile := filepath.Join(skillshareSkillDir, "SKILL.md") - - ui.Header("Updating skillshare skill") - - // Check if skill exists - exists := false - if _, err := os.Stat(skillshareSkillFile); err == nil { - exists = true - } - - if dryRun { - ui.Warning("Dry run mode - no changes will be made") - fmt.Println() - if exists { - ui.Info("Would update: %s", skillshareSkillFile) - } else { - ui.Info("Would download: %s", skillshareSkillFile) - } - ui.Info("Source: %s", skillshareSkillURL) - return nil - } - - // Confirm if exists and not forced - if exists && !force { - fmt.Print(" Overwrite existing skillshare skill? [y/N]: ") - var input string - fmt.Scanln(&input) - if input != "y" && input != "Y" && input != "yes" { - ui.Info("Cancelled") - return nil - } - } - - // Create directory if needed - if err := os.MkdirAll(skillshareSkillDir, 0755); err != nil { - return fmt.Errorf("failed to create directory: %w", err) - } - - // Download - ui.Info("Downloading from GitHub...") - if err := downloadSkillshareSkill(skillshareSkillFile); err != nil { - return fmt.Errorf("failed to download: %w", err) - } - - ui.Success("Updated skillshare skill") - ui.Info("Path: %s", skillshareSkillFile) - ui.Info("") - ui.Info("Run 'skillshare sync' to distribute to all targets") - - return nil -} diff --git a/cmd/skillshare/upgrade.go b/cmd/skillshare/upgrade.go new file mode 100644 index 000000000..b57dd825f --- /dev/null +++ b/cmd/skillshare/upgrade.go @@ -0,0 +1,345 @@ +package main + +import ( + "archive/tar" + "compress/gzip" + "encoding/json" + "fmt" + "io" + "net/http" + "os" + "os/exec" + "path/filepath" + "runtime" + "strings" + + "skillshare/internal/config" + "skillshare/internal/ui" +) + +const githubRepo = "runkids/skillshare" + +func cmdUpgrade(args []string) error { + dryRun := false + force := false + skillOnly := false + cliOnly := false + + // Parse args + for _, arg := range args { + switch arg { + case "--dry-run", "-n": + dryRun = true + case "--force", "-f": + force = true + case "--skill": + skillOnly = true + case "--cli": + cliOnly = true + case "--help", "-h": + printUpgradeHelp() + return nil + } + } + + // Default: upgrade both + upgradeCLI := !skillOnly + upgradeSkill := !cliOnly + + if dryRun { + ui.Warning("Dry run mode - no changes will be made") + fmt.Println() + } + + var cliErr, skillErr error + + // Upgrade CLI + if upgradeCLI { + cliErr = upgradeCLIBinary(dryRun, force) + } + + // Upgrade skill + if upgradeSkill { + if upgradeCLI { + fmt.Println() + } + skillErr = upgradeSkillshareSkill(dryRun, force) + } + + // Return first error + if cliErr != nil { + return cliErr + } + return skillErr +} + +func upgradeCLIBinary(dryRun, force bool) error { + ui.Header("Upgrading CLI") + + // Get current executable path + execPath, err := os.Executable() + if err != nil { + return fmt.Errorf("failed to get executable path: %w", err) + } + execPath, err = filepath.EvalSymlinks(execPath) + if err != nil { + return fmt.Errorf("failed to resolve symlink: %w", err) + } + + // Check if installed via Homebrew + if isHomebrewInstall(execPath) { + ui.Info("Detected Homebrew installation") + if dryRun { + ui.Info("Would run: brew install runkids/tap/skillshare") + return nil + } + ui.Info("Running: brew install runkids/tap/skillshare") + return runBrewInstall() + } + + // Get current version + currentVersion := version + + // Get latest version from GitHub + latestVersion, downloadURL, err := getLatestRelease() + if err != nil { + return fmt.Errorf("failed to check latest version: %w", err) + } + + ui.Info("Current version: %s", currentVersion) + ui.Info("Latest version: %s", latestVersion) + + if currentVersion == latestVersion && !force { + ui.Success("Already up to date") + return nil + } + + if dryRun { + ui.Info("Would download: %s", downloadURL) + return nil + } + + // Confirm if not forced + if !force { + fmt.Printf(" Upgrade to %s? [y/N]: ", latestVersion) + var input string + fmt.Scanln(&input) + if input != "y" && input != "Y" && input != "yes" { + ui.Info("Cancelled") + return nil + } + } + + ui.Info("Downloading %s...", latestVersion) + + // Download and extract + if err := downloadAndReplace(downloadURL, execPath); err != nil { + return fmt.Errorf("failed to upgrade: %w", err) + } + + ui.Success("Upgraded to %s", latestVersion) + return nil +} + +func upgradeSkillshareSkill(dryRun, force bool) error { + ui.Header("Upgrading skillshare skill") + + cfg, err := config.Load() + if err != nil { + return fmt.Errorf("config not found: run 'skillshare init' first") + } + + skillshareSkillDir := filepath.Join(cfg.Source, "skillshare") + skillshareSkillFile := filepath.Join(skillshareSkillDir, "SKILL.md") + + // Check if skill exists + exists := false + if _, err := os.Stat(skillshareSkillFile); err == nil { + exists = true + } + + if dryRun { + if exists { + ui.Info("Would upgrade: %s", skillshareSkillFile) + } else { + ui.Info("Would download: %s", skillshareSkillFile) + } + ui.Info("Source: %s", skillshareSkillURL) + return nil + } + + // Confirm if exists and not forced + if exists && !force { + fmt.Print(" Overwrite existing skillshare skill? [y/N]: ") + var input string + fmt.Scanln(&input) + if input != "y" && input != "Y" && input != "yes" { + ui.Info("Cancelled") + return nil + } + } + + // Create directory if needed + if err := os.MkdirAll(skillshareSkillDir, 0755); err != nil { + return fmt.Errorf("failed to create directory: %w", err) + } + + // Download + ui.Info("Downloading from GitHub...") + if err := downloadSkillshareSkill(skillshareSkillFile); err != nil { + return fmt.Errorf("failed to download: %w", err) + } + + ui.Success("Upgraded skillshare skill") + ui.Info("Path: %s", skillshareSkillFile) + ui.Info("") + ui.Info("Run 'skillshare sync' to distribute to all targets") + + return nil +} + +type githubRelease struct { + TagName string `json:"tag_name"` + Assets []struct { + Name string `json:"name"` + BrowserDownloadURL string `json:"browser_download_url"` + } `json:"assets"` +} + +func getLatestRelease() (version string, downloadURL string, err error) { + url := fmt.Sprintf("https://api.github.com/repos/%s/releases/latest", githubRepo) + + resp, err := http.Get(url) + if err != nil { + return "", "", err + } + defer resp.Body.Close() + + if resp.StatusCode != 200 { + return "", "", fmt.Errorf("GitHub API returned %d", resp.StatusCode) + } + + var release githubRelease + if err := json.NewDecoder(resp.Body).Decode(&release); err != nil { + return "", "", err + } + + version = strings.TrimPrefix(release.TagName, "v") + + // Find matching asset + osName := runtime.GOOS + archName := runtime.GOARCH + expectedName := fmt.Sprintf("skillshare_%s_%s_%s.tar.gz", version, osName, archName) + + for _, asset := range release.Assets { + if asset.Name == expectedName { + return version, asset.BrowserDownloadURL, nil + } + } + + return "", "", fmt.Errorf("no release found for %s/%s", osName, archName) +} + +func downloadAndReplace(url, destPath string) error { + // Download tarball + resp, err := http.Get(url) + if err != nil { + return err + } + defer resp.Body.Close() + + if resp.StatusCode != 200 { + return fmt.Errorf("download failed with status %d", resp.StatusCode) + } + + // Extract from tar.gz + gzr, err := gzip.NewReader(resp.Body) + if err != nil { + return err + } + defer gzr.Close() + + tr := tar.NewReader(gzr) + + // Find skillshare binary in archive + for { + header, err := tr.Next() + if err == io.EOF { + return fmt.Errorf("skillshare binary not found in archive") + } + if err != nil { + return err + } + + if header.Name == "skillshare" || header.Name == "./skillshare" { + // Write to temp file first + tmpFile, err := os.CreateTemp(filepath.Dir(destPath), "skillshare-upgrade-*") + if err != nil { + return err + } + tmpPath := tmpFile.Name() + + if _, err := io.Copy(tmpFile, tr); err != nil { + tmpFile.Close() + os.Remove(tmpPath) + return err + } + tmpFile.Close() + + // Make executable + if err := os.Chmod(tmpPath, 0755); err != nil { + os.Remove(tmpPath) + return err + } + + // Replace original + if err := os.Rename(tmpPath, destPath); err != nil { + os.Remove(tmpPath) + return err + } + + return nil + } + } +} + +func isHomebrewInstall(execPath string) bool { + // Check common Homebrew paths + homebrewPaths := []string{ + "/usr/local/Cellar/skillshare", + "/opt/homebrew/Cellar/skillshare", + "/home/linuxbrew/.linuxbrew/Cellar/skillshare", + } + for _, prefix := range homebrewPaths { + if strings.HasPrefix(execPath, prefix) { + return true + } + } + return false +} + +func runBrewInstall() error { + cmd := exec.Command("brew", "install", "runkids/tap/skillshare") + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + return cmd.Run() +} + +func printUpgradeHelp() { + fmt.Println(`Usage: skillshare upgrade [options] + +Upgrade the CLI binary and/or built-in skillshare skill. + +Options: + --skill Upgrade skill only + --cli Upgrade CLI only + --force, -f Skip confirmation prompts + --dry-run, -n Preview without making changes + --help, -h Show this help + +Examples: + skillshare upgrade # Upgrade both CLI and skill + skillshare upgrade --cli # Upgrade CLI only + skillshare upgrade --skill # Upgrade skill only + skillshare upgrade --dry-run # Preview upgrades`) +} diff --git a/internal/install/install.go b/internal/install/install.go index 6187fcd36..b232c0f68 100644 --- a/internal/install/install.go +++ b/internal/install/install.go @@ -356,10 +356,8 @@ func handleUpdate(source *Source, destPath string, result *InstallResult, opts I return result, nil } - // For other cases, need to reinstall - if !opts.Force { - return nil, fmt.Errorf("cannot update '%s': use --force to reinstall", source.Name) - } + // For other cases (e.g., git with subdir), reinstall automatically + // --update implies willingness to reinstall when git pull is not possible // Remove and reinstall if !opts.DryRun { @@ -370,7 +368,7 @@ func handleUpdate(source *Source, destPath string, result *InstallResult, opts I return Install(source, destPath, InstallOptions{ Name: opts.Name, - Force: false, // Already handled + Force: true, // Force=true to handle dry-run case where destPath still exists DryRun: opts.DryRun, Update: false, }) diff --git a/internal/testutil/testutil.go b/internal/testutil/testutil.go index 2874229f3..d9e39e516 100644 --- a/internal/testutil/testutil.go +++ b/internal/testutil/testutil.go @@ -40,10 +40,15 @@ func NewSandbox(t *testing.T) *Sandbox { // Try to find it relative to the project root // This works when running from the project directory cwd, _ := os.Getwd() - sb.BinaryPath = filepath.Join(cwd, "..", "..", "bin", "skillshare") - // Also try the project root bin directory - if _, err := os.Stat(sb.BinaryPath); os.IsNotExist(err) { - sb.BinaryPath = filepath.Join(cwd, "bin", "skillshare") + candidates := []string{ + filepath.Join(cwd, "bin", "skillshare"), + filepath.Join(cwd, "..", "..", "bin", "skillshare"), + } + for _, path := range candidates { + if _, err := os.Stat(path); err == nil { + sb.BinaryPath = path + break + } } } diff --git a/skills/skillshare/SKILL.md b/skills/skillshare/SKILL.md index 4b7c48e05..cb9c440f9 100644 --- a/skills/skillshare/SKILL.md +++ b/skills/skillshare/SKILL.md @@ -1,277 +1,116 @@ --- name: skillshare version: 0.5.0 -description: Manage and sync skills across AI CLI tools. Use when asked to "sync my skills", "pull skills", "show skillshare status", "list my skills", "install a skill", "create a new skill", "backup skills", or manage skill targets. +description: Manages and syncs skills across AI CLI tools (Claude, Cursor, Codex) from a single source of truth. Use when asked to "sync my skills", "pull skills", "show skillshare status", "list my skills", "install a skill", or manage skill targets. argument-hint: "[command] [target] [--dry-run]" --- # Skillshare CLI -Manage and sync skills across multiple AI CLI tools from a single source of truth. +Syncs skills across multiple AI CLI tools from a single source of truth. -## Zero-Install Execution - -**IMPORTANT:** Before running any `skillshare` command, use this runner function to ensure skillshare is available (downloads to cache if not installed): +## Quick Start ```bash -skillshare_run() { - if command -v skillshare >/dev/null 2>&1; then - skillshare "$@" - elif [ -x "${XDG_CACHE_HOME:-$HOME/.cache}/skillshare/bin/skillshare" ]; then - "${XDG_CACHE_HOME:-$HOME/.cache}/skillshare/bin/skillshare" "$@" - else - curl -fsSL https://raw.githubusercontent.com/runkids/skillshare/main/run.sh | sh -s -- "$@" - fi -} +skillshare status # See current state (always run first) +skillshare sync # Push skills to all targets +skillshare sync --dry-run # Preview changes before sync +skillshare pull claude # Bring new skills from target to source +skillshare list # Show installed skills ``` -Use `skillshare_run` instead of `skillshare` for all commands. Example: - -```bash -skillshare_run status -skillshare_run sync --dry-run -``` - -Or run directly without defining the function: - -```bash -curl -fsSL https://raw.githubusercontent.com/runkids/skillshare/main/run.sh | sh -s -- status -``` - -## When to Use This Skill - -Activate when the user: -- Asks to sync, pull, or manage skills across CLI tools -- Wants to see skillshare status or differences -- Needs to install, uninstall, or list skills -- Asks about backup, restore, or target management -- Creates a new skill and wants to distribute it -- Mentions "skillshare" directly - -**Natural language triggers:** -- "sync my skills to all tools" -- "pull my new skill from Claude" -- "what skills do I have?" -- "show skillshare status" -- "add cursor as a target" -- "backup my skills" -- "install that skill from GitHub" - -## How It Works - -1. **Check current state** with `skillshare status` -2. **Preview changes** with `--dry-run` before any destructive operation -3. **Execute the command** if user approves or didn't request preview -4. **Report results** with relevant output - ## AI Behavior Guide -Map user intents to command sequences: - -| User Says | Commands to Run | -|-----------|-----------------| +| User Intent | Commands | +|-------------|----------| | "sync my skills" | `skillshare sync` | -| "sync but show me first" | `skillshare sync --dry-run`, then `skillshare sync` if approved | -| "pull from Claude and sync" | `skillshare pull claude` then `skillshare sync` | -| "pull all and sync everywhere" | `skillshare pull --all` then `skillshare sync` | -| "pull from remote/other machine" | `skillshare pull --remote` (git pull + sync) | -| "push to remote/backup" | `skillshare push` (git commit + push) | -| "sync across machines" | `skillshare push` on machine A, `skillshare pull --remote` on B | -| "show status" / "what's the state" | `skillshare status` | -| "show differences" | `skillshare diff` | -| "what skills do I have" | `skillshare list` (or `skillshare list --verbose`) | -| "install X skill" | `skillshare install ` then `skillshare sync` | -| "remove/uninstall X skill" | `skillshare uninstall ` then `skillshare sync` | +| "sync but show me first" | `skillshare sync --dry-run` → `skillshare sync` | +| "pull from Claude" | `skillshare pull claude` → `skillshare sync` | +| "pull all" | `skillshare pull --all` → `skillshare sync` | +| "pull from remote" | `skillshare pull --remote` | +| "push to remote" | `skillshare push` | +| "show status" | `skillshare status` | +| "what skills do I have" | `skillshare list` | +| "install X skill" | `skillshare install ` → `skillshare sync` | +| "remove X skill" | `skillshare uninstall ` → `skillshare sync` | | "add cursor as target" | `skillshare target add cursor ~/.cursor/skills` | -| "remove target X" | `skillshare target remove ` | -| "backup my skills" | `skillshare backup` | -| "restore from backup" | `skillshare restore ` | | "something's broken" | `skillshare doctor` | -| "create a new skill" | Guide user to create in source: `~/.config/skillshare/skills/` | +| "initialize skillshare" | See [Init Workflow](#init-workflow) | -## Quick Reference +## Init Workflow -| Priority | Command | Use Case | -|----------|---------|----------| -| 1 | `status` | First command - see current state | -| 2 | `sync` | Push skills to all targets | -| 3 | `sync --dry-run` | Preview sync changes | -| 4 | `pull ` | Bring target's new skills to source | -| 5 | `pull --all` | Pull from all targets | -| 6 | `diff` | See what differs between source and targets | -| 7 | `list` | Show installed skills | -| 8 | `install ` | Add skill from path or git repo | -| 9 | `uninstall ` | Remove a skill | -| 10 | `doctor` | Diagnose configuration issues | +**CRITICAL:** AI cannot respond to CLI prompts. Use flags for non-interactive mode. -## Commands Reference +### Init Checklist -### Status & Inspection +Copy and track when initializing: +- [ ] Ask: "Do you have existing skills to copy?" → `--copy-from ` or `--no-copy` +- [ ] Ask: "Which CLI tools to sync?" → `--targets `, `--all-targets`, or `--no-targets` +- [ ] Ask: "Initialize git?" → `--git` or `--no-git` +- [ ] Run: `skillshare init [flags]` +- [ ] Verify: `skillshare status` + +### Quick Defaults + +If user just says "initialize skillshare": +```bash +skillshare init --no-copy --all-targets --git +``` + +### Examples ```bash -skillshare status # Source, targets, sync state -skillshare diff # All targets -skillshare diff claude # Specific target -skillshare list # List skills -skillshare list --verbose # With source and install info +skillshare init --copy-from claude --targets "claude,cursor" --git +skillshare init --no-copy --all-targets --git # Fresh start +skillshare init --no-copy --no-targets --no-git # Minimal ``` -**Expected output (status):** -``` -Source: ~/.config/skillshare/skills (4 skills) -Targets: - claude ✓ synced ~/.claude/skills - codex ✓ synced ~/.codex/skills - cursor ⚠ 1 diff ~/.cursor/skills -``` +## Core Commands -### Sync & Pull +| Command | Use Case | +|---------|----------| +| `status` | First command - see current state | +| `sync` | Push skills to all targets | +| `pull ` | Bring target's skills to source | +| `diff` | See differences between source and targets | +| `list` | Show installed skills | +| `install ` | Add skill from path or git repo | +| `doctor` | Diagnose issues | -```bash -skillshare sync # Sync to all targets -skillshare sync --dry-run # Preview only +## Symlink Safety -skillshare pull claude # Pull from specific target -skillshare pull --all # Pull from all targets -skillshare pull --remote # Pull from git remote + sync all -``` +**CRITICAL:** In `merge` mode, editing a skill in ANY target edits the source. -### Push (Cross-Machine Sync) - -```bash -skillshare push # Git add, commit, push -skillshare push -m "message" # Custom commit message -skillshare push --dry-run # Preview only -``` - -**Local workflow:** -1. Create skill in any target (e.g., `~/.claude/skills/my-skill/`) -2. `skillshare pull claude` - bring to source -3. `skillshare sync` - distribute to all targets - -**Cross-machine workflow:** -1. Machine A: `skillshare push` - commit and push to remote -2. Machine B: `skillshare pull --remote` - pull from remote + sync to all targets - -### Install & Uninstall - -```bash -# Install from various sources -skillshare install github.com/user/repo # Discovery mode -skillshare install github.com/user/repo/path/skill # Direct path -skillshare install ~/Downloads/my-skill # Local path -skillshare install --name custom-name # Custom name -skillshare install --force # Overwrite existing -skillshare install --update # Update git-based skill - -# Uninstall -skillshare uninstall my-skill # With confirmation -skillshare uninstall my-skill --force # Skip confirmation -``` - -After install/uninstall, run `skillshare sync` to update targets. - -### Target Management - -```bash -skillshare target list # List all targets -skillshare target claude # Show target info -skillshare target add myapp ~/.myapp/skills # Add custom target -skillshare target remove myapp # Remove target -skillshare target claude --mode merge # Change sync mode -skillshare target claude --mode symlink # Change to symlink mode -``` - -**Sync modes:** -- `merge`: Individual skill symlinks, local skills preserved (recommended) -- `symlink`: Entire directory symlinked, all targets identical - -### Backup & Restore - -```bash -skillshare backup # Backup all targets -skillshare backup claude # Backup specific target -skillshare backup --list # List available backups -skillshare backup --cleanup # Remove old backups - -skillshare restore claude # Restore from latest -skillshare restore claude --from 2026-01-14_21-22-18 # Specific backup -``` - -Backups location: `~/.config/skillshare/backups//` - -### Diagnostics - -```bash -skillshare doctor # Check configuration health -skillshare init --dry-run # Preview what init would do -``` - -## Common Issues & Solutions - -| Problem | Diagnosis | Solution | -|---------|-----------|----------| -| "config not found" | Config missing | Run `skillshare init` | -| Target shows differences | Files out of sync | Run `skillshare sync` | -| Lost source files | Deleted via symlink | `cd ~/.config/skillshare/skills && git checkout -- /` | -| Target has local skills | Need to preserve | Ensure `merge` mode, then `skillshare pull` before sync | -| Skill not appearing | Not synced yet | Run `skillshare sync` after install | -| Can't find installed skills | Wrong directory | Check `skillshare status` for source path | - -**Recovery workflow:** -```bash -skillshare doctor # Diagnose issues -skillshare backup # Create safety backup -skillshare sync --dry-run # Preview fix -skillshare sync # Apply fix -``` - -## Tips for AI - -### Symlink Behavior -- In `merge` mode: editing a skill in ANY target edits the source (changes are immediate) -- In `symlink` mode: entire target directory is a symlink to source - **NEVER** use `rm -rf` on symlinked skills - this deletes the source +- Use `skillshare target remove ` to safely unlink targets +- Use `skillshare uninstall ` to safely remove skills -### When to Use --dry-run -- Before `sync` if user is cautious or first-time -- Before `pull --all` to see what will be imported -- Before `install` from unknown sources -- Before `restore` to preview what will change -- Before `target remove` to understand impact +## Cross-Machine Workflow -### Git Workflow Recommendations -After any skill changes, remind user: ```bash -skillshare push # Simple: commit and push in one command -skillshare push -m "Add new skill" # With custom message +# Machine A: push changes +skillshare push -m "Add new skill" + +# Machine B: pull and sync +skillshare pull --remote ``` -Or manually: +## Zero-Install Runner + +If skillshare is not installed, run directly via curl: + ```bash -cd ~/.config/skillshare/skills -git add . && git commit -m "Add/update skills" && git push +curl -fsSL https://raw.githubusercontent.com/runkids/skillshare/main/skills/skillshare/scripts/run.sh | sh -s -- status ``` -### Creating New Skills -Guide users to create skills in source directory: -- Path: `~/.config/skillshare/skills//SKILL.md` -- Must have frontmatter with `name` and `description` -- After creation: `skillshare sync` to distribute +See [scripts/run.sh](scripts/run.sh) for the full runner script. -### Safe Target Removal -To unlink a target without losing source: -```bash -skillshare target remove # Safe: only removes link -# NOT: rm -rf ~/.target/skills # Dangerous: may delete source -``` +## References -## File Locations - -| Item | Path | -|------|------| -| Source directory | Defined in config (default: `~/.config/skillshare/skills/`) | -| Config file | `~/.config/skillshare/config.yaml` | -| Backups | `~/.config/skillshare/backups/` | - -Run `skillshare status` to see actual paths. +- [status.md](references/status.md) - status, diff, list, doctor +- [sync.md](references/sync.md) - sync, pull, push +- [install.md](references/install.md) - install, uninstall +- [targets.md](references/targets.md) - target management +- [backup.md](references/backup.md) - backup, restore +- [init.md](references/init.md) - init flags reference +- [TROUBLESHOOTING.md](references/TROUBLESHOOTING.md) - Common issues and recovery diff --git a/skills/skillshare/references/TROUBLESHOOTING.md b/skills/skillshare/references/TROUBLESHOOTING.md new file mode 100644 index 000000000..620fce42a --- /dev/null +++ b/skills/skillshare/references/TROUBLESHOOTING.md @@ -0,0 +1,143 @@ +# Skillshare Troubleshooting + +Common issues, solutions, and tips for AI assistants. + +## Common Issues + +| Problem | Diagnosis | Solution | +|---------|-----------|----------| +| "config not found" | Config missing | Run `skillshare init` | +| Target shows differences | Files out of sync | Run `skillshare sync` | +| Lost source files | Deleted via symlink | `cd ~/.config/skillshare/skills && git checkout -- /` | +| Target has local skills | Need to preserve | Ensure `merge` mode, then `skillshare pull` before sync | +| Skill not appearing | Not synced yet | Run `skillshare sync` after install | +| Can't find installed skills | Wrong directory | Check `skillshare status` for source path | +| "permission denied" | Symlink issues | Check file ownership and permissions | +| Git remote not set | Push fails | Run `git remote add origin ` in source | + +## Recovery Workflow + +When something goes wrong: + +```bash +skillshare doctor # 1. Diagnose issues +skillshare backup # 2. Create safety backup +skillshare sync --dry-run # 3. Preview fix +skillshare sync # 4. Apply fix +``` + +## Git Recovery + +If source files were accidentally deleted: + +```bash +cd ~/.config/skillshare/skills +git status # See what's missing +git checkout -- / # Restore specific skill +git checkout -- . # Restore all deleted files +``` + +If you need to restore from backup: + +```bash +skillshare backup --list # List available backups +skillshare restore claude --from +``` + +## Tips for AI Assistants + +### Symlink Behavior + +Understanding symlinks is critical: + +1. **merge mode** (default): Each skill in target is a symlink to source + - Editing `~/.claude/skills/my-skill/SKILL.md` edits the source + - Changes are immediate and affect all targets + - Safe: `skillshare uninstall my-skill` + - **DANGEROUS**: `rm -rf ~/.claude/skills/my-skill` - deletes source! + +2. **symlink mode**: Entire target directory is a symlink + - `~/.claude/skills` → `~/.config/skillshare/skills` + - All targets are identical + - No local skills possible + +### When to Use --dry-run + +Always use `--dry-run` in these situations: + +- User is cautious or new to skillshare +- Before `sync` on first use +- Before `pull --all` to see what will be imported +- Before `install` from unknown sources +- Before `restore` to preview what will change +- Before `target remove` to understand impact + +### Safe vs Dangerous Operations + +**Safe operations:** +```bash +skillshare target remove # Removes symlinks, keeps source +skillshare uninstall # Removes skill properly +skillshare sync # Creates/updates symlinks +``` + +**NEVER do this:** +```bash +rm -rf ~/.claude/skills/my-skill # Deletes source via symlink! +rm -rf ~/.claude/skills # May delete entire source! +``` + +### Creating New Skills + +Guide users to create skills in source: + +1. Create directory: `~/.config/skillshare/skills//` +2. Create `SKILL.md` with required frontmatter: + ```yaml + --- + name: skill-name + description: What this skill does + --- + ``` +3. Run `skillshare sync` to distribute + +### Git Workflow Reminders + +After any skill changes, remind user to push: + +```bash +skillshare push # Simple: commit + push +skillshare push -m "Add new skill" # With custom message +``` + +### Handling Init Prompts + +AI cannot respond to CLI prompts. When user asks to initialize: + +1. Ask clarifying questions in chat +2. Build the command with appropriate flags +3. Run non-interactively + +Example conversation: +- AI: "Do you have existing skills to copy from Claude or another tool?" +- User: "Yes, from Claude" +- AI: "Which CLI tools should I set up as targets?" +- User: "Claude and Cursor" +- AI: "Should I initialize git for version control?" +- User: "Yes" +- AI runs: `skillshare init --copy-from claude --targets "claude,cursor" --git` + +### Debugging Sync Issues + +If sync seems stuck or wrong: + +```bash +skillshare status # Check current state +skillshare diff # See actual differences +ls -la ~/.claude/skills # Check symlink targets +``` + +Look for: +- Broken symlinks (pointing to non-existent files) +- Regular files instead of symlinks +- Wrong symlink targets diff --git a/skills/skillshare/references/backup.md b/skills/skillshare/references/backup.md new file mode 100644 index 000000000..f14250d66 --- /dev/null +++ b/skills/skillshare/references/backup.md @@ -0,0 +1,23 @@ +# Backup & Restore Commands + +## backup + +Creates backup of target skills. + +```bash +skillshare backup # Backup all targets +skillshare backup claude # Backup specific target +skillshare backup --list # List available backups +skillshare backup --cleanup # Remove old backups +``` + +Backups stored in: `~/.config/skillshare/backups//` + +## restore + +Restores skills from backup. + +```bash +skillshare restore claude # From latest backup +skillshare restore claude --from 2026-01-14_21-22-18 # From specific backup +``` diff --git a/skills/skillshare/references/init.md b/skills/skillshare/references/init.md new file mode 100644 index 000000000..36ffc7fdb --- /dev/null +++ b/skills/skillshare/references/init.md @@ -0,0 +1,49 @@ +# Init Command + +Initializes skillshare configuration. + +## Copy Source Flags (mutually exclusive) + +| Flag | Description | +|------|-------------| +| `--copy-from ` | Copy skills from target name or directory path | +| `--no-copy` | Start with empty source | + +## Target Flags (mutually exclusive) + +| Flag | Description | +|------|-------------| +| `--targets ` | Comma-separated targets: `"claude,cursor,codex"` | +| `--all-targets` | Add all detected CLI targets | +| `--no-targets` | Skip target setup | + +## Git Flags (mutually exclusive) + +| Flag | Description | +|------|-------------| +| `--git` | Initialize git in source (recommended) | +| `--no-git` | Skip git initialization | + +## Other Flags + +| Flag | Description | +|------|-------------| +| `--source ` | Custom source directory | +| `--remote ` | Set git remote (implies `--git`) | +| `--dry-run` | Preview without making changes | + +## Examples + +```bash +# Fresh start with all targets and git +skillshare init --no-copy --all-targets --git + +# Copy from Claude, specific targets +skillshare init --copy-from claude --targets "claude,cursor" --git + +# Minimal setup +skillshare init --no-copy --no-targets --no-git + +# Custom source with remote +skillshare init --source ~/my-skills --remote git@github.com:user/skills.git +``` diff --git a/skills/skillshare/references/install.md b/skills/skillshare/references/install.md new file mode 100644 index 000000000..9dcf6adbf --- /dev/null +++ b/skills/skillshare/references/install.md @@ -0,0 +1,36 @@ +# Install & Uninstall Commands + +## install + +Adds a skill from various sources. + +```bash +skillshare install github.com/user/repo # Discovery mode +skillshare install github.com/user/repo/path/skill # Direct path +skillshare install ~/Downloads/my-skill # Local path +``` + +**Flags:** + +| Flag | Description | +|------|-------------| +| `--name ` | Custom skill name | +| `--force` | Overwrite existing skill | +| `--update` | Update existing (git pull if possible, else reinstall) | + +**`--force` vs `--update`:** +- `--update`: Tries `git pull` first (for git repos without subdir), falls back to reinstall +- `--force`: Always delete and reinstall + +After install, run `skillshare sync` to distribute to targets. + +## uninstall + +Removes a skill from source. + +```bash +skillshare uninstall my-skill # With confirmation +skillshare uninstall my-skill --force # Skip confirmation +``` + +After uninstall, run `skillshare sync` to update targets. diff --git a/skills/skillshare/references/status.md b/skills/skillshare/references/status.md new file mode 100644 index 000000000..6254e9f1c --- /dev/null +++ b/skills/skillshare/references/status.md @@ -0,0 +1,44 @@ +# Status & Inspection Commands + +## status + +Shows source location, targets, and sync state. + +```bash +skillshare status +``` + +**Expected output:** +``` +Source: ~/.config/skillshare/skills (4 skills) +Targets: + claude ✓ synced ~/.claude/skills + codex ✓ synced ~/.codex/skills + cursor ⚠ 1 diff ~/.cursor/skills +``` + +## diff + +Shows differences between source and targets. + +```bash +skillshare diff # All targets +skillshare diff claude # Specific target +``` + +## list + +Lists installed skills. + +```bash +skillshare list # Basic list +skillshare list --verbose # With source and install info +``` + +## doctor + +Checks configuration health and diagnoses issues. + +```bash +skillshare doctor +``` diff --git a/skills/skillshare/references/sync.md b/skills/skillshare/references/sync.md new file mode 100644 index 000000000..c8c6f22f4 --- /dev/null +++ b/skills/skillshare/references/sync.md @@ -0,0 +1,41 @@ +# Sync, Pull & Push Commands + +## sync + +Pushes skills from source to all targets. + +```bash +skillshare sync # Execute sync +skillshare sync --dry-run # Preview only +``` + +## pull + +Brings skills from target(s) to source. + +```bash +skillshare pull claude # Pull from specific target +skillshare pull --all # Pull from all targets +skillshare pull --remote # Pull from git remote + sync all +``` + +## push + +Commits and pushes source to git remote. + +```bash +skillshare push # Default commit message +skillshare push -m "message" # Custom commit message +skillshare push --dry-run # Preview only +``` + +## Workflows + +**Local workflow:** +1. Create skill in any target (e.g., `~/.claude/skills/my-skill/`) +2. `skillshare pull claude` - bring to source +3. `skillshare sync` - distribute to all targets + +**Cross-machine workflow:** +1. Machine A: `skillshare push` - commit and push to remote +2. Machine B: `skillshare pull --remote` - pull from remote + sync diff --git a/skills/skillshare/references/targets.md b/skills/skillshare/references/targets.md new file mode 100644 index 000000000..661ea8304 --- /dev/null +++ b/skills/skillshare/references/targets.md @@ -0,0 +1,33 @@ +# Target Management + +## target + +Manages sync targets. + +```bash +skillshare target list # List all targets +skillshare target claude # Show target info +skillshare target add myapp ~/.myapp/skills # Add custom target +skillshare target remove myapp # Remove target +``` + +## Sync Modes + +```bash +skillshare target claude --mode merge # Individual skill symlinks (default) +skillshare target claude --mode symlink # Entire directory symlinked +``` + +**Mode comparison:** + +| Mode | Behavior | Local Skills | +|------|----------|--------------| +| `merge` | Creates individual symlinks for each skill | Preserved | +| `symlink` | Entire target directory is a symlink | Not possible | + +## Safe Target Removal + +```bash +skillshare target remove # Safe: only removes link +# NOT: rm -rf ~/.target/skills # Dangerous: may delete source +``` diff --git a/run.sh b/skills/skillshare/scripts/run.sh similarity index 97% rename from run.sh rename to skills/skillshare/scripts/run.sh index f2572df50..dc918e8eb 100755 --- a/run.sh +++ b/skills/skillshare/scripts/run.sh @@ -1,6 +1,6 @@ #!/bin/sh # skillshare runner - npx-style execution without installation -# Usage: curl -fsSL https://raw.githubusercontent.com/runkids/skillshare/main/run.sh | sh -s -- [command] [args] +# Usage: curl -fsSL https://raw.githubusercontent.com/runkids/skillshare/main/skills/skillshare/scripts/run.sh | sh -s -- [command] [args] # Or: sh run.sh [command] [args] set -e diff --git a/tests/integration/init_test.go b/tests/integration/init_test.go index de679718e..c2169c26e 100644 --- a/tests/integration/init_test.go +++ b/tests/integration/init_test.go @@ -279,3 +279,272 @@ targets: {} result.AssertSuccess(t) result.AssertOutputContains(t, "already configured") } + +// ============================================ +// Non-interactive flag tests +// ============================================ + +func TestInit_NoCopy_StartsEmpty(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Create existing skills directory + claudeSkillsPath := filepath.Join(sb.Home, ".claude", "skills") + os.MkdirAll(claudeSkillsPath, 0755) + testSkillPath := filepath.Join(claudeSkillsPath, "my-skill") + os.MkdirAll(testSkillPath, 0755) + os.WriteFile(filepath.Join(testSkillPath, "SKILL.md"), []byte("# Test"), 0644) + + // Run init with --no-copy and --no-targets to skip prompts + result := sb.RunCLI("init", "--no-copy", "--no-targets", "--no-git") + + result.AssertSuccess(t) + result.AssertOutputContains(t, "--no-copy") + + // Verify skill was NOT copied (only skillshare skill should exist) + copiedSkillPath := filepath.Join(sb.SourcePath, "my-skill") + if sb.FileExists(copiedSkillPath) { + t.Error("skill should NOT be copied when using --no-copy") + } +} + +func TestInit_CopyFromByName(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Create existing claude skills directory with a skill + claudeSkillsPath := filepath.Join(sb.Home, ".claude", "skills") + os.MkdirAll(claudeSkillsPath, 0755) + testSkillPath := filepath.Join(claudeSkillsPath, "copy-test-skill") + os.MkdirAll(testSkillPath, 0755) + os.WriteFile(filepath.Join(testSkillPath, "SKILL.md"), []byte("# Copy Test"), 0644) + + // Run init with --copy-from claude + result := sb.RunCLI("init", "--copy-from", "claude", "--no-targets", "--no-git") + + result.AssertSuccess(t) + result.AssertOutputContains(t, "matched by name") + + // Verify skill was copied + copiedSkillPath := filepath.Join(sb.SourcePath, "copy-test-skill", "SKILL.md") + if !sb.FileExists(copiedSkillPath) { + t.Error("skill should be copied when using --copy-from claude") + } +} + +func TestInit_CopyFromByPath(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Create custom skills directory + customPath := filepath.Join(sb.Home, "custom-skills") + os.MkdirAll(customPath, 0755) + testSkillPath := filepath.Join(customPath, "path-test-skill") + os.MkdirAll(testSkillPath, 0755) + os.WriteFile(filepath.Join(testSkillPath, "SKILL.md"), []byte("# Path Test"), 0644) + + // Run init with --copy-from as a path + result := sb.RunCLI("init", "--copy-from", customPath, "--no-targets", "--no-git") + + result.AssertSuccess(t) + + // Verify skill was copied + copiedSkillPath := filepath.Join(sb.SourcePath, "path-test-skill", "SKILL.md") + if !sb.FileExists(copiedSkillPath) { + t.Error("skill should be copied when using --copy-from with path") + } +} + +func TestInit_TargetsCSV(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Create both claude and cursor directories + claudeSkillsPath := filepath.Join(sb.Home, ".claude", "skills") + os.MkdirAll(claudeSkillsPath, 0755) + cursorSkillsPath := filepath.Join(sb.Home, ".cursor", "skills") + os.MkdirAll(cursorSkillsPath, 0755) + + // Run init with --targets specifying both + result := sb.RunCLI("init", "--no-copy", "--targets", "claude,cursor", "--no-git") + + result.AssertSuccess(t) + result.AssertOutputContains(t, "Added 2 targets") + + // Verify config has both targets + configContent := sb.ReadFile(sb.ConfigPath) + if !strings.Contains(configContent, "claude:") { + t.Error("config should contain claude target") + } + if !strings.Contains(configContent, "cursor:") { + t.Error("config should contain cursor target") + } +} + +func TestInit_AllTargets(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Create multiple CLI directories + claudeSkillsPath := filepath.Join(sb.Home, ".claude", "skills") + os.MkdirAll(claudeSkillsPath, 0755) + cursorSkillsPath := filepath.Join(sb.Home, ".cursor", "skills") + os.MkdirAll(cursorSkillsPath, 0755) + + // Run init with --all-targets + result := sb.RunCLI("init", "--no-copy", "--all-targets", "--no-git") + + result.AssertSuccess(t) + result.AssertOutputContains(t, "--all-targets") + + // Verify config has targets + configContent := sb.ReadFile(sb.ConfigPath) + if !strings.Contains(configContent, "claude:") || !strings.Contains(configContent, "cursor:") { + t.Errorf("config should contain all detected targets, got: %s", configContent) + } +} + +func TestInit_NoTargets(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Create a CLI directory + claudeSkillsPath := filepath.Join(sb.Home, ".claude", "skills") + os.MkdirAll(claudeSkillsPath, 0755) + + // Run init with --no-targets + result := sb.RunCLI("init", "--no-copy", "--no-targets", "--no-git") + + result.AssertSuccess(t) + result.AssertOutputContains(t, "--no-targets") + + // Verify config has empty targets + configContent := sb.ReadFile(sb.ConfigPath) + if strings.Contains(configContent, "claude:") { + t.Error("config should NOT contain any targets when using --no-targets") + } +} + +func TestInit_NoGit_SkipsGitInit(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Run init with --no-git + result := sb.RunCLI("init", "--no-copy", "--no-targets", "--no-git") + + result.AssertSuccess(t) + result.AssertOutputContains(t, "--no-git") + + // Verify .git was NOT created + gitDir := filepath.Join(sb.SourcePath, ".git") + if sb.FileExists(gitDir) { + t.Error(".git directory should NOT exist when using --no-git") + } +} + +func TestInit_GitFlag_InitializesGit(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Run init with --git + result := sb.RunCLI("init", "--no-copy", "--no-targets", "--git") + + result.AssertSuccess(t) + + // Verify .git was created + gitDir := filepath.Join(sb.SourcePath, ".git") + if !sb.FileExists(gitDir) { + t.Error(".git directory should exist when using --git") + } +} + +func TestInit_MutualExclusion_CopyFromAndNoCopy(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Run init with both --copy-from and --no-copy + result := sb.RunCLI("init", "--copy-from", "claude", "--no-copy") + + result.AssertFailure(t) + result.AssertAnyOutputContains(t, "mutually exclusive") +} + +func TestInit_MutualExclusion_TargetsFlags(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Run init with both --targets and --all-targets + result := sb.RunCLI("init", "--no-copy", "--targets", "claude", "--all-targets", "--no-git") + + result.AssertFailure(t) + result.AssertAnyOutputContains(t, "mutually exclusive") +} + +func TestInit_MutualExclusion_GitFlags(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Run init with both --git and --no-git + result := sb.RunCLI("init", "--no-copy", "--no-targets", "--git", "--no-git") + + result.AssertFailure(t) + result.AssertAnyOutputContains(t, "mutually exclusive") +} + +func TestInit_FullNonInteractive(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + os.Remove(sb.ConfigPath) + + // Create existing skills + claudeSkillsPath := filepath.Join(sb.Home, ".claude", "skills") + os.MkdirAll(claudeSkillsPath, 0755) + testSkillPath := filepath.Join(claudeSkillsPath, "full-test") + os.MkdirAll(testSkillPath, 0755) + os.WriteFile(filepath.Join(testSkillPath, "SKILL.md"), []byte("# Full Test"), 0644) + + // Full non-interactive: copy from claude, all targets, with git + result := sb.RunCLI("init", "--copy-from", "claude", "--all-targets", "--git") + + result.AssertSuccess(t) + result.AssertOutputContains(t, "Initialized successfully") + + // Verify skill was copied + if !sb.FileExists(filepath.Join(sb.SourcePath, "full-test", "SKILL.md")) { + t.Error("skill should be copied") + } + + // Verify git was initialized + if !sb.FileExists(filepath.Join(sb.SourcePath, ".git")) { + t.Error(".git should exist") + } + + // Verify config has target + configContent := sb.ReadFile(sb.ConfigPath) + if !strings.Contains(configContent, "claude:") { + t.Error("config should contain claude target") + } +} diff --git a/tests/integration/install_test.go b/tests/integration/install_test.go index 2ca3e2c61..1e533f572 100644 --- a/tests/integration/install_test.go +++ b/tests/integration/install_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "skillshare/internal/install" "skillshare/internal/testutil" ) @@ -99,14 +100,12 @@ func TestInstall_Force_Overwrites(t *testing.T) { sb := testutil.NewSandbox(t) defer sb.Cleanup() - // Create existing skill in source sb.CreateSkill("existing-skill", map[string]string{"SKILL.md": "# Old Version"}) sb.WriteConfig(`source: ` + sb.SourcePath + ` targets: {} `) - // Create local skill to install localSkillPath := filepath.Join(sb.Root, "existing-skill") os.MkdirAll(localSkillPath, 0755) os.WriteFile(filepath.Join(localSkillPath, "SKILL.md"), []byte("# New Version"), 0644) @@ -116,13 +115,164 @@ targets: {} result.AssertSuccess(t) result.AssertOutputContains(t, "Installed") - // Verify new content content := sb.ReadFile(filepath.Join(sb.SourcePath, "existing-skill", "SKILL.md")) if !strings.Contains(content, "New Version") { t.Error("skill content should be updated") } } +func TestInstall_Force_ByName_UsesMetadata(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + + localSkillPath := filepath.Join(sb.Root, "local-source") + os.MkdirAll(localSkillPath, 0755) + os.WriteFile(filepath.Join(localSkillPath, "SKILL.md"), []byte("# Version 1"), 0644) + + result := sb.RunCLI("install", localSkillPath, "--name", "reinstall-skill") + result.AssertSuccess(t) + + os.WriteFile(filepath.Join(localSkillPath, "SKILL.md"), []byte("# Version 2"), 0644) + + result = sb.RunCLI("install", "reinstall-skill", "--force") + result.AssertSuccess(t) + + content := sb.ReadFile(filepath.Join(sb.SourcePath, "reinstall-skill", "SKILL.md")) + if !strings.Contains(content, "Version 2") { + t.Error("skill should be reinstalled from stored source") + } +} + +func TestInstall_Update_ByName_ReinstallsNonGit(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + + localSkillPath := filepath.Join(sb.Root, "update-source") + os.MkdirAll(localSkillPath, 0755) + os.WriteFile(filepath.Join(localSkillPath, "SKILL.md"), []byte("# Version 1"), 0644) + + result := sb.RunCLI("install", localSkillPath, "--name", "update-skill") + result.AssertSuccess(t) + + // Update source content + os.WriteFile(filepath.Join(localSkillPath, "SKILL.md"), []byte("# Version 2"), 0644) + + // --update should reinstall for non-git sources + result = sb.RunCLI("install", "update-skill", "--update") + result.AssertSuccess(t) + + // Verify updated content + content := sb.ReadFile(filepath.Join(sb.SourcePath, "update-skill", "SKILL.md")) + if !strings.Contains(content, "Version 2") { + t.Error("skill should be reinstalled with updated content") + } +} + +func TestInstall_Update_ByName_GitPull(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + + gitRepoPath := filepath.Join(sb.Root, "git-skill") + os.MkdirAll(gitRepoPath, 0755) + sb.WriteFile(filepath.Join(gitRepoPath, "SKILL.md"), "# Version 1") + + cmd := exec.Command("git", "init") + cmd.Dir = gitRepoPath + if err := cmd.Run(); err != nil { + t.Skip("git not available, skipping git test") + } + + cmd = exec.Command("git", "config", "user.email", "test@test.com") + cmd.Dir = gitRepoPath + cmd.Run() + + cmd = exec.Command("git", "config", "user.name", "Test") + cmd.Dir = gitRepoPath + cmd.Run() + + cmd = exec.Command("git", "add", ".") + cmd.Dir = gitRepoPath + cmd.Run() + + cmd = exec.Command("git", "commit", "-m", "Initial commit") + cmd.Dir = gitRepoPath + cmd.Run() + + source, err := install.ParseSource("file://" + gitRepoPath) + if err != nil { + t.Fatalf("failed to parse source: %v", err) + } + + result, err := install.Install(source, filepath.Join(sb.SourcePath, "git-skill"), install.InstallOptions{Force: true}) + if err != nil { + t.Fatalf("failed to install from git source: %v", err) + } + if result.Action != "cloned" { + t.Fatalf("expected install action cloned, got %s", result.Action) + } + + metaPath := filepath.Join(sb.SourcePath, "git-skill", ".skillshare-meta.json") + metaContent := sb.ReadFile(metaPath) + if !strings.Contains(metaContent, "\"source\": \"file://") { + t.Fatalf("expected metadata source to use file:// clone URL") + } + + content := sb.ReadFile(filepath.Join(sb.SourcePath, "git-skill", "SKILL.md")) + if !strings.Contains(content, "Version 1") { + t.Fatalf("expected installed skill to contain Version 1") + } + + sb.WriteFile(filepath.Join(gitRepoPath, "SKILL.md"), "# Version 2") + + cmd = exec.Command("git", "add", ".") + cmd.Dir = gitRepoPath + cmd.Run() + + cmd = exec.Command("git", "commit", "-m", "Update skill") + cmd.Dir = gitRepoPath + cmd.Run() + + updateResult := sb.RunCLI("install", "git-skill", "--update") + updateResult.AssertSuccess(t) + updateResult.AssertAnyOutputContains(t, "Installed") + + metaContent = sb.ReadFile(metaPath) + if !strings.Contains(metaContent, "\"source\": \"file://") { + t.Fatalf("expected metadata source to use file:// clone URL") + } + + content = sb.ReadFile(filepath.Join(sb.SourcePath, "git-skill", "SKILL.md")) + if !strings.Contains(content, "Version 2") { + t.Fatalf("skill should be updated via git pull") + } +} + +func TestInstall_Update_ByName_NotInstalled_Errors(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + + result := sb.RunCLI("install", "missing-skill", "--update") + + result.AssertFailure(t) + result.AssertAnyOutputContains(t, "invalid source") +} + func TestInstall_DryRun_NoChanges(t *testing.T) { sb := testutil.NewSandbox(t) defer sb.Cleanup() diff --git a/tests/integration/update_test.go b/tests/integration/upgrade_test.go similarity index 74% rename from tests/integration/update_test.go rename to tests/integration/upgrade_test.go index 0119fa27e..965a5d5f3 100644 --- a/tests/integration/update_test.go +++ b/tests/integration/upgrade_test.go @@ -8,20 +8,20 @@ import ( "skillshare/internal/testutil" ) -func TestUpdate_NoConfig_ReturnsError(t *testing.T) { +func TestUpgrade_NoConfig_ReturnsError(t *testing.T) { sb := testutil.NewSandbox(t) defer sb.Cleanup() // Remove config os.Remove(sb.ConfigPath) - result := sb.RunCLI("update") + result := sb.RunCLI("upgrade") result.AssertFailure(t) result.AssertAnyOutputContains(t, "config not found") } -func TestUpdate_DryRun_DoesNotModify(t *testing.T) { +func TestUpgrade_DryRun_DoesNotModify(t *testing.T) { sb := testutil.NewSandbox(t) defer sb.Cleanup() @@ -36,10 +36,10 @@ targets: {} os.MkdirAll(filepath.Dir(skillPath), 0755) os.WriteFile(skillPath, []byte("# Old Content"), 0644) - result := sb.RunCLI("update", "--dry-run") + result := sb.RunCLI("upgrade", "--dry-run") result.AssertSuccess(t) - result.AssertOutputContains(t, "Would update") + result.AssertOutputContains(t, "Would upgrade") // Verify file was not changed content, _ := os.ReadFile(skillPath) @@ -48,7 +48,7 @@ targets: {} } } -func TestUpdate_Force_SkipsConfirmation(t *testing.T) { +func TestUpgrade_Force_SkipsConfirmation(t *testing.T) { sb := testutil.NewSandbox(t) defer sb.Cleanup() @@ -63,19 +63,19 @@ targets: {} os.MkdirAll(filepath.Dir(skillPath), 0755) os.WriteFile(skillPath, []byte("# Old Content"), 0644) - // Force update (will fail to download but should attempt) - result := sb.RunCLI("update", "--force") + // Force upgrade skill only (don't upgrade CLI during tests!) + result := sb.RunCLI("upgrade", "--skill", "--force") // Should either succeed (if network available) or fail with download error // But should NOT ask for confirmation if result.ExitCode == 0 { - result.AssertOutputContains(t, "Updated") + result.AssertOutputContains(t, "Upgraded") } else { result.AssertAnyOutputContains(t, "download") } } -func TestUpdate_NoExistingSkill_CreatesNew(t *testing.T) { +func TestUpgrade_NoExistingSkill_CreatesNew(t *testing.T) { sb := testutil.NewSandbox(t) defer sb.Cleanup() @@ -89,8 +89,8 @@ targets: {} // Ensure skill doesn't exist os.RemoveAll(filepath.Dir(skillPath)) - // Update (will attempt download) - result := sb.RunCLI("update") + // Upgrade skill only (don't upgrade CLI during tests!) + result := sb.RunCLI("upgrade", "--skill") // Should either succeed or fail with download error // But should create directory @@ -101,7 +101,7 @@ targets: {} } } -func TestUpdate_ShowsSourceURL(t *testing.T) { +func TestUpgrade_ShowsSourceURL(t *testing.T) { sb := testutil.NewSandbox(t) defer sb.Cleanup() @@ -110,7 +110,7 @@ func TestUpdate_ShowsSourceURL(t *testing.T) { targets: {} `) - result := sb.RunCLI("update", "--dry-run") + result := sb.RunCLI("upgrade", "--skill", "--dry-run") result.AssertSuccess(t) // URL is raw.githubusercontent.com