Files
Willie 2a91a72f6e fix(server): sync matrix agent handling and stale test routes
- 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
2026-04-09 04:07:35 +08:00

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")
}