mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
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.
181 lines
3.9 KiB
Go
181 lines
3.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"time"
|
|
|
|
"skillshare/internal/config"
|
|
"skillshare/internal/oplog"
|
|
"skillshare/internal/skillignore"
|
|
"skillshare/internal/ui"
|
|
)
|
|
|
|
func cmdDisable(args []string) error {
|
|
return cmdToggleSkill(args, false)
|
|
}
|
|
|
|
func cmdEnable(args []string) error {
|
|
return cmdToggleSkill(args, true)
|
|
}
|
|
|
|
func cmdToggleSkill(args []string, enable bool) error {
|
|
start := time.Now()
|
|
action := "disable"
|
|
if enable {
|
|
action = "enable"
|
|
}
|
|
|
|
mode, rest, err := parseModeArgs(args)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
// Extract --kind flag before parsing other args
|
|
kind, rest, err := parseKindFlag(rest)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var dryRun bool
|
|
var patterns []string
|
|
for _, arg := range rest {
|
|
switch arg {
|
|
case "--dry-run", "-n":
|
|
dryRun = true
|
|
case "--help", "-h":
|
|
printToggleHelp(action)
|
|
return nil
|
|
default:
|
|
if len(arg) > 0 && arg[0] == '-' {
|
|
return fmt.Errorf("unknown flag: %s", arg)
|
|
}
|
|
patterns = append(patterns, arg)
|
|
}
|
|
}
|
|
|
|
if len(patterns) == 0 {
|
|
return fmt.Errorf("usage: skillshare %s <name|pattern>", action)
|
|
}
|
|
|
|
cwd, err := os.Getwd()
|
|
if err != nil {
|
|
return fmt.Errorf("cannot determine working directory: %w", err)
|
|
}
|
|
|
|
if mode == modeAuto {
|
|
if projectConfigExists(cwd) {
|
|
mode = modeProject
|
|
} else {
|
|
mode = modeGlobal
|
|
}
|
|
}
|
|
applyModeLabel(mode)
|
|
|
|
isAgent := kind == kindAgents
|
|
|
|
var ignorePath string
|
|
var cfgPath string
|
|
if mode == modeProject {
|
|
projectCfg, loadErr := config.LoadProject(cwd)
|
|
if loadErr != nil {
|
|
return fmt.Errorf("failed to load project config: %w", loadErr)
|
|
}
|
|
if isAgent {
|
|
ignorePath = filepath.Join(projectCfg.EffectiveAgentsSource(cwd), ".agentignore")
|
|
} else {
|
|
ignorePath = filepath.Join(projectCfg.EffectiveSkillsSource(cwd), ".skillignore")
|
|
}
|
|
cfgPath = config.ProjectConfigPath(cwd)
|
|
} else {
|
|
cfg, err := config.Load()
|
|
if err != nil {
|
|
return fmt.Errorf("failed to load config: %w", err)
|
|
}
|
|
if isAgent {
|
|
ignorePath = filepath.Join(cfg.EffectiveAgentsSource(), ".agentignore")
|
|
} else {
|
|
ignorePath = filepath.Join(cfg.EffectiveSkillsSource(), ".skillignore")
|
|
}
|
|
cfgPath = config.ConfigPath()
|
|
}
|
|
|
|
ignoreLabel := ".skillignore"
|
|
if isAgent {
|
|
ignoreLabel = ".agentignore"
|
|
}
|
|
|
|
changed := false
|
|
for _, pattern := range patterns {
|
|
if dryRun {
|
|
if enable {
|
|
ui.Info("Would remove %q from %s", pattern, ignorePath)
|
|
} else {
|
|
ui.Info("Would add %q to %s", pattern, ignorePath)
|
|
}
|
|
continue
|
|
}
|
|
|
|
if enable {
|
|
removed, err := skillignore.RemovePattern(ignorePath, pattern)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to update %s: %w", ignoreLabel, err)
|
|
}
|
|
if !removed {
|
|
ui.Warning("%s is not disabled", pattern)
|
|
continue
|
|
}
|
|
changed = true
|
|
ui.Success("Enabled: %s (removed from %s)", pattern, ignoreLabel)
|
|
} else {
|
|
added, err := skillignore.AddPattern(ignorePath, pattern)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to update %s: %w", ignoreLabel, err)
|
|
}
|
|
if !added {
|
|
ui.Warning("%s is already disabled", pattern)
|
|
continue
|
|
}
|
|
changed = true
|
|
ui.Success("Disabled: %s (added to %s)", pattern, ignoreLabel)
|
|
}
|
|
}
|
|
|
|
if !dryRun && changed {
|
|
ui.Info("Run \"skillshare sync\" to apply changes.")
|
|
|
|
e := oplog.NewEntry(action, "ok", time.Since(start))
|
|
e.Args = map[string]any{
|
|
"patterns": patterns,
|
|
"kind": kind.String(),
|
|
}
|
|
oplog.Write(cfgPath, oplog.OpsFile, e)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func printToggleHelp(action string) {
|
|
opposite := "enable"
|
|
if action == "enable" {
|
|
opposite = "disable"
|
|
}
|
|
fmt.Printf(`Usage: skillshare %s <name|pattern> [flags]
|
|
|
|
%s skills by adding/removing patterns from .skillignore.
|
|
|
|
Arguments:
|
|
<name|pattern> Skill name or glob pattern (e.g. "my-skill", "draft-*")
|
|
|
|
Flags:
|
|
-p, --project Use project-mode .skillignore
|
|
-g, --global Use global-mode .skillignore
|
|
-n, --dry-run Preview changes without writing
|
|
-h, --help Show this help
|
|
|
|
See also: skillshare %s
|
|
`, action, strings.ToUpper(action[:1])+action[1:], opposite)
|
|
}
|