diff --git a/internal/check/agent_check.go b/internal/check/agent_check.go index 9bb633e39..2e711b26b 100644 --- a/internal/check/agent_check.go +++ b/internal/check/agent_check.go @@ -139,10 +139,10 @@ func checkOneAgent(store *install.MetadataStore, sourcePath, relPath string) Age return result } -// EnrichAgentResultsWithRemote checks agents that have RepoURL + Version -// against the remote head of the branch they were installed from. -// Each remote branch is probed once; every agent is compared with its own version. -func EnrichAgentResultsWithRemote(results []AgentCheckResult, onDone func(), parseOpts install.ParseOptions) { +// agentRemotes groups the agents that have RepoURL + Version by the remote +// branch they were installed from: the branches in the order first seen, and +// the indexes of each one's agents. +func agentRemotes(results []AgentCheckResult) ([]remoteKey, map[remoteKey][]int) { groups := make(map[remoteKey][]int) var refs []remoteKey for i, r := range results { @@ -155,7 +155,21 @@ func EnrichAgentResultsWithRemote(results []AgentCheckResult, onDone func(), par } groups[ref] = append(groups[ref], i) } + return refs, groups +} +// AgentRemotes counts the remote branches EnrichAgentResultsWithRemote probes +// for results. +func AgentRemotes(results []AgentCheckResult) int { + refs, _ := agentRemotes(results) + return len(refs) +} + +// EnrichAgentResultsWithRemote checks agents that have RepoURL + Version +// against the remote head of the branch they were installed from. +// Each remote branch is probed once; every agent is compared with its own version. +func EnrichAgentResultsWithRemote(results []AgentCheckResult, onDone func(), parseOpts install.ParseOptions) { + refs, groups := agentRemotes(results) if len(refs) == 0 { return } diff --git a/internal/server/handler_check.go b/internal/server/handler_check.go index 756837828..e9167f1ad 100644 --- a/internal/server/handler_check.go +++ b/internal/server/handler_check.go @@ -84,6 +84,15 @@ func dashboardSkillResults(results []check.SkillResult) []skillCheckResult { return out } +// dashboardAgentResults converts agent statuses to the dashboard payload. +func dashboardAgentResults(results []check.AgentCheckResult) []skillCheckResult { + out := make([]skillCheckResult, 0, len(results)) + for _, r := range results { + out = append(out, skillCheckResult{Name: r.Name, Source: r.Source, Version: r.Version, Status: r.Status, Message: r.Message}) + } + return out +} + // checkTrackedRepo checks one tracked repo with the same logic as the CLI: // auth-aware fetch and a reported dirty-check error. func checkTrackedRepo(name, repoPath string, parseOpts install.ParseOptions) repoCheckResult { diff --git a/internal/server/handler_check_resolution_test.go b/internal/server/handler_check_resolution_test.go index c12711bc2..2b35a884a 100644 --- a/internal/server/handler_check_resolution_test.go +++ b/internal/server/handler_check_resolution_test.go @@ -4,6 +4,8 @@ import ( "encoding/json" "net/http" "net/http/httptest" + "os" + "path/filepath" "reflect" "sort" "strings" @@ -12,25 +14,29 @@ import ( "skillshare/internal/check/checktest" ) -// checkPayload is the body of GET /api/check and of the stream's done event. +// checkPayload is the body of GET /api/check and of the stream's done event, +// which also reports agents. type checkPayload struct { TrackedRepos []repoCheckResult `json:"tracked_repos"` LinkedRepos []any `json:"linked_repos"` Skills []skillCheckResult `json:"skills"` + Agents []skillCheckResult `json:"agents"` } -func decodeCheckPayload(t *testing.T, raw string) checkPayload { +// decodeCheckPayload decodes a check payload that must hold exactly the three +// keys of GET /api/check and the extra ones named. +func decodeCheckPayload(t *testing.T, raw string, extra ...string) checkPayload { t.Helper() var keys map[string]json.RawMessage if err := json.Unmarshal([]byte(raw), &keys); err != nil { t.Fatalf("invalid payload: %v: %s", err, raw) } - for _, key := range []string{"tracked_repos", "linked_repos", "skills"} { + for _, key := range append([]string{"tracked_repos", "linked_repos", "skills"}, extra...) { if _, ok := keys[key]; !ok { t.Errorf("payload lacks %q: %s", key, raw) } } - if len(keys) != 3 { + if len(keys) != 3+len(extra) { t.Errorf("payload has unexpected keys: %s", raw) } var payload checkPayload @@ -131,18 +137,63 @@ func TestHandleCheckStream_EventSequence(t *testing.T) { if done.name != "done" { t.Fatalf("last event = %+v, want done", done) } - payload := decodeCheckPayload(t, done.data) + payload := decodeCheckPayload(t, done.data, "agents") sortSkillResults(payload.Skills) if want := wantDashboardSkills(versions); !reflect.DeepEqual(payload.Skills, want) { t.Errorf("skills:\n got %+v\nwant %+v", payload.Skills, want) } } +// addOutdatedAgentRepo clones a tracked agent repo holding tutor.md into the +// agents source as _team, then moves its origin on. +func addOutdatedAgentRepo(t *testing.T, s *Server) { + t.Helper() + origin := t.TempDir() + initGitRepo(t, origin) + if err := os.WriteFile(filepath.Join(origin, "tutor.md"), []byte("# Tutor\n"), 0644); err != nil { + t.Fatal(err) + } + runGit(t, origin, "add", ".") + runGit(t, origin, "commit", "-m", "add tutor") + agentsDir := s.agentsSource() + if err := os.MkdirAll(agentsDir, 0755); err != nil { + t.Fatal(err) + } + runGit(t, agentsDir, "clone", origin, "_team") + runGit(t, origin, "commit", "--allow-empty", "-m", "newer") +} + +func TestHandleCheckStream_ReportsAgents(t *testing.T) { + s, _ := newTestServer(t) + addOutdatedAgentRepo(t, s) + + rr := httptest.NewRecorder() + s.handleCheckStream(rr, httptest.NewRequest(http.MethodGet, "/api/check/stream", nil)) + + blocks := strings.Split(strings.TrimSpace(rr.Body.String()), "\n\n") + if len(blocks) < 3 { + t.Fatalf("expected at least discovering, start and done, got %q", rr.Body.String()) + } + // The agent repo's remote is the one unit of work. + if want := "event: start\ndata: " + `{"repos":0,"sources":1,"total":1}`; blocks[1] != want { + t.Errorf("second event = %q, want %q", blocks[1], want) + } + _, done, ok := strings.Cut(blocks[len(blocks)-1], "event: done\ndata: ") + if !ok { + t.Fatalf("last event = %q, want done", blocks[len(blocks)-1]) + } + agents := decodeCheckPayload(t, done, "agents").Agents + if len(agents) != 1 || agents[0].Name != "_team/tutor" || agents[0].Status != "update_available" { + t.Errorf("agents = %+v, want _team/tutor with an update available", agents) + } +} + func TestHandleCheckStream_NamesLimitTheCheck(t *testing.T) { s, src := newTestServer(t) checktest.Seed(t, t.TempDir(), src) addTrackedRepoWithBrokenIndex(t, src, "_team") addTrackedRepoWithBrokenIndex(t, src, "_other") + addOutdatedAgentRepo(t, s) s.reloadSkillsStore() rr := httptest.NewRecorder() @@ -159,11 +210,14 @@ func TestHandleCheckStream_NamesLimitTheCheck(t *testing.T) { if !ok { t.Fatalf("last event = %q, want done", blocks[len(blocks)-1]) } - payload := decodeCheckPayload(t, done) + payload := decodeCheckPayload(t, done, "agents") if len(payload.TrackedRepos) != 1 || payload.TrackedRepos[0].Name != "_team" { t.Errorf("tracked repos = %+v, want only _team", payload.TrackedRepos) } if len(payload.Skills) != 1 || payload.Skills[0].Name != "changed" { t.Errorf("skills = %+v, want only changed", payload.Skills) } + if len(payload.Agents) != 0 { + t.Errorf("agents = %+v, want none: names are tracked repos and skills", payload.Agents) + } } diff --git a/internal/server/handler_check_stream.go b/internal/server/handler_check_stream.go index ecda5c8f7..42208e7b5 100644 --- a/internal/server/handler_check_stream.go +++ b/internal/server/handler_check_stream.go @@ -16,13 +16,13 @@ import ( // - "discovering" → {"phase":"..."} immediately on connect // - "start" → {"total": N, "repos": R, "sources": S} after discovery (N = work units) // - "progress" → {"checked": N} every 200ms -// - "done" → {"tracked_repos":…,"skills":…} final payload (same shape as GET /api/check) +// - "done" → {"tracked_repos":…,"skills":…,"agents":…} final payload (GET /api/check plus agents) // // "total" counts actual work units (repos + remote URL groups), NOT individual skills. // This ensures the progress bar advances evenly — one tick per network call. // // Query params: names (comma-separated) limits the check to those tracked repos -// and skills; the events then cover only them. +// and skills; the events then cover only them, and no agent is checked. func (s *Server) handleCheckStream(w http.ResponseWriter, r *http.Request) { safeSend, ok := initSSE(w) if !ok { @@ -34,6 +34,7 @@ func (s *Server) handleCheckStream(w http.ResponseWriter, r *http.Request) { // Snapshot config under RLock, then release before slow I/O. s.mu.RLock() sourceDir := s.skillsSource() + agentsDir := s.agentsSource() projectRoot := s.projectRoot walk := s.skillsWalk() parseOpts := s.parseOpts() @@ -49,13 +50,18 @@ func (s *Server) handleCheckStream(w http.ResponseWriter, r *http.Request) { } // Group skills by remote (fast, local only). plan := s.planSkillCheck(sourceDir, projectRoot, walk, only) + // Names are tracked repos and skills, so only a full check covers agents. + var agents []check.AgentCheckResult + if only == nil { + agents = check.CheckAgents(agentsDir) + } // Total = repos + URL groups (the actual network-bound work units). - total := len(repos) + plan.Remotes() + sources := plan.Remotes() + check.AgentRemotes(agents) safeSend("start", map[string]any{ - "total": total, + "total": len(repos) + sources, "repos": len(repos), - "sources": plan.Remotes(), + "sources": sources, }) // Atomic counter + ticker for progress events @@ -98,6 +104,11 @@ func (s *Server) handleCheckStream(w http.ResponseWriter, r *http.Request) { // --- Phase 2: Check skills by remote (1 work unit per remote) --- resolved, err := plan.Run(ctx, check.Options{ParseOptions: parseOpts, OnRemoteDone: func(int) { checked.Add(1) }}) + // --- Phase 3: Check agents by remote (1 work unit per remote) --- + if err == nil { + check.EnrichAgentResultsWithRemote(agents, func() { checked.Add(1) }, parseOpts) + } + // Stop ticker close(done) wg.Wait() @@ -113,5 +124,6 @@ func (s *Server) handleCheckStream(w http.ResponseWriter, r *http.Request) { "tracked_repos": repoResults, "linked_repos": linked, "skills": dashboardSkillResults(resolved), + "agents": dashboardAgentResults(agents), }) } diff --git a/ui/src/api/types/install.ts b/ui/src/api/types/install.ts index d7f30ec46..91de87e75 100644 --- a/ui/src/api/types/install.ts +++ b/ui/src/api/types/install.ts @@ -111,6 +111,8 @@ export interface CheckResult { linked_repos?: LinkedRepo[]; tracked_repos: RepoCheckResult[]; skills: SkillCheckResult[]; + /** Only a full stream check reports agents, each by its path without `.md`. */ + agents?: SkillCheckResult[]; } // Hub saved config types diff --git a/ui/src/pages/UpdatePage.tsx b/ui/src/pages/UpdatePage.tsx index f506ff96a..eb29b2820 100644 --- a/ui/src/pages/UpdatePage.tsx +++ b/ui/src/pages/UpdatePage.tsx @@ -256,8 +256,9 @@ export default function UpdatePage({ kind }: { kind: Kind }) { } } - // The backend returns one entry per repo directory (e.g. `_awesome-claude-agents`); - // copy it to every item in that repo. + // The backend returns one entry per skills repo directory (e.g. `_awesome-claude-agents`); + // copy it to every skill in that repo. An agents repo of the same name is a separate + // checkout, reported under `agents`. for (const repo of result.tracked_repos) { const repoStatus: CheckItemStatus = repo.status === 'behind' @@ -268,7 +269,7 @@ export default function UpdatePage({ kind }: { kind: Kind }) { ? { status: 'error', message: repo.message, checkedAt } : { status: 'up-to-date', message: repo.message, checkedAt }; for (const item of updatable) { - if (repoOf(item) !== repo.name) continue; + if (item.kind !== 'skill' || repoOf(item) !== repo.name) continue; next.set(checkKey(item), repoStatus); pending.delete(checkKey(item)); } @@ -277,7 +278,9 @@ export default function UpdatePage({ kind }: { kind: Kind }) { // Nested installs are reported by metadata relative path while the list shows the // basename; match every stable identifier so nested items don't stay checking. for (const skill of result.skills) { - const item = updatable.find((i) => !i.isInRepo && matchesCheckSkill(i, skill.name)); + const item = updatable.find( + (i) => i.kind === 'skill' && !i.isInRepo && matchesCheckSkill(i, skill.name), + ); if (!item) continue; next.set(checkKey(item), { status: @@ -297,6 +300,26 @@ export default function UpdatePage({ kind }: { kind: Kind }) { pending.delete(checkKey(item)); } + for (const agent of result.agents ?? []) { + const item = updatable.find((i) => agentKey(i) === agent.name); + if (!item) continue; + const edited = agent.status === 'drifted' || agent.status === 'dirty'; + next.set(checkKey(item), { + status: + agent.status === 'update_available' + ? 'update-available' + : edited + ? 'dirty' + : agent.status === 'error' + ? 'error' + : 'up-to-date', + // As for a modified skill, the translated label says it. + message: edited ? undefined : agent.message, + checkedAt, + }); + pending.delete(checkKey(item)); + } + for (const name of pending) { if (next.get(name)?.status === 'checking') next.set(name, { status: 'error', checkedAt }); } @@ -610,7 +633,8 @@ export default function UpdatePage({ kind }: { kind: Kind }) { {t('update.check.dirty')} - {!unit.isRepo && unit.items[0] && ( + {/* Local changes can be listed for skills only. */} + {kind === 'skill' && !unit.isRepo && unit.items[0] && ( {t('update.check.viewChanges')} @@ -825,7 +849,7 @@ export default function UpdatePage({ kind }: { kind: Kind }) { {t(lastChecked ? 'update.tab.checkAgain' : 'update.tab.checkNow')} - {/* The check does not cover agents, so only skills can be checked by selection. */} + {/* A check limited by names leaves agents out, so only skills can be checked by selection. */} {kind === 'skill' && shown.length > 0 && (