Files
skillshare/internal/check
Willie 53a3207a17 fix(update): keep an agent's source when updating it (#778)
* fix(update): keep an agent's source when updating it

After the first `update agents`, an agent's recorded source became
`/agents/<name>.md` with type `unknown-subdir` and no repo URL, so
`check agents` stopped looking upstream and later changes never arrived
(#777).

The batch path rebuilt the repository source from the clone URL, subdir
and branch only, leaving Raw and Type empty, and the metadata written
back was built from that empty Raw. The fallback reinstall and the
dashboard update kept the agent's full source as Raw while clearing the
subdir, so the written source repeated the agent path.

AgentRepoSource now rebuilds the repository source once, by cutting the
agent path off the recorded source, and all three paths use it, so the
source written back is the one install recorded.

Agents whose metadata was already rewritten have no repository left in
it and need to be installed again.

* fix(check): compare each agent at its own branch and report unchecked agents

Agent update checks gave wrong answers in several cases next to #777:

- Agents from one repository were compared with the first agent's
  version, so an older agent sharing a repo with a current one never
  showed its update.
- The installed branch was never sent to the remote, so an agent pinned
  to a non-default branch was compared with the default branch head.
- A tracked agent repo records its full commit while the remote hash is
  abbreviated, so a fresh clone always read as update_available; its
  checked-out branch was also ignored.
- `update agents` printed "All agents are up to date" and exited 0 when
  agents could not be checked at all: an unreachable remote, unreadable
  metadata, or a source erased by the #777 bug.

Each agent is now compared with its own version at its own branch, and
an agent whose source the old bug erased reports an error asking for a
reinstall, since its metadata no longer names a repository. Update lists
the agents it could not check and exits non-zero, counting them apart
from agents that failed to update. The docs describe the error status
and the reinstall fix.

* fix(update): repair dashboard-doubled agent sources and share the update flow

Review of the previous commits found gaps in recovering agents that
earlier updates broke, and in how the two update handlers report them:

- A dashboard update before the #777 fix appended the agent path to its
  source a second time. Those agents keep their repo URL, so check offers
  an update, but discovery then failed on the doubled path. Every copy of
  the path is now cut, and the update writes the source back correctly.
- On the dashboard, an agent whose source the CLI bug erased failed with
  "invalid source: source cannot be empty". AgentRepoSource now returns
  the same reinstall error check shows, and both use one detector.
- When every tracked agent was such an erased agent, no remote was asked,
  so the "Checking agents" spinner was never stopped and drew over the
  error rows. It is now stopped once the check returns.
- The global and project handlers repeated the check-and-update flow,
  and the project copy had already drifted (no dry-run log entry, spinner
  in --json). Both now run one shared flow.

Tests cover the erased agent next to an updatable one in global, --json,
--dry-run and project mode, and the doubled and erased sources in
AgentRepoSource.
2026-11-04 22:15:55 +08:00
..