21 Commits
Author SHA1 Message Date
Willie c040917bc7 fix(security): enforce credential and filesystem trust boundaries (#861)
Bind provider credentials to canonical or explicitly configured HTTPS origins and preserve that policy across remote consumers. Reject cross-site credentialed reads, linked fallback directories, and discovered-agent writes outside the source; audit staged content before rooted atomic publication.

Add boundary regressions, private Git update coverage, stable cross-platform fixtures, and aligned documentation. Verified the integrated main baseline with all executed CI checks passing.
2026-11-11 23:17:54 +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 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 1bc009c668 refactor(check): resolve update status in internal/check
The CLI, GET /api/check and the check stream each wrote out the same
sequence: group skills by URL and branch, ask the remote hash, skip the
tree fetch when every skill matches, otherwise compare tree hashes and
assign a status. A fix such as branch handling had to be made three
times, and the sequence could only be tested against real repositories.

internal/check now owns it as Plan and Resolution.Run, with the remote
hash source injected and a per-remote progress callback. The CLI
progress bar and the SSE counter are adapters on that callback; the JSON
handler passes none.

The callers disagreed in two places, and both behaviours are kept: the
dashboard reports a skill removed upstream as update_available where the
CLI says stale, and gives no source or version for a skill without a
remote. The server adapter narrows the result accordingly.

Refs #444
2026-10-07 00:03:34 +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 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 1a1eeee844 fix(check): compare project-relative local sources and record install layout (#337)
* fix(check): compare project-relative local sources and record install layout

Project installs record a local source as typed (./vendor/skill), relative
to the project root, so check skipped them. Resolve them against the project
root in both the CLI and the dashboard.

The copied shape of a local install was inferred from its file hashes, so a
CLI install whose source held only SKILL.md looked like a dashboard
collection-root install: a child skill added at the source later was neither
reported by check nor copied by update. Record the layout (skill-file or
directory) at install time and keep the hash heuristic only for entries
written before the field existed.

* fix(install): let a recorded layout decide the update shape without hashes

An entry whose hashing failed at install time still knows what was copied;
returning false there would turn a SKILL.md-only update into a full copy.
2026-10-02 20:56:55 +08:00
Willie 9847f59a3e feat(check): detect changes at local install sources (#334)
* feat(check): detect changes at local install sources

Skills installed from a local path (for example a skill shipped inside an
app bundle) could already be refreshed with `update`, but `check` always
reported them as "local source", so users had no signal that the source
had changed after an app update.

`check` now re-hashes the files at the recorded source path and compares
them with the hashes stored at install/update time. It reports
update_available on a difference, up_to_date on a match, and an error
naming the path when the source is gone. The path is resolved the same
way `update` resolves it before re-copying, so a successful update always
brings the status back to up_to_date. The CLI and both Web API check
handlers share the comparison in internal/check.

Refs #206

* fix(check): avoid false local-source updates and show check errors

Review follow-ups for local-source change detection:

- The dashboard installs the root of a directory that also holds child
  skills as its SKILL.md alone, so hashing the whole source reported
  update_available right after a clean install. Compare only the files
  such an install copies, recognized by recorded hashes that contain none
  of the child skills present in the source.
- A relative source path resolves against the cwd of the install, which
  is not recorded, so checking from another directory reported a missing
  source. Relative sources are no longer compared.
- The dashboard dropped the new check `message`, so a missing source only
  showed a generic "Check failed". Carry it into the status tooltip.

* revert: restore video files accidentally removed in 1fb13b75

The review-fix commit picked up unrelated staged deletions under video/. They belong to separate work and are not part of this change.
2026-10-02 19:50:58 +08:00
Willie 115236a6fb fix(server): use token auth when checking default-branch skill remotes
The dashboard check fetched the remote HEAD without credentials when a
skill had no pinned branch. Private repos therefore reported an error in
the dashboard while the CLI check, which uses
GetRemoteHeadHashWithAuth, succeeded. The pinned-branch path already
used auth, and the default-branch path now matches it.
2026-09-30 01:44:50 +08:00
Willie 20ae89a838 fix(server): stop dropping git and metadata errors in check, uninstall and batch targets
The dashboard check reimplemented the CLI's per-repo check but fetched
without the HTTPS token and ignored git status errors. Private tracked
repos could fail in the dashboard while `skillshare check` worked, and a
repo whose status could not be read showed as up to date. Both check
endpoints now call check.ParallelCheckRepos, the same code the CLI uses.
The JSON and SSE response shape does not change.

Batch uninstall treated a failed dirty check as clean and moved the
repo to trash. Without force, that item now fails with the git error
instead. This is stricter than the CLI, which only warns and continues.

Batch target updates ignored metadata save failures and still reported
success, so an override could silently disappear on the next reload.
They now return 500.
2026-09-30 01:34:58 +08:00
Willie 5dd83a8412 fix(server): guard metadata store access against concurrent requests
Every API request reloads the skills and agents metadata stores and
swaps the server's pointers under s.mu, but several handlers read or
wrote the stores outside that lock: listing, skill detail, check, the
update stream, and the hash refresh after setting targets. Concurrent
requests could race on the pointer or on the stores' maps, which the
race detector reported hundreds of times under load and which can
crash the server with a concurrent map access.

Store access now always happens under s.mu. Reads return a copy of
the entry so it can be used after unlocking, and target handlers hash
files outside the lock and only write the result under it.
2026-09-26 21:12:57 +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 68d5eadc0b feat: support custom project source directories via sources map
Add ProjectSources struct to ProjectConfig with optional skills, agents,
and extras fields. When set, project-mode commands resolve source paths
from these values instead of hardcoded .skillshare/{skills,agents,extras}/.

Config example:
  sources:
    skills: ./docs/skills
    agents: ./docs/agents

Three EffectiveXxxSource(projectRoot) methods provide the central
resolution logic with fallback to defaults. The projectRuntime gateway
and server layer route through these methods, so most commands get
custom source support automatically.

Closes #153
2026-05-20 15:42:53 +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 ed1beb1ccb refactor: replace all remaining ReadMeta/LoadRegistry with MetadataStore
Replace every remaining call to the old per-skill metadata API
(ReadMeta, RefreshMetaHashes, config.LoadRegistry) with the centralized
MetadataStore across 10 files:

Server handlers:
- handler_check.go: use s.skillsStore.Get() instead of ReadMeta
- handler_check_stream.go: same pattern as handler_check.go
- handler_skills_batch.go: use s.skillsStore.RefreshHashes() + Save()

CLI commands:
- check.go: load store once in collectCheckItems, use MetadataEntry
- doctor.go: load store once in checkSkillIntegrity
- list.go: load store once in buildSkillEntries (replaces parallel ReadMeta)
- uninstall.go: use skillsStore for display/dry-run/finalize
- uninstall_project.go: same pattern, remove config.LoadRegistry
- update_batch.go: pruneRegistry now uses MetadataStore

Hub:
- hub/index.go: load store once in BuildIndex

The only remaining ReadMeta call is in a test file
(search_batch_meta_roundtrip_test.go) which tests the shim itself.
2026-04-08 11:19:27 +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 5307b3276e fix(server): use snapshot pattern to eliminate map races and narrow lock scope
Addresses P1 and P2 from code review on the RWMutex commit:

P1 — Stream handlers now snapshot config under RLock before streaming:
- handleDiffStream: clone Targets map to prevent concurrent map panic
- handleCheckStream, handleAuditStream: snapshot source/projectRoot
- handleUpdateStream: snapshot source (per-item Lock already correct)

P2 — All read handlers now use narrow snapshot instead of defer RUnlock:
- RLock → copy needed fields to locals → RUnlock → do work with locals
- Prevents slow I/O (git fetch, version check, audit scan) from blocking
  the auto-reload middleware's exclusive Lock on concurrent requests

Other changes:
- computeTargetDiff takes source parameter (no more s.cfg.Source access)
- Add cloneTargets() helper for safe map copying
- Add writeOpsLogTo/writeAuditLogTo for lock-free oplog writes
2026-03-17 04:48:42 +08:00
Willie 11f696cffe fix(server): upgrade Mutex to RWMutex for concurrent read safety
Addresses PR #82 review: read-only handlers accessed s.cfg without
synchronization, risking data races with concurrent config reloads.

- Upgrade sync.Mutex → sync.RWMutex (drop-in compatible)
- Add RLock to 26 non-streaming read handlers
- Keep exclusive Lock for write handlers (unchanged)
- Skip SSE streaming handlers to avoid blocking writes during streams
- Fix isConfigGitignored to propagate GitignoreContains errors
2026-03-17 04:48:42 +08:00
Willie ce8608a6b1 fix(check): normalize leading slash in subdir for tree hash comparison
The // subdir syntax (e.g., repo//skills/foo) stores meta.Subdir with
a leading "/". git rev-parse and ls-tree paths never have leading
slashes, causing tree hash lookups to fail silently.

Strip leading "/" in getSubdirTreeHash(), resolveSkillStatuses(), and
handler_check.go. Add LeadingSlash unit test and E2E runbook.
2026-02-25 07:02:54 +08:00
Willie 117b319050 feat(check): per-skill tree hash comparison for precise update detection
Previously `skillshare check` compared repo-level commit hashes, causing
all skills from a registry repo to show "update_available" whenever any
commit was pushed — even if the individual skill's files were unchanged.

Now each skill records its git tree hash (subdir-level SHA) at install
time. During check, a three-tier comparison is used:

1. Fast path: commit hash matches → up_to_date (zero extra cost)
2. Tree hash path: blobless fetch (~150KB) + batch ls-tree → per-skill
   comparison; unchanged subdirs stay up_to_date
3. Fallback: no tree hash (old installs) → commit comparison (unchanged)

Also fixes pterm progress bar printing twice when it auto-stops at 100%.
2026-02-25 07:02:54 +08:00
Willie 0c49860d63 feat: add project mode labels, privacy-first messaging, and UI polish
- Add (project) labels to status, sync, collect, target, and uninstall
  headers for clear mode distinction (matching list/target list pattern)
- Add ui.WithModeLabel() helper for shared functions that run in both modes
- Update uninstall confirmation prompt: "from the project?" in project mode
- Add "Privacy-first" to README Why section and website homepage
- Replace "Unified Source" card with "Privacy-First" card on website
- Unify Quick Actions card heights with h-full in DashboardPage
- Add frontend rebuild note to Docker sandbox docs
2026-02-09 21:08:03 +08:00