mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
A single-file extra added from the dashboard with the shared source got <extras dir>/<name> as its folder, so a second file in the same folder needed the same name and was refused as a duplicate. Project mode had no source setting at all, so it could never share a folder. The add dialog now has a source folder field that defaults to the name, and project extras accept a source relative to the project root, from the dashboard and from `extras init -p --source`. Paths shown for single-file extras also keep the folder's own separator, so Windows paths no longer mix backslashes with a slash before the file name. Refs #300
126 lines
2.9 KiB
Go
126 lines
2.9 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"skillshare/internal/git"
|
|
"skillshare/internal/install"
|
|
"skillshare/internal/resource"
|
|
"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, _ := os.ReadDir(source)
|
|
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
|
|
}
|