Files
skillshare/internal/install/extension_install.go
T
Willie cb2bcec948 feat(agents): convert agents with a target extension
Tools disagree on agent frontmatter and some need another format entirely,
so an agent written for Claude is misread elsewhere. An `extension` on a
target's agents block reuses the extras transform mechanism to convert each
agent during sync.

Converted targets hold transformed output, so collect never pulls them back
into the source. Leftover symlinks from merge or symlink mode are removed
rather than written through, and a failed conversion drops the old output
so an unconverted agent never stays active.

The bundled opencode-agents extension keeps only fields OpenCode documents
and refuses agents that restrict their tools, since dropping those fields
would widen the agent's access.

Refs #267
Refs #241
2026-09-21 13:31:38 +08:00

54 lines
2.0 KiB
Go

package install
import (
"fmt"
"path/filepath"
"slices"
)
// BuiltinExtension is one transform extension bundled in the skillshare repo
// under extensions/, with a human-readable description so the dashboard can
// explain what it does before it is installed.
type BuiltinExtension struct {
Name string
Description string
}
// BuiltinExtensions is the catalog of bundled transform extensions. The
// dashboard offers these for one-click install so users don't have to copy the
// reference scripts by hand.
var BuiltinExtensions = []BuiltinExtension{
{Name: "codex-agents", Description: "Convert Markdown subagents (Claude format) into Codex CLI TOML agents"},
{Name: "gemini-commands", Description: "Convert Markdown slash-commands (Claude/Cursor format) into Gemini CLI TOML commands"},
{Name: "opencode-agents", Description: "Convert Markdown subagents (Claude format) into OpenCode agents"},
}
// IsBuiltinExtension reports whether name is a known bundled extension. It
// doubles as a whitelist guard against path traversal in download requests.
func IsBuiltinExtension(name string) bool {
return slices.ContainsFunc(BuiltinExtensions, func(b BuiltinExtension) bool { return b.Name == name })
}
// BuiltinExtensionDescription returns the catalog description for name, or an
// empty string if name is not a bundled extension.
func BuiltinExtensionDescription(name string) string {
for _, b := range BuiltinExtensions {
if b.Name == name {
return b.Description
}
}
return ""
}
// InstallBuiltinExtension downloads the bundled extension `name` from the
// skillshare repo (extensions/<name>) into destRoot/<name>. destRoot is the
// target extensions directory for the current mode (global or project).
func InstallBuiltinExtension(name, destRoot string) error {
if !IsBuiltinExtension(name) {
return fmt.Errorf("unknown built-in extension: %q", name)
}
dest := filepath.Join(destRoot, name)
_, err := downloadGitHubDirWithAPIBase("runkids", "skillshare", "extensions/"+name, dest, "https://api.github.com", nil, nil)
return err
}