mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
fix(ui): check agents on the Updates tab (#966)
* fix(ui): check agents on the Updates tab Pressing Check on the Agents Updates tab marked every agent "Check failed". The page marks the items of both kinds as checking and turns the ones without a result into failures, but the check stream only ever looked at the skills source, so no agent got a result. The stream now reports agents as well, using the checks the CLI runs for `skillshare check agents`, and counts their remotes in the progress total. A check limited by names still covers tracked repos and skills only. A locally edited agent can now show "Modified locally". The link that lists local changes reads skills only, so it is left out for agents. * fix(ui): apply skill check results to skills only A mixed repository installed with --track for both kinds gives the skills source and the agents source a checkout with the same folder name. The check reports a tracked repo of the skills source under tracked_repos, but the Updates tab copied that status to every item whose repo folder matched, whatever its kind. A full check hid this because the agents' own results are applied afterwards. "Check N selected" returns no agent results, so checking the skills repo replaced an agents repo's "Update available" or "Modified locally" with "Up to date". The per-skill results had the same gap: a skill result could land on an agent of the same name. Both loops now match skills only, as the update results already do.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 }) {
|
||||
<span className="ss-st warn" title={c.message}>
|
||||
{t('update.check.dirty')}
|
||||
</span>
|
||||
{!unit.isRepo && unit.items[0] && (
|
||||
{/* Local changes can be listed for skills only. */}
|
||||
{kind === 'skill' && !unit.isRepo && unit.items[0] && (
|
||||
<RouterLink className="ss-btn sm" to={`${resourceHref(unit.items[0])}?changes=1`}>
|
||||
{t('update.check.viewChanges')}
|
||||
</RouterLink>
|
||||
@@ -825,7 +849,7 @@ export default function UpdatePage({ kind }: { kind: Kind }) {
|
||||
<RefreshCw size={15} />
|
||||
{t(lastChecked ? 'update.tab.checkAgain' : 'update.tab.checkNow')}
|
||||
</Button>
|
||||
{/* 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 && (
|
||||
<Button variant="secondary" disabled={busy} onClick={() => runCheck(shown)}>
|
||||
{t('update.header.checkSelected', { count: shown.length })}
|
||||
|
||||
+1
-1
@@ -43,7 +43,7 @@ Compare routes in `internal/server/server.go`, `handler_*.go` files, handler tes
|
||||
|
||||
`GET /api/resources` returns `resources` and `sourceLinkWarnings` (one string per first-level source link skipped during discovery). Healthy resources remain in the inventory when a link is unavailable. It also returns `linked_repos: [{name, target}]` so the Updates tab knows which followed Git checkouts are user-owned before running a check.
|
||||
|
||||
`GET /api/check` and the `done` event of `GET /api/check/stream` return the same `linked_repos` field separately from `tracked_repos`. Linked checkouts are excluded from Git checks and work-unit totals. Dashboard update endpoints return a `skipped` result for them before running Git, including force retries and skills within those checkouts.
|
||||
`GET /api/check` and the `done` event of `GET /api/check/stream` return the same `linked_repos` field separately from `tracked_repos`. Linked checkouts are excluded from Git checks and work-unit totals. Dashboard update endpoints return a `skipped` result for them before running Git, including force retries and skills within those checkouts. Only the stream's `done` event also reports `agents`, and only when the check is not limited by `names`; their remotes count in the `start` event's `sources` and `total`.
|
||||
|
||||
`GET /api/resources/{name}/local-changes` (`name` is the skill's relative path) returns `{files: [{path, status, diff}]}` with `status` `modified`, `added` or `deleted`, each diffed against the commit the skill was installed at; it backs the same comparison as `check <name> --diff` through `install.LocalChanges`. Skills without an install record of their own (local, tracked, no recorded hashes) are 404.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user