mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
feat(agents): implement project-mode agent support for all commands
Remove all "not yet supported in project mode" errors. Every command that supports agents in global mode now also supports project mode: - status -p agents: shows project agent source + per-target status - status -p all: shows both skills and agents - check -p agents: checks agent status from .skillshare/agents/ - diff -p agents: computes agent diffs (missing/orphan per target) - diff agents (global): also now fully implemented via diffGlobalAgents - collect -p agents: collects local agents from project targets - audit -p agents: scans .skillshare/agents/ for security patterns New file: diff_agents.go — shared agent diff logic for both modes (computeAgentDiff, diffProjectAgents, diffGlobalAgents). 11 new integration tests covering all 5 commands in project mode. Total agent tests: 56.
This commit is contained in:
@@ -183,14 +183,15 @@ func cmdAudit(args []string) error {
|
||||
cfgPath = config.ConfigPath()
|
||||
}
|
||||
} else if mode == modeProject {
|
||||
if kind == kindAgents {
|
||||
return fmt.Errorf("audit agents is not yet supported in project mode")
|
||||
}
|
||||
rt, err := loadProjectRuntime(cwd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
sourcePath = rt.sourcePath
|
||||
if kind == kindAgents {
|
||||
sourcePath = rt.agentsSourcePath
|
||||
} else {
|
||||
sourcePath = rt.sourcePath
|
||||
}
|
||||
projectRoot = cwd
|
||||
defaultThreshold = rt.config.Audit.BlockThreshold
|
||||
configProfile = rt.config.Audit.Profile
|
||||
|
||||
+29
-1
@@ -192,7 +192,35 @@ func cmdCheck(args []string) error {
|
||||
if mode == modeProject {
|
||||
cfgPath = config.ProjectConfigPath(cwd)
|
||||
if kind == kindAgents {
|
||||
return fmt.Errorf("check agents is not yet supported in project mode")
|
||||
agentsDir := filepath.Join(cwd, ".skillshare", "agents")
|
||||
agentResults := check.CheckAgents(agentsDir)
|
||||
if opts.json {
|
||||
out, _ := json.MarshalIndent(agentResults, "", " ")
|
||||
fmt.Println(string(out))
|
||||
} else {
|
||||
ui.Header(ui.WithModeLabel("Checking agents"))
|
||||
ui.StepStart("Agents source", agentsDir)
|
||||
if len(agentResults) == 0 {
|
||||
ui.Info("No agents found")
|
||||
} else {
|
||||
fmt.Println()
|
||||
for _, r := range agentResults {
|
||||
switch r.Status {
|
||||
case "up_to_date":
|
||||
ui.ListItem("success", r.Name, "up to date")
|
||||
case "drifted":
|
||||
ui.ListItem("warning", r.Name, r.Message)
|
||||
case "local":
|
||||
ui.ListItem("info", r.Name, "local agent")
|
||||
case "error":
|
||||
ui.ListItem("error", r.Name, r.Message)
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println()
|
||||
}
|
||||
logCheckOp(cfgPath, 0, len(agentResults), 0, 0, scope, start, nil)
|
||||
return nil
|
||||
}
|
||||
cmdErr := cmdCheckProject(cwd, opts)
|
||||
logCheckOp(cfgPath, 0, 0, 0, 0, scope, start, cmdErr)
|
||||
|
||||
@@ -87,7 +87,7 @@ func cmdCollect(args []string) error {
|
||||
|
||||
if mode == modeProject {
|
||||
if kind == kindAgents {
|
||||
return fmt.Errorf("collect agents is not yet supported in project mode")
|
||||
return cmdCollectProjectAgents(cwd)
|
||||
}
|
||||
err := cmdCollectProject(rest, cwd)
|
||||
logCollectOp(config.ProjectConfigPath(cwd), start, err)
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"skillshare/internal/config"
|
||||
@@ -63,3 +64,50 @@ func cmdCollectAgents(cfg *config.Config, dryRun, jsonOutput bool, start time.Ti
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// cmdCollectProjectAgents collects non-symlinked agent .md files from project targets.
|
||||
func cmdCollectProjectAgents(projectRoot string) error {
|
||||
agentsSource := filepath.Join(projectRoot, ".skillshare", "agents")
|
||||
if err := os.MkdirAll(agentsSource, 0755); err != nil {
|
||||
return fmt.Errorf("cannot create project agents directory: %w", err)
|
||||
}
|
||||
|
||||
projCfg, err := config.LoadProject(projectRoot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot load project config: %w", err)
|
||||
}
|
||||
|
||||
builtinAgents := config.ProjectAgentTargets()
|
||||
var allCollected []string
|
||||
|
||||
ui.Header(ui.WithModeLabel("Collect agents"))
|
||||
|
||||
for _, entry := range projCfg.Targets {
|
||||
agentPath := resolveProjectAgentTargetPath(entry, builtinAgents, projectRoot)
|
||||
if agentPath == "" {
|
||||
continue
|
||||
}
|
||||
if _, statErr := os.Stat(agentPath); statErr != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
collected, collectErr := sync.CollectAgents(agentPath, agentsSource, false, os.Stdout)
|
||||
if collectErr != nil {
|
||||
ui.Warning("%s: collect failed: %v", entry.Name, collectErr)
|
||||
continue
|
||||
}
|
||||
if len(collected) > 0 {
|
||||
allCollected = append(allCollected, collected...)
|
||||
ui.Success("%s: collected %d agent(s)", entry.Name, len(collected))
|
||||
}
|
||||
}
|
||||
|
||||
if len(allCollected) == 0 {
|
||||
ui.Info("No local agents found to collect")
|
||||
} else {
|
||||
fmt.Println()
|
||||
ui.Info("Collected %d agent(s) to %s", len(allCollected), agentsSource)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -368,6 +368,11 @@ func cmdDiffGlobal(targetName string, kind resourceKindFilter, opts diffRenderOp
|
||||
return err
|
||||
}
|
||||
|
||||
// Agent-only diff
|
||||
if kind == kindAgents {
|
||||
return diffGlobalAgents(cfg, targetName, opts, start)
|
||||
}
|
||||
|
||||
var spinner *ui.Spinner
|
||||
if !opts.jsonOutput {
|
||||
spinner = ui.StartSpinner("Discovering skills")
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/resource"
|
||||
"skillshare/internal/ui"
|
||||
)
|
||||
|
||||
// diffProjectAgents computes agent diffs for project mode.
|
||||
func diffProjectAgents(root, targetName string, opts diffRenderOpts, start time.Time) error {
|
||||
if !projectConfigExists(root) {
|
||||
if err := performProjectInit(root, projectInitOptions{}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
rt, err := loadProjectRuntime(root)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
agentsSource := rt.agentsSourcePath
|
||||
agents, _ := resource.AgentKind{}.Discover(agentsSource)
|
||||
|
||||
builtinAgents := config.ProjectAgentTargets()
|
||||
var results []targetDiffResult
|
||||
|
||||
for _, entry := range rt.config.Targets {
|
||||
if targetName != "" && entry.Name != targetName {
|
||||
continue
|
||||
}
|
||||
agentPath := resolveProjectAgentTargetPath(entry, builtinAgents, root)
|
||||
if agentPath == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
r := computeAgentDiff(entry.Name, agentPath, agents)
|
||||
results = append(results, r)
|
||||
}
|
||||
|
||||
if opts.jsonOutput {
|
||||
return diffOutputJSON(results, start)
|
||||
}
|
||||
|
||||
if len(results) == 0 {
|
||||
ui.Info("No agent-capable targets found")
|
||||
return nil
|
||||
}
|
||||
|
||||
renderGroupedDiffs(results, opts)
|
||||
return nil
|
||||
}
|
||||
|
||||
// diffGlobalAgents computes agent diffs for global mode.
|
||||
func diffGlobalAgents(cfg *config.Config, targetName string, opts diffRenderOpts, start time.Time) error {
|
||||
agentsSource := cfg.EffectiveAgentsSource()
|
||||
agents, _ := resource.AgentKind{}.Discover(agentsSource)
|
||||
|
||||
builtinAgents := config.DefaultAgentTargets()
|
||||
var results []targetDiffResult
|
||||
|
||||
for name := range cfg.Targets {
|
||||
if targetName != "" && name != targetName {
|
||||
continue
|
||||
}
|
||||
agentPath := resolveAgentTargetPath(cfg.Targets[name], builtinAgents, name)
|
||||
if agentPath == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
r := computeAgentDiff(name, agentPath, agents)
|
||||
results = append(results, r)
|
||||
}
|
||||
|
||||
if opts.jsonOutput {
|
||||
return diffOutputJSON(results, start)
|
||||
}
|
||||
|
||||
if len(results) == 0 {
|
||||
ui.Info("No agent-capable targets found")
|
||||
return nil
|
||||
}
|
||||
|
||||
renderGroupedDiffs(results, opts)
|
||||
return nil
|
||||
}
|
||||
|
||||
// computeAgentDiff compares source agents against a target directory.
|
||||
func computeAgentDiff(targetName, targetDir string, agents []resource.DiscoveredResource) targetDiffResult {
|
||||
r := targetDiffResult{
|
||||
name: targetName,
|
||||
mode: "merge",
|
||||
synced: true,
|
||||
}
|
||||
|
||||
// Build map of expected agents
|
||||
expected := make(map[string]resource.DiscoveredResource, len(agents))
|
||||
for _, a := range agents {
|
||||
expected[a.FlatName] = a
|
||||
}
|
||||
|
||||
// Check what exists in target
|
||||
existing := make(map[string]bool)
|
||||
if entries, err := os.ReadDir(targetDir); err == nil {
|
||||
for _, e := range entries {
|
||||
if e.IsDir() || !strings.HasSuffix(strings.ToLower(e.Name()), ".md") {
|
||||
continue
|
||||
}
|
||||
existing[e.Name()] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Missing in target (need sync)
|
||||
for flatName := range expected {
|
||||
if !existing[flatName] {
|
||||
r.items = append(r.items, copyDiffEntry{
|
||||
action: "add",
|
||||
name: flatName,
|
||||
kind: "agent",
|
||||
reason: "not in target",
|
||||
isSync: true,
|
||||
})
|
||||
r.synced = false
|
||||
r.syncCount++
|
||||
}
|
||||
}
|
||||
|
||||
// Extra in target (orphans)
|
||||
for name := range existing {
|
||||
if _, ok := expected[name]; !ok {
|
||||
fullPath := filepath.Join(targetDir, name)
|
||||
fi, _ := os.Lstat(fullPath)
|
||||
if fi != nil && fi.Mode()&os.ModeSymlink != 0 {
|
||||
r.items = append(r.items, copyDiffEntry{
|
||||
action: "remove",
|
||||
name: name,
|
||||
kind: "agent",
|
||||
reason: "orphan symlink",
|
||||
isSync: true,
|
||||
})
|
||||
r.synced = false
|
||||
} else {
|
||||
r.items = append(r.items, copyDiffEntry{
|
||||
action: "local",
|
||||
name: name,
|
||||
kind: "agent",
|
||||
reason: "local file",
|
||||
})
|
||||
r.localCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func cmdDiffProject(root, targetName string, kind resourceKindFilter, opts diffRenderOpts, start time.Time) error {
|
||||
if kind == kindAgents {
|
||||
return fmt.Errorf("diff agents is not yet supported in project mode")
|
||||
return diffProjectAgents(root, targetName, opts, start)
|
||||
}
|
||||
if !projectConfigExists(root) {
|
||||
if err := performProjectInit(root, projectInitOptions{}); err != nil {
|
||||
|
||||
@@ -103,14 +103,10 @@ func cmdStatus(args []string) error {
|
||||
return fmt.Errorf("unexpected arguments: %v", rest)
|
||||
}
|
||||
}
|
||||
if kind == kindAgents {
|
||||
// Agent-only project status is not yet implemented
|
||||
return fmt.Errorf("status agents is not yet supported in project mode")
|
||||
}
|
||||
if jsonOutput {
|
||||
return cmdStatusProjectJSON(cwd)
|
||||
return cmdStatusProjectJSON(cwd, kind)
|
||||
}
|
||||
return cmdStatusProject(cwd)
|
||||
return cmdStatusProject(cwd, kind)
|
||||
}
|
||||
|
||||
cfg, err := config.Load()
|
||||
|
||||
@@ -9,12 +9,13 @@ import (
|
||||
"skillshare/internal/audit"
|
||||
"skillshare/internal/config"
|
||||
"skillshare/internal/git"
|
||||
"skillshare/internal/resource"
|
||||
"skillshare/internal/skillignore"
|
||||
"skillshare/internal/sync"
|
||||
"skillshare/internal/ui"
|
||||
)
|
||||
|
||||
func cmdStatusProject(root string) error {
|
||||
func cmdStatusProject(root string, kind resourceKindFilter) error {
|
||||
if !projectConfigExists(root) {
|
||||
if err := performProjectInit(root, projectInitOptions{}); err != nil {
|
||||
return err
|
||||
@@ -26,34 +27,40 @@ func cmdStatusProject(root string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
sp := ui.StartSpinner("Discovering skills...")
|
||||
discovered, stats, discoverErr := sync.DiscoverSourceSkillsWithStats(runtime.sourcePath)
|
||||
if discoverErr != nil {
|
||||
discovered = nil
|
||||
}
|
||||
trackedRepos := extractTrackedRepos(discovered)
|
||||
sp.Stop()
|
||||
if kind.IncludesSkills() {
|
||||
sp := ui.StartSpinner("Discovering skills...")
|
||||
discovered, stats, discoverErr := sync.DiscoverSourceSkillsWithStats(runtime.sourcePath)
|
||||
if discoverErr != nil {
|
||||
discovered = nil
|
||||
}
|
||||
trackedRepos := extractTrackedRepos(discovered)
|
||||
sp.Stop()
|
||||
|
||||
printProjectSourceStatus(runtime.sourcePath, len(discovered), stats)
|
||||
printProjectTrackedReposStatus(runtime.sourcePath, discovered, trackedRepos)
|
||||
if err := printProjectTargetsStatus(runtime, discovered); err != nil {
|
||||
return err
|
||||
printProjectSourceStatus(runtime.sourcePath, len(discovered), stats)
|
||||
printProjectTrackedReposStatus(runtime.sourcePath, discovered, trackedRepos)
|
||||
if err := printProjectTargetsStatus(runtime, discovered); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Extras
|
||||
if len(runtime.config.Extras) > 0 {
|
||||
ui.Header("Extras (project)")
|
||||
printExtrasStatus(runtime.config.Extras, func(extra config.ExtraConfig) string {
|
||||
return config.ExtrasSourceDirProject(root, extra.Name)
|
||||
})
|
||||
}
|
||||
|
||||
printAuditStatus(runtime.config.Audit)
|
||||
}
|
||||
|
||||
// Extras
|
||||
if len(runtime.config.Extras) > 0 {
|
||||
ui.Header("Extras (project)")
|
||||
printExtrasStatus(runtime.config.Extras, func(extra config.ExtraConfig) string {
|
||||
return config.ExtrasSourceDirProject(root, extra.Name)
|
||||
})
|
||||
if kind.IncludesAgents() {
|
||||
printProjectAgentStatus(runtime)
|
||||
}
|
||||
|
||||
printAuditStatus(runtime.config.Audit)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func cmdStatusProjectJSON(root string) error {
|
||||
func cmdStatusProjectJSON(root string, kind resourceKindFilter) error {
|
||||
if !projectConfigExists(root) {
|
||||
if err := performProjectInit(root, projectInitOptions{}); err != nil {
|
||||
return writeJSONError(err)
|
||||
@@ -65,62 +72,144 @@ func cmdStatusProjectJSON(root string) error {
|
||||
return writeJSONError(err)
|
||||
}
|
||||
|
||||
discovered, stats, _ := sync.DiscoverSourceSkillsWithStats(runtime.sourcePath)
|
||||
trackedRepos := extractTrackedRepos(discovered)
|
||||
|
||||
output := statusJSONOutput{
|
||||
Source: statusJSONSource{
|
||||
Version: version,
|
||||
}
|
||||
|
||||
if kind.IncludesSkills() {
|
||||
discovered, stats, _ := sync.DiscoverSourceSkillsWithStats(runtime.sourcePath)
|
||||
trackedRepos := extractTrackedRepos(discovered)
|
||||
|
||||
output.Source = statusJSONSource{
|
||||
Path: runtime.sourcePath,
|
||||
Exists: dirExists(runtime.sourcePath),
|
||||
Skillignore: buildSkillignoreJSON(stats),
|
||||
},
|
||||
SkillCount: len(discovered),
|
||||
Version: version,
|
||||
}
|
||||
|
||||
// Tracked repos (parallel dirty checks)
|
||||
output.TrackedRepos = buildTrackedRepoJSON(runtime.sourcePath, trackedRepos, discovered)
|
||||
|
||||
// Targets
|
||||
for _, entry := range runtime.config.Targets {
|
||||
target, ok := runtime.targets[entry.Name]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
sc := target.SkillsConfig()
|
||||
mode := sc.Mode
|
||||
if mode == "" {
|
||||
mode = "merge"
|
||||
output.SkillCount = len(discovered)
|
||||
output.TrackedRepos = buildTrackedRepoJSON(runtime.sourcePath, trackedRepos, discovered)
|
||||
|
||||
for _, entry := range runtime.config.Targets {
|
||||
target, ok := runtime.targets[entry.Name]
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
sc := target.SkillsConfig()
|
||||
mode := sc.Mode
|
||||
if mode == "" {
|
||||
mode = "merge"
|
||||
}
|
||||
res := getTargetStatusDetail(target, runtime.sourcePath, mode)
|
||||
output.Targets = append(output.Targets, statusJSONTarget{
|
||||
Name: entry.Name,
|
||||
Path: sc.Path,
|
||||
Mode: mode,
|
||||
Status: res.statusStr,
|
||||
SyncedCount: res.syncedCount,
|
||||
Include: sc.Include,
|
||||
Exclude: sc.Exclude,
|
||||
})
|
||||
}
|
||||
res := getTargetStatusDetail(target, runtime.sourcePath, mode)
|
||||
output.Targets = append(output.Targets, statusJSONTarget{
|
||||
Name: entry.Name,
|
||||
Path: sc.Path,
|
||||
Mode: mode,
|
||||
Status: res.statusStr,
|
||||
SyncedCount: res.syncedCount,
|
||||
Include: sc.Include,
|
||||
Exclude: sc.Exclude,
|
||||
|
||||
policy := audit.ResolvePolicy(audit.PolicyInputs{
|
||||
ConfigProfile: runtime.config.Audit.Profile,
|
||||
ConfigThreshold: runtime.config.Audit.BlockThreshold,
|
||||
ConfigDedupe: runtime.config.Audit.DedupeMode,
|
||||
ConfigAnalyzers: runtime.config.Audit.EnabledAnalyzers,
|
||||
})
|
||||
output.Audit = statusJSONAudit{
|
||||
Profile: string(policy.Profile),
|
||||
Threshold: policy.Threshold,
|
||||
Dedupe: string(policy.DedupeMode),
|
||||
Analyzers: policy.EffectiveAnalyzers(),
|
||||
}
|
||||
}
|
||||
|
||||
// Audit
|
||||
policy := audit.ResolvePolicy(audit.PolicyInputs{
|
||||
ConfigProfile: runtime.config.Audit.Profile,
|
||||
ConfigThreshold: runtime.config.Audit.BlockThreshold,
|
||||
ConfigDedupe: runtime.config.Audit.DedupeMode,
|
||||
ConfigAnalyzers: runtime.config.Audit.EnabledAnalyzers,
|
||||
})
|
||||
output.Audit = statusJSONAudit{
|
||||
Profile: string(policy.Profile),
|
||||
Threshold: policy.Threshold,
|
||||
Dedupe: string(policy.DedupeMode),
|
||||
Analyzers: policy.EffectiveAnalyzers(),
|
||||
if kind.IncludesAgents() {
|
||||
output.Agents = buildProjectAgentStatusJSON(runtime)
|
||||
}
|
||||
|
||||
return writeJSON(&output)
|
||||
}
|
||||
|
||||
// printProjectAgentStatus prints agent status for project mode (text).
|
||||
func printProjectAgentStatus(rt *projectRuntime) {
|
||||
ui.Header("Agents (project)")
|
||||
|
||||
exists := dirExists(rt.agentsSourcePath)
|
||||
if !exists {
|
||||
ui.Info("Source: .skillshare/agents/ (not created)")
|
||||
return
|
||||
}
|
||||
|
||||
agents, _ := resource.AgentKind{}.Discover(rt.agentsSourcePath)
|
||||
ui.Info("Source: .skillshare/agents/ (%d agents)", len(agents))
|
||||
|
||||
builtinAgents := config.ProjectAgentTargets()
|
||||
for _, entry := range rt.config.Targets {
|
||||
agentPath := resolveProjectAgentTargetPath(entry, builtinAgents, rt.root)
|
||||
if agentPath == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
linked := countLinkedAgents(agentPath)
|
||||
driftLabel := ""
|
||||
if linked != len(agents) && len(agents) > 0 {
|
||||
driftLabel = ui.Yellow + " (drift)" + ui.Reset
|
||||
}
|
||||
ui.Info(" %s: %s (%d/%d linked)%s", entry.Name, agentPath, linked, len(agents), driftLabel)
|
||||
}
|
||||
}
|
||||
|
||||
// buildProjectAgentStatusJSON builds the agents section for project status --json.
|
||||
func buildProjectAgentStatusJSON(rt *projectRuntime) *statusJSONAgents {
|
||||
exists := dirExists(rt.agentsSourcePath)
|
||||
result := &statusJSONAgents{
|
||||
Source: rt.agentsSourcePath,
|
||||
Exists: exists,
|
||||
}
|
||||
|
||||
if !exists {
|
||||
return result
|
||||
}
|
||||
|
||||
agents, _ := resource.AgentKind{}.Discover(rt.agentsSourcePath)
|
||||
result.Count = len(agents)
|
||||
|
||||
builtinAgents := config.ProjectAgentTargets()
|
||||
for _, entry := range rt.config.Targets {
|
||||
agentPath := resolveProjectAgentTargetPath(entry, builtinAgents, rt.root)
|
||||
if agentPath == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
linked := countLinkedAgents(agentPath)
|
||||
result.Targets = append(result.Targets, statusJSONAgentTarget{
|
||||
Name: entry.Name,
|
||||
Path: agentPath,
|
||||
Expected: len(agents),
|
||||
Linked: linked,
|
||||
Drift: linked != len(agents) && len(agents) > 0,
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// resolveProjectAgentTargetPath resolves the agent path for a project target entry.
|
||||
func resolveProjectAgentTargetPath(entry config.ProjectTargetEntry, builtinAgents map[string]config.TargetConfig, projectRoot string) string {
|
||||
ac := entry.AgentsConfig()
|
||||
if ac.Path != "" {
|
||||
if filepath.IsAbs(ac.Path) {
|
||||
return config.ExpandPath(ac.Path)
|
||||
}
|
||||
return filepath.Join(projectRoot, ac.Path)
|
||||
}
|
||||
if builtin, ok := builtinAgents[entry.Name]; ok {
|
||||
return config.ExpandPath(builtin.Path)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func printProjectSourceStatus(sourcePath string, skillCount int, stats *skillignore.IgnoreStats) {
|
||||
ui.Header("Source (project)")
|
||||
info, err := os.Stat(sourcePath)
|
||||
|
||||
@@ -0,0 +1,206 @@
|
||||
//go:build !online
|
||||
|
||||
package integration
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"skillshare/internal/testutil"
|
||||
)
|
||||
|
||||
// setupProjectWithAgents creates a project directory with skills, agents, and config.
|
||||
// Returns the project root path.
|
||||
func setupProjectWithAgents(t *testing.T, sb *testutil.Sandbox) string {
|
||||
t.Helper()
|
||||
|
||||
projectDir := filepath.Join(sb.Root, "myproject")
|
||||
skillsDir := filepath.Join(projectDir, ".skillshare", "skills")
|
||||
agentsDir := filepath.Join(projectDir, ".skillshare", "agents")
|
||||
os.MkdirAll(skillsDir, 0755)
|
||||
os.MkdirAll(agentsDir, 0755)
|
||||
|
||||
// Create a skill
|
||||
skillDir := filepath.Join(skillsDir, "my-skill")
|
||||
os.MkdirAll(skillDir, 0755)
|
||||
os.WriteFile(filepath.Join(skillDir, "SKILL.md"), []byte("---\nname: my-skill\n---\n# Content"), 0644)
|
||||
|
||||
// Create an agent
|
||||
os.WriteFile(filepath.Join(agentsDir, "tutor.md"), []byte("# Tutor agent"), 0644)
|
||||
|
||||
// Write project config with a target that has agent path
|
||||
claudeAgents := filepath.Join(projectDir, ".claude", "agents")
|
||||
os.MkdirAll(claudeAgents, 0755)
|
||||
claudeSkills := filepath.Join(projectDir, ".claude", "skills")
|
||||
os.MkdirAll(claudeSkills, 0755)
|
||||
|
||||
configContent := `targets:
|
||||
- name: claude
|
||||
skills:
|
||||
path: ` + claudeSkills + `
|
||||
agents:
|
||||
path: ` + claudeAgents + `
|
||||
`
|
||||
os.WriteFile(filepath.Join(projectDir, ".skillshare", "config.yaml"), []byte(configContent), 0644)
|
||||
|
||||
// Global config (needed by CLI)
|
||||
sb.WriteConfig(`source: ` + sb.SourcePath + "\ntargets: {}\n")
|
||||
|
||||
return projectDir
|
||||
}
|
||||
|
||||
// --- status -p agents ---
|
||||
|
||||
func TestStatusProject_Agents(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
result := sb.RunCLIInDir(projectDir, "status", "-p", "agents")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, "Agents")
|
||||
result.AssertAnyOutputContains(t, "1 agents")
|
||||
}
|
||||
|
||||
func TestStatusProject_Agents_JSON(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
result := sb.RunCLIInDir(projectDir, "status", "-p", "agents", "--json")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, `"agents"`)
|
||||
result.AssertAnyOutputContains(t, `"count"`)
|
||||
}
|
||||
|
||||
func TestStatusProject_All(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
result := sb.RunCLIInDir(projectDir, "status", "-p", "all")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, "Source") // skill section
|
||||
result.AssertAnyOutputContains(t, "Agents") // agent section
|
||||
}
|
||||
|
||||
// --- check -p agents ---
|
||||
|
||||
func TestCheckProject_Agents(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
result := sb.RunCLIInDir(projectDir, "check", "-p", "agents")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, "tutor")
|
||||
result.AssertAnyOutputContains(t, "local")
|
||||
}
|
||||
|
||||
func TestCheckProject_Agents_JSON(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
result := sb.RunCLIInDir(projectDir, "check", "-p", "agents", "--json")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, `"name"`)
|
||||
result.AssertAnyOutputContains(t, `"status"`)
|
||||
}
|
||||
|
||||
// --- diff -p agents ---
|
||||
|
||||
func TestDiffProject_Agents(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
// Before sync, diff should show agents as "add"
|
||||
result := sb.RunCLIInDir(projectDir, "diff", "-p", "agents", "--no-tui")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, "tutor")
|
||||
}
|
||||
|
||||
func TestDiffProject_Agents_JSON(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
result := sb.RunCLIInDir(projectDir, "diff", "-p", "agents", "--json")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, `"agent"`)
|
||||
}
|
||||
|
||||
// --- collect -p agents ---
|
||||
|
||||
func TestCollectProject_Agents_NoLocal(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
// Sync agents first
|
||||
sb.RunCLIInDir(projectDir, "sync", "-p", "agents")
|
||||
|
||||
// No local agents to collect
|
||||
result := sb.RunCLIInDir(projectDir, "collect", "-p", "agents")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, "No local agents")
|
||||
}
|
||||
|
||||
func TestCollectProject_Agents_CollectsLocal(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
// Create a local agent directly in target (not via sync)
|
||||
claudeAgents := filepath.Join(projectDir, ".claude", "agents")
|
||||
os.WriteFile(filepath.Join(claudeAgents, "local-agent.md"), []byte("# Local"), 0644)
|
||||
|
||||
result := sb.RunCLIInDir(projectDir, "collect", "-p", "agents")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, "collected")
|
||||
|
||||
// Verify copied to project agents source
|
||||
agentsSource := filepath.Join(projectDir, ".skillshare", "agents")
|
||||
if _, err := os.Stat(filepath.Join(agentsSource, "local-agent.md")); err != nil {
|
||||
t.Error("local-agent.md should be collected to project agents source")
|
||||
}
|
||||
}
|
||||
|
||||
// --- audit -p agents ---
|
||||
|
||||
func TestAuditProject_Agents(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
result := sb.RunCLIInDir(projectDir, "audit", "-p", "agents")
|
||||
result.AssertSuccess(t)
|
||||
// Audit should scan agents, not error
|
||||
result.AssertOutputNotContains(t, "not yet supported")
|
||||
}
|
||||
|
||||
// --- default -p (skills only, unchanged) ---
|
||||
|
||||
func TestStatusProject_Default_SkillsOnly(t *testing.T) {
|
||||
sb := testutil.NewSandbox(t)
|
||||
defer sb.Cleanup()
|
||||
|
||||
projectDir := setupProjectWithAgents(t, sb)
|
||||
|
||||
result := sb.RunCLIInDir(projectDir, "status", "-p")
|
||||
result.AssertSuccess(t)
|
||||
result.AssertAnyOutputContains(t, "Source")
|
||||
result.AssertOutputNotContains(t, "Agents")
|
||||
}
|
||||
Reference in New Issue
Block a user