Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions internal/agentskills/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func (s *Service) fetchPayload(ctx context.Context, release Release) (payload, e
defer gzipReader.Close()

result := payload{skills: make(map[string]map[string]archiveFile)}
pluginSkills := make(map[string]map[string]archiveFile)
reader := tar.NewReader(gzipReader)
var expanded int64
for {
Expand Down Expand Up @@ -138,17 +139,15 @@ func (s *Service) fetchPayload(ctx context.Context, release Release) (payload, e
switch {
case name == "VERSION":
result.version = strings.TrimSpace(string(contents))
case strings.HasPrefix(name, "skills/"):
parts := strings.SplitN(strings.TrimPrefix(name, "skills/"), "/", 2)
if len(parts) != 2 || !validSkillName(parts[0]) || parts[1] == "" {
continue
}
if result.skills[parts[0]] == nil {
result.skills[parts[0]] = make(map[string]archiveFile)
}
result.skills[parts[0]][parts[1]] = file
case strings.HasPrefix(name, pluginSkillsPrefix):
addSkillFile(pluginSkills, strings.TrimPrefix(name, pluginSkillsPrefix), file)
case strings.HasPrefix(name, rootSkillsPrefix):
addSkillFile(result.skills, strings.TrimPrefix(name, rootSkillsPrefix), file)
}
}
if len(pluginSkills) > 0 {
result.skills = pluginSkills
}

if limited.N <= 0 {
return payload{}, fmt.Errorf("skills archive exceeds %d bytes", maxDownloadSize)
Expand Down Expand Up @@ -199,8 +198,25 @@ func stripArchiveRoot(name string) (string, bool) {
return clean, true
}

// Releases from 2.7.0 keep the skills in the plugin folder; earlier ones at the archive root.
const (
pluginSkillsPrefix = "plugins/fortrabbit/skills/"
rootSkillsPrefix = "skills/"
)

func wantedArchivePath(name string) bool {
return name == "VERSION" || strings.HasPrefix(name, "skills/")
return name == "VERSION" || strings.HasPrefix(name, rootSkillsPrefix) || strings.HasPrefix(name, pluginSkillsPrefix)
}

func addSkillFile(skills map[string]map[string]archiveFile, path string, file archiveFile) {
parts := strings.SplitN(path, "/", 2)
if len(parts) != 2 || !validSkillName(parts[0]) || parts[1] == "" {
return
}
if skills[parts[0]] == nil {
skills[parts[0]] = make(map[string]archiveFile)
}
skills[parts[0]][parts[1]] = file
}

// validSkillName deliberately uses a platform-independent allowlist. Archive
Expand Down
20 changes: 20 additions & 0 deletions internal/cmd/skills/skills_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ func TestInstallMergedReleaseRemovesLegacyFiles(t *testing.T) {
assertFileContents(t, filepath.Join(project, ".github", "instructions", "other.instructions.md"), "# other\n")
}

func TestInstallReadsSkillsFromThePluginFolder(t *testing.T) {
project := t.TempDir()
files := map[string]string{
"plugins/fortrabbit/skills/fortrabbit/SKILL.md": "# fortrabbit plugin\n",
"plugins/fortrabbit/skills/fortrabbit/references/deploy.md": "deploy\n",
"plugins/fortrabbit/.claude-plugin/plugin.json": "{}\n",
".github/scripts/check-manifests.sh": "#!/bin/sh\n",
}
transport := &fixtureTransport{version: "2.7.0", archive: skillsArchive(t, "2.7.0", files)}
service := fixtureService(t.TempDir(), project, transport)
factory := &app.Factory{IOStreams: iostreams.IOStreams{In: strings.NewReader("")}}
executeSkills(t, factory, service, "install", "--project", "--agent", "claude-code")

skill := filepath.Join(project, ".claude", "skills", "fortrabbit")
assertFileContents(t, filepath.Join(skill, "SKILL.md"), "# fortrabbit plugin\n")
assertFileContents(t, filepath.Join(skill, "references", "deploy.md"), "deploy\n")
assertFileContents(t, filepath.Join(skill, ".version"), "2.7.0\n")
assertMissing(t, filepath.Join(project, ".claude", "skills", "skills"))
}

func TestListAndRemoveFindLegacyCopilotInstructions(t *testing.T) {
project := t.TempDir()
instructions := filepath.Join(project, ".github", "instructions", "fortrabbit.instructions.md")
Expand Down