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.
100 lines
2.5 KiB
Go
100 lines
2.5 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"time"
|
|
|
|
"skillshare/internal/sync"
|
|
)
|
|
|
|
type skillignoreStats struct {
|
|
PatternCount int `json:"pattern_count"`
|
|
IgnoredCount int `json:"ignored_count"`
|
|
Patterns []string `json:"patterns"`
|
|
IgnoredSkills []string `json:"ignored_skills"`
|
|
}
|
|
|
|
type skillignoreResponse struct {
|
|
Exists bool `json:"exists"`
|
|
Path string `json:"path"`
|
|
Raw string `json:"raw"`
|
|
Stats *skillignoreStats `json:"stats,omitempty"`
|
|
}
|
|
|
|
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.EffectiveSkillsSource()
|
|
s.mu.RUnlock()
|
|
|
|
ignorePath := filepath.Join(source, ".skillignore")
|
|
|
|
raw, err := os.ReadFile(ignorePath)
|
|
|
|
resp := skillignoreResponse{
|
|
Exists: err == nil,
|
|
Path: ignorePath,
|
|
Raw: string(raw), // empty if file doesn't exist
|
|
}
|
|
|
|
// Always discover stats — tracked repos may have their own .skillignore
|
|
_, stats, discoverErr := sync.DiscoverSourceSkillsWithStats(source)
|
|
if discoverErr == nil && stats != nil {
|
|
patterns := stats.Patterns
|
|
if patterns == nil {
|
|
patterns = []string{}
|
|
}
|
|
ignoredSkills := stats.IgnoredSkills
|
|
if ignoredSkills == nil {
|
|
ignoredSkills = []string{}
|
|
}
|
|
resp.Stats = &skillignoreStats{
|
|
PatternCount: stats.PatternCount(),
|
|
IgnoredCount: stats.IgnoredCount(),
|
|
Patterns: patterns,
|
|
IgnoredSkills: ignoredSkills,
|
|
}
|
|
}
|
|
|
|
writeJSON(w, resp)
|
|
}
|
|
|
|
func (s *Server) handlePutSkillignore(w http.ResponseWriter, r *http.Request) {
|
|
start := time.Now()
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
|
|
var body struct {
|
|
Raw string `json:"raw"`
|
|
}
|
|
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
|
writeError(w, http.StatusBadRequest, "invalid JSON body")
|
|
return
|
|
}
|
|
|
|
source := s.cfg.EffectiveSkillsSource()
|
|
ignorePath := filepath.Join(source, ".skillignore")
|
|
|
|
if body.Raw == "" {
|
|
if err := os.Remove(ignorePath); err != nil && !errors.Is(err, os.ErrNotExist) {
|
|
writeError(w, http.StatusInternalServerError, "failed to delete .skillignore: "+err.Error())
|
|
return
|
|
}
|
|
} else {
|
|
if err := os.WriteFile(ignorePath, []byte(body.Raw), 0644); err != nil {
|
|
writeError(w, http.StatusInternalServerError, "failed to write .skillignore: "+err.Error())
|
|
return
|
|
}
|
|
}
|
|
|
|
s.writeOpsLog("skillignore", "ok", start, map[string]any{
|
|
"scope": "ui",
|
|
}, "")
|
|
|
|
writeJSON(w, map[string]any{"success": true})
|
|
}
|