feat(config): migrate consumers to Effective*Source helpers (Phase 3+5)

Make the v0.19.16 sources map actually do something: route all path
reads through Config.EffectiveSkillsSource() / EffectiveAgentsSource() /
EffectiveExtrasSource() so users who set sources.skills / sources.agents /
sources.extras get the configured paths everywhere.

Mechanical changes (~50 files):
- cmd/skillshare/**: replace cfg.Source / cfg.ExtrasSource reads with
  cfg.EffectiveSkillsSource() / cfg.EffectiveExtrasSource()
- internal/server/**: replace s.cfg.Source / s.cfg.ExtrasSource reads
  with the same helpers; server.skillsSource() / gitignoreDir() use the
  global-mode helper
- internal/config/config_validate.go: validate using EffectiveSkillsSource
  while still rejecting configs that set neither field explicitly
- internal/config/reconcile.go, registry.go: read via helpers

Behavioral fixes (paired with the migration):
- extras init / extras source / POST /api/extras no longer silently
  backfill the legacy extras_source field — the runtime fallback inside
  EffectiveExtrasSource() handles it. This stops surprise diffs in users'
  config.yaml after running extras commands.
- extras source command writes back to whichever field the user already
  configured (sources.extras if set, otherwise legacy extras_source) so
  the update is not shadowed.
- source_type in /api/extras and extras list correctly reports "default"
  vs "extras_source" by inspecting the raw (unresolved) configured value;
  sources.extras counts as configured for this purpose.

UI:
- ui/src/lib/fieldDocs.ts: neutralize sources / sources.* descriptions
  so they describe both project and global modes (Phase 5).

Preserved (intentional):
- Direct writes to cfg.Source / cfg.AgentsSource / cfg.ExtrasSource in
  init, migrate.go, cloneForSave, and server.reloadConfig — these are
  raw-field writes, not path reads.
- Updated test expectations for the removed backfills.
This commit is contained in:
Willie
2026-05-21 14:49:11 +08:00
parent 2b802012c4
commit 996d00e342
61 changed files with 279 additions and 246 deletions
+2 -2
View File
@@ -208,7 +208,7 @@ func runAnalyze(opts *analyzeOptions) error {
}
if opts.targetName == "" && !opts.json && shouldLaunchTUI(opts.noTUI, cfg) {
loadFn := func() analyzeLoadResult {
discovered, err := ssync.DiscoverSourceSkillsForAnalyze(cfg.Source)
discovered, err := ssync.DiscoverSourceSkillsForAnalyze(cfg.EffectiveSkillsSource())
if err != nil {
return analyzeLoadResult{err: err}
}
@@ -220,7 +220,7 @@ func runAnalyze(opts *analyzeOptions) error {
}
return runAnalyzeTUI(loadFn, "global", opts.filter)
}
return runAnalyzeCore(cfg.Source, cfg.Targets, cfg.Mode, cfg.ContextBudget, opts)
return runAnalyzeCore(cfg.EffectiveSkillsSource(), cfg.Targets, cfg.Mode, cfg.ContextBudget, opts)
}
const charsPerToken = 4
+1 -1
View File
@@ -201,7 +201,7 @@ func cmdAudit(args []string) error {
if err != nil {
return err
}
sourcePath = cfg.Source
sourcePath = cfg.EffectiveSkillsSource()
agentsSourcePath = cfg.EffectiveAgentsSource()
defaultThreshold = cfg.Audit.BlockThreshold
configProfile = cfg.Audit.Profile
+2 -2
View File
@@ -225,13 +225,13 @@ func cmdCheck(args []string) error {
// No names and no groups → check all (existing behavior)
if len(opts.names) == 0 && len(opts.groups) == 0 {
cmdErr := runCheck(cfg.Source, opts.json, targetNamesFromConfig(cfg.Targets))
cmdErr := runCheck(cfg.EffectiveSkillsSource(), opts.json, targetNamesFromConfig(cfg.Targets))
logCheckOp(cfgPath, 0, 0, 0, 0, scope, start, cmdErr)
return cmdErr
}
// Filtered check: resolve targets then check only those
cmdErr := runCheckFiltered(cfg.Source, opts)
cmdErr := runCheckFiltered(cfg.EffectiveSkillsSource(), opts)
logCheckOp(cfgPath, 0, 0, 0, 0, scope, start, cmdErr)
return cmdErr
}
+3 -3
View File
@@ -114,10 +114,10 @@ func cmdCollectGlobal(cfg *config.Config, opts collectOptions, start time.Time)
}
return runCollectPlan(collectPlan{
kind: kindSkills, source: cfg.Source,
kind: kindSkills, source: cfg.EffectiveSkillsSource(),
scan: func(warn bool) collectResources {
skills := collectLocalSkills(targets, cfg.Source, cfg.Mode, warn)
return toCollectResources(skills, cfg.Source, skillDisplayItem, sync.PullSkills)
skills := collectLocalSkills(targets, cfg.EffectiveSkillsSource(), cfg.Mode, warn)
return toCollectResources(skills, cfg.EffectiveSkillsSource(), skillDisplayItem, sync.PullSkills)
},
}, opts, start, "global")
}
+3 -3
View File
@@ -377,7 +377,7 @@ func cmdDiffGlobal(targetName string, kind resourceKindFilter, opts diffRenderOp
if !opts.jsonOutput {
spinner = ui.StartSpinner("Discovering skills")
}
discovered, discoverErr := sync.DiscoverSourceSkills(cfg.Source)
discovered, discoverErr := sync.DiscoverSourceSkills(cfg.EffectiveSkillsSource())
if discoverErr != nil {
if spinner != nil {
spinner.Fail("Discovery failed")
@@ -460,7 +460,7 @@ func cmdDiffGlobal(targetName string, kind resourceKindFilter, opts diffRenderOp
defer wg.Done()
defer func() { <-sem }()
progress.startTarget(fe.name)
r := collectTargetDiff(fe.name, fe.target, cfg.Source, fe.mode, fe.filtered, progress)
r := collectTargetDiff(fe.name, fe.target, cfg.EffectiveSkillsSource(), fe.mode, fe.filtered, progress)
progress.doneTarget(fe.name, r)
results[idx] = r
}(i, fe)
@@ -475,7 +475,7 @@ func cmdDiffGlobal(targetName string, kind resourceKindFilter, opts diffRenderOp
var extrasResults []extraDiffResult
if len(cfg.Extras) > 0 {
extrasResults = collectExtrasDiff(cfg.Extras, func(extra config.ExtraConfig) string {
return config.ResolveExtrasSourceDir(extra, cfg.ExtrasSource, cfg.Source)
return config.ResolveExtrasSourceDir(extra, cfg.EffectiveExtrasSource(), cfg.EffectiveSkillsSource())
})
}
+17 -17
View File
@@ -139,7 +139,7 @@ func cmdDoctorGlobal(jsonMode bool) error {
}
runDoctorChecks(cfg, result, false)
checkExtras(cfg.Extras, result, false, cfg.Source, cfg.ExtrasSource, "", "")
checkExtras(cfg.Extras, result, false, cfg.EffectiveSkillsSource(), cfg.EffectiveExtrasSource(), "", "")
ui.Header("Storage")
checkBackupStatus(result, false, backup.BackupDir())
checkTrashStatus(result, trash.TrashDir())
@@ -216,7 +216,7 @@ func cmdDoctorProject(root string, jsonMode bool) error {
func runDoctorChecks(cfg *config.Config, result *doctorResult, isProject bool) {
// Single discovery pass for all checks (with .skillignore stats)
sp := ui.StartSpinner("Discovering skills...")
discovered, stats, discoverErr := sync.DiscoverSourceSkillsWithStats(cfg.Source)
discovered, stats, discoverErr := sync.DiscoverSourceSkillsWithStats(cfg.EffectiveSkillsSource())
if discoverErr != nil {
discovered = nil
}
@@ -229,11 +229,11 @@ func runDoctorChecks(cfg *config.Config, result *doctorResult, isProject bool) {
checkTheme(result)
if !isProject {
checkGitStatus(cfg.Source, result)
checkGitStatus(cfg.EffectiveSkillsSource(), result)
}
fmt.Println() // visual break before skill validation
checkSkillsValidity(cfg.Source, result, discovered)
checkSkillsValidity(cfg.EffectiveSkillsSource(), result, discovered)
checkSkillIntegrity(result, discovered)
checkSkillTargetsField(result, discovered, targetNamesFromConfig(cfg.Targets))
targetCache := checkTargets(cfg, result, isProject)
@@ -278,18 +278,18 @@ func checkSkillignore(result *doctorResult, stats *skillignore.IgnoreStats) {
}
func checkSource(cfg *config.Config, result *doctorResult, discovered []sync.DiscoveredSkill, discoverErr error) {
info, err := os.Stat(cfg.Source)
info, err := os.Stat(cfg.EffectiveSkillsSource())
if err != nil {
ui.Error("Source not found: %s", cfg.Source)
ui.Error("Source not found: %s", cfg.EffectiveSkillsSource())
result.addError()
result.addCheck("source", checkError, fmt.Sprintf("Source not found: %s", cfg.Source), nil)
result.addCheck("source", checkError, fmt.Sprintf("Source not found: %s", cfg.EffectiveSkillsSource()), nil)
return
}
if !info.IsDir() {
ui.Error("Source is not a directory: %s", cfg.Source)
ui.Error("Source is not a directory: %s", cfg.EffectiveSkillsSource())
result.addError()
result.addCheck("source", checkError, fmt.Sprintf("Source is not a directory: %s", cfg.Source), nil)
result.addCheck("source", checkError, fmt.Sprintf("Source is not a directory: %s", cfg.EffectiveSkillsSource()), nil)
return
}
@@ -297,15 +297,15 @@ func checkSource(cfg *config.Config, result *doctorResult, discovered []sync.Dis
if discoverErr == nil {
skillCount = len(discovered)
} else {
entries, _ := os.ReadDir(cfg.Source)
entries, _ := os.ReadDir(cfg.EffectiveSkillsSource())
for _, e := range entries {
if e.IsDir() && !utils.IsHidden(e.Name()) {
skillCount++
}
}
}
ui.Success("Source: %s (%d skills)", cfg.Source, skillCount)
result.addCheck("source", checkPass, fmt.Sprintf("Source: %s (%d skills)", cfg.Source, skillCount), nil)
ui.Success("Source: %s (%d skills)", cfg.EffectiveSkillsSource(), skillCount)
result.addCheck("source", checkPass, fmt.Sprintf("Source: %s (%d skills)", cfg.EffectiveSkillsSource(), skillCount), nil)
}
func checkAgentsSource(cfg *config.Config, result *doctorResult) {
@@ -480,7 +480,7 @@ func checkTargets(cfg *config.Config, result *doctorResult, isProject bool) map[
result.addWarning()
}
targetIssues := checkTargetIssues(target, cfg.Source)
targetIssues := checkTargetIssues(target, cfg.EffectiveSkillsSource())
// Target name header
fmt.Printf("%s%s%s\n", ui.Bold, name, ui.Reset)
@@ -491,7 +491,7 @@ func checkTargets(cfg *config.Config, result *doctorResult, isProject bool) map[
details = append(details, fmt.Sprintf("%s: %s", name, strings.Join(targetIssues, ", ")))
hasError = true
} else {
cached := displayTargetStatus(target, cfg.Source, mode)
cached := displayTargetStatus(target, cfg.EffectiveSkillsSource(), mode)
cache[name] = cached
}
@@ -1213,17 +1213,17 @@ func checkVersionDoctor(cfg *config.Config, result *doctorResult, isProject bool
result.addCheck("cli_version", checkPass, fmt.Sprintf("CLI: %s", version), nil)
// Skill version: try SKILL.md frontmatter first, then metadata store
localVersion := versioncheck.ReadLocalSkillVersion(cfg.Source)
localVersion := versioncheck.ReadLocalSkillVersion(cfg.EffectiveSkillsSource())
if localVersion == "" {
// Try metadata store (tracks installed version even without metadata.version in SKILL.md)
store := install.LoadMetadataOrNew(cfg.Source)
store := install.LoadMetadataOrNew(cfg.EffectiveSkillsSource())
if entry := store.Get("skillshare"); entry != nil && entry.Version != "" {
localVersion = strings.TrimPrefix(entry.Version, "v")
}
}
if localVersion == "" {
skillFile := filepath.Join(cfg.Source, "skillshare", "SKILL.md")
skillFile := filepath.Join(cfg.EffectiveSkillsSource(), "skillshare", "SKILL.md")
if _, err := os.Stat(skillFile); os.IsNotExist(err) {
if isProject {
ui.Info("Skill: not installed")
+1 -1
View File
@@ -97,7 +97,7 @@ func cmdToggleSkill(args []string, enable bool) error {
if isAgent {
ignorePath = filepath.Join(cfg.EffectiveAgentsSource(), ".agentignore")
} else {
ignorePath = filepath.Join(cfg.Source, ".skillignore")
ignorePath = filepath.Join(cfg.EffectiveSkillsSource(), ".skillignore")
}
cfgPath = config.ConfigPath()
}
+1 -1
View File
@@ -79,7 +79,7 @@ func extrasCollectGlobal(name, fromPath string, dryRun bool, start time.Time) er
}
targetPath = config.ExpandPath(targetPath)
sourceDir := config.ResolveExtrasSourceDir(*extra, cfg.ExtrasSource, cfg.Source)
sourceDir := config.ResolveExtrasSourceDir(*extra, cfg.EffectiveExtrasSource(), cfg.EffectiveSkillsSource())
return runCollect(sourceDir, targetPath, extra.Name, dryRun, flatten, "global", config.ConfigPath(), start, "")
}
+1 -6
View File
@@ -126,11 +126,6 @@ func extrasInitGlobal(name string, targets []string, syncMode string, sourceOver
return err
}
// Backfill extras_source if not set
if cfg.ExtrasSource == "" {
cfg.ExtrasSource = config.ExtrasParentDir(cfg.Source)
}
// Build extra config
extra := config.ExtraConfig{Name: name, Source: sourceOverride}
for _, t := range targets {
@@ -142,7 +137,7 @@ func extrasInitGlobal(name string, targets []string, syncMode string, sourceOver
}
// Create source directory
sourceDir := config.ResolveExtrasSourceDir(extra, cfg.ExtrasSource, cfg.Source)
sourceDir := config.ResolveExtrasSourceDir(extra, cfg.EffectiveExtrasSource(), cfg.EffectiveSkillsSource())
if err := os.MkdirAll(sourceDir, 0755); err != nil {
return fmt.Errorf("failed to create extras source directory: %w", err)
}
+10 -1
View File
@@ -127,9 +127,15 @@ func cmdExtrasList(args []string) error {
return err
}
extras = cfg.Extras
// extrasSource holds the user's explicit configuration (legacy
// extras_source or new sources.extras); used by ResolveExtrasSourceType
// to distinguish "default" (derived) from "extras_source" (configured).
extrasSource = cfg.ExtrasSource
if extrasSource == "" {
extrasSource = cfg.Sources.Extras
}
sourceFunc = func(extra config.ExtraConfig) string {
return config.ResolveExtrasSourceDir(extra, cfg.ExtrasSource, cfg.Source)
return config.ResolveExtrasSourceDir(extra, cfg.EffectiveExtrasSource(), cfg.EffectiveSkillsSource())
}
configPath = config.ConfigPath()
}
@@ -167,6 +173,9 @@ func cmdExtrasList(args []string) error {
}
ex = c.Extras
es = c.ExtrasSource
if es == "" {
es = c.Sources.Extras
}
}
return buildExtrasListEntries(ex, es, sourceFunc), nil
}
+1 -1
View File
@@ -602,7 +602,7 @@ func (m *extrasListTUIModel) reloadExtras() {
extrasSource := ""
if m.cfg != nil {
extrasSource = m.cfg.ExtrasSource
extrasSource = m.cfg.EffectiveExtrasSource()
}
entries := buildExtrasListEntries(extras, extrasSource, m.sourceFunc)
m.allItems = entries
+2 -2
View File
@@ -74,7 +74,7 @@ func removeExtraFromGlobalConfig(cfg *config.Config, name string) (string, error
return "", fmt.Errorf("extra %q not found in config", name)
}
sourceDir := config.ResolveExtrasSourceDir(removed, cfg.ExtrasSource, cfg.Source)
sourceDir := config.ResolveExtrasSourceDir(removed, cfg.EffectiveExtrasSource(), cfg.EffectiveSkillsSource())
cfg.Extras = append(cfg.Extras[:idx], cfg.Extras[idx+1:]...)
if err := cfg.Save(); err != nil {
@@ -126,7 +126,7 @@ func extrasRemoveGlobal(name string, force bool, start time.Time) error {
if idx == -1 {
return fmt.Errorf("extra %q not found in config", name)
}
sourceDir := config.ResolveExtrasSourceDir(found, cfg.ExtrasSource, cfg.Source)
sourceDir := config.ResolveExtrasSourceDir(found, cfg.EffectiveExtrasSource(), cfg.EffectiveSkillsSource())
if !force {
ui.Warning("This will remove %q from config.", name)
+12 -6
View File
@@ -52,12 +52,11 @@ func cmdExtrasSource(args []string) error {
// No argument → show current value
if newPath == "" {
current := cfg.ExtrasSource
if current == "" {
current = config.ExtrasParentDir(cfg.Source)
ui.Info("extras_source: %s (default)", shortenPath(current))
effective := cfg.EffectiveExtrasSource()
if cfg.Sources.Extras == "" && cfg.ExtrasSource == "" {
ui.Info("extras_source: %s (default)", shortenPath(effective))
} else {
ui.Info("extras_source: %s", shortenPath(current))
ui.Info("extras_source: %s", shortenPath(effective))
}
return nil
}
@@ -68,7 +67,14 @@ func cmdExtrasSource(args []string) error {
return fmt.Errorf("invalid path: %w", err)
}
cfg.ExtrasSource = absPath
// Write to whichever field the user already uses; default to legacy field
// for fresh configs to preserve the existing on-disk shape. If the user
// has migrated to sources.extras, update that to avoid being shadowed.
if cfg.Sources.Extras != "" {
cfg.Sources.Extras = absPath
} else {
cfg.ExtrasSource = absPath
}
if err := cfg.Save(); err != nil {
return fmt.Errorf("failed to save config: %w", err)
}
+1 -1
View File
@@ -235,7 +235,7 @@ func resolveSourcePath(mode runMode, cwd string) (string, error) {
if err != nil {
return "", fmt.Errorf("failed to load config: %w", err)
}
return cfg.Source, nil
return cfg.EffectiveSkillsSource(), nil
}
func printHubHelp() {
+4 -4
View File
@@ -265,7 +265,7 @@ func parseOptsFromProjectConfig(cfg *config.ProjectConfig) install.ParseOptions
// resolveSkillFromName resolves a skill name to source using metadata
func resolveSkillFromName(skillName string, cfg *config.Config) (*install.Source, error) {
store, err := install.LoadMetadataWithMigration(cfg.Source, "")
store, err := install.LoadMetadataWithMigration(cfg.EffectiveSkillsSource(), "")
if err != nil {
return nil, fmt.Errorf("skill '%s' not found or has no metadata", skillName)
}
@@ -426,7 +426,7 @@ func cmdInstall(args []string) error {
return err
}
parsed.opts.SourceDir = cfg.Source
parsed.opts.SourceDir = cfg.EffectiveSkillsSource()
source, resolvedFromMeta, err := resolveInstallSource(parsed.sourceArg, parsed.opts, cfg)
if err == nil && parsed.opts.Branch != "" {
source.Branch = parsed.opts.Branch
@@ -463,7 +463,7 @@ func cmdInstall(args []string) error {
summary.Source = parsed.sourceArg
}
if err == nil && !parsed.opts.DryRun && len(summary.InstalledSkills) > 0 {
store, storeErr := install.LoadMetadataWithMigration(cfg.Source, "")
store, storeErr := install.LoadMetadataWithMigration(cfg.EffectiveSkillsSource(), "")
if storeErr != nil {
ui.Warning("Failed to load metadata: %v", storeErr)
} else if rErr := config.ReconcileGlobalSkills(cfg, store); rErr != nil {
@@ -485,7 +485,7 @@ func cmdInstall(args []string) error {
summary.Source = parsed.sourceArg
}
if err == nil && !parsed.opts.DryRun && len(summary.InstalledSkills) > 0 {
store, storeErr := install.LoadMetadataWithMigration(cfg.Source, "")
store, storeErr := install.LoadMetadataWithMigration(cfg.EffectiveSkillsSource(), "")
if storeErr != nil {
ui.Warning("Failed to load metadata: %v", storeErr)
} else if rErr := config.ReconcileGlobalSkills(cfg, store); rErr != nil {
+1 -1
View File
@@ -41,7 +41,7 @@ type globalInstallContext struct {
store *install.MetadataStore
}
func (g *globalInstallContext) SourcePath() string { return g.cfg.Source }
func (g *globalInstallContext) SourcePath() string { return g.cfg.EffectiveSkillsSource() }
func (g *globalInstallContext) ConfigSkills() []install.SkillEntryDTO {
return storeToSkillEntryDTOs(g.store)
}
+12 -12
View File
@@ -22,7 +22,7 @@ func handleTrackedRepoInstall(source *install.Source, cfg *config.Config, opts i
}
opts.Kind = trackedKind
trackSourceDir := cfg.Source
trackSourceDir := cfg.EffectiveSkillsSource()
if trackedKind == "agent" {
trackSourceDir = cfg.EffectiveAgentsSource()
}
@@ -180,7 +180,7 @@ func handleGitInstall(source *install.Source, cfg *config.Config, opts install.I
// Cross-path duplicate detection: block if same repo is already installed
// at a different location (e.g. user forgot they used --into before).
if !opts.Force && source.CloneURL != "" {
if err := install.CheckCrossPathDuplicate(cfg.Source, source.CloneURL, opts.Into); err != nil {
if err := install.CheckCrossPathDuplicate(cfg.EffectiveSkillsSource(), source.CloneURL, opts.Into); err != nil {
return logSummary, err
}
}
@@ -203,8 +203,8 @@ func handleGitInstall(source *install.Source, cfg *config.Config, opts install.I
renderSkillMeta(skill, displayPath)
destPath := destWithInto(cfg.Source, opts, skill.Name)
if err := ensureIntoDirExists(cfg.Source, opts); err != nil {
destPath := destWithInto(cfg.EffectiveSkillsSource(), opts, skill.Name)
if err := ensureIntoDirExists(cfg.EffectiveSkillsSource(), opts); err != nil {
return logSummary, fmt.Errorf("failed to create --into directory: %w", err)
}
@@ -296,8 +296,8 @@ func handleGitInstall(source *install.Source, cfg *config.Config, opts install.I
renderSkillMeta(skill, displayPath)
destPath := destWithInto(cfg.Source, opts, skill.Name)
if err := ensureIntoDirExists(cfg.Source, opts); err != nil {
destPath := destWithInto(cfg.EffectiveSkillsSource(), opts, skill.Name)
if err := ensureIntoDirExists(cfg.EffectiveSkillsSource(), opts); err != nil {
return logSummary, fmt.Errorf("failed to create --into directory: %w", err)
}
fmt.Println()
@@ -417,7 +417,7 @@ func installSelectedSkills(selected []install.SkillInfo, discovery *install.Disc
// Ensure Into directory exists for batch installs
if opts.Into != "" {
if err := ensureIntoDirExists(cfg.Source, opts); err != nil {
if err := ensureIntoDirExists(cfg.EffectiveSkillsSource(), opts); err != nil {
if installSpinner != nil {
installSpinner.Fail("Failed to create --into directory")
}
@@ -444,7 +444,7 @@ func installSelectedSkills(selected []install.SkillInfo, discovery *install.Disc
// at the top level (or under --into if specified). Root orchestrator
// skills (Path=".") get only their SKILL.md copied (handled in
// install_apply.go), so no nesting is needed.
destPath := destWithInto(cfg.Source, opts, skill.Name)
destPath := destWithInto(cfg.EffectiveSkillsSource(), opts, skill.Name)
skillOpts := opts
installResult, err := install.InstallFromDiscovery(discovery, skill, destPath, skillOpts)
@@ -806,16 +806,16 @@ func handleDirectInstall(source *install.Source, cfg *config.Config, opts instal
source.Name = skillName
// Determine destination path
destPath := destWithInto(cfg.Source, opts, skillName)
destPath := destWithInto(cfg.EffectiveSkillsSource(), opts, skillName)
// Ensure Into directory exists
if err := ensureIntoDirExists(cfg.Source, opts); err != nil {
if err := ensureIntoDirExists(cfg.EffectiveSkillsSource(), opts); err != nil {
return logSummary, fmt.Errorf("failed to create --into directory: %w", err)
}
// Cross-path duplicate detection (same as handleGitInstall)
if !opts.Force && source.CloneURL != "" {
if err := install.CheckCrossPathDuplicate(cfg.Source, source.CloneURL, opts.Into); err != nil {
if err := install.CheckCrossPathDuplicate(cfg.EffectiveSkillsSource(), source.CloneURL, opts.Into); err != nil {
return logSummary, err
}
}
@@ -892,7 +892,7 @@ func installFromGlobalConfig(cfg *config.Config, opts install.InstallOptions) (i
AuditVerbose: opts.AuditVerbose,
}
store, storeErr := install.LoadMetadataWithMigration(cfg.Source, "")
store, storeErr := install.LoadMetadataWithMigration(cfg.EffectiveSkillsSource(), "")
if storeErr != nil {
return summary, fmt.Errorf("failed to load metadata: %w", storeErr)
}
+4 -4
View File
@@ -601,7 +601,7 @@ func cmdList(args []string) error {
loadFn := func() listLoadResult {
// Always load both skills and agents — tab UI filters the view.
var allEntries []skillEntry
discovered, discErr := sync.DiscoverSourceSkillsAll(cfg.Source)
discovered, discErr := sync.DiscoverSourceSkillsAll(cfg.EffectiveSkillsSource())
if discErr != nil {
return listLoadResult{err: fmt.Errorf("cannot discover skills: %w", discErr)}
}
@@ -615,7 +615,7 @@ func cmdList(args []string) error {
sortSkillEntries(allEntries, opts.SortBy)
return listLoadResult{skills: toSkillItems(allEntries), totalCount: total}
}
action, skillName, skillKind, err := runListTUI(loadFn, "global", cfg.Source, cfg.EffectiveAgentsSource(), cfg.Targets, kind)
action, skillName, skillKind, err := runListTUI(loadFn, "global", cfg.EffectiveSkillsSource(), cfg.EffectiveAgentsSource(), cfg.Targets, kind)
if err != nil {
return err
}
@@ -665,7 +665,7 @@ func cmdList(args []string) error {
if kind.IncludesSkills() {
var discErr error
discoveredSkills, discErr = sync.DiscoverSourceSkillsAll(cfg.Source)
discoveredSkills, discErr = sync.DiscoverSourceSkillsAll(cfg.EffectiveSkillsSource())
if discErr != nil {
if sp != nil {
sp.Fail("Discovery failed")
@@ -739,7 +739,7 @@ func cmdList(args []string) error {
// Hide tracked repos section when filter/pattern is active
if len(trackedRepos) > 0 && !hasFilter {
displayTrackedRepos(trackedRepos, discoveredSkills, cfg.Source)
displayTrackedRepos(trackedRepos, discoveredSkills, cfg.EffectiveSkillsSource())
}
// Show match stats when filter is active
+1 -1
View File
@@ -93,7 +93,7 @@ func cmdNew(args []string) error {
if err != nil {
return fmt.Errorf("failed to load config: %w (run 'skillshare init' first)", err)
}
sourceDir = cfg.Source
sourceDir = cfg.EffectiveSkillsSource()
}
// Create skill directory path
+7 -7
View File
@@ -66,14 +66,14 @@ func pullFromRemote(cfg *config.Config, dryRun, force bool) error {
spinner := ui.StartSpinner("Checking repository...")
// Check if source is a git repo with a configured remote
err := checkGitRepo(cfg.Source, spinner)
err := checkGitRepo(cfg.EffectiveSkillsSource(), spinner)
if err != nil {
return nil
}
// Check for uncommitted changes
cmd := exec.Command("git", "status", "--porcelain")
cmd.Dir = cfg.Source
cmd.Dir = cfg.EffectiveSkillsSource()
output, err := cmd.Output()
if err != nil {
spinner.Fail("Failed to check git status")
@@ -83,7 +83,7 @@ func pullFromRemote(cfg *config.Config, dryRun, force bool) error {
if len(strings.TrimSpace(string(output))) > 0 {
spinner.Fail("Local changes detected")
ui.Info(" Run: skillshare push")
ui.Info(" Or: cd %s && git stash -u", cfg.Source)
ui.Info(" Or: cd %s && git stash -u", cfg.EffectiveSkillsSource())
return nil
}
@@ -100,15 +100,15 @@ func pullFromRemote(cfg *config.Config, dryRun, force bool) error {
// upstream. This mirrors tryPullAfterRemoteSetup() in init.go and avoids
// merge conflicts between the local init commit and remote history.
// Subsequent pulls: normal git pull.
authEnv := gitops.AuthEnvForRepo(cfg.Source)
if !gitops.HasUpstream(cfg.Source) {
if _, err := firstPull(cfg.Source, authEnv, force, spinner); err != nil {
authEnv := gitops.AuthEnvForRepo(cfg.EffectiveSkillsSource())
if !gitops.HasUpstream(cfg.EffectiveSkillsSource()) {
if _, err := firstPull(cfg.EffectiveSkillsSource(), authEnv, force, spinner); err != nil {
return err
}
} else {
spinner.Update("Running git pull...")
cmd = exec.Command("git", "pull")
cmd.Dir = cfg.Source
cmd.Dir = cfg.EffectiveSkillsSource()
if len(authEnv) > 0 {
cmd.Env = append(os.Environ(), authEnv...)
}
+4 -4
View File
@@ -227,11 +227,11 @@ func cmdPush(args []string) error {
spinner := ui.StartSpinner("Checking repository...")
if err := checkGitRepo(cfg.Source, spinner); err != nil {
if err := checkGitRepo(cfg.EffectiveSkillsSource(), spinner); err != nil {
return nil // Error already displayed
}
changes, err := getGitChanges(cfg.Source)
changes, err := getGitChanges(cfg.EffectiveSkillsSource())
if err != nil {
spinner.Fail("Failed to check git status")
return err
@@ -257,12 +257,12 @@ func cmdPush(args []string) error {
}
if hasChanges {
if err := stageAndCommit(cfg.Source, opts.message, spinner); err != nil {
if err := stageAndCommit(cfg.EffectiveSkillsSource(), opts.message, spinner); err != nil {
return err
}
}
if err := gitPush(cfg.Source, spinner); err != nil {
if err := gitPush(cfg.EffectiveSkillsSource(), spinner); err != nil {
return nil // Error already displayed
}
+2 -2
View File
@@ -541,7 +541,7 @@ func installFromSearchResult(result search.SearchResult, cfg *config.Config) (er
}
// Determine destination
destPath := filepath.Join(cfg.Source, result.Name)
destPath := filepath.Join(cfg.EffectiveSkillsSource(), result.Name)
// Check if already exists
if _, err := os.Stat(destPath); err == nil {
@@ -581,7 +581,7 @@ func installFromSearchResult(result search.SearchResult, cfg *config.Config) (er
logSummary.InstalledSkills = []string{result.Name}
// Reconcile global config with installed skills
store, _ := install.LoadMetadataWithMigration(cfg.Source, "")
store, _ := install.LoadMetadataWithMigration(cfg.EffectiveSkillsSource(), "")
if store == nil {
store = install.NewMetadataStore()
}
+3 -3
View File
@@ -348,7 +348,7 @@ func collectSearchInstallGlobal(result search.SearchResult, cfg *config.Config,
return r
}
destPath := filepath.Join(cfg.Source, result.Name)
destPath := filepath.Join(cfg.EffectiveSkillsSource(), result.Name)
// Check if already exists
if _, err := os.Stat(destPath); err == nil {
@@ -565,7 +565,7 @@ func batchInstallFromSearchWithProgress(selected []search.SearchResult, mode run
_ = reconcileProjectRemoteSkills(runtime)
}
} else {
store, _ := install.LoadMetadataWithMigration(cfg.Source, "")
store, _ := install.LoadMetadataWithMigration(cfg.EffectiveSkillsSource(), "")
if store == nil {
store = install.NewMetadataStore()
}
@@ -602,7 +602,7 @@ func resolveBatchSourceDir(mode runMode, cfg *config.Config, cwd string) (string
}
return runtime.sourcePath, nil
}
return cfg.Source, nil
return cfg.EffectiveSkillsSource(), nil
}
// installFromDiscoveryResult installs a single skill from a pre-cloned discovery result.
+13 -13
View File
@@ -114,7 +114,7 @@ func cmdStatus(args []string) error {
if !jsonOutput {
sp := ui.StartSpinner("Discovering skills...")
discovered, stats, discoverErr := sync.DiscoverSourceSkillsWithStats(cfg.Source)
discovered, stats, discoverErr := sync.DiscoverSourceSkillsWithStats(cfg.EffectiveSkillsSource())
if discoverErr != nil {
discovered = nil
}
@@ -131,7 +131,7 @@ func cmdStatus(args []string) error {
if len(cfg.Extras) > 0 {
ui.Header("Extras")
printExtrasStatus(cfg.Extras, func(extra config.ExtraConfig) string {
return config.ResolveExtrasSourceDir(extra, cfg.ExtrasSource, cfg.Source)
return config.ResolveExtrasSourceDir(extra, cfg.EffectiveExtrasSource(), cfg.EffectiveSkillsSource())
})
}
@@ -145,21 +145,21 @@ func cmdStatus(args []string) error {
Version: version,
}
discovered, stats, _ := sync.DiscoverSourceSkillsWithStats(cfg.Source)
discovered, stats, _ := sync.DiscoverSourceSkillsWithStats(cfg.EffectiveSkillsSource())
trackedRepos := extractTrackedRepos(discovered)
output.Source = statusJSONSource{
Path: cfg.Source,
Exists: dirExists(cfg.Source),
Path: cfg.EffectiveSkillsSource(),
Exists: dirExists(cfg.EffectiveSkillsSource()),
Skillignore: buildSkillignoreJSON(stats),
}
output.SkillCount = len(discovered)
output.TrackedRepos = buildTrackedRepoJSON(cfg.Source, trackedRepos, discovered)
output.TrackedRepos = buildTrackedRepoJSON(cfg.EffectiveSkillsSource(), trackedRepos, discovered)
for name, target := range cfg.Targets {
sc := target.SkillsConfig()
tMode := getTargetMode(sc.Mode, cfg.Mode)
res := getTargetStatusDetail(target, cfg.Source, tMode)
res := getTargetStatusDetail(target, cfg.EffectiveSkillsSource(), tMode)
output.Targets = append(output.Targets, statusJSONTarget{
Name: name,
Path: sc.Path,
@@ -215,13 +215,13 @@ func printExtrasStatus(extras []config.ExtraConfig, sourceDirFn func(config.Extr
func printSourceStatus(cfg *config.Config, skillCount int, stats *skillignore.IgnoreStats) {
ui.Header("Source")
info, err := os.Stat(cfg.Source)
info, err := os.Stat(cfg.EffectiveSkillsSource())
if err != nil {
ui.Error("%s (not found)", cfg.Source)
ui.Error("%s (not found)", cfg.EffectiveSkillsSource())
return
}
ui.Success("%s (%d skills, %s)", cfg.Source, skillCount, info.ModTime().Format("2006-01-02 15:04"))
ui.Success("%s (%d skills, %s)", cfg.EffectiveSkillsSource(), skillCount, info.ModTime().Format("2006-01-02 15:04"))
printSkillignoreLine(stats)
// Agents source
@@ -281,7 +281,7 @@ func printTrackedReposStatus(cfg *config.Config, discovered []sync.DiscoveredSki
ui.Header("Tracked Repositories")
for _, repoName := range trackedRepos {
repoPath := filepath.Join(cfg.Source, repoName)
repoPath := filepath.Join(cfg.EffectiveSkillsSource(), repoName)
skillCount := 0
for _, d := range discovered {
@@ -388,7 +388,7 @@ func printTargetsStatus(cfg *config.Config, discovered []sync.DiscoveredSkill) e
// Skills sub-item
sc := target.SkillsConfig()
mode := getTargetMode(sc.Mode, cfg.Mode)
res := getTargetStatusDetail(target, cfg.Source, mode)
res := getTargetStatusDetail(target, cfg.EffectiveSkillsSource(), mode)
printTargetSubItem("skills", res.statusStr, res.detail)
if mode == "merge" || mode == "copy" {
@@ -533,7 +533,7 @@ func checkSkillVersion(cfg *config.Config) {
ui.Success("CLI: %s", version)
// Skill version
localVersion := versioncheck.ReadLocalSkillVersion(cfg.Source)
localVersion := versioncheck.ReadLocalSkillVersion(cfg.EffectiveSkillsSource())
if localVersion == "" {
ui.Warning("Skill: not found or missing version")
+10 -10
View File
@@ -190,7 +190,7 @@ func cmdSync(args []string) error {
if !jsonOutput {
spinner = ui.StartSpinner("Discovering skills")
}
discoveredSkills, ignoreStats, discoverErr := sync.DiscoverSourceSkillsWithStatsAndContext(cfg.Source)
discoveredSkills, ignoreStats, discoverErr := sync.DiscoverSourceSkillsWithStatsAndContext(cfg.EffectiveSkillsSource())
if discoverErr != nil {
if spinner != nil {
spinner.Fail("Discovery failed")
@@ -226,9 +226,9 @@ func cmdSync(args []string) error {
var results []syncTargetResult
var failedTargets int
if jsonOutput {
results, failedTargets = runParallelSyncQuiet(entries, cfg.Source, discoveredSkills, dryRun, force, "")
results, failedTargets = runParallelSyncQuiet(entries, cfg.EffectiveSkillsSource(), discoveredSkills, dryRun, force, "")
} else {
results, failedTargets = runParallelSync(entries, cfg.Source, discoveredSkills, dryRun, force, "")
results, failedTargets = runParallelSync(entries, cfg.EffectiveSkillsSource(), discoveredSkills, dryRun, force, "")
}
var syncErr error
@@ -294,7 +294,7 @@ func cmdSync(args []string) error {
if hasAll && len(cfg.Extras) > 0 {
agentPaths := collectAgentTargetPathsGlobal(cfg)
extrasEntries := runExtrasSyncEntries(cfg.Extras, func(extra config.ExtraConfig) string {
return config.ResolveExtrasSourceDir(extra, cfg.ExtrasSource, cfg.Source)
return config.ResolveExtrasSourceDir(extra, cfg.EffectiveExtrasSource(), cfg.EffectiveSkillsSource())
}, dryRun, force, "", agentPaths)
return syncOutputJSON(results, dryRun, start, ignoreStats, syncErr, ctxCost, extrasEntries)
}
@@ -491,11 +491,11 @@ func syncTarget(name string, target config.TargetConfig, cfg *config.Config, dry
switch mode {
case "merge":
return syncMergeMode(name, target, cfg.Source, dryRun, force)
return syncMergeMode(name, target, cfg.EffectiveSkillsSource(), dryRun, force)
case "copy":
return syncCopyMode(name, target, cfg.Source, dryRun, force)
return syncCopyMode(name, target, cfg.EffectiveSkillsSource(), dryRun, force)
default:
return syncSymlinkMode(name, target, cfg.Source, dryRun, force)
return syncSymlinkMode(name, target, cfg.EffectiveSkillsSource(), dryRun, force)
}
}
@@ -516,11 +516,11 @@ func syncTargetWithSkillsStats(name string, target config.TargetConfig, cfg *con
switch mode {
case "merge":
return syncMergeModeWithSkills(name, target, cfg.Source, skills, dryRun, force)
return syncMergeModeWithSkills(name, target, cfg.EffectiveSkillsSource(), skills, dryRun, force)
case "copy":
return syncCopyModeWithSkills(name, target, cfg.Source, skills, dryRun, force)
return syncCopyModeWithSkills(name, target, cfg.EffectiveSkillsSource(), skills, dryRun, force)
default:
err := syncSymlinkMode(name, target, cfg.Source, dryRun, force)
err := syncSymlinkMode(name, target, cfg.EffectiveSkillsSource(), dryRun, force)
return syncModeStats{}, err
}
}
+3 -3
View File
@@ -72,7 +72,7 @@ func cmdSyncExtrasGlobal(dryRun, force, jsonOutput bool, start time.Time) error
if len(cfg.Extras) == 0 {
// Clean up empty extras directory
removeEmptyDir(config.ExtrasParentDir(cfg.Source))
removeEmptyDir(config.ExtrasParentDir(cfg.EffectiveSkillsSource()))
if jsonOutput {
return writeJSON(&syncExtrasJSONOutput{Extras: []syncExtrasJSONEntry{}, Duration: formatDuration(start)})
@@ -90,7 +90,7 @@ func cmdSyncExtrasGlobal(dryRun, force, jsonOutput bool, start time.Time) error
return nil
}
configDir := filepath.Dir(cfg.Source)
configDir := filepath.Dir(cfg.EffectiveSkillsSource())
// Auto-migrate legacy extras directories (flat → extras/<name>/)
if warnings := config.MigrateExtrasDir(configDir, cfg.Extras); len(warnings) > 0 {
@@ -120,7 +120,7 @@ func cmdSyncExtrasGlobal(dryRun, force, jsonOutput bool, start time.Time) error
}
for _, extra := range cfg.Extras {
extraSource := config.ResolveExtrasSourceDir(extra, cfg.ExtrasSource, cfg.Source)
extraSource := config.ResolveExtrasSourceDir(extra, cfg.EffectiveExtrasSource(), cfg.EffectiveSkillsSource())
// Auto-create source directory if it doesn't exist
if _, statErr := os.Stat(extraSource); os.IsNotExist(statErr) {
+3 -3
View File
@@ -339,7 +339,7 @@ func targetRemove(args []string) error {
ui.Header("Unlinking targets")
for _, targetName := range toRemove {
target := cfg.Targets[targetName]
if err := unlinkTarget(targetName, target, cfg.Source); err != nil {
if err := unlinkTarget(targetName, target, cfg.EffectiveSkillsSource()); err != nil {
ui.Error("%s: %v", targetName, err)
continue
}
@@ -702,10 +702,10 @@ func showTargetInfo(cfg *config.Config, name string, target config.TargetConfig)
status, managed, local := sync.CheckStatusCopy(sc.Path)
statusLine = fmt.Sprintf("%s (managed: %d, local: %d)", status, managed, local)
case "merge":
status, linked, local := sync.CheckStatusMerge(sc.Path, cfg.Source)
status, linked, local := sync.CheckStatusMerge(sc.Path, cfg.EffectiveSkillsSource())
statusLine = fmt.Sprintf("%s (linked: %d, local: %d)", status, linked, local)
default:
statusLine = sync.CheckStatus(sc.Path, cfg.Source).String()
statusLine = sync.CheckStatus(sc.Path, cfg.EffectiveSkillsSource()).String()
}
namingDisplay := config.EffectiveTargetNaming(sc.TargetNaming)
+1 -1
View File
@@ -212,7 +212,7 @@ func buildTargetTUIItems(isProject bool, cwd string) ([]targetTUIItem, error) {
name: name,
target: t,
displayPath: t.SkillsConfig().Path,
skillSync: buildTargetSkillSyncSummary(t.SkillsConfig().Path, cfg.Source, t.SkillsConfig().Mode),
skillSync: buildTargetSkillSyncSummary(t.SkillsConfig().Path, cfg.EffectiveSkillsSource(), t.SkillsConfig().Mode),
agentConfig: config.ResourceTargetConfig{Mode: agentSummaryMode(agentSummary), Include: agentSummaryInclude(agentSummary), Exclude: agentSummaryExclude(agentSummary)},
agentSummary: agentSummary,
})
+1 -1
View File
@@ -321,7 +321,7 @@ func resolveSourceDir(mode runMode, cwd string, kind resourceKindFilter) (string
if err != nil {
return "", fmt.Errorf("failed to load config: %w", err)
}
return cfg.Source, nil
return cfg.EffectiveSkillsSource(), nil
}
// formatAge is an alias for the shared formatDurationShort.
+1 -1
View File
@@ -193,7 +193,7 @@ func loadUIConfig() (*config.Config, error) {
return nil, fmt.Errorf("skillshare is not initialized: run 'skillshare init' first")
}
source := strings.TrimSpace(cfg.Source)
source := strings.TrimSpace(cfg.EffectiveSkillsSource())
if source == "" {
return nil, fmt.Errorf("invalid config: source is empty (run 'skillshare init' first)")
}
+14 -14
View File
@@ -137,23 +137,23 @@ func resolveUninstallTarget(skillName string, cfg *config.Config) (*uninstallTar
// Normalize _ prefix for tracked repos
if !strings.HasPrefix(skillName, "_") {
prefixedPath := filepath.Join(cfg.Source, "_"+skillName)
prefixedPath := filepath.Join(cfg.EffectiveSkillsSource(), "_"+skillName)
if install.IsGitRepo(prefixedPath) {
skillName = "_" + skillName
}
}
skillPath := filepath.Join(cfg.Source, skillName)
skillPath := filepath.Join(cfg.EffectiveSkillsSource(), skillName)
info, err := os.Stat(skillPath)
if err != nil {
if os.IsNotExist(err) {
// Fallback: search by basename in nested directories
resolved, resolveErr := resolveNestedSkillDir(cfg.Source, skillName)
resolved, resolveErr := resolveNestedSkillDir(cfg.EffectiveSkillsSource(), skillName)
if resolveErr != nil {
return nil, resolveErr
}
skillName = resolved
skillPath = filepath.Join(cfg.Source, resolved)
skillPath = filepath.Join(cfg.EffectiveSkillsSource(), resolved)
} else {
return nil, fmt.Errorf("cannot access skill: %w", err)
}
@@ -171,7 +171,7 @@ func resolveUninstallTarget(skillName string, cfg *config.Config) (*uninstallTar
// resolveUninstallByGlob scans the source directory for top-level entries
// whose names match the given glob pattern (e.g. "core-*", "_team-?").
func resolveUninstallByGlob(pattern string, cfg *config.Config) ([]*uninstallTarget, error) {
entries, err := os.ReadDir(cfg.Source)
entries, err := os.ReadDir(cfg.EffectiveSkillsSource())
if err != nil {
return nil, fmt.Errorf("cannot read source directory: %w", err)
}
@@ -182,7 +182,7 @@ func resolveUninstallByGlob(pattern string, cfg *config.Config) ([]*uninstallTar
continue
}
if matchGlob(pattern, e.Name()) {
skillPath := filepath.Join(cfg.Source, e.Name())
skillPath := filepath.Join(cfg.EffectiveSkillsSource(), e.Name())
targets = append(targets, &uninstallTarget{
name: e.Name(),
path: skillPath,
@@ -605,7 +605,7 @@ func cmdUninstall(args []string) error {
}
// Load centralized metadata store for display/reinstall hints.
skillsStore, _ := install.LoadMetadataWithMigration(cfg.Source, "")
skillsStore, _ := install.LoadMetadataWithMigration(cfg.EffectiveSkillsSource(), "")
if skillsStore == nil {
skillsStore = install.NewMetadataStore()
}
@@ -620,7 +620,7 @@ func cmdUninstall(args []string) error {
if !opts.jsonOutput {
sp = ui.StartSpinner("Discovering skills...")
}
discovered, _, err := sync.DiscoverSourceSkillsLite(cfg.Source)
discovered, _, err := sync.DiscoverSourceSkillsLite(cfg.EffectiveSkillsSource())
if err != nil {
if sp != nil {
sp.Fail("Discovery failed")
@@ -647,7 +647,7 @@ func cmdUninstall(args []string) error {
topDirs[topLevelDir(d.RelPath)] = true
}
for dir := range topDirs {
skillPath := filepath.Join(cfg.Source, dir)
skillPath := filepath.Join(cfg.EffectiveSkillsSource(), dir)
targets = append(targets, &uninstallTarget{
name: dir,
path: skillPath,
@@ -693,7 +693,7 @@ func cmdUninstall(args []string) error {
}
for _, group := range opts.groups {
groupTargets, err := resolveGroupSkills(group, cfg.Source)
groupTargets, err := resolveGroupSkills(group, cfg.EffectiveSkillsSource())
if err != nil {
resolveWarnings = append(resolveWarnings, fmt.Sprintf("--group %s: %v", group, err))
continue
@@ -949,7 +949,7 @@ func cmdUninstall(args []string) error {
}
}
if len(gitignoreEntries) > 0 {
install.RemoveFromGitIgnoreBatch(cfg.Source, gitignoreEntries) //nolint:errcheck
install.RemoveFromGitIgnoreBatch(cfg.EffectiveSkillsSource(), gitignoreEntries) //nolint:errcheck
}
}
} else if batch {
@@ -976,7 +976,7 @@ func cmdUninstall(args []string) error {
}
}
if len(gitignoreEntries) > 0 {
install.RemoveFromGitIgnoreBatch(cfg.Source, gitignoreEntries) //nolint:errcheck
install.RemoveFromGitIgnoreBatch(cfg.EffectiveSkillsSource(), gitignoreEntries) //nolint:errcheck
}
}
@@ -1064,7 +1064,7 @@ func cmdUninstall(args []string) error {
}
}
if len(gitignoreEntries) > 0 {
if _, err := install.RemoveFromGitIgnoreBatch(cfg.Source, gitignoreEntries); err != nil {
if _, err := install.RemoveFromGitIgnoreBatch(cfg.EffectiveSkillsSource(), gitignoreEntries); err != nil {
ui.Warning("Could not update .gitignore: %v", err)
}
}
@@ -1079,7 +1079,7 @@ func cmdUninstall(args []string) error {
removedNames[t.name] = true
}
skillsStore.RemoveByNames(removedNames)
if saveErr := skillsStore.Save(cfg.Source); saveErr != nil {
if saveErr := skillsStore.Save(cfg.EffectiveSkillsSource()); saveErr != nil {
ui.Warning("Failed to update metadata after uninstall: %v", saveErr)
}
}
+2 -2
View File
@@ -182,7 +182,7 @@ func cmdUpdate(args []string) error {
if opts.threshold == "" {
opts.threshold = cfg.Audit.BlockThreshold
}
sourcePath := utils.ResolveSymlink(cfg.Source)
sourcePath := utils.ResolveSymlink(cfg.EffectiveSkillsSource())
// In JSON mode, redirect all UI output to stderr early so the
// header, step, spinner, and handler output don't corrupt stdout.
@@ -199,7 +199,7 @@ func cmdUpdate(args []string) error {
}
ui.Header(ui.WithModeLabel("Updating"))
ui.StepStart("Source", cfg.Source)
ui.StepStart("Source", cfg.EffectiveSkillsSource())
// --- Resolve targets ---
var targets []updateTarget
+6 -6
View File
@@ -237,8 +237,8 @@ func upgradeSkillshareSkill(dryRun, force bool) error {
return fmt.Errorf("config not found: run 'skillshare init' first")
}
skillshareSkillDir := filepath.Join(cfg.Source, "skillshare")
localVersion := versionpkg.ReadLocalSkillVersion(cfg.Source)
skillshareSkillDir := filepath.Join(cfg.EffectiveSkillsSource(), "skillshare")
localVersion := versionpkg.ReadLocalSkillVersion(cfg.EffectiveSkillsSource())
// Skill not installed
if localVersion == "" {
@@ -249,7 +249,7 @@ func upgradeSkillshareSkill(dryRun, force bool) error {
ui.StepEnd("Action", "Would download")
return nil
}
return doSkillDownload(skillshareSkillDir, cfg.Source, "")
return doSkillDownload(skillshareSkillDir, cfg.EffectiveSkillsSource(), "")
}
if dryRun {
@@ -269,7 +269,7 @@ func upgradeSkillshareSkill(dryRun, force bool) error {
return nil
}
return doSkillDownload(skillshareSkillDir, cfg.Source, "")
return doSkillDownload(skillshareSkillDir, cfg.EffectiveSkillsSource(), "")
}
// Skill installed — compare versions
@@ -280,7 +280,7 @@ func upgradeSkillshareSkill(dryRun, force bool) error {
ui.StepEnd("Action", "Would re-download (forced)")
return nil
}
return doSkillDownload(skillshareSkillDir, cfg.Source, localVersion)
return doSkillDownload(skillshareSkillDir, cfg.EffectiveSkillsSource(), localVersion)
}
treeSpinner := ui.StartTreeSpinner("Checking latest version...", false)
@@ -301,7 +301,7 @@ func upgradeSkillshareSkill(dryRun, force bool) error {
return nil
}
return doSkillDownload(skillshareSkillDir, cfg.Source, localVersion)
return doSkillDownload(skillshareSkillDir, cfg.EffectiveSkillsSource(), localVersion)
}
func doSkillDownload(skillshareSkillDir, sourceDir, fromVersion string) error {
+8 -6
View File
@@ -13,20 +13,22 @@ import (
func ValidateConfig(cfg *Config) (warnings []string, err error) {
var errs []string
// Source path validation
if cfg.Source == "" {
// Source path validation — requires the user to explicitly configure
// either the legacy `source:` field or the new `sources.skills:` map,
// then verifies the resolved path exists and is a directory.
if cfg.Source == "" && cfg.Sources.Skills == "" {
errs = append(errs, "source path is empty")
} else {
expanded := ExpandPath(cfg.Source)
info, statErr := os.Stat(expanded)
sourcePath := cfg.EffectiveSkillsSource()
info, statErr := os.Stat(sourcePath)
if statErr != nil {
if os.IsNotExist(statErr) {
errs = append(errs, fmt.Sprintf("source path does not exist: %s", cfg.Source))
errs = append(errs, fmt.Sprintf("source path does not exist: %s", sourcePath))
} else {
errs = append(errs, fmt.Sprintf("cannot access source path: %v", statErr))
}
} else if !info.IsDir() {
errs = append(errs, fmt.Sprintf("source path is not a directory: %s", cfg.Source))
errs = append(errs, fmt.Sprintf("source path is not a directory: %s", sourcePath))
}
}
+1 -1
View File
@@ -11,7 +11,7 @@ import (
// skills (those with install metadata or tracked repos) and ensures they are
// present in the MetadataStore.
func ReconcileGlobalSkills(cfg *Config, store *install.MetadataStore) error {
sourcePath := cfg.Source
sourcePath := cfg.EffectiveSkillsSource()
if _, err := os.Stat(sourcePath); os.IsNotExist(err) {
return nil
}
+1 -1
View File
@@ -13,7 +13,7 @@ const registryFileName = "registry.yaml"
// SourceRoot returns the git repo root for the given source path.
// Walks up from source to find .git/ directory. If none found,
// returns source as-is. Handles --subdir where cfg.Source includes
// returns source as-is. Handles --subdir where cfg.EffectiveSkillsSource() includes
// a subdirectory within the git repo.
func SourceRoot(source string) string {
dir := source
+1 -1
View File
@@ -38,7 +38,7 @@ const analyzeCharsPerToken = 4
func (s *Server) handleAnalyze(w http.ResponseWriter, r *http.Request) {
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
targets := s.cfg.Targets
defaultMode := s.cfg.Mode
s.mu.RUnlock()
+2 -2
View File
@@ -280,7 +280,7 @@ func (s *Server) resolveAuditSource(r *http.Request) (string, string, bool) {
if kind == "agents" {
return s.agentsSource(), "agent", true
}
return s.cfg.Source, "skill", false
return s.cfg.EffectiveSkillsSource(), "skill", false
}
func (s *Server) handleAuditAll(w http.ResponseWriter, r *http.Request) {
@@ -338,7 +338,7 @@ func (s *Server) handleAuditAll(w http.ResponseWriter, r *http.Request) {
func (s *Server) handleAuditSkill(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
policy := s.auditPolicy()
projectRoot := s.projectRoot
+2 -2
View File
@@ -41,7 +41,7 @@ type collectSkillRef struct {
func (s *Server) handleCollectScan(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
globalMode := s.cfg.Mode
targets := s.cloneTargets()
agentsSource := s.agentsSource()
@@ -223,7 +223,7 @@ func (s *Server) handleCollect(w http.ResponseWriter, r *http.Request) {
})
}
result, err := ssync.PullSkills(resolved, s.cfg.Source, opts)
result, err := ssync.PullSkills(resolved, s.cfg.EffectiveSkillsSource(), opts)
if err != nil {
writeError(w, http.StatusInternalServerError, "collect failed: "+err.Error())
return
+1 -1
View File
@@ -64,7 +64,7 @@ func (s *Server) handleCreateSkill(w http.ResponseWriter, r *http.Request) {
s.mu.Lock()
defer s.mu.Unlock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
skillDir := filepath.Join(source, req.Name)
// Check if skill already exists
+1 -1
View File
@@ -27,7 +27,7 @@ func (s *Server) handleDiffStream(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before slow I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
globalMode := s.cfg.Mode
targets := s.cloneTargets()
+18 -14
View File
@@ -35,7 +35,7 @@ func (s *Server) extrasSourceDir(extra config.ExtraConfig) string {
if s.IsProjectMode() {
return config.ExtrasSourceDirProject(s.projectCfg.EffectiveExtrasSource(s.projectRoot), extra.Name)
}
return config.ResolveExtrasSourceDir(extra, s.cfg.ExtrasSource, s.cfg.Source)
return config.ResolveExtrasSourceDir(extra, s.cfg.EffectiveExtrasSource(), s.cfg.EffectiveSkillsSource())
}
// extrasConfig returns the extras slice for the current mode.
@@ -52,8 +52,16 @@ func (s *Server) handleExtras(w http.ResponseWriter, r *http.Request) {
s.mu.RLock()
extras := s.extrasConfig()
projectRoot := s.projectRoot
source := s.cfg.Source
extrasSource := s.cfg.ExtrasSource
source := s.cfg.EffectiveSkillsSource()
extrasSource := s.cfg.EffectiveExtrasSource()
// rawExtrasSource is the user's explicit configuration value (either the
// legacy extras_source field or the new sources.extras field). It is empty
// only when the user did not configure either, so source_type can
// distinguish "default" (derived) from "extras_source" (user-configured).
rawExtrasSource := s.cfg.ExtrasSource
if rawExtrasSource == "" {
rawExtrasSource = s.cfg.Sources.Extras
}
var projectExtrasParent string
if s.IsProjectMode() {
projectExtrasParent = s.projectCfg.EffectiveExtrasSource(s.projectRoot)
@@ -65,7 +73,7 @@ func (s *Server) handleExtras(w http.ResponseWriter, r *http.Request) {
// Resolve the extras_source value for source_type resolution (global mode only).
resolvedExtrasSource := ""
if !isProjectMode {
resolvedExtrasSource = extrasSource
resolvedExtrasSource = rawExtrasSource
}
entries := make([]extrasListEntry, 0, len(extras))
@@ -139,8 +147,8 @@ func (s *Server) handleExtrasDiff(w http.ResponseWriter, r *http.Request) {
s.mu.RLock()
extras := s.extrasConfig()
projectRoot := s.projectRoot
source := s.cfg.Source
extrasSource := s.cfg.ExtrasSource
source := s.cfg.EffectiveSkillsSource()
extrasSource := s.cfg.EffectiveExtrasSource()
var projectExtrasParent string
if s.IsProjectMode() {
projectExtrasParent = s.projectCfg.EffectiveExtrasSource(s.projectRoot)
@@ -318,12 +326,8 @@ func (s *Server) handleExtrasCreate(w http.ResponseWriter, r *http.Request) {
extra.Targets = append(extra.Targets, et)
}
// Backfill extras_source if not set (global mode only)
if !s.IsProjectMode() && s.cfg.ExtrasSource == "" {
s.cfg.ExtrasSource = config.ExtrasParentDir(s.cfg.Source)
}
// Append to config
// Append to config (extras source resolution is handled by
// s.cfg.EffectiveExtrasSource() inside s.extrasSourceDir; no backfill needed).
if s.IsProjectMode() {
s.projectCfg.Extras = append(s.projectCfg.Extras, extra)
} else {
@@ -373,8 +377,8 @@ func (s *Server) handleExtrasSync(w http.ResponseWriter, r *http.Request) {
s.mu.RLock()
extras := s.extrasConfig()
projectRoot := s.projectRoot
source := s.cfg.Source
extrasSource := s.cfg.ExtrasSource
source := s.cfg.EffectiveSkillsSource()
extrasSource := s.cfg.EffectiveExtrasSource()
var projectExtrasParent string
if s.IsProjectMode() {
projectExtrasParent = s.projectCfg.EffectiveExtrasSource(s.projectRoot)
+17 -6
View File
@@ -349,9 +349,12 @@ func TestHandleExtras_ProjectMode_DefaultSourceType(t *testing.T) {
}
}
// TestHandleExtrasCreate_BackfillsExtrasSource verifies that POST /api/extras
// auto-populates extras_source in config when it's missing.
func TestHandleExtrasCreate_BackfillsExtrasSource(t *testing.T) {
// TestHandleExtrasCreate_PreservesEmptyExtrasSource verifies that POST /api/extras
// does NOT silently write the legacy extras_source field when the user has
// not explicitly set it. The runtime fallback is provided by
// Config.EffectiveExtrasSource(), so backfilling on save would surprise
// users with an unexpected diff in their config.yaml.
func TestHandleExtrasCreate_PreservesEmptyExtrasSource(t *testing.T) {
// Create server with NO extras_source set
s, sourceDir := newTestServerWithExtras(t, nil, "")
@@ -371,13 +374,21 @@ func TestHandleExtrasCreate_BackfillsExtrasSource(t *testing.T) {
t.Fatalf("expected 200, got %d: %s", rr.Code, rr.Body.String())
}
// Reload config from disk and verify extras_source was backfilled
// Reload config from disk and verify extras_source is still empty —
// no silent backfill — and that EffectiveExtrasSource() resolves to
// the derived default.
cfg, err := config.Load()
if err != nil {
t.Fatalf("failed to reload config: %v", err)
}
if cfg.ExtrasSource != "" {
t.Errorf("expected empty ExtrasSource (no silent backfill), got %q", cfg.ExtrasSource)
}
if cfg.Sources.Extras != "" {
t.Errorf("expected empty Sources.Extras (no silent backfill), got %q", cfg.Sources.Extras)
}
expected := config.ExtrasParentDir(sourceDir)
if cfg.ExtrasSource != expected {
t.Errorf("expected ExtrasSource %q, got %q", expected, cfg.ExtrasSource)
if got := cfg.EffectiveExtrasSource(); got != expected {
t.Errorf("expected EffectiveExtrasSource %q (derived), got %q", expected, got)
}
}
+5 -5
View File
@@ -26,7 +26,7 @@ type gitStatusResponse struct {
func (s *Server) handleGitStatus(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
src := s.cfg.Source
src := s.cfg.EffectiveSkillsSource()
s.mu.RUnlock()
resp := gitStatusResponse{
SourceDir: src,
@@ -85,7 +85,7 @@ type gitBranchesResponse struct {
func (s *Server) handleGitBranches(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
src := s.cfg.Source
src := s.cfg.EffectiveSkillsSource()
s.mu.RUnlock()
if !git.IsRepo(src) {
@@ -155,7 +155,7 @@ func (s *Server) handleGitCheckout(w http.ResponseWriter, r *http.Request) {
return
}
src := s.cfg.Source
src := s.cfg.EffectiveSkillsSource()
if !git.IsRepo(src) {
writeError(w, http.StatusBadRequest, "source directory is not a git repository")
@@ -231,7 +231,7 @@ func (s *Server) handlePush(w http.ResponseWriter, r *http.Request) {
return
}
src := s.cfg.Source
src := s.cfg.EffectiveSkillsSource()
if !git.IsRepo(src) {
writeError(w, http.StatusBadRequest, "source directory is not a git repository")
@@ -320,7 +320,7 @@ func (s *Server) handlePull(w http.ResponseWriter, r *http.Request) {
}
json.NewDecoder(r.Body).Decode(&body)
src := s.cfg.Source
src := s.cfg.EffectiveSkillsSource()
if !git.IsRepo(src) {
writeError(w, http.StatusBadRequest, "source directory is not a git repository")
+10 -10
View File
@@ -126,7 +126,7 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) {
// Ensure Into directory exists
if body.Into != "" {
baseDir := s.cfg.Source
baseDir := s.cfg.EffectiveSkillsSource()
if body.Kind == "agent" {
baseDir = s.agentsSource()
}
@@ -145,7 +145,7 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) {
SkipAudit: body.SkipAudit,
AuditThreshold: s.auditThreshold(),
Branch: body.Branch,
SourceDir: s.cfg.Source,
SourceDir: s.cfg.EffectiveSkillsSource(),
}
if s.IsProjectMode() {
installOpts.AuditProjectRoot = s.projectRoot
@@ -187,7 +187,7 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) {
})
} else {
// Skill install: copy directory to skills source
destPath := filepath.Join(s.cfg.Source, body.Into, skillName)
destPath := filepath.Join(s.cfg.EffectiveSkillsSource(), body.Into, skillName)
res, err := install.InstallFromDiscovery(discovery, install.SkillInfo{
Name: sel.Name,
Path: sel.Path,
@@ -269,7 +269,7 @@ func (s *Server) handleInstallBatch(w http.ResponseWriter, r *http.Request) {
}
}
if s.IsProjectMode() {
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.Source); rErr != nil {
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil {
log.Printf("warning: failed to reconcile project skills config: %v", rErr)
}
} else {
@@ -329,7 +329,7 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) {
return
}
trackSourceDir := s.cfg.Source
trackSourceDir := s.cfg.EffectiveSkillsSource()
if trackedKind == "agent" {
trackSourceDir = s.agentsSource()
}
@@ -373,7 +373,7 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) {
// Reconcile config after tracked repo install
if trackedKind == "skill" {
if s.IsProjectMode() {
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.Source); rErr != nil {
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil {
log.Printf("warning: failed to reconcile project skills config: %v", rErr)
}
} else {
@@ -418,16 +418,16 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) {
// Cross-path duplicate detection
if !body.Force && source.CloneURL != "" {
if err := install.CheckCrossPathDuplicate(s.cfg.Source, source.CloneURL, body.Into); err != nil {
if err := install.CheckCrossPathDuplicate(s.cfg.EffectiveSkillsSource(), source.CloneURL, body.Into); err != nil {
writeError(w, http.StatusConflict, err.Error())
return
}
}
// Regular install
destPath := filepath.Join(s.cfg.Source, body.Into, source.Name)
destPath := filepath.Join(s.cfg.EffectiveSkillsSource(), body.Into, source.Name)
if body.Into != "" {
if err := os.MkdirAll(filepath.Join(s.cfg.Source, body.Into), 0755); err != nil {
if err := os.MkdirAll(filepath.Join(s.cfg.EffectiveSkillsSource(), body.Into), 0755); err != nil {
writeError(w, http.StatusInternalServerError, "failed to create into directory: "+err.Error())
return
}
@@ -461,7 +461,7 @@ func (s *Server) handleInstall(w http.ResponseWriter, r *http.Request) {
// Reconcile config after single install
if s.IsProjectMode() {
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.Source); rErr != nil {
if rErr := config.ReconcileProjectSkills(s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil {
log.Printf("warning: failed to reconcile project skills config: %v", rErr)
}
} else {
+2 -2
View File
@@ -23,9 +23,9 @@ type trackedRepoItem struct {
func (s *Server) handleOverview(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
extrasSource := s.cfg.ExtrasSource
extrasSource := s.cfg.EffectiveExtrasSource()
if s.IsProjectMode() {
extrasSource = filepath.Join(s.projectRoot, ".skillshare", "extras")
}
+2 -2
View File
@@ -35,7 +35,7 @@ func (s *Server) handlePutSkillContent(w http.ResponseWriter, r *http.Request) {
start := time.Now()
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
s.mu.RUnlock()
@@ -123,7 +123,7 @@ func (s *Server) handlePatchSkillSource(w http.ResponseWriter, r *http.Request)
newRepoURL = parsed.CloneURL
}
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
m := s.findMetadataEntry(name, kind, source, agentsSource)
+2 -2
View File
@@ -28,7 +28,7 @@ type skillignoreResponse struct {
func (s *Server) handleGetSkillignore(w http.ResponseWriter, r *http.Request) {
// Snapshot source path under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
s.mu.RUnlock()
ignorePath := filepath.Join(source, ".skillignore")
@@ -76,7 +76,7 @@ func (s *Server) handlePutSkillignore(w http.ResponseWriter, r *http.Request) {
return
}
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
ignorePath := filepath.Join(source, ".skillignore")
if body.Raw == "" {
+8 -8
View File
@@ -49,7 +49,7 @@ func (s *Server) handleListSkills(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
s.mu.RUnlock()
@@ -137,7 +137,7 @@ func (s *Server) handleListSkills(w http.ResponseWriter, r *http.Request) {
func (s *Server) handleGetSkill(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
s.mu.RUnlock()
@@ -292,7 +292,7 @@ func (s *Server) handleGetSkill(w http.ResponseWriter, r *http.Request) {
func (s *Server) handleGetSkillFile(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
s.mu.RUnlock()
name := r.PathValue("name")
@@ -430,7 +430,7 @@ func (s *Server) handleUninstallRepo(w http.ResponseWriter, r *http.Request) {
}
}
if err := s.skillsStore.Save(s.cfg.Source); err != nil {
if err := s.skillsStore.Save(s.cfg.EffectiveSkillsSource()); err != nil {
log.Printf("warning: failed to save metadata after repo uninstall: %v", err)
}
@@ -492,7 +492,7 @@ func (s *Server) handleUninstallSkill(w http.ResponseWriter, r *http.Request) {
}
// Find skill path
discovered, err := sync.DiscoverSourceSkills(s.cfg.Source)
discovered, err := sync.DiscoverSourceSkills(s.cfg.EffectiveSkillsSource())
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
@@ -529,10 +529,10 @@ func (s *Server) handleUninstallSkill(w http.ResponseWriter, r *http.Request) {
}
// resolveTrackedRepo resolves a repo name (flat or nested) to its directory name
// and absolute path under s.cfg.Source. Returns ("", "", nil) if not found.
// and absolute path under s.cfg.EffectiveSkillsSource(). Returns ("", "", nil) if not found.
// Returns a non-nil error for ambiguous matches or internal failures.
func (s *Server) resolveTrackedRepo(input string) (string, string, error) {
sourceRoot := filepath.Clean(s.cfg.Source)
sourceRoot := filepath.Clean(s.cfg.EffectiveSkillsSource())
candidates := []string{input}
if !strings.HasPrefix(filepath.Base(input), "_") {
if dir := filepath.Dir(input); dir != "." && dir != "" {
@@ -553,7 +553,7 @@ func (s *Server) resolveTrackedRepo(input string) (string, string, error) {
}
// Fallback: match nested tracked repos by basename.
repos, err := install.GetTrackedRepos(s.cfg.Source)
repos, err := install.GetTrackedRepos(s.cfg.EffectiveSkillsSource())
if err != nil {
return "", "", fmt.Errorf("failed to list tracked repositories: %w", err)
}
+4 -4
View File
@@ -61,7 +61,7 @@ func (s *Server) handleBatchSetTargets(w http.ResponseWriter, r *http.Request) {
// Snapshot config under read lock, then discover without holding the lock.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
s.mu.RUnlock()
discovered, err := ssync.DiscoverSourceSkillsAll(source)
@@ -118,7 +118,7 @@ func (s *Server) handleBatchSetTargets(w http.ResponseWriter, r *http.Request) {
s.skillsStore.RefreshHashes(sk.name, sk.path)
}
if len(updatedSkills) > 0 {
s.skillsStore.Save(s.cfg.Source) //nolint:errcheck
s.skillsStore.Save(s.cfg.EffectiveSkillsSource()) //nolint:errcheck
}
s.writeOpsLog("batch-set-targets", "ok", start, map[string]any{
@@ -157,7 +157,7 @@ func (s *Server) handleSetSkillTargets(w http.ResponseWriter, r *http.Request) {
}
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
s.mu.RUnlock()
discovered, err := ssync.DiscoverSourceSkillsAll(source)
@@ -193,7 +193,7 @@ func (s *Server) handleSetSkillTargets(w http.ResponseWriter, r *http.Request) {
}
s.skillsStore.RefreshHashes(d.RelPath, d.SourcePath)
s.skillsStore.Save(s.cfg.Source) //nolint:errcheck
s.skillsStore.Save(s.cfg.EffectiveSkillsSource()) //nolint:errcheck
s.writeOpsLog("set-skill-targets", "ok", start, map[string]any{
"name": name,
+6 -6
View File
@@ -83,7 +83,7 @@ func (s *Server) handleSync(w http.ResponseWriter, r *http.Request) {
// Skill sync (skip when kind == "agent")
if body.Kind != kindAgent {
var err error
allSkills, ignoreStats, err = ssync.DiscoverSourceSkillsWithStatsAndContext(s.cfg.Source)
allSkills, ignoreStats, err = ssync.DiscoverSourceSkillsWithStatsAndContext(s.cfg.EffectiveSkillsSource())
if err != nil {
writeError(w, http.StatusInternalServerError, "failed to discover skills: "+err.Error())
return
@@ -123,7 +123,7 @@ func (s *Server) handleSync(w http.ResponseWriter, r *http.Request) {
switch mode {
case "merge":
mergeResult, err := ssync.SyncTargetMergeWithSkills(name, target, allSkills, s.cfg.Source, body.DryRun, body.Force, s.projectRoot)
mergeResult, err := ssync.SyncTargetMergeWithSkills(name, target, allSkills, s.cfg.EffectiveSkillsSource(), body.DryRun, body.Force, s.projectRoot)
if err != nil {
s.writeOpsLog("sync", "error", start, syncErrArgs, err.Error())
writeError(w, http.StatusInternalServerError, "sync failed for "+name+": "+err.Error())
@@ -135,7 +135,7 @@ func (s *Server) handleSync(w http.ResponseWriter, r *http.Request) {
res.DirCreated = mergeResult.DirCreated
pruneResult, err := ssync.PruneOrphanLinksWithSkills(ssync.PruneOptions{
TargetPath: sc.Path, SourcePath: s.cfg.Source, Skills: allSkills,
TargetPath: sc.Path, SourcePath: s.cfg.EffectiveSkillsSource(), Skills: allSkills,
Include: sc.Include, Exclude: sc.Exclude, TargetNaming: sc.TargetNaming, TargetName: name,
DryRun: body.DryRun, Force: body.Force,
})
@@ -144,7 +144,7 @@ func (s *Server) handleSync(w http.ResponseWriter, r *http.Request) {
}
case "copy":
copyResult, err := ssync.SyncTargetCopyWithSkills(name, target, allSkills, s.cfg.Source, body.DryRun, body.Force, nil)
copyResult, err := ssync.SyncTargetCopyWithSkills(name, target, allSkills, s.cfg.EffectiveSkillsSource(), body.DryRun, body.Force, nil)
if err != nil {
s.writeOpsLog("sync", "error", start, syncErrArgs, err.Error())
writeError(w, http.StatusInternalServerError, "sync failed for "+name+": "+err.Error())
@@ -161,7 +161,7 @@ func (s *Server) handleSync(w http.ResponseWriter, r *http.Request) {
}
default:
err := ssync.SyncTarget(name, target, s.cfg.Source, body.DryRun, s.projectRoot)
err := ssync.SyncTarget(name, target, s.cfg.EffectiveSkillsSource(), body.DryRun, s.projectRoot)
if err != nil {
s.writeOpsLog("sync", "error", start, syncErrArgs, err.Error())
writeError(w, http.StatusInternalServerError, "sync failed for "+name+": "+err.Error())
@@ -425,7 +425,7 @@ type diffTarget struct {
func (s *Server) handleDiff(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before slow I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
globalMode := s.cfg.Mode
targets := s.cloneTargets()
+2 -2
View File
@@ -53,7 +53,7 @@ func newSyncMatrixEntry(skill, target, status, reason, kind string) syncMatrixEn
func (s *Server) handleSyncMatrix(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
targets := s.cloneTargets()
s.mu.RUnlock()
@@ -128,7 +128,7 @@ func (s *Server) handleSyncMatrix(w http.ResponseWriter, r *http.Request) {
func (s *Server) handleSyncMatrixPreview(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
targets := s.cloneTargets()
s.mu.RUnlock()
+2 -2
View File
@@ -39,7 +39,7 @@ type targetItem struct {
func (s *Server) handleListTargets(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
cfgMode := s.cfg.Mode
targets := s.cloneTargets()
isProjectMode := s.IsProjectMode()
@@ -454,7 +454,7 @@ func (s *Server) unlinkMergeSymlinks(targetPath string) {
return
}
absSource, err := filepath.Abs(s.cfg.Source)
absSource, err := filepath.Abs(s.cfg.EffectiveSkillsSource())
if err != nil {
return
}
+1 -1
View File
@@ -30,7 +30,7 @@ func (s *Server) handleToggleSkill(w http.ResponseWriter, r *http.Request, enabl
// Resolve under RLock — discovery is I/O-heavy, don't hold write lock
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
agentsSource := s.agentsSource()
s.mu.RUnlock()
+4 -4
View File
@@ -144,7 +144,7 @@ func (s *Server) handleBatchUninstallAgents(w http.ResponseWriter, body batchUni
}
func (s *Server) handleBatchUninstallSkills(w http.ResponseWriter, body batchUninstallRequest, start time.Time) {
discovered, err := sync.DiscoverSourceSkills(s.cfg.Source)
discovered, err := sync.DiscoverSourceSkills(s.cfg.EffectiveSkillsSource())
if err != nil {
writeError(w, http.StatusInternalServerError, "failed to discover skills: "+err.Error())
return
@@ -167,7 +167,7 @@ func (s *Server) handleBatchUninstallSkills(w http.ResponseWriter, body batchUni
res := batchUninstallItemResult{Name: name, Kind: "skill"}
if strings.HasPrefix(name, "_") {
repoPath := filepath.Join(s.cfg.Source, name)
repoPath := filepath.Join(s.cfg.EffectiveSkillsSource(), name)
if !install.IsGitRepo(repoPath) {
res.Success = false
res.Error = "not a tracked repository: " + name
@@ -303,13 +303,13 @@ func (s *Server) handleBatchUninstallSkills(w http.ResponseWriter, body batchUni
}
}
if err := s.skillsStore.Save(s.cfg.Source); err != nil {
if err := s.skillsStore.Save(s.cfg.EffectiveSkillsSource()); err != nil {
log.Printf("warning: failed to save metadata: %v", err)
}
if s.IsProjectMode() {
if rErr := config.ReconcileProjectSkills(
s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.Source); rErr != nil {
s.projectRoot, s.projectCfg, s.skillsStore, s.cfg.EffectiveSkillsSource()); rErr != nil {
log.Printf("warning: failed to reconcile project skills config: %v", rErr)
}
} else {
+5 -5
View File
@@ -138,7 +138,7 @@ func (s *Server) updateSingleByKind(name, kind string, force, skipAudit bool) up
return s.updateAgent(name, force, skipAudit)
}
// Try exact skill path first (prevents basename collision with nested repos)
skillPath := filepath.Join(s.cfg.Source, name)
skillPath := filepath.Join(s.cfg.EffectiveSkillsSource(), name)
if entry := s.skillsStore.GetByPath(name); entry != nil && entry.Source != "" {
return s.updateRegularSkill(name, skillPath, skipAudit)
}
@@ -425,19 +425,19 @@ func (s *Server) updateAll(force, skipAudit bool) []updateResultItem {
var results []updateResultItem
// Update tracked repos
repos, err := install.GetTrackedRepos(s.cfg.Source)
repos, err := install.GetTrackedRepos(s.cfg.EffectiveSkillsSource())
if err == nil {
for _, repo := range repos {
repoPath := filepath.Join(s.cfg.Source, repo)
repoPath := filepath.Join(s.cfg.EffectiveSkillsSource(), repo)
results = append(results, s.updateTrackedRepo(repo, repoPath, force, skipAudit))
}
}
// Update regular skills with source metadata
skills, err := getServerUpdatableSkills(s.cfg.Source, s.skillsStore)
skills, err := getServerUpdatableSkills(s.cfg.EffectiveSkillsSource(), s.skillsStore)
if err == nil {
for _, skill := range skills {
skillPath := filepath.Join(s.cfg.Source, skill)
skillPath := filepath.Join(s.cfg.EffectiveSkillsSource(), skill)
results = append(results, s.updateRegularSkill(skill, skillPath, skipAudit))
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ func (s *Server) handleUpdateStream(w http.ResponseWriter, r *http.Request) {
// Snapshot source under RLock, then release before slow I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
s.mu.RUnlock()
// Collect items to update based on "names" query param.
+1 -1
View File
@@ -10,7 +10,7 @@ import (
func (s *Server) handleVersionCheck(w http.ResponseWriter, r *http.Request) {
// Snapshot config under RLock, then release before I/O.
s.mu.RLock()
source := s.cfg.Source
source := s.cfg.EffectiveSkillsSource()
projectRoot := s.projectRoot
s.mu.RUnlock()
+4 -4
View File
@@ -83,7 +83,7 @@ func (s *Server) wrapBasePath() {
// New creates a new Server for global mode.
// uiDistDir, when non-empty, serves UI from disk instead of the embedded SPA.
func New(cfg *config.Config, addr, basePath, uiDistDir string) *Server {
skillsStore, _ := install.LoadMetadataWithMigration(cfg.Source, "")
skillsStore, _ := install.LoadMetadataWithMigration(cfg.EffectiveSkillsSource(), "")
if skillsStore == nil {
skillsStore = install.NewMetadataStore()
}
@@ -147,7 +147,7 @@ func (s *Server) skillsSource() string {
if s.IsProjectMode() {
return s.projectCfg.EffectiveSkillsSource(s.projectRoot)
}
return s.cfg.Source
return s.cfg.EffectiveSkillsSource()
}
// agentsSource returns the agents source directory for the current mode.
@@ -192,7 +192,7 @@ func (s *Server) gitignoreDir() string {
dir, _ := config.ProjectGitignoreTarget(s.projectRoot, s.skillsSource())
return dir
}
return s.cfg.Source
return s.cfg.EffectiveSkillsSource()
}
func (s *Server) projectGitignorePrefix() string {
@@ -258,7 +258,7 @@ func (s *Server) reloadConfig() error {
return err
}
s.cfg = newCfg
if st, err := install.LoadMetadata(newCfg.Source); err == nil {
if st, err := install.LoadMetadata(newCfg.EffectiveSkillsSource()); err == nil {
s.skillsStore = st
}
if st, err := install.LoadMetadata(newCfg.EffectiveAgentsSource()); err == nil {
+15 -9
View File
@@ -960,9 +960,12 @@ func TestInit_SetsExtrasSource(t *testing.T) {
}
}
// TestExtrasInit_BackfillsExtrasSource verifies that "extras init" backfills
// extras_source when it is missing from an existing config.
func TestExtrasInit_BackfillsExtrasSource(t *testing.T) {
// TestExtrasInit_PreservesEmptyExtrasSource verifies that "extras init" does
// NOT silently backfill the legacy extras_source field when it was absent.
// Config.EffectiveExtrasSource() handles the runtime fallback, so writing the
// derived path into the user's config would surprise them with an unexpected
// diff. The extras source directory must still be created on disk.
func TestExtrasInit_PreservesEmptyExtrasSource(t *testing.T) {
sb := testutil.NewSandbox(t)
defer sb.Cleanup()
@@ -983,14 +986,17 @@ func TestExtrasInit_BackfillsExtrasSource(t *testing.T) {
result := sb.RunCLI("extras", "init", "rules", "--target", rulesTarget, "-g")
result.AssertSuccess(t)
// Verify extras_source was backfilled
// Verify extras_source was NOT silently backfilled.
configAfter := sb.ReadFile(sb.ConfigPath)
if !strings.Contains(configAfter, "extras_source:") {
t.Errorf("expected extras_source to be backfilled after extras init, got:\n%s", configAfter)
if strings.Contains(configAfter, "extras_source:") {
t.Errorf("expected no extras_source backfill, got:\n%s", configAfter)
}
expected := filepath.Join(filepath.Dir(sb.SourcePath), "extras")
if !strings.Contains(configAfter, expected) {
t.Errorf("expected extras_source %s, got:\n%s", expected, configAfter)
// But the derived extras source directory must still exist on disk so
// the new extra has somewhere to live.
expected := filepath.Join(filepath.Dir(sb.SourcePath), "extras", "rules")
if _, err := os.Stat(expected); err != nil {
t.Errorf("expected extras source directory %s to exist: %v", expected, err)
}
}
+4 -4
View File
@@ -24,22 +24,22 @@ export const fieldDocs: Record<string, FieldDoc> = {
example: 'extras_source: ~/.config/skillshare/extras',
},
sources: {
description: 'Project-mode custom source directories. Each key (skills, agents, extras) overrides the default .skillshare/<type>/ path. All keys are optional — omit any key to fall back to the default.',
description: 'Custom source directories. Each key (skills, agents, extras) overrides the default source path. All keys are optional. Project mode falls back to .skillshare/<type>/; global mode falls back to <base>/<type>/ (or the legacy source / agents_source / extras_source field if present).',
type: 'object',
example: 'sources:\n skills: ./docs/skills\n agents: ./docs/agents\n extras: ./docs/extras',
},
'sources.skills': {
description: 'Custom skills source directory for project mode. Relative paths resolve from the project root; absolute paths and ~ are supported. Default: .skillshare/skills/. Sync rejects configs where this aliases or nests with a target path.',
description: 'Custom skills source directory. Relative paths resolve from the project root (project mode); absolute paths and ~ are supported (both modes). Project mode default: .skillshare/skills/. Global mode default: <base>/skills/ (or the legacy `source` field). Project-mode sync rejects configs where this aliases or nests with a target path.',
type: 'string',
example: 'sources:\n skills: ./docs/skills',
},
'sources.agents': {
description: 'Custom agents source directory for project mode. Relative paths resolve from the project root. Default: .skillshare/agents/.',
description: 'Custom agents source directory. Relative paths resolve from the project root (project mode). Project mode default: .skillshare/agents/. Global mode default: <base>/agents/ (or the legacy `agents_source` field).',
type: 'string',
example: 'sources:\n agents: ./docs/agents',
},
'sources.extras': {
description: 'Custom extras source directory for project mode. Relative paths resolve from the project root. Default: .skillshare/extras/.',
description: 'Custom extras source directory. Relative paths resolve from the project root (project mode). Project mode default: .skillshare/extras/. Global mode default: the `extras` sibling of the skills source (or the legacy `extras_source` field).',
type: 'string',
example: 'sources:\n extras: ./docs/extras',
},