mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
- Fix sync matrix using wrong builtin agent targets in project mode (DefaultAgentTargets → branch on IsProjectMode) - Fix sync matrix not skipping filters for agent symlink mode, matching the existing skill symlink behavior - Remove double-defensive slice copies in handleListTargets since targetsummary.Builder already clones Include/Exclude - Extract shared findAgent() to deduplicate discovery logic between resolveAgentResource and resolveAgentRelPathWithStatus - Update test URLs from /api/skills to /api/resources and response keys from skills/skill to resources/resource to match the route rename from the resources refactor
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"skillshare/internal/resource"
|
|
)
|
|
|
|
func agentDisplayName(relPath string) string {
|
|
return strings.TrimSuffix(relPath, ".md")
|
|
}
|
|
|
|
func matchesAgentName(d resource.DiscoveredResource, name string) bool {
|
|
return d.FlatName == name ||
|
|
d.Name == name ||
|
|
d.RelPath == name ||
|
|
agentDisplayName(d.RelPath) == name
|
|
}
|
|
|
|
func findAgent(agentsSource, name string) (resource.DiscoveredResource, error) {
|
|
discovered, err := resource.AgentKind{}.Discover(agentsSource)
|
|
if err != nil {
|
|
return resource.DiscoveredResource{}, fmt.Errorf("failed to discover agents: %w", err)
|
|
}
|
|
for _, d := range discovered {
|
|
if matchesAgentName(d, name) {
|
|
return d, nil
|
|
}
|
|
}
|
|
return resource.DiscoveredResource{}, fmt.Errorf("agent not found: %s", name)
|
|
}
|
|
|
|
func resolveAgentResource(agentsSource, name string) (resource.DiscoveredResource, error) {
|
|
return findAgent(agentsSource, name)
|
|
}
|
|
|
|
func (s *Server) resolveAgentRelPathWithStatus(agentsSource, name string) (string, bool, error) {
|
|
d, err := findAgent(agentsSource, name)
|
|
if err != nil {
|
|
return "", false, err
|
|
}
|
|
return d.RelPath, d.Disabled, nil
|
|
}
|
|
|
|
func agentMetaKey(relPath string) string {
|
|
return strings.TrimSuffix(filepath.ToSlash(relPath), ".md")
|
|
}
|