Commit Graph
19 Commits
Author SHA1 Message Date
Willie d572ba3b32 perf(backup): walk each snapshot once when listing backups
The list endpoint walked every snapshot to size it, then walked all of
them again for the total. With thousands of files and a cold file cache
(right after an upgrade, for example) the Backup page took visibly long
to open.

Each snapshot folder is now walked once for both its size and file
count. Backup and total sizes are sums of those, and the per-folder
counts are returned as `entries` so the dashboard can show what each
folder holds.
2026-09-28 21:51:11 +08:00
Willie 86dca7924f feat(backup): browse and restore file history, delete snapshots
skillshare backs up AGENTS.md, CLAUDE.md and shared-file locations before
rewriting them, but nothing could list or restore those copies, and a
target snapshot could not be deleted on its own. The file backups now
record why they were taken in their name (<time>.<reason>.bak; older ones
have none), and the server and CLI can list them, show a version and
restore it, saving the current content first. A link is only replaced
when the caller asks for it.

Also:
- DELETE /api/backups/{timestamp} and `backup --delete`.
- Agents snapshots (<target>-agents) could not be restored from the
  dashboard: the name was looked up as a target.
- Project mode uses the project's backups folder for snapshots and lists
  only file backups inside the project.
- MCP backups report which servers they changed and when.

Refs #299
2026-09-28 19:23:16 +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
Willie 29bde9af3d fix: address review findings 2026-07-30 01:34:52 +08:00
Willie 98c1af18b3 fix(backup): back up only local target content, prune snapshots automatically
Pre-sync backups followed merge-mode skill symlinks and copied the resolved
content, so every snapshot duplicated the source — including gitignored
artifacts still sitting on disk (model weights, .venv, browser profiles).
Combined with retention that only ever ran on demand, backup directories grew
without bound; one user reported 500 GB and sync failing with ENOSPC.

A backup only needs to protect what sync can destroy: local content that
exists in the target but not in the source. Symlinks point into the source,
which is the single source of truth and already safe, and sync recreates them.
copyDir already skips symlinks, so copyDirFollowTopSymlinks is deleted.

Retention now runs after every automatic backup using the existing default
policy — in global sync and in both agent sync paths, since project agent
backups had the same unbounded growth.

Two related defects surfaced while wiring this up:

- Cleanup's size check could remove the newest snapshot, leaving no restore
  point at all when a single snapshot exceeded the cap. It now always keeps
  the newest.
- A target holding nothing but symlinks produced an empty snapshot that
  consumed a retention slot and evicted snapshots that had content. Empty
  snapshots are now discarded.

Behaviour change: restoring a merge-mode target recovers local content only;
run `skillshare sync` afterwards to recreate symlinks. Copy mode is unaffected
because those targets hold real files.

Refs #252
2026-07-30 00:55:41 +08:00
Willie 30f8fb0131 feat(agents): add project-mode backup and restore for agents
Add -p/--project support to 'backup agents' and 'restore agents' commands.
Project-mode backups are stored under .skillshare/backups/ (parallel to
.skillshare/trash/).

Backup engine changes:
- Add ProjectBackupDir(), CreateInDir(), ListInDir() to internal/backup
- Add RestoreLatestInDir(), FindBackupsForTargetInDir(),
  GetBackupByTimestampInDir() to restore.go
- Existing global functions become thin wrappers (zero caller churn)

Command layer changes:
- Allow project mode through for kind=agents in cmdBackup/cmdRestore
- Auto-detect project mode when .skillshare/config.yaml exists
- Refactor backup_agents.go with resolveAgentBackupContext() to
  resolve backup dir + agent targets per mode

Skills backup in project mode remains unsupported (error unchanged).
2026-04-07 18:27:08 +08:00
Willie 4cbaa5f3ab perf(tui): async dirSize and lazy loading in restore TUI
dirSize() was called synchronously for every backup version during list
population and on each cursor move, blocking the entire TUI event loop.

- Add ListBackupVersionsLite() that skips dirSize (TotalSize = -1)
- Compute size asynchronously via tea.Cmd, cache in versionSizeCache
- Replace redundant ListBackupVersions() in renderTargetDetail() with
  direct os.ReadDir() on the latest backup directory
- Cap per-skill I/O (readSkillDescription + listSkillFiles) to 20 items
  in both renderTargetDetail() and renderVersionDetail()
2026-03-14 04:01:10 +08:00
Willie 924487b334 feat(diff): add file list, text diff, and time info to TUI detail panel
- Add expand state (Enter key toggle) for file-level diff display
- Show file list with +/-/~ icons for add/delete/modify files
- Show colored unified diff (green/red/cyan) for modified files
- Add source/target mtime rows in detail header
- Replace "Actions" section with "Next Steps" using prominent styling
- Update list item description with sync/local breakdown
- Add stat counts (err/diff/ok) to TUI title bar
- Fix freeze: defer file walk to Enter toggle instead of every render
- Fix gofmt in trash_tui.go and restore.go
2026-03-02 02:23:50 +08:00
Willie 71dea4ee14 feat(backup): add version listing and follow top-level symlinks
Add ListBackupVersions() and ListTargetsWithBackups() for TUI timestamp
selection. Fix merge-mode targets producing empty backups by following
top-level symlinks in copyDirFollowTopSymlinks().
2026-03-02 02:23:50 +08:00
Willie 2bcd2bf4de feat(backup): add ListTargetsWithBackups for TUI discovery
Scans backup directory and returns per-target summaries (count,
oldest, latest) sorted by target name. Uses timestamp parsing
instead of modtime for accuracy.
2026-03-02 02:23:50 +08:00
Willie e873a730e2 fix(backup): use os.Lstat in ValidateRestore to detect symlink targets
os.Stat resolves symlinks so ModeSymlink was never set, causing
symlink targets pointing to non-empty dirs to wrongly require --force.
2026-02-25 07:02:54 +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 78924f08ea fix(backup): replace filepath.Walk with os.ReadDir to handle Windows junctions
filepath.Walk fails on Windows NTFS junctions with "Incorrect function"
because os.Lstat returns nil info, bypassing all junction-detection logic
and crashing the entire backup for that target. This means one unreadable
junction prevents ALL local skills from being backed up.

Replace with os.ReadDir + os.Lstat so junctions are identified and skipped
before any read attempt. Also add Windows CI and unit tests for copyDir.

Fixes runkids/skillshare#7
2026-02-07 00:35:11 +08:00
Willie Hung 83849bd557 fix(backup): handle Windows junctions in copyDir
On Windows, filepath.Walk may fail when encountering junctions with
"Incorrect function" error. This fix:
- Gracefully handles walk errors for symlinks/junctions
- Uses SkipDir to avoid entering junction directories
- Double-checks with Lstat for Windows reparse points
2026-01-31 01:57:58 +08:00
Willie Hung 0a410234fd feat: add skill installer and expand dry-run previews 2026-01-15 23:15:38 +08:00
Willie f5e9d9644e docs: improve README with better structure and content
- Add badges (License, Go version, Release)
- Add ASCII flow diagram showing architecture
- Add Table of Contents for navigation
- Add "Why skillshare?" comparison table
- Add Use Cases section (Individual, Team, Open Source)
- Add FAQ section with common questions
- Add Contributing guide with development setup
- Reorganize sections for better readability
2026-01-14 22:12:56 +08:00
Willie 98d0ddf189 feat: add diff, backup, doctor commands and backup mechanism
- Add `diff` command to show differences between source and target
- Add `backup` command for manual backup with recent backup list
- Add `doctor` command to diagnose configuration issues
- Add internal/backup package for backup functionality
- Fix diff command incorrectly showing "not linked" for symlink mode targets
- Update README with new commands documentation
2026-01-14 20:24:40 +08:00