diff --git a/cmd/skillshare/install_handlers.go b/cmd/skillshare/install_handlers.go index 415624b5c..2df82e72f 100644 --- a/cmd/skillshare/install_handlers.go +++ b/cmd/skillshare/install_handlers.go @@ -218,6 +218,7 @@ func handleGitInstall(source *install.Source, cfg *config.Config, opts install.I logSummary.InstalledSkills = append(logSummary.InstalledSkills, skill.Name) logSummary.SkillCount = len(logSummary.InstalledSkills) } + installDiscoveredAgents(discovery, cfg, opts) return logSummary, nil } @@ -234,7 +235,11 @@ func handleGitInstall(source *install.Source, cfg *config.Config, opts install.I return handleAgentInstall(discovery, agentsDir, opts, logSummary) } - ui.StepEnd("Found", fmt.Sprintf("%d skill(s)", len(discovery.Skills))) + foundMsg := fmt.Sprintf("%d skill(s)", len(discovery.Skills)) + if len(discovery.Agents) > 0 { + foundMsg += fmt.Sprintf(", %d agent(s)", len(discovery.Agents)) + } + ui.StepEnd("Found", foundMsg) // Apply --exclude early so excluded skills never appear in prompts if len(opts.Exclude) > 0 { @@ -302,6 +307,7 @@ func handleGitInstall(source *install.Source, cfg *config.Config, opts install.I logSummary.InstalledSkills = append(logSummary.InstalledSkills, skill.Name) logSummary.SkillCount = len(logSummary.InstalledSkills) } + installDiscoveredAgents(discovery, cfg, opts) return logSummary, nil } @@ -326,6 +332,7 @@ func handleGitInstall(source *install.Source, cfg *config.Config, opts install.I logSummary.InstalledSkills = append(logSummary.InstalledSkills, batchSummary.InstalledSkills...) logSummary.FailedSkills = append(logSummary.FailedSkills, batchSummary.FailedSkills...) logSummary.SkillCount = len(logSummary.InstalledSkills) + installDiscoveredAgents(discovery, cfg, opts) return logSummary, nil } @@ -361,6 +368,7 @@ func handleGitInstall(source *install.Source, cfg *config.Config, opts install.I logSummary.InstalledSkills = append(logSummary.InstalledSkills, batchSummary.InstalledSkills...) logSummary.FailedSkills = append(logSummary.FailedSkills, batchSummary.FailedSkills...) logSummary.SkillCount = len(logSummary.InstalledSkills) + installDiscoveredAgents(discovery, cfg, opts) return logSummary, nil } @@ -1108,6 +1116,37 @@ func handleAgentInstall(discovery *install.DiscoveryResult, agentsDir string, op return logSummary, nil } +// installDiscoveredAgents installs agents from a mixed repo after skills have been installed. +func installDiscoveredAgents(discovery *install.DiscoveryResult, cfg *config.Config, opts install.InstallOptions) { + if len(discovery.Agents) == 0 { + return + } + if opts.Kind == "skill" { + return + } + + agentsDir := cfg.EffectiveAgentsSource() + fmt.Println() + ui.Header("Installing agents") + + for _, agent := range discovery.Agents { + spinner := ui.StartSpinner(fmt.Sprintf("Installing agent %s...", agent.Name)) + result, err := install.InstallAgentFromDiscovery(discovery, agent, agentsDir, opts) + spinner.Stop() + if err != nil { + ui.ErrorMsg("Failed to install agent %s: %v", agent.Name, err) + continue + } + if result.Action == "skipped" { + ui.StepSkip(agent.Name, strings.Join(result.Warnings, "; ")) + } else if opts.DryRun { + ui.Warning("[dry-run] Would install agent: %s", agent.Name) + } else { + ui.SuccessMsg("Installed agent: %s", agent.Name) + } + } +} + // agentInstallResult tracks the outcome of a single agent install. type agentInstallResult struct { agent install.AgentInfo diff --git a/tests/integration/install_agent_test.go b/tests/integration/install_agent_test.go index fe964b0e4..d471f9f83 100644 --- a/tests/integration/install_agent_test.go +++ b/tests/integration/install_agent_test.go @@ -128,3 +128,44 @@ targets: {} result := sb.RunCLI("uninstall", "-g", "agents", "nonexistent") result.AssertOutputNotContains(t, "unknown option") } + +func TestInstall_MixedRepo_InstallsAgentsToAgentsDir(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + sb.WriteConfig(`source: ` + sb.SourcePath + ` +targets: {} +`) + + // Create a git repo with both skills and agents + repoDir := filepath.Join(sb.Home, "mixed-repo") + os.MkdirAll(filepath.Join(repoDir, "skills", "my-skill"), 0755) + os.WriteFile(filepath.Join(repoDir, "skills", "my-skill", "SKILL.md"), + []byte("---\nname: my-skill\n---\n# My Skill"), 0644) + os.MkdirAll(filepath.Join(repoDir, "agents"), 0755) + os.WriteFile(filepath.Join(repoDir, "agents", "my-agent.md"), + []byte("# My Agent"), 0644) + initGitRepo(t, repoDir) + + result := sb.RunCLI("install", "file://"+repoDir, "--yes") + result.AssertSuccess(t) + + // Skill should be in skills source + skillPath := filepath.Join(sb.SourcePath, "my-skill") + if !sb.FileExists(filepath.Join(skillPath, "SKILL.md")) { + t.Error("skill should be installed to skills source dir") + } + + // Agent should be in agents source (NOT skills source) + agentsDir := filepath.Join(filepath.Dir(sb.SourcePath), "agents") + agentPath := filepath.Join(agentsDir, "my-agent.md") + if !sb.FileExists(agentPath) { + t.Errorf("agent should be installed to agents dir (%s), not skills dir", agentsDir) + } + + // Agent should NOT be in skills source + wrongPath := filepath.Join(sb.SourcePath, "my-agent.md") + if sb.FileExists(wrongPath) { + t.Error("agent should NOT be in skills source dir") + } +}