Commit Graph
15 Commits
Author SHA1 Message Date
Willie c8faab039f test(integration): consolidate redundant filtering and sync cases
Reduce repeated fixtures while retaining CLI flag, output, pruning,
copy-mode, and combined source/target symlink coverage. Keep manifest
orphan pruning and exercise repeated sync through both symlinked paths.

Removed integration cases and their retained unit coverage:
- TestSync_MergeMode_IncludeFilter -> TestFilterSkills_IncludeOnly.
- TestSync_MergeMode_ExcludeFilter -> TestFilterSkills_ExcludeOnly.
- TestSync_Pruning_PreservesLocalDirectories -> TestPruneOrphanLinks_KeepsLocal.
- TestSync_Agents_IncludeFilter -> TestFilterAgents_IncludeOnly.
- TestSync_Agents_ExcludeFilter -> TestFilterAgents_ExcludeOnly.
- TestSync_Agents_GlobExcludePattern -> TestFilterAgents_ExcludeOnly and
  TestFilterSkills_GlobPatterns (shared flat-name matcher).
- TestSync_SourceDirIsSymlink -> TestSyncTargetMerge_SourceIsSymlink.
- TestSync_TargetDirIsSymlink -> TestSyncTargetMerge_TargetIsSymlink.

For the removed TestInstall_SkillIgnore_* cases, internal/skillignore
retains the following semantic coverage:
- ExcludesMatchedSkills -> TestMatch_ExactMatch and TestMatch_NoMatch.
- GroupPattern -> TestMatch_GroupPrefix and TestMatcherMatch parent
  directory inheritance cases.
- PrecisePathInGroup -> TestMatcherMatch contains / is anchored cases;
  also folded into the retained Git-discovery WildcardPattern test.
- DoubleStarPattern -> TestMatcherMatch double-star cases and
  TestDiscoverSourceSkills_IgnorePatterns/DoubleStarPattern.
- DirOnlyPattern -> TestMatcherMatch directory-only cases,
  TestRegressions/#83_trailing_slash, and
  TestDiscoverSourceSkills_IgnorePatterns/DirOnlyPattern.
- CharClassPattern -> TestMatcherMatch character-class cases and
  TestDiscoverSourceSkills_IgnorePatterns/CharClassPattern.
- CombinedPatterns -> TestMatcherMatch negation cases,
  TestReadPatterns_ParsesFile, and TestRegressions.
Keep Git discovery wildcard and negation tests, including nested paths
and traversal into an ignored parent with a negated child.

Convert five TestDiscoverSourceSkills_*Pattern functions into matching
named subtests of TestDiscoverSourceSkills_IgnorePatterns, preserving
all fixtures and asserting the exact retained skill set. Preserve the
separate Lite traversal and WithStats behavior tests.

Convert all 18 Test{MoveToTrash,MoveAgentToTrash,Restore,RestoreAgent}
_RejectsTraversal_* cases into identically named subtests under their
respective Test*_RejectsTraversal functions. Retain every malicious
input, rejection assertion, and canary check.

Validation (Linux devcontainer):
- make build
- go test ./tests/integration/... ./internal/sync/... ./internal/trash/... -count=1
- make check
- git diff --check (host)
All passed.
2026-09-30 01:46:27 +08:00
Willie 97499ebcc4 fix: recognise Windows junctions wherever links are detected
Since Go 1.23, os.Lstat reports NTFS junctions as irregular files instead
of symlinks (winsymlink, active for go 1.25 in go.mod). Every check that
looked only at os.ModeSymlink therefore missed the junctions skillshare
itself creates on Windows: linked skills could be treated as local folders,
backed up, copied through, or left behind on prune.

Detect links through utils.IsLinkMode, which also asks the OS about the
reparse tag of irregular entries, and count only real symlinks and
junctions as links so OneDrive placeholders and deduplicated files stay
regular files. restore.go also used os.Stat for its link check, which
follows the link and never matched.

Refs #299
2026-09-28 13:53:16 +08:00
Rusty ShacklefordandWillie 60e19f96d5 feat(project): support a visible skillshare/ project directory (#256) (#258)
* fix(project): refuse to re-init a project that lost its config.yaml

Every project-mode command auto-initializes when .skillshare/config.yaml
is missing. That is right for a repository with no project directory at
all, and for the shared skills repo produced by 'init -p --config local',
which gitignores config.yaml so each developer regenerates their own.

It was wrong for the case in between. A .skillshare/ that already held
skills or agents, whose config.yaml was simply gone, was re-initialized
into an empty config. Every configured target was dropped, the target
symlinks were left behind pointing at a project the config no longer
described, and the command exited 0. Nothing said anything had happened.

Add ensureProjectConfig, which replaces the open-coded auto-init at every
project command entry point. It initializes as before when there is no
project directory, and when config.yaml is gitignored, so both intentional
cases keep working untouched. When the directory holds skills or agents
and its config is neither present nor gitignored, it now returns an error
pointing at version control or an explicit 'skillshare init -p' instead of
writing over the project.

The gitignore check is treated as inconclusive on error, so a repository
that cannot be inspected is guarded rather than overwritten.

* feat(project): support a visible skillshare/ project directory

Project mode is identified only by .skillshare/config.yaml, and trash,
backups, logs and audit-rules.yaml anchor to that same hidden directory.
The sources option (#153) made project content relocatable, but the
marker and operational state stay hidden, so repositories that treat
skills as reviewable content still carry a hidden directory whose only
job is to hold config.yaml.

Resolve the project directory through a new leaf package that checks
.skillshare/config.yaml first and skillshare/config.yaml second, and
derive every config, state, source-default and gitignore path from the
result. The hidden name wins whenever both exist, so an existing project
never moves and no migration is needed. The package imports nothing else
internal because internal/audit cannot import internal/config without a
cycle.

Add init -p --visible to create the visible layout. Default init -p
behaviour and output are unchanged.

Two ambiguities the visible name introduces:

- The global config directory is also called skillshare
  (<config-home>/skillshare), so the two places that infer scope from a
  config path now exclude the global location by full path rather than
  by directory name. TestLogDir_Global asserted a fixture path without
  declaring a config home, which hid this; it now sets XDG_CONFIG_HOME.
- An unrelated directory named skillshare/ must not be adopted as a
  partially initialized project, so the visible name is only claimed
  when it carries a marker of its own: a skills/ or agents/ directory,
  or a .gitignore that ignores config.yaml.

The missing-config guard added in the previous commit is generalized to
resolve through the new package, so it covers both layouts. The
gitignored-config marker matters there too. A repository shared by
'init -p --visible --config local' before any skill was committed clones
with nothing but that .gitignore, because git drops the empty skills/
and agents/ directories; recognizing it keeps the repair pointed at the
visible directory instead of writing a hidden one beside it.

Refs #256

* fix(project): reconcile visible directory support with main

Consolidate the missing-config guard and regression tests already merged in #260. Preserve both directory layouts and document and test resyncing target links after a rename. Follow-up for #258.

---------

Co-authored-by: Willie <egg358358@gmail.com>
2026-09-05 12:07:00 +08:00
jnhu 6bddfbbe1d fix(trash): fix two regressions from PR #230 path hardening
- List() now uses trashLogicalName() to produce slash-separated logical
  names, preventing Windows backslash paths that validateTrashName rejects.
- ensureUnderBase/ensureStrictlyUnderBase now use filepath.Abs+filepath.Rel
  instead of string prefix, fixing false escapes when base is '.'.
- Add regression tests for Restore(entry, '.'), nested List->Restore roundtrip,
  sibling prefix rejection, and validateTrashName backslash enforcement.
2026-06-17 14:30:24 +08:00
jnhu 1ad13588ad harden trash path boundary checks 2026-06-16 22:57:28 +08:00
Willie 43c5154a78 Flatten nested agent sync names
Align agent target naming with the skills-style __ flattening so nested agents do not collide by basename in flat agent directories. Add unit and project-mode integration coverage to verify repeated syncs stay stable and no longer report false updates.
2026-04-08 20:52:29 +08:00
Willie dc4ef279c0 feat(tui): add agent badge and correct restore routing in trash TUI 2026-04-07 18:59:35 +08:00
Willie cb55ffe55c feat(agents): add positional kind filter and wire agents into list, sync, update, uninstall, collect, trash
Phase 1 — Foundation:
- parseKindArg() defaults to kindSkills, adds "all" keyword
- list: discover agents via resource.AgentKind, populate Kind field in JSON/TUI
- sync agents / sync all: new sync_agents.go handles agent sync to targets
- uninstall: migrate from --kind flag to positional ("uninstall agents <name>")

Phase 2 — Core CRUD:
- update agents: check status, enrich with remote, reinstall from source
- uninstall agents: move .md + sidecar to agent trash with confirmation
- collect agents: CollectAgents from agent-capable targets to source
- trash agents: list/restore/delete/empty for agent trash directory
- trash.RestoreAgent(): file-level restore (vs directory-level for skills)

Behavior: all commands default to skills-only (no breaking change).
"cmd agents" = agents only, "cmd all" = skills + agents.

Fix: TestLog_SyncPartialStatus uses dangling symlink instead of chmod
(root ignores permissions in devcontainer).

25 new integration tests, all passing.
2026-04-07 18:05:40 +08:00
Willie 949fd444e0 feat(check,trash): add agent drift detection and agent trash support
Add CheckAgents() in internal/check/ that scans agents source directory,
reads per-agent metadata (<name>.skillshare-meta.json), and compares
file hashes to detect drift. Statuses: up_to_date, drifted, local, error.

Add agent trash functions in internal/trash/:
- AgentTrashDir() / ProjectAgentTrashDir() for agent-specific trash paths
- MoveAgentToTrash() moves agent .md file + metadata to timestamped
  trash subdirectory with rename-or-copy-then-delete fallback

6 unit tests for agent check covering empty dir, local agent, hash
match, drift detection, nonexistent dir, and non-md filtering.
2026-04-07 18:05:40 +08:00
Willie 4fbee521ce fix(server): batch targets folder matching + reduce mutex scope
- Fix folder trailing slash bug: filepath.Clean now normalizes input
  before matchesFolder comparison (e.g. 'frontend/' → 'frontend')
- Narrow mutex scope in handleBatchSetTargets: RLock for config read,
  no lock during DiscoverSourceSkillsAll, Lock only for write loop
  (matches existing handleSetSkillTargets pattern)
- Defensive filepath.Clean on cleanEmptyParents inputs
- Add TestMatchesFolder unit test and trailing slash handler test
2026-04-04 17:05:22 +08:00
Willie 115edf3f24 fix(server): correct project-mode gitignore path + prevent registry prune basename collision
P2-1: handleUninstallRepo and handleBatchUninstall used s.cfg.Source for
gitignore removal, but project-mode installs write to .skillshare/.gitignore
with a "skills/" prefix. Add gitignoreDir() helper that returns the correct
base directory per mode, and prefix entries in project mode.

P2-2: Registry prune used filepath.Base(repoName) to derive the legacy group,
causing sibling nested repos (e.g., org/_team-skills vs dept/_team-skills) to
collide on the same basename. Now uses exact Group match for nested repos and
restricts legacy basename matching to top-level repos only.

Tests added (15 new):
- resolveTrackedRepo: auto _ prefix, nested, already-prefixed, not-found,
  basename fallback
- Registry prune: full-path Group, nested members by prefix, sibling isolation
- Project-mode gitignore: single + batch uninstall
- updateSingle: basename fallback, not-found, regular skill priority
- cleanEmptyParents: multi-level, stops at non-empty, stops at boundary
2026-04-04 17:05:22 +08:00
Willie 7e160dee16 fix(trash): support nested tracked repo names in trash lifecycle
MoveToTrash, List, Restore, and Cleanup all assumed flat names.
When a nested tracked repo like org/_team-skills was uninstalled,
the trash entry landed in a subdirectory that List could not see
and Restore could not reach.

- MoveToTrash: create intermediate dirs via filepath.Dir(trashPath)
- List: recursive WalkDir to discover nested entries, store full
  relative path in TrashEntry.Name
- Restore: MkdirAll on destination parent before rename
- Cleanup: remove empty intermediate dirs after expiry via
  cleanEmptyParents helper

Closes runkids/skillshare#116 follow-up (nested trash path)
2026-04-04 17:05:22 +08:00
Willie 0bf84493cc feat: split XDG data/state dirs and add Windows legacy migration
Separate backups/trash into XDG_DATA_HOME and logs into XDG_STATE_HOME
instead of keeping everything under XDG_CONFIG_HOME. Add automatic
migration at startup to move existing data to the new locations.

Fix Windows path resolution: DataDir() and StateDir() now fall back to
%AppData% on Windows (matching BaseDir()), preventing incorrect use of
~/.local/share and ~/.local/state paths.

Add MigrateWindowsLegacyDir() to move pre-v0.13.0 data from
~\.config\skillshare\ to %AppData%\skillshare\ on Windows.

Update doctor, oplog, backup, trash, and all tests/docs accordingly.
2026-02-16 10:41:14 +08:00
Willie 80c2d52fef feat: respect XDG Base Directory Specification (#26)
Add config.BaseDir() as single source of truth for base directory
resolution. Replace all hardcoded ~/.config/skillshare paths.

Path resolution priority:
  1. SKILLSHARE_CONFIG env var (unchanged)
  2. $XDG_CONFIG_HOME/skillshare (any platform)
  3. %AppData%/skillshare (Windows only)
  4. ~/.config/skillshare (Linux, macOS fallback)

- Add config.BaseDir() with XDG_CONFIG_HOME + Windows %AppData% support
- Update BackupDir(), TrashDir(), init default source to use BaseDir()
- Show resolved base directory in doctor output
- Add unit tests and integration tests for XDG override
- Document XDG_CONFIG_HOME and update Windows paths in docs
2026-02-16 01:23:36 +08:00
Willie 3a920610f2 feat: add trash (soft-delete) for uninstall with 7-day retention
Replace permanent deletion with soft-delete: uninstall now moves skills
to a trash directory instead of using os.RemoveAll. Skills are retained
for 7 days and automatically cleaned up during sync/uninstall operations.

- Add internal/trash package (MoveToTrash, List, Cleanup, Restore, FindByName)
- Add `skillshare trash list` and `skillshare trash restore <name>` commands
- Show reinstall hint from metadata when uninstalling remote skills
- Add trash status to `skillshare doctor` output
- Opportunistic cleanup of expired items during sync and uninstall
- Support both global (~/.config/skillshare/trash/) and project (.skillshare/trash/) modes
- 10 unit tests + 10 integration tests
- Update docs: uninstall, trash, doctor, FAQ, file-structure, sync, daily-workflow
2026-02-09 22:46:36 +08:00