Files
skillshare/internal/server/handler_overview.go
T
Willie d15d9d794c fix: use the --into repo path in skill counts, list groups and the tree
Codex review of #472 found three views still deriving a skill's repo
from the first path segment:

- Skill counts in `list`, human-readable `status` and the dashboard
  overview matched `<repo>/` prefixes, so an `org/_team` repo whose only
  skill is its root SKILL.md counted zero, and `status` disagreed with
  `status --json`. They now compare RepoRelPath with the repo name.
- The list TUI took the group as the second path segment, so a skill at
  org/_team/skills/vue got group `_team` instead of `skills` and the
  `g:` filter missed it. The group is now the first segment below
  RepoName. Test fixtures that used a RepoName unrelated to RelPath now
  use the repo path, as real entries do.
- The dashboard tree treated only top-level `_` folders as repo roots,
  and merged `org / _team / skills` into one row, so an --into repo had
  no update or uninstall actions in Tree view. buildTree now marks repo
  roots from each skill's repo path, and a merged chain stops at one.
2026-10-07 21:35:05 +08:00

126 lines
2.9 KiB
Go

package server
import (
"net/http"
"path/filepath"
"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()
walk := s.skillsWalk()
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, walk)
if err != nil {
writeError(w, http.StatusInternalServerError, err.Error())
return
}
// Count top-level source entries (for display)
topLevelCount := 0
entries, _ := sourcewalk.ReadDir(source, walk)
for _, e := range entries {
if e.IsDir() && !utils.IsHidden(e.Name()) {
topLevelCount++
}
}
mode := cfgMode
if mode == "" {
mode = "merge"
}
// Tracked repos
trackedRepos := buildTrackedRepos(source, skills, walk)
// 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, walk sourcewalk.Options) []trackedRepoItem {
repoNames, err := install.GetTrackedRepos(sourceDir, walk)
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.RepoRelPath == repoName {
skillCount++
}
}
// Check git dirty status
dirty, _ := git.IsDirty(repoPath)
items = append(items, trackedRepoItem{
Name: repoName,
SkillCount: skillCount,
Dirty: dirty,
})
}
return items
}