mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
* feat(targets): support OpenCode config directory accounts OpenCode v2 introduces support for custom configuration directories via OPENCODE_CONFIG_DIR, storing opencode.json and agent directories. Previously, skillshare rejected OpenCode accounts configured with a custom config directory because OpenCode was missing config_dir and was excluded from accountAgents in hooks and MCP services. - Define default config_dir (~/.config/opencode) in targets.yaml - Add OpenCode to account agents and register OPENCODE_CONFIG_DIR across hooks and MCP service handlers - Route OpenCode account MCP configuration to opencode.json inside the account config directory Resolves #593. * fix(targets): add OpenCode to schemas, completions and docs Add opencode to the targetConfig.agent enum and config_dir description in schemas/config.schema.json so configurations containing OpenCode account targets pass schema validation. Include opencode in the target --agent completion scripts for Bash, Zsh, Fish, PowerShell, and Nushell. Update website documentation and built-in skill references to describe OpenCode accounts and OPENCODE_CONFIG_DIR management alongside other account agents. * fix(targets): support plugin accounts and overlap Add OpenCode account recognition and OPENCODE_CONFIG_DIR resolution to the plugin service so plugin sync works for OpenCode account targets. Introduce TargetScanPaths to resolve cross-runtime scan paths using TargetConfig.Agent for account targets while retaining the account's own primary directory. Update path overlap detection, doctor checks, and LeakedSkills to warn about leaked skills for account targets. Update localized docs (zh-Hans, zh-Hant, ja, ko) and plugin references to document OpenCode account targets and OPENCODE_CONFIG_DIR. Update the available targets handler test to expect OpenCode's configDir. * fix(targets): isolate OpenCode accounts and scan paths Reject OPENCODE_CONFIG overrides when operating on OpenCode accounts and clear OPENCODE_CONFIG in the account execution environment so plugin operations target the account directory. In TargetScanPaths, remap config-root paths to the account directory while preserving external scan paths like Codex's ~/.agents/skills. * fix(plugins): use account target in OpenCode update probe Pass c.Target instead of a hardcoded "opencode" when probing whether OpenCode supports plugin updates, ensuring account-configured CLI binaries and account environment variables are used during preview. * test(mcp): isolate XDG_CONFIG_HOME in account test service Isolate XDG_CONFIG_HOME to the temporary test directory in agentAccountService to prevent runner environment variables from leaking into TestAccountEnvOverrideDoesNotPruneDefaultHome when testing OpenCode account shell overrides. --------- Co-authored-by: Willie <egg358358@gmail.com>
112 lines
4.0 KiB
Go
112 lines
4.0 KiB
Go
package sync
|
|
|
|
import (
|
|
"cmp"
|
|
"os"
|
|
"path/filepath"
|
|
"sort"
|
|
"strings"
|
|
|
|
"skillshare/internal/config"
|
|
)
|
|
|
|
// LeakedSkills returns the skills scanner's runtime loads from writer's folder
|
|
// although sync leaves them out of scanner's own folder: source skills its
|
|
// filters skip, and skills the user keeps in writer's folder. It needs a
|
|
// runtime that loads one skill per name (config.LoadsOneSkillPerName): which
|
|
// copy wins is not fixed (OpenCode loads them concurrently), but a source skill
|
|
// synced to both folders has the same content either way. known is false when
|
|
// that cannot be told (the runtime's rule for same-named skills is unknown, a
|
|
// filter is invalid, or nothing was discovered); every skill in writer's folder
|
|
// may then reach scanner.
|
|
func LeakedSkills(scanner, writer string, targets map[string]config.TargetConfig, defaultMode string, discovered []DiscoveredSkill) (leaked []string, known bool) {
|
|
scannerAgent := scanner
|
|
if a := targets[scanner].Agent; a != "" {
|
|
scannerAgent = a
|
|
}
|
|
if !config.LoadsOneSkillPerName(scannerAgent) || discovered == nil {
|
|
return nil, false
|
|
}
|
|
// A symlink-mode folder is the source itself, .skillignore'd skills that
|
|
// discovery leaves out included; only a scanner that links it too sees them all.
|
|
if isSymlinkMode(targets[writer], defaultMode) && !isSymlinkMode(targets[scanner], defaultMode) {
|
|
return nil, false
|
|
}
|
|
own, err := syncedSkills(scanner, targets[scanner], defaultMode, discovered)
|
|
if err != nil {
|
|
return nil, false
|
|
}
|
|
theirs, err := syncedSkills(writer, targets[writer], defaultMode, discovered)
|
|
if err != nil {
|
|
return nil, false
|
|
}
|
|
|
|
synced := make(map[string]bool, len(own))
|
|
ownNames := make(map[string]bool, len(own))
|
|
for _, s := range own {
|
|
synced[s.Skill.FlatName] = true
|
|
ownNames[s.TargetName] = true
|
|
}
|
|
managed := make(map[string]bool, len(theirs))
|
|
for _, s := range theirs {
|
|
managed[s.TargetName] = true
|
|
if !synced[s.Skill.FlatName] {
|
|
leaked = append(leaked, s.Skill.FlatName)
|
|
}
|
|
}
|
|
// Merge and copy mode keep what the user put in writer's folder.
|
|
w, sc := targets[writer], targets[scanner]
|
|
writerDir := config.ExpandPath(w.SkillsConfig().Path)
|
|
ownDir := config.ExpandPath(sc.SkillsConfig().Path)
|
|
entries, _ := os.ReadDir(writerDir)
|
|
for _, e := range entries {
|
|
name := e.Name()
|
|
if strings.HasPrefix(name, ".") || managed[name] || ownNames[name] {
|
|
continue
|
|
}
|
|
// Only a folder with SKILL.md is a skill the runtime loads.
|
|
if !isFile(filepath.Join(writerDir, name, "SKILL.md")) || isFile(filepath.Join(ownDir, name, "SKILL.md")) {
|
|
continue
|
|
}
|
|
leaked = append(leaked, name)
|
|
}
|
|
sort.Strings(leaked)
|
|
return leaked, true
|
|
}
|
|
|
|
// syncedSkills returns the source skills sync puts in a target's folder: the
|
|
// whole source in symlink mode, otherwise what its filters and target_naming
|
|
// let through.
|
|
func syncedSkills(name string, target config.TargetConfig, defaultMode string, discovered []DiscoveredSkill) ([]ResolvedTargetSkill, error) {
|
|
if isSymlinkMode(target, defaultMode) {
|
|
skills := make([]ResolvedTargetSkill, len(discovered))
|
|
for i, d := range discovered {
|
|
skills[i] = ResolvedTargetSkill{Skill: d, TargetName: d.FlatName}
|
|
}
|
|
return skills, nil
|
|
}
|
|
res, err := ResolveTargetSkillsForTarget(name, target.SkillsConfig(), discovered)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return res.Skills, nil
|
|
}
|
|
|
|
func isFile(path string) bool {
|
|
info, err := os.Stat(path)
|
|
return err == nil && !info.IsDir()
|
|
}
|
|
|
|
func isSymlinkMode(target config.TargetConfig, defaultMode string) bool {
|
|
return cmp.Or(target.SkillsConfig().Mode, defaultMode) == "symlink"
|
|
}
|
|
|
|
// HarmlessOverlap returns a check for config.DetectPathOverlap: scanner reading
|
|
// writer's folder is harmless when it loads nothing sync leaves out of its own.
|
|
func HarmlessOverlap(targets map[string]config.TargetConfig, defaultMode string, discovered []DiscoveredSkill) func(scanner, writer string) bool {
|
|
return func(scanner, writer string) bool {
|
|
leaked, known := LeakedSkills(scanner, writer, targets, defaultMode, discovered)
|
|
return known && len(leaked) == 0
|
|
}
|
|
}
|