Commit Graph
51 Commits
Author SHA1 Message Date
Willieandsim 5e90cf4b71 feat(ui): show a skill's branch and switch it from the detail page (#784)
* feat(ui): show a skill's branch and switch it from the detail page

A skill installed with --branch looked the same in the dashboard as one
from the default branch, and moving it to another branch meant a manual
reinstall from the CLI (#783).

The list, tiles, tree pane and Updates tab now tag the branch a skill was
installed from. The detail page lists the source's branches; picking one
confirms, then reinstalls through POST /api/update with a new `branch`
field, so the audit gate and the local-changes check still apply and a
branch without the skill leaves the install in place.

In project mode, reconciling config.yaml only added missing skills, so a
reinstall from another branch (the switch, or install --branch --force)
left config.yaml naming the old branch while the lock pinned the new
commit. Reconcile now moves the declared branch with the record.

Closes #783

* fix(update): make branch switches install the requested branch safely

Codex review of #784 found four ways a switch could misreport or lose work:

- A root skill installed as a full clone took the pull fast path on later
  switches, pulling its current branch instead of the requested one. The fast
  path now applies only when the checkout is already on that branch.
- A branch whose skill folder lacks SKILL.md replaced the skill with a plain
  folder. A staged update now refuses a candidate without SKILL.md when the
  installed copy has one, and keeps the install.
- Reconciling config.yaml from local metadata could rewrite a teammate's
  newer branch declaration back to a stale one on an unrelated install. The
  generic reconcile change is reverted; the switch updates only the switched
  skill's declaration.
- The config editor cache kept the old branch after a switch, so a later save
  could undo it. A successful switch now invalidates the config query.

---------

Co-authored-by: sim <sim@example.invalid>
2026-11-05 22:44:03 +08:00
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
Willie 23c9453f87 fix(update): serialize checkout updates across skillshare processes (#666)
Two dashboards (or a dashboard and the CLI) serving the same source ran
"Update all" at once. The server mutex only covers one process, so both
pulled into the same checkouts: one saw the other's half-applied merge as
"local changes would be overwritten", and concurrent fetches into a
blob:none clone failed with "fetch-pack: invalid index-pack output".
update.TrackedRepo, install --track --update, and the in-place pull of a
git-installed skill now hold a flock in the checkout's git directory; a
second process waits up to a minute, then fails with a clear message.

Force on a git-installed skill only skipped the local-modification check
and then ran a plain pull, which refused to merge over the edits the docs
say --force discards. It now fetches and resets to upstream, so a failed
fetch still keeps the edits. Followed checkouts keep pulling, since they
must be clean and may hold the user's unpushed commits.

The pull error dropped the file list git indents under it, and the
finished-update subtitle said everything was up to date even when items
had failed.
2026-10-29 16:20:30 +08:00
Willie 7a7cceefab feat(update): flag and protect skills edited since install (#622)
* feat(update): flag and protect skills edited since install

A skill installed from a repository and then edited by hand looked
exactly like an untouched one: check said up to date, and update either
reported it current or silently reinstalled it over the edit (#621).

Install already records each file's hash, so check now compares a
remote skill's files with those hashes and reports "modified", and
update skips such a skill until --force (CLI single, --all/--group,
dashboard). --force, the dashboard's Force Retry on the skipped row, or
the confirmation on the skill page discards the edit and reinstalls.

Two hash paths had to be made reliable for this to be trusted: the
dashboard's folder-wide target edit refreshed hashes by basename, so a
nested skill looked edited after skillshare's own change, and a skill
whose files cannot be hashed now counts as modified instead of being
overwritten.

* fix(server): keep earlier local edits when a target change rewrites SKILL.md

Changing a skill's targets in the dashboard rewrites its SKILL.md, and
both the folder-wide and the single-skill handler then re-hashed the
whole directory as the new baseline. An edit the user had already made
to any file in the skill was absorbed into that baseline, so the skill
stopped counting as modified and the next update overwrote the edit
without --force.

Both handlers now move only SKILL.md's recorded hash, and only when the
file still matched it before the rewrite. skillshare's own target edit
no longer reads as a local change, and an earlier edit still does. The
whole-directory refresh helpers lost their last callers and are removed.
2026-10-24 16:33:37 +08:00
Willie 2bba224cdf fix(ui): update agents from the Updates tab and repo detail page (#601)
The Agents Updates tab updates through /api/update/stream, which resolved
every name against the skills source, so agent updates failed there. The
agent detail page names a tracked repo by its folder, which updateAgent
did not resolve, so updating an agent inside a repo failed with "agent not
found".

The stream now takes a kind and routes agent names to updateAgent, which
also resolves an agent repo folder under the agents source. The tab sends
its kind to the stream and to Prune, and matches update results by kind and
by the agent's path, so a nested agent is marked up to date after it
updates.

Closes #600
2026-10-22 00:39:12 +08:00
Willie 7b952c02a9 fix(update): honor accepted findings in dashboard tracked updates (#599)
* fix(update): honor accepted findings in dashboard tracked updates

The dashboard ignored findings accepted through the CLI, so a tracked repo
that `update --force` let through was blocked again on the next dashboard
update, and every dashboard Force Retry had to be repeated. Regular skill
updates in the dashboard already honored and recorded acceptances, so only
tracked repos differed.

Tracked-repo updates now always honor accepted findings and record the ones
an override lets through, for both callers. The opt-in option and the
AuditGate flag it fed are removed, since no caller turns them off.

Dashboard agent tracked repos passed an empty source dir, so a nested repo
kept acceptances in its group folder under a different key than the CLI.
They now pass the agents source, as the CLI does.

* fix(update): reload the agents store after agent repo refresh

Dashboard agent tracked repos now refresh metadata in the agents source,
but a metadata change reloaded the skills store, leaving the agents store
as it was until the next request. Reload the store that matches the source.

Every caller of update.TrackedRepo now passes a source dir, so the
empty-dir guard and its doc no longer describe a supported mode. The new
agent test reuses the tracked fixture instead of rebuilding it.
2026-10-21 23:28:16 +08:00
Willie e3af6274fc feat(install): install config entries from the dashboard and name repos by owner
Bare `skillshare install` already restores everything .metadata.json records
but the disk lacks, yet the dashboard could only re-clone missing tracked
repos through a separate rehydrate path. Expose the CLI's install-from-config
flow instead (GET /api/install/missing, POST /api/install/from-config) so both
surfaces share one detection and one installer, and drop the old
missingTrackedRepos plumbing from update responses.

The install summary now counts tracked repos and their skills apart from
standalone skills, since "Installed 1 skill" hid a whole repo. New tracked
repos are named `_<owner>-<repo>` so two `skills` repos no longer collide;
existing installs keep their names. `check` passes the stale status through
so the dashboard can offer to prune skills deleted upstream.
2026-10-08 12:01:42 +08:00
Willie 8bf43f2480 fix(update): clean the name before the single-update skill lookup
Codex review of #481 round two: POST /api/update looked up an exact skill
with the raw name before resolving a repo. The shared helper now accepts
`org/team/`, so with a skill at org/team beside org/_team the raw lookup
missed the skill and the shorthand updated the repo. Clean the name once
at the top of updateSingleByKind so the skill lookup and repo resolution
see the same name.
2026-10-08 00:05:10 +08:00
Willie 3479c42420 fix(update): share the tracked checkout rule and tighten the repair
Simplify and code-review passes over #474 found the fix spread over
several definitions of "tracked repo" and three holes in the repair.

One install.IsTrackedCheckout (a _-prefixed git checkout) now backs
GetTrackedRepos, GetUpdatableSkills, the dashboard routing and the repair.
GetUpdatableSkills skipping such entries replaces the two CLI resolver
filters, so `skillshare check` and the dashboard Updates tab no longer list
a rewritten repo a second time as a regular skill. The repair checks that
one path instead of walking the whole source tree.

- Reconcile sets tracked on a checkout again without dropping type or
  repo_url, so a rewritten entry that went through it was never cleaned.
  The repair now also runs when those regular-install fields remain.
- The repair used GetByPath, whose basename fallback can return another
  top-level item's entry; it now uses the repo's own key.
- A tracked entry whose checkout is gone fell through to the basename
  fallback of resolveTrackedRepo and pulled a different repo with the same
  basename. It now reports the repo as missing on disk.
2026-10-07 22:33:54 +08:00
Willie 51d0a1e5e9 fix(update): repair tracked repo entries rewritten as regular installs
The old dashboard update rewrote a tracked repo's metadata entry as a
regular install: tracked was dropped and type, repo_url and version were
added. Those repos stayed broken after the routing fix, because
`skillshare update <repo>` found the name twice (as a repo and as a
regular skill) and refused it, and nothing restored the entry.

The shared tracked-repo update now restores such an entry to what
install --track records (source, branch, group, tracked) when its path is
a checkout GetTrackedRepos lists, so regular skills are never touched.
CLI name and glob resolution skip a regular-skill match whose path is
already a tracked repo, so the update can reach that repair.

Codex review: the routing fix sent every git checkout with metadata to
the tracked-repo update, including standalone skills installed as a full
checkout, whose regular update records the new version and commit.
Their version stayed stale and update checks kept reporting an update.
Only tracked entries and _-prefixed checkouts now skip the regular path.
2026-10-07 22:16:56 +08:00
Willie 72f2e31664 fix(server): update tracked repos as repos from the dashboard
A tracked repo's own metadata entry carries a Source, so updateSingleByKind
sent it to updateRegularSkill. The reinstall reported isRepo false and
rewrote the entry without tracked: true, after which `skillshare update
<repo>` found the name twice (as a repo and as a regular skill) and refused
to update it. Route tracked entries and git checkouts to the tracked-repo
update before the regular-skill branch.

Closes #473
2026-10-07 22:10:48 +08:00
Willie f2f663689b fix(install): warn about submodules on tracked updates
The CLI and dashboard update a tracked repo through update.TrackedRepo,
which never looked for submodules. A pull that turned a skill directory
into a submodule reported success and the skill vanished on the next
sync. TrackedRepoResult now carries the skipped-submodule warnings and
both callers show them.

Refs #433
2026-10-07 09:35:59 +08:00
Willie 7bc61698ee refactor(update): load metadata only for root-skill repos, report once
The dashboard update of N tracked repos loaded the metadata store 2N times
under the server lock, and each load walks the whole source tree. The refresh
now returns before loading when the repo has no root SKILL.md, reports
whether it saved a change, and the server reloads its store only then,
through the existing reloadSkillsStore.

The CLI single-repo path tracked its output with two flags and a OnceFunc.
The caller hook now runs once for every outcome, so the spinner stop, the
discard warning and the pull summary live in one place and print in the same
order as before.

auditGateFailClosed rebuilt three of its messages by hand; they are
AuditGateError's own wording with another subject, so both now come from one
function.

Refs #443
2026-10-07 00:20:06 +08:00
Willie 277b28316e fix(update): keep the tracked-repository wording and log metadata errors
Review of the shared tracked-repo update found two regressions.

`install --track --update` lost "in tracked repository" from its message when
findings blocked and the rollback failed. The CLI builds its summary from
that phrase, so the old sentence is back, with the rollback part still coming
from AuditGateError.RollbackNote.

The dashboard dropped a failed metadata refresh without a trace, while the
CLI prints a warning. It is now logged.

trackedBlockMessage also gets a test: the dashboard offers Force Retry based
on its exact wording, and the server-level tests for the failed-rollback
branches went away with the old gate.

Refs #443
2026-10-07 00:16:36 +08:00
Willie 2edf7649fd refactor(update): update tracked repos through one shared operation
Updating a tracked repo is a fail-closed sequence: check for uncommitted
changes, pull, audit what was pulled, reset to the pre-pull commit when the
audit blocks. The CLI had two copies of the pull flow, the dashboard a third,
and the audit gate existed four times (CLI, dashboard, and two in install).
The copies had drifted: the dashboard ignored a failed git status and never
refreshed root-skill metadata, and each copy worded a failed rollback on its
own.

update.TrackedRepo now owns the sequence and returns a structured result;
install.AuditGate is the only gate. internal/update is a new package because
internal/git already imports internal/install. The CLI keeps its spinner,
rows and the "Apply anyway?" prompt, passed in as one Confirm callback; the
dashboard turns the result into its JSON item.

Behaviour changes, all towards the stricter copy:
- the dashboard reports a failed git status as an error instead of pulling;
- the dashboard refreshes root-skill metadata after an update, like the CLI;
- a prompt that fails rolls the update back instead of leaving it applied;
- the rollback-failed and rollback-unavailable texts come from one place.

Accepted findings stay as they were (CLI honours and records them, the
dashboard does neither), now as the explicit AcceptedFindings input. The
"blocked and rolled back" texts are unchanged per caller because the
dashboard matches on them.

Refs #443
2026-10-07 00:10:54 +08:00
Willie e8242affc3 fix(update): exclude followed checkouts from missing repo recovery
Missing-repo discovery ignored the operation follow policy, so tracked metadata added a skipped checkout back to update --all and allowed --force to reset it. Thread the policy through missing-repo detection and its CLI/server callers, including rehydration, so existing followed checkouts remain excluded.

Cover global and project updates with dirty tracked checkouts and force, as well as shared and dashboard rehydration. Document that --force does not override the batch skip.
2026-10-05 21:22:47 +08:00
Willie aafb7e7e96 fix(ui): keep followed checkouts out of dashboard updates
Separate user-owned followed Git checkouts into linked_repos in check and resources responses so the Updates tab renders information instead of tracked errors or retry actions. Refuse dashboard updates before Git runs, including force retries and descendant skills, while leaving managed repositories unchanged.
2026-10-05 18:26:12 +08:00
Willie d2b322ed87 fix(server): carry follow policy through skill updates
Use one skills traversal policy for dashboard update discovery, post-pull audits, and staged regular-skill writes so linked repositories are audited and child updates preserve their source links. Keep agent updates and disabled follow behavior on the nil-policy path.

Cover global and project modes through HTTP and SSE handlers, including audit rollback and disabled-follow parity.
2026-10-05 15:46:04 +08:00
Willie 89fc4fbdf1 feat(sourcewalk): follow first-level source links when enabled
Users link a checkout directly under the skills source (e.g.
skills/_dev-skills -> ~/code/dev-skills) and expect it to behave like any
other first-level entry. sourcewalk resolved only the root, so these links
were invisible to discovery, sync, update, and the dashboard.

follow_source_links (global and project config, default false) enables a
per-operation sourcewalk.Follow policy. Walk, WalkDir, and ReadDir report a
followed link under its own name as a directory and descend into its
target, so names, RelPath, FlatName, SourcePath, tracked-repo detection, and
metadata keys stay logical. Only entries directly under the source root are
followed. The policy is built from config and passed explicitly to every
discovery caller in the CLI, server, and reconcile, so counts agree; the
server keeps a per-instance snapshot refreshed on config load and save
instead of a process-global flag.

A link is skipped, with one warning per operation, when its target is
missing or unreadable, is the source or a parent of it, or overlaps an
active skills target. A missing or unreadable target marks the operation
incomplete: sync then skips pruning and copy-orphan deletion, and reconcile
keeps metadata, so an unmounted drive or a re-clone in progress cannot
erase target entries or install records. A link to an existing file is not
a directory link and stays an ordinary entry; treating it as incomplete
would disable pruning for anyone sharing a file such as .skillignore.

doctor keeps raw link identity: with the key off it still says the link is
not followed and names follow_source_links: true; with it on it reports
followed links and skipped links with the reason.

The raw-walk allowlist gains entries for the policy path in Walk and
WalkDir: the source root walk with a policy, and the walk of a validated
link target whose paths are remapped to the logical link path. Both live
in sourcewalk itself, the package that owns source traversal.

Refs #274
2026-10-05 14:26:09 +08:00
Willie c61f48865e fix(server): reject skill names that escape the skills source (#408)
GET /api/audit/{name} joined the client-supplied name to the source
without checking it, so a name such as ../../x scanned a directory
outside the skills source and returned a clean result for it. The
single-skill update, the update stream, and the batch uninstall built
paths the same way; the tracked-repo uninstall route already refused
such names inline.

One helper, validSourceName, now holds that rule: non-empty, relative,
not starting with "..", and no Windows separators or volume prefixes on
any host, as sourcewalk does for declared names. The audit and update
routes answer 400, the update stream reports the name as an error
result, the batch uninstall fails that item, and the repo uninstall
route uses the same helper. Nested names such as group/skill still
resolve.

Closes #402
2026-10-05 11:03:39 +08:00
Willie 8c60f51b9f feat(source): add the sourcewalk walker and sourcefs write boundary for proposal 274 (#385)
Implements rollout steps 1 and 2 of proposals/274-skillfollow.md. Nothing follows a link or parses .skillfollow yet.

Step 1: doctor reports first-level symlinks and junctions in the skills source as info, in text and JSON, without following them.

Step 2a: internal/sourcewalk owns traversal of the skills source. Thirteen raw walks move onto it with identical behavior, and a go/parser ratchet fails the tests on any new unclassified walk.

Step 2b: internal/sourcefs wraps an os.Root opened at the skills source and refuses any write whose path has a link component. The six write sites the proposal found in review move onto it, including the cross-device copy fallback, and a second ratchet covers raw os write calls. The only behavior change is that an explicit path crossing a link inside the source is refused instead of written through.

Refs #274

Release-As: 0.24.3
2026-10-04 15:15:43 +08:00
Willie 36a314442b refactor(server): decode JSON request bodies through one size-limited helper
About 57 handlers decoded request bodies with no size limit, and the few
that had one each picked their own. They now go through decodeJSON with a
1 MiB default; handlers that need more keep their larger limit. An
oversized body gets 413 instead of whatever the handler returned for bad
JSON (MCP and plugin requests used to answer 400). Every other decode
error keeps the handler's existing status and message.
2026-09-30 02:25:42 +08:00
Willie 6a325037f2 refactor(server): share the skills config reconcile step
Install, batch install, tracked-repo install, uninstall and rehydrate
each repeated the same nine-line block to reconcile the project or
global skills config. reconcileSkillsConfig now holds that block, so a
change to reconcile behavior or logging is made once instead of five
times. Each caller still passes its own source directory, so behavior
is unchanged.
2026-09-30 01:35:10 +08:00
a352b8d243 feat(install): pin skills to a tag or commit from their web URL (#293)
* feat(install): pin GitHub tree/blob URLs to their ref

Hub entries only carry a source URL, so a team hub had no way to pin a
third-party skill to a reviewed tag or commit. The parser already read
tree/<ref>/ and blob/<ref>/ URLs but discarded the ref, installing from
the default branch instead of the version the URL names.

Keep that ref as Source.Branch. An explicit --branch (CLI) or branch
(API body) still overrides it; the server handlers now only override
when a branch is given. Batch installs group by repo and ref so two
pinned versions of one repo get separate clones.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(install): describe pinning hub sources to a tag or commit

Explain that a GitHub tree/<ref>/ source URL pins the install, in both
the hub index guide and the install reference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* feat(install): pin GitLab/Bitbucket URLs and resolve refs containing "/"

Pinning should not depend on the host, so GitLab (-/tree/<ref>/) and
Bitbucket (src/<ref>/) web URLs now keep their ref too.

Taking the first path segment as the ref broke branch names containing
"/": tree/feature/x/skills/foo cloned branch "feature" and failed. When
the first segment is not a branch or tag on the remote, the longest
matching one is used instead. A ref the remote does not have fails
with a hint to use --branch, rather than silently installing the
default branch. A saved branch that covers more of the path (from
--branch or config) moves the subdir without asking the remote.

The grouped-install round-trip test pinned -/tree/main/ against a repo
on master; the ref used to be ignored, so its branch is now renamed.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* docs(install): cover GitLab, Bitbucket and "/" branches in URL pinning

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(install): keep web URL refs correct on reinstall, --branch and grouping

Review of the slash-branch resolution found four gaps:

- A saved branch equal to the whole URL tail (tree/feature/x) did not
  move the subdir back, so every reinstall or update looked for "x".
- An unrelated --branch with a slash-branch URL kept the parse-time
  subdir (x/skills/foo) instead of the URL's real one.
- Grouped installs copy the source to a repo root; resolution then put
  the subdir back and discovery looked under a doubled path. Grouping
  also keyed on the unresolved first segment, so tree/feature/x and
  tree/feature/y could share one clone. Web URLs with a ref now install
  on their own, and resolution leaves a repo-root copy at its root.
- A skill named after the parse-time subdir kept that name once the
  path turned out to be all ref (tree/feature/x named the skill "x").

The unknown-ref error now reads as a missing ref first, since a stale
ref (tree/master after a rename) is more common than a slash branch.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* fix(update): keep legacy installs on the default branch

Skills installed before URL refs were honoured got the default branch
and recorded no branch. Single-skill update re-parses the recorded
source, so it moved them to the URL's ref (or failed on a stale one,
with a hint to pass --branch, which update does not accept), while
update --all rebuilds from RepoURL and kept the default branch.

ApplyRecordedBranch treats an empty recorded branch as the remote
default and drops the URL's ref. It replaces the branch handling at
every site that reinstalls from recorded metadata: CLI and server
update for skills and agents, and tracked-repo rehydration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* perf(search): share one clone across pinned hub skills from a repo

Any web URL with a path after its ref installed on its own, so a hub
listing many tree/<tag>/ skills from one repo cloned it once per skill.

groupByRepo now resolves each URL's ref before grouping, with a
RemoteRefs cache that lists each remote's refs once, and groups by
repo and resolved ref. Only refs containing "/" (whose subdir the
discovery match cannot re-derive) and refs that fail to resolve still
install alone. A resolved source is marked settled so the grouped
clone does not resolve it again, and ApplyRecordedBranch settles the
subdir from a recorded branch without asking the remote.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Willie <egg358358@gmail.com>
2026-09-28 22:08:16 +08:00
Willie de1abd4b33 feat(install): pin project skills to a commit with a lockfile
config.yaml records which skills a project wants, but not which commit
each one resolved to, so two teammates running `install -p` a week apart
could end up with different skill contents.

Project mode now writes .skillshare/skills.lock.json next to the config.
`install -p` checks out the locked commit for skills and tracked repos,
and brings an already installed skill to the lock when they differ.
`update -p` and the dashboard move a pin only for skills whose commit
actually changed, so a stale local copy cannot roll the team back, and
uninstall drops the pin. A locked value is only honoured when it is a
full SHA for the same source, since it ends up as a git argument.
2026-09-21 04:31:22 +08:00
Willie efcc3e6f61 fix(update): honour installed branch in batch update and web UI check/update
Skills installed from a non-default branch record that branch in metadata,
but the grouped update path (update --all) cloned the remote default branch,
so the skills were either downgraded or reported as removed upstream and
pruned. The web UI update and check handlers had the same gap, comparing
against the remote HEAD instead of the installed branch.

Group batch updates and web UI checks by URL+branch, pass the branch through
to the clone, and resolve remote tree hashes for that branch as well.

Refs #268
2026-09-02 13:08:40 +08:00
Willie 0a3e669b09 fix(audit): decouple audit override from Force so --force reaches the gate
InstallOptions.Force carried two meanings: "overwrite what is already
there" and "proceed despite audit findings". Update paths set Force
unconditionally to overwrite a staged temp dir, so they had to leave it
off to keep the audit gate alive -- which swallowed the caller's --force
and made the gate impossible to override from either the CLI or the web
UI.

Split the audit intent into InstallOptions.AuditOverride and route every
gate through it alone. Entry points translate --force explicitly, so a
missed one degrades to "force has no effect" rather than "audit is
bypassed". Scan failures stay fail-closed regardless: accepting known
findings is not the same as being unable to learn any.

This also closes two paths that bypassed the gate outright, since both
inherited Force for overwrite reasons alone: install --json and grouped
batch updates.

In the web UI, Force Retry now appears only on failures force can
actually resolve -- a permission-denied unlink previously offered a
button that could never succeed -- and CLI-only flag hints are stripped
from messages rendered there.

Behaviour change: a --force at install time no longer exempts later
updates from the audit gate; it is a one-off decision per command.
2026-08-27 17:10:29 +08:00
Willie 54dd7d12a3 fix(update): surface missing tracked repos in update --all across CLI, API, and UI
When tracked repo metadata is committed but the gitignored clone dirs are
absent on a fresh machine, `update --all` silently reported zero work: the
batch path skipped missing repos with no message, and the web UI's
update-all paths only listed repos present on disk.

Missing tracked repos are now detected and surfaced everywhere:
- CLI: a warning block (human output) plus an aggregated
  `missing_tracked_repos` summary (names + one-shot rehydrate hint) in JSON;
  the per-item error is concise. Fixed for both global and project modes,
  and batch and single-target paths.
- Server: GET /api/update/missing-tracked-repos and the update-all/stream
  summaries report them; POST /api/update/rehydrate re-clones them from
  metadata (mirrors bare `skillshare install`).
- UI: the Update page shows a warning banner listing missing repos with a
  Rehydrate button; strings added to all 11 locales.

Closes #212
2026-06-11 15:32:28 +08:00
Willie 0e091a5e63 fix: refresh metadata after nested skill updates 2026-05-26 13:37:47 +08:00
Willie 996d00e342 feat(config): migrate consumers to Effective*Source helpers (Phase 3+5)
Make the v0.19.16 sources map actually do something: route all path
reads through Config.EffectiveSkillsSource() / EffectiveAgentsSource() /
EffectiveExtrasSource() so users who set sources.skills / sources.agents /
sources.extras get the configured paths everywhere.

Mechanical changes (~50 files):
- cmd/skillshare/**: replace cfg.Source / cfg.ExtrasSource reads with
  cfg.EffectiveSkillsSource() / cfg.EffectiveExtrasSource()
- internal/server/**: replace s.cfg.Source / s.cfg.ExtrasSource reads
  with the same helpers; server.skillsSource() / gitignoreDir() use the
  global-mode helper
- internal/config/config_validate.go: validate using EffectiveSkillsSource
  while still rejecting configs that set neither field explicitly
- internal/config/reconcile.go, registry.go: read via helpers

Behavioral fixes (paired with the migration):
- extras init / extras source / POST /api/extras no longer silently
  backfill the legacy extras_source field — the runtime fallback inside
  EffectiveExtrasSource() handles it. This stops surprise diffs in users'
  config.yaml after running extras commands.
- extras source command writes back to whichever field the user already
  configured (sources.extras if set, otherwise legacy extras_source) so
  the update is not shadowed.
- source_type in /api/extras and extras list correctly reports "default"
  vs "extras_source" by inspecting the raw (unresolved) configured value;
  sources.extras counts as configured for this purpose.

UI:
- ui/src/lib/fieldDocs.ts: neutralize sources / sources.* descriptions
  so they describe both project and global modes (Phase 5).

Preserved (intentional):
- Direct writes to cfg.Source / cfg.AgentsSource / cfg.ExtrasSource in
  init, migrate.go, cloneForSave, and server.reloadConfig — these are
  raw-field writes, not path reads.
- Updated test expectations for the removed backfills.
2026-05-21 14:49:11 +08:00
Willie 204340c2e0 fix: wire azure_hosts through project install and agent update paths
- install_project.go: pass AzureHosts to temporary Config (was only
  passing GitLabHosts, so project-mode direct install ignored azure_hosts)
- update_agents.go: thread ParseOptions through batchUpdateAgents and
  reinstallAgent, replacing bare ParseSource with ParseSourceWithOptions
- handler_update.go: use ParseSourceWithOptions with s.parseOpts() for
  agent update in web UI

Without this fix, azure_hosts in .skillshare/config.yaml was silently
ignored during project install and agent update, causing on-prem Azure
DevOps URLs to be parsed incorrectly.
2026-05-05 18:54:45 +08:00
Willie 788f9bc6e9 feat(agents): JSON output + audit gate for install/update
Extend install/update with agent-aware --json output and apply the same
audit block-threshold gate skills already use.

Install:
- install --json: imply --force; imply --all only when neither
  --skill nor --agent is set (so explicit selectors still work)
- project-mode install now routes through cmdInstallProjectParsed
  so --json suppresses UI and emits a pure-JSON payload
- agent installs propagate SourceDir so metadata lands in the
  agents root, not the install subdir
- validation error lists --agent / --kind / --branch explicitly

Update agents:
- update agents supports --force, --skip-audit, --audit-threshold
- tracked agent repos + metadata-backed single-file agents now run
  the same audit gate as skills; blocks roll back from a temp stage
- JSON output returns the final per-agent status
  (updated/skipped/failed/up_to_date/...) by merging check results
  with batch update outcomes

Audit:
- auditInstalledAgent shares one helper with auditInstalledSkill
  (scan + cleanup callbacks); single-file agent scans now use
  audit.ScanFile / ScanFileForProject instead of staging the file
  into a temp directory
- UpdateAgentFromDiscovery stages to temp, audits, then renames
  atomically (rename already overwrites on POSIX)

Refactors pulled in while reworking these paths:
- extract jsonUISuppressor helper in json_output.go and use it
  from install/update/update_agents; collapses 4 copies of the
  suppress/restore closure dance and the per-error failJSON block
- drop relPath plumbing from installAgentFromDiscoveryInternal
  now that ScanFile doesn't need a staged relative path
- list.go render functions now use theme.ANSI() so NO_COLOR is
  respected in plain-text output

Tests:
- add TestInstallAgentFromDiscovery_HighFindingBlocked (unit)
- add TestUpdate_Agents_HighFindingBlockedByThreshold (integration)
- add TestInstall_Project_JSON_Agent_PureJSON,
  TestUpdate_Agents_JSON_ReportsFinalStatus
- fix TestList_SKILLSHARE_THEME_Light / TestList_NO_COLOR to
  write a config before invoking list
- fix TestTargetList_NoTUI_FallsBackToPlainText assertion to match
  the new structured Mode: merge output
- fix TestDoctor_AllGood_PassesAll by pinning SKILLSHARE_THEME=dark
  so the no-TTY theme fallback warning doesn't fire
- add list_tui_content_test.go covering light/dark glamour base
- list detail pane now picks LightStyleConfig on light terminals

Docs:
- update install.md, update.md, understand/agents.md for the new
  flags, JSON shapes, and agents update workflow
2026-04-10 23:27:26 +08:00
Willie da000c4d07 feat(server): agent tracked repo install, prune-on-empty, audit guards
- appendAgentDiffs helper deduplicates diff/stream agent logic
- handler_agent_diff: skip local copies, junction-aware checks
- handler_sync: prune orphan agents even when source is empty
- handler_install: tracked agent repo auto-detection and routing
- handler_skills: expose RepoRelPath and Targets for agents
- handler_skills_batch: agent target assignment via frontmatter
- handler_sync_matrix: pass agent Targets to ClassifySkillForTarget
- handler_update: tracked agent repo git pull update
- handler_audit: guard empty/missing source dirs gracefully
- Tests for all of the above
2026-04-10 02:05:13 +08:00
Willie b8a189ba58 Improve resource install agent support
Add local-path resource discovery so install flows can detect agents as well as skills. Preserve nested agent paths and suffixless agent metadata keys during batch install and update, and refresh the UI copy to use resource-aware wording on the install surface.
2026-04-10 01:26:40 +08:00
Willie 5836a8802f feat: add agent filter support to Filter Studio, targets CLI, and overview API
Backend:
- PATCH /api/targets/:name accepts agent_include/agent_exclude fields
- POST /api/sync-matrix/preview returns agent entries with kind=agent
- GET /api/overview returns agentsSource and extrasSource paths
- Fix ResolveProjectTargets to resolve Agents sub-key (path + filters)
- Add agent filter CLI flags: --add-agent-include, --add-agent-exclude,
  --remove-agent-include, --remove-agent-exclude, --agent-mode
- Unify target list JSON/TUI to show agent info and filters

Frontend:
- FilterStudioPage: kind-driven single-context view (?kind=skill|agent)
- KindBadge: use design system tokens (ss-badge + wobble in playful)
- TargetsPage: link to Filter Studio with ?kind= param
- ResourceDetailPage: capitalize type labels (Local, GitHub)
- ResourcesPage: sync activeTab from URL searchParams on navigation
- DashboardPage: show agents/extras source dirs, link skills card
  with ?tab=skills for reliable tab switching
- API client: extend updateTarget and previewSyncMatrix for agent filters

Tests:
- Agent include/exclude round-trip persistence
- Invalid agent pattern returns 400
- Preview with agent entries and kind field
- No agent entries for targets without agent path
- CLI target agent filter integration tests
2026-04-09 03:50:28 +08:00
Willie 4af128fcf0 fix: migrate metadata consumers from Get(basename) to GetByPath
All call sites that looked up metadata entries using filepath.Base()
now use store.GetByPath(relPath) which handles both full-path keys
and legacy basename+group keys transparently.

Also fixes makeInstallOpts() to set SourceDir from updateContext,
preventing nested skill updates from writing metadata to wrong dir.
2026-04-08 16:35:27 +08:00
Willie d0a1df3e8b refactor: replace ReadMeta in server handler_skills and handler_update
handler_skills.go uses s.skillsStore.Get() for skill metadata.
handler_update.go uses store parameter in getServerUpdatableSkills.
2026-04-08 11:11:03 +08:00
Willie c176d89405 feat(api): add kind field to sync, audit, check, update, and install handlers
handler_sync: add Kind field to diff stream item struct.
handler_audit: add Kind field to audit stream result.
handler_check: add Kind field to check stream result.
handler_update: add Kind field to update stream result.
handler_install: add Kind field to install request for agent support.
2026-04-07 18:05:40 +08:00
Willie 657e400f8c fix(server): resolve order + registry prune for repo uninstall
- updateSingle: check exact skill path before resolveTrackedRepo
  fallback, preventing basename collision with nested repos
- handleUninstallRepo: match repo's own registry entry by FullName
  in addition to group-based matching for member skills
2026-04-04 17:05:22 +08:00
Willie a4984cd322 fix(server): resolve nested repos in update + prune registry on uninstall
P1: updateSingle now uses resolveTrackedRepo (shared with uninstall)
to find nested tracked repos like org/_team-skills instead of only
probing root-level _name/name.

P2: handleUninstallRepo now prunes registry entries belonging to the
uninstalled repo and runs ReconcileGlobalSkills/ReconcileProjectSkills,
matching the cleanup that handleUninstallBatch already does.

Extracted resolveTrackedRepo as a Server method to deduplicate the
nested path resolution logic between uninstall and update handlers.
2026-04-04 17:05:22 +08:00
Willie 0a3305f617 fix(update): capture git stderr and show actionable error messages
The update handler used internal/git which ran git commands without
capturing stderr, so failures like divergent branches only showed
"exit status 128". Now runGitWithProgress captures stderr and pipes
it through install.WrapGitError for meaningful messages.

Also adds:
- extractGitFatal() strips verbose hint: lines from git output
- Force checkbox and per-item Force retry button in Update UI
- "(try force update)" / "(try --force)" hint on pull failures
2026-03-13 09:45:56 +08:00
Willie a4d52615f7 feat(config): add gitlab_hosts for custom GitLab domain support
Self-managed GitLab instances on custom domains (e.g., git.company.com)
without "gitlab" in the hostname were parsed with 2-segment owner/repo
split instead of full-path repo. Users can now declare extra GitLab
hostnames in config so the parser treats them like gitlab.com (nested
subgroup support).

- Add `gitlab_hosts` field to both global and project Config structs
- Validate entries at load time (reject scheme, path, port, empty)
- Add `ParseOptions` / `ParseSourceWithOptions` to thread hosts into parser
- Add `isGitLabHost()` helper combining built-in + custom host detection
- Extend `InstallContext` interface with `GitLabHosts()` method
- Update all ParseSource call sites (install, search, update, server)
- Add JSON schemas for both config files
- Add unit tests for config validation and source parsing
- Add E2E runbook for devcontainer verification
- Document in configuration reference and URL formats appendix
2026-03-12 16:45:02 +08:00
Willie 38f8f1c796 fix(symlink): resolve symlinked source/target dirs across all Walk callsites
filepath.Walk/WalkDir silently skip symlinked root directories because
os.Lstat sees the root as a non-directory symlink and never enters it.
This affected update, uninstall, reconcile, and server handlers when
the source directory was a symlink (common with dotfiles managers).

Extract ResolveSymlink() from sync.go into internal/utils/path.go and
apply it at every filepath.Walk/WalkDir callsite on source/target dirs.

Also add containment guards to resolveGroupSkills (uninstall) and
resolveGroupUpdatable (update) to reject group directories that are
symlinks pointing outside the source tree.
2026-03-02 10:05:57 +08:00
Willie cd5902c590 feat: unify update audit threshold gate and docs 2026-02-23 04:18:01 +08:00
Willie bd76ec9aa5 feat: surface audit risk score in update API and UI
Return auditRiskScore and auditRiskLabel in update results so the
dashboard can show security posture after both tracked-repo and
regular-skill updates. auditGateTrackedRepo now returns the audit
result alongside the blocked indicator.
2026-02-23 04:18:01 +08:00
Willie 5ce6507799 fix: server rollback error reporting and isSecurityError classification
- handler_update.go: check git.ResetHard return value; if rollback
  fails, append explicit warning to blocked message instead of
  silently claiming rolled back
- update.go: add "post-update audit" to isSecurityError keywords
  so install.Install audit failures are correctly classified as
  security blocks in batch exit code
2026-02-23 04:18:01 +08:00
Willie a0bfe9958a fix: batch update error propagation, skip-audit passthrough, and security hardening (#39)
- P1: Batch/all update now returns non-zero when repos are blocked by
  security audit (fail-closed for CI pipelines)
- P2: Pass --skip-audit to regular skill update via InstallOptions
- P2: Add path containment check in content integrity to prevent
  directory traversal via crafted file_hashes keys
- P3: Switch git diff parsing to NUL-delimited (-z) for safe handling
  of special filenames
2026-02-23 04:18:01 +08:00
Willie 3b8c681bb2 feat: auto-inject auth tokens for hub search and Web UI git operations
Add token auto-injection for private repo support across all platforms:
- Hub search (--hub): normalize web URLs to raw-content URLs and apply
  platform-specific auth headers (GitLab, GitHub, Bitbucket)
- Web UI push/pull/update: use *WithAuth variants for git operations
- Export ResolveTokenForURL and DetectPlatformForURL from install/auth
2026-02-22 15:13:10 +08:00
Willie 3a132ab72e fix: update nested skills by full relative path in Web UI
The Update button on SkillDetailPage passed only the skill basename
(e.g. "ascii-box-check") instead of the full relative path
("utils/ascii-box-check"), causing "not found as tracked repo or
updatable skill" errors for nested skills.

- Frontend: use skill.relPath instead of skill.name for non-repo skills
- Backend: rewrite getServerUpdatableSkills with filepath.WalkDir so
  Update All also discovers nested skills
2026-02-13 14:21:36 +08:00
Willie e5813cc7e0 feat: add oplog instrumentation to all API handlers, improve audit/log/sync CLI
- Add oplog write helpers to server (oplog_helper.go) and instrument
  all handler_*.go endpoints with ops/audit logging
- Improve audit CLI with structured auditRunSummary and severity counts
- Enhance log CLI with richer filtering and detail display
- Improve sync CLI with drift detection summaries in oplog
- Reorder web UI sidebar nav by user workflow (core → acquire → distribute → maintain → monitor)
- Enhance LogPage with better formatting and filtering
- Add server oplog unit tests (logging_test.go, log_test.go)
- Update docs for log command and quick-reference
2026-02-10 03:50:03 +08:00