(root, p, base string, kind entities.Kind)
| 121 | } |
| 122 | |
| 123 | func resourceFromFile(root, p, base string, kind entities.Kind) (DiscoveredResource, bool) { |
| 124 | switch kind { |
| 125 | case entities.KindSkill: |
| 126 | if !strings.EqualFold(base, "SKILL.md") { |
| 127 | return DiscoveredResource{}, false |
| 128 | } |
| 129 | dir := filepath.Dir(p) |
| 130 | name, desc := parseManifest(p, filepath.Base(dir)) |
| 131 | return DiscoveredResource{ |
| 132 | Name: name, |
| 133 | Description: desc, |
| 134 | RelPath: relPath(root, dir), |
| 135 | ManifestRel: relPath(root, p), |
| 136 | }, true |
| 137 | |
| 138 | case entities.KindPlugin: |
| 139 | if !strings.EqualFold(base, "plugin.json") { |
| 140 | return DiscoveredResource{}, false |
| 141 | } |
| 142 | dir := filepath.Dir(p) |
| 143 | // .claude-plugin/plugin.json → the plugin is the parent of that dir. |
| 144 | if strings.EqualFold(filepath.Base(dir), ".claude-plugin") { |
| 145 | dir = filepath.Dir(dir) |
| 146 | } |
| 147 | name, desc := parsePluginJSON(p, filepath.Base(dir)) |
| 148 | return DiscoveredResource{ |
| 149 | Name: name, |
| 150 | Description: desc, |
| 151 | RelPath: relPath(root, dir), |
| 152 | ManifestRel: relPath(root, p), |
| 153 | }, true |
| 154 | |
| 155 | case entities.KindAgent, entities.KindPrompt, entities.KindInstruction: |
| 156 | if !strings.HasSuffix(strings.ToLower(base), ".md") { |
| 157 | return DiscoveredResource{}, false |
| 158 | } |
| 159 | if isDocFile(base) { |
| 160 | return DiscoveredResource{}, false |
| 161 | } |
| 162 | name := strings.TrimSuffix(base, filepath.Ext(base)) |
| 163 | parsedName, desc := parseManifest(p, name) |
| 164 | return DiscoveredResource{ |
| 165 | Name: parsedName, |
| 166 | Description: desc, |
| 167 | RelPath: relPath(root, p), |
| 168 | ManifestRel: relPath(root, p), |
| 169 | }, true |
| 170 | } |
| 171 | return DiscoveredResource{}, false |
| 172 | } |
| 173 | |
| 174 | func relPath(root, p string) string { |
| 175 | rel, err := filepath.Rel(root, p) |
no test coverage detected