Files
skillshare/internal/server/handler_overview.go
T
Willie 8c60f51b9f feat(source): add the sourcewalk walker and sourcefs write boundary for proposal 274 (#385)
Implements rollout steps 1 and 2 of proposals/274-skillfollow.md. Nothing follows a link or parses .skillfollow yet.

Step 1: doctor reports first-level symlinks and junctions in the skills source as info, in text and JSON, without following them.

Step 2a: internal/sourcewalk owns traversal of the skills source. Thirteen raw walks move onto it with identical behavior, and a go/parser ratchet fails the tests on any new unclassified walk.

Step 2b: internal/sourcefs wraps an os.Root opened at the skills source and refuses any write whose path has a link component. The six write sites the proposal found in review move onto it, including the cross-device copy fallback, and a second ratchet covers raw os write calls. The only behavior change is that an explicit path crossing a link inside the source is refused instead of written through.

Refs #274

Release-As: 0.24.3
2026-10-04 15:15:43 +08:00

126 lines
2.9 KiB
Go

package server
import (
"net/http"
"path/filepath"
"strings"
"skillshare/internal/git"
"skillshare/internal/install"
"skillshare/internal/resource"
"skillshare/internal/sourcewalk"
"skillshare/internal/sync"
"skillshare/internal/utils"
versioncheck "skillshare/internal/version"
)
type trackedRepoItem struct {
Name string `json:"name"`
SkillCount int `json:"skillCount"`
Dirty bool `json:"dirty"`
}
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.EffectiveSkillsSource()
agentsSource := s.agentsSource()
extrasSource := s.cfg.EffectiveExtrasSource()
if s.IsProjectMode() {
extrasSource = s.projectCfg.EffectiveExtrasSource(s.projectRoot)
}
cfgMode := s.cfg.Mode
targetCount := len(s.cfg.Targets)
projectRoot := s.projectRoot
configDir := filepath.Dir(s.configPath())
s.mu.RUnlock()
isProjectMode := projectRoot != ""
// Count skills
skills, err := sync.DiscoverSourceSkills(source)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
// Count top-level source entries (for display)
topLevelCount := 0
entries, _ := sourcewalk.ReadDir(source, sourcewalk.Options{})
for _, e := range entries {
if e.IsDir() && !utils.IsHidden(e.Name()) {
topLevelCount++
}
}
mode := cfgMode
if mode == "" {
mode = "merge"
}
// Tracked repos
trackedRepos := buildTrackedRepos(source, skills)
// Count agents
agentCount := 0
if agentsSource != "" {
if agents, discoverErr := (resource.AgentKind{}).Discover(agentsSource); discoverErr == nil {
agentCount = len(agents)
}
}
resp := map[string]any{
"source": source,
"skillCount": len(skills),
"agentCount": agentCount,
"topLevelCount": topLevelCount,
"targetCount": targetCount,
"mode": mode,
"version": versioncheck.Version,
"trackedRepos": trackedRepos,
"isProjectMode": isProjectMode,
"configDir": configDir,
}
if agentsSource != "" {
resp["agentsSource"] = agentsSource
}
if extrasSource != "" {
resp["extrasSource"] = extrasSource
}
if isProjectMode {
resp["projectRoot"] = projectRoot
}
writeJSON(w, resp)
}
func buildTrackedRepos(sourceDir string, skills []sync.DiscoveredSkill) []trackedRepoItem {
repoNames, err := install.GetTrackedRepos(sourceDir)
if err != nil || len(repoNames) == 0 {
return []trackedRepoItem{}
}
items := make([]trackedRepoItem, 0, len(repoNames))
for _, repoName := range repoNames {
repoPath := filepath.Join(sourceDir, repoName)
// Count skills belonging to this repo
skillCount := 0
for _, sk := range skills {
if sk.IsInRepo && strings.HasPrefix(sk.RelPath, repoName+"/") {
skillCount++
}
}
// Check git dirty status
dirty, _ := git.IsDirty(repoPath)
items = append(items, trackedRepoItem{
Name: repoName,
SkillCount: skillCount,
Dirty: dirty,
})
}
return items
}