Commit Graph
28 Commits
Author SHA1 Message Date
Willie 7baf716c63 feat(instructions): translate dashboard warnings and errors
Mode changes, attach and the other AGENTS.md actions returned English
sentences, so a zh-TW dashboard showed "backed up ... before replacing
it" and "... is a directory" untranslated. Warnings are now
{code, params, message} and every instructions error carries a code,
so the dashboard shows them from i18n and falls back to the English
message for unknown codes. CLI output is unchanged.

Also from the Windows re-test:
- replacing a user's junction says so and where it pointed;
- status, doctor and sync agree on identical unowned copies (kept, not
  linked), and an identical copy no longer suggests --force;
- the targets list shows a Developer Mode tooltip when file links are
  unavailable;
- file names are taken from Windows paths too.

Refs #299
2026-09-28 16:12:59 +08:00
Willie 87e6cc9538 fix(extras): guard shared-file ownership and keep user files on restore
Exploratory CLI, dashboard and real-Windows testing of single-file extras
found paths that corrupted another shared file, lost user content, or
reported the wrong state.

- One shared file per link/copy target is now enforced in config
  validation, so the CLI, sync and API all refuse it; an import is never
  written through a link into another shared file (409
  instructions_target_held in the API).
- Restore recreates an original Windows junction as a junction, which
  needs no privilege, and remove restores before saving config so a
  failed restore no longer orphans the record.
- Imports into dotfiles links, damaged managed blocks, repointed links
  and CRLF files keep the user's content; project imports use paths
  relative to the file so a moved repo keeps working.
- Mode and assign responses carry sync warnings; dry-run says when an
  edit would be backed up; invalid modes no longer show as healthy.
- An edited copy reports modified, identical unowned copies count as
  synced without being owned, and relative project links no longer show
  drift.
- sync extras --json exits non-zero on errors; extras <name> --help
  works; --add-target gains --as; detach messages match behavior.

Refs #299
2026-09-28 15:27:02 +08:00
Willie f307c8a114 fix(sync): keep user files safe in copy fallback and mode switches
Review of the file-link fallback found paths that lost or misreported
user data:

- An identical local file was adopted as a skillshare copy and later
  pruned without backup. Only files sync writes are tracked now.
- Clearing all own text in import mode was treated as no record, so
  switching back resurrected the attach-time content.
- The mode API saved the new mode and returned success when a directory
  blocked the sync; it now keeps the old mode and returns 409.
- Restore preview promised a delete for files restore leaves alone; both
  now share one ownership decision.
- Prune forgot ownership even when removing the copy failed.

Refs #299
2026-09-28 14:27:53 +08:00
Willie c7eb59a78f fix(sync): stop linking single files with junctions on Windows
createLink always tried `mklink /J` first. mklink does not check the
source type, so agents, single-file extras such as a shared AGENTS.md, and
per-file extras links became directory junctions that point at a file:
Explorer shows a folder and tools cannot read it. Sync then compared only
the link destination and kept the broken junction forever.

Files now get real symlinks only. When the OS cannot create them (Windows
without Developer Mode, non-elevated), file-based link modes fall back to
copies at the mode level, so status, doctor, the API and later syncs all
see an effective `copy` mode. Fallback copies are tracked by hash so they
keep updating and pruning without touching the user's own files, and turn
back into links once links work. Single-file extras remember what they last
wrote, so an unedited copy is replaced silently instead of producing a
drift backup on every source edit, and switching a target back to import
restores the user's attach-time content plus the import block.

Includes a Windows runbook and script, verified on a Windows 11 ARM64 VM
with and without symlink rights.

Refs #299
2026-09-28 13:54:52 +08:00
Willie 188193d12d feat(extras): let collect overwrite source files with --force
In copy mode, sync --force can push source over target, but collect
skipped every file already in source, so edits made directly in a
copy-mode target could not be pulled back. collect --force now
overwrites those files; identical ones are still skipped.

Collect also replaced collected files with symlinks regardless of mode,
turning copy-mode targets into symlinks. Copy-mode targets now keep
their files, in the CLI and the extras TUI.

With flatten, two target files sharing a basename map to one source
file; the second is now reported instead of overwriting the first under
--force. --from paths are matched after expanding ~ and cleaning, so a
spelling that differs from config no longer drops the target's mode.

Refs #291
2026-09-24 00:05:55 +08:00
Willie 86b91efe95 feat(extras): refine per-target management UI and path resolution
UI (Extras page):
- Label per-target flatten/extension/mode controls with column headers
- Render flatten as a dropdown so it matches the adjacent selects
- Collapse the add-target form behind a button and widen the path input
- Confirm before removing a target
- Polish layout: tinted icon, inset source chip, hover rows, aligned columns

Components:
- Select: bound the dropdown width so long option descriptions wrap instead
  of stretching the popup across the page
- Toast: render messages multi-line, widen the container, and give
  error/warning toasts more time to read

Sync feedback:
- Restructure extras sync-failure toasts into readable lines and fix the
  contradictory "N more errors" count (new nMoreErrors translation)

CLI/server:
- Match extra target paths by resolved absolute path (handles ~ vs /home)
  when adding, removing, or updating targets
2026-06-02 18:40:00 +08:00
Willie c47785abd9 feat(sync): add PruneExtraTarget wrapper for per-target cleanup 2026-06-02 17:06:12 +08:00
Willie e1c4761333 fix(extras): apply output_ext when computing diff target filenames
The /api/extras/diff path resolved the copy mode but ignored a transform
extension's output_ext, so buildExtrasDiffItems compared source relative
paths against the target directory. After a .md -> .toml transform sync,
the diff looked for the original .md name and reported false drift, even
though the status path already handled this.

Export ApplyOutputExt as the single source of truth for source->target
filename mapping (previously unexported applyOutputExt) and use it in the
diff path so sync, status, and diff all agree on the transformed name.
2026-05-30 19:23:12 +08:00
Willie 4435429ada fix(extras): detect target conflicts in transform sync dry-run
A transform-mode dry-run counted every file as synced without inspecting the target, so it claimed it would sync files that a real non-force sync would skip. Report an existing real file (under the transformed name) as a skip needing --force, mirroring the non-dry-run path. The dry-run still never spawns the extension subprocess, so content is compared conservatively by existence rather than by output.
2026-05-30 19:23:12 +08:00
Willie 403b51f380 fix(extras): never destroy a target directory in transform sync without --force
The previous conflict guard lumped symlinks and directories together and
os.RemoveAll'd both unconditionally, so a real directory sitting at a
generated output path (e.g. a.toml/keep.txt) was silently deleted during
`sync extras` even without --force — more destructive than the copy/merge
path, where syncOneExtraFile only auto-replaces symlinks.

Transform conflict handling now mirrors copy semantics exactly:
- symlink  → auto-replace (os.Remove, link only)
- directory→ skip unless --force; with --force, replace wholesale (os.RemoveAll)
- file     → idempotent if identical, else skip unless --force

Also fix the real deleter: pruneExtraOrphans descended into a skipped
conflict directory and pruned its contents as orphans. It now SkipDirs any
directory occupying a claimed output path, leaving it fully untouched.

Adds regression tests for the directory-conflict skip and the forced
replacement.
2026-05-30 19:23:12 +08:00
Willie 372dd65768 fix(extras): enforce --force contract and consistent status for transform extensions
Transform-extension sync previously wrote each generated file via
runExtensionFile unconditionally, so a regular local target file (e.g. a
hand-edited hello.toml) could be overwritten from hello.md without --force,
violating the same conflict contract that copy/merge modes honor.

- Split runExtension (subprocess → bytes) from runExtensionFile (writes),
  and have syncExtraTransform apply the conflict/force rules: idempotent
  when identical, skipped on conflict without --force, overwrite with
  --force, and auto-replace leftover symlinks.
- Centralize the copy-only mode rule in SyncExtra so the API and CLI reject
  extension+merge/symlink identically; align the server sync handler's mode
  normalization (EffectiveMode's "merge" default no longer leaks through).
- CLI `extras list` no longer short-circuits to an "extension" status before
  existence/drift checks. Status is now computed via output_ext-aware
  CheckSyncStatus; a new Extension field carries the display label, decoupled
  from sync status (plain-text + TUI rendering updated).
- Roll back the optimistic cache update in the UI mode-change handler on
  failure (fixes the unused-var build break).

Adds regression tests covering conflict skip/force/idempotent/symlink-replace
and non-copy mode rejection.
2026-05-30 19:23:12 +08:00
Willie 157eddc3d9 fix(extras): never sync skillshare's .metadata.json store
Installed-skill source dirs carry a .metadata.json tracking store. Extras
discovery walked it like user content, so a transform extension renamed it
to .metadata.toml in the target. Skip the reserved file in
DiscoverExtraFiles so it is never synced or transformed in any mode.
2026-05-30 19:23:12 +08:00
Willie f88044e2cc fix(extras): report synced status for transform targets
CheckSyncStatus compared each source file against targetDir/<source-name>,
but a transform extension renames output (foo.md -> foo.toml), so the
.toml file was never found and the target was always reported as drift —
even right after a successful sync. Thread the extension's output_ext
through CheckSyncStatus so the expected target filename matches the
transformed output. The web list now resolves the spec to pass it.
2026-05-30 19:23:12 +08:00
Willie 1b9d25de7a feat(sync): implement per-file transform with output rename and prune 2026-05-30 19:23:12 +08:00
Willie 425c32d489 refactor(sync): thread extension spec param through SyncExtra 2026-05-30 19:23:12 +08:00
Willie 9ff006988a fix(sync): canonicalize paths for relative symlinks, atomic reformat
Two correctness improvements from Codex review:

1. EvalSymlinks before relative-link decisions: shouldUseRelative and
   createLink now resolve symlinked ancestors via EvalSymlinks so that
   a project opened through a symlinked workspace, or a target dir that
   traverses a symlink, produces correct relative paths (or falls back
   to absolute when paths diverge from the project root).

2. Atomic reformat via reformatLink: instead of remove→create (which
   loses the link on createLink failure), reformat now creates a temp
   link and renames it over the original. On Unix this is atomic; on
   Windows it falls back to remove→create when rename fails.

Tests added for symlinked project root, divergent target symlink,
and reformatLink atomic swap.
2026-04-07 17:26:37 +08:00
Willie 3316c9073e fix(sync): resolve relative readlink against link parent, check os.Remove errors
filepath.Abs(dest) on a relative readlink result resolves against CWD,
not the symlink's parent directory. This broke the 'already correct'
check when comparing relative symlinks to absolute source paths.

Add resolveReadlink() helper that joins relative targets with
filepath.Dir(linkPath) before calling filepath.Abs.

Also check os.Remove errors in all reformat paths instead of ignoring
them silently.

Addresses PR #122 review feedback.
2026-04-07 17:26:37 +08:00
Willie e51fe60254 fix(sync): upgrade existing absolute symlinks to relative in project mode
sync previously skipped symlinks that pointed to the correct source,
even if their format (absolute vs relative) didn't match the expected
mode. This meant existing absolute symlinks in project mode were never
converted to relative on subsequent syncs.

Add linkNeedsReformat(dest, wantRelative) helper that checks whether
the raw readlink result has the wrong format. All four 'already
correct' skip points now check format and recreate when mismatched:

- SyncTargetMergeWithSkills (skills merge mode)
- SyncTarget (skills symlink mode)
- syncExtraSymlinkMode (extras directory symlink)
- syncOneExtraFile (extras per-file merge)

Global mode is unaffected: shouldUseRelative returns false, so
linkNeedsReformat never triggers on absolute links.

Also fix macOS /var → /private/var path mismatch in
TestSyncProject_RelativeSymlinks by EvalSymlinks on expected path.
2026-04-07 17:26:37 +08:00
Willie fe244e8289 refactor(sync): simplify shouldUseRelative and hoist extras computation
- Use utils.PathHasPrefix/PathsEqual for Windows case-insensitivity
- Eliminate redundant filepath.Clean call
- Hoist shouldUseRelative in syncExtraPerFile (compute once, pass bool)
- Add invariant comment in SyncTargetMergeWithSkills
2026-04-07 17:26:37 +08:00
Willie bbf2e4343e feat(sync): unify extras symlinks through createLink
Replace direct os.Symlink calls in extras.go with createLink, gaining:
- Relative symlink support in project mode
- Windows junction fallback for extras (previously missing)

Thread projectRoot through SyncExtra, CollectExtraFiles, and all callers.

Ref: #120
2026-04-07 17:26:37 +08:00
Willie 2ce1544dd1 docs: add flatten documentation, changelog, and contributor
Extras command docs, config reference, built-in skill, website
changelog, release notes. Add mk-imagine to README contributors.

Ref: #97
2026-03-25 21:14:16 +08:00
Willie 5d9dd0cdbb feat(extras): add flatten option to extras sync engine
When flatten=true, SyncExtra maps subdirectory files to target root
using filepath.Base(). First file wins on collision, subsequent are
skipped with warnings. Includes config validation, sync-time guard,
CheckSyncStatus collision handling, and CollectExtraFiles support.

Ref: #97
2026-03-25 21:14:16 +08:00
Willie 405a2f907a feat(extras): add mode command for CLI, TUI, and Web UI
Add ability to change sync mode of an extra's target across all three
interfaces: CLI (`extras mode`/shorthand `extras <name> --mode`),
TUI (`M` key with mode picker overlay), and Web UI (inline Select
dropdown per target with PATCH /api/extras/{name}/mode endpoint).

Fix sync behavior so symlinks from a previous mode are auto-replaced
without --force, while regular files still require explicit --force.

Consolidate sync mode list into config.ExtraSyncModes single source
of truth. Fix Select component missing disabled prop and add viewport
collision detection with useLayoutEffect.

Includes 8 integration tests covering mode command happy path, error
cases, shorthand syntax, and mode-switch sync behavior.
2026-03-12 16:45:02 +08:00
Willie d97e5a7c33 refactor(extras): consolidate duplicate logic and fix sync --all --json output
- Move checkExtrasSyncStatus to sync.CheckSyncStatus (shared)
- Add sync.EffectiveMode helper to replace inline mode defaults
- Add config.ValidateExtraMode to centralize mode validation
- Fix sync --all --json outputting two separate JSON objects
  by merging extras into the skills JSON output
- Fix swallowed JSON decode error in handleExtrasSync
- Remove dead symlink check in CollectExtraFiles (filepath.Walk
  follows symlinks so the check was unreachable)
- Fix integration test extras paths to use extras/<name>/ layout
2026-03-12 16:45:02 +08:00
Willie a786c1fe79 feat(extras): add init TUI wizard, collect command, and sync --json
- extras init TUI: multi-step bubbletea wizard (name → target → mode → confirm)
- extras collect: reverse-sync local files from target back to extras source
  with --from, --dry-run flags and dual-mode (global/project) support
- sync extras --json: structured JSON output for sync extras command
- CollectExtraFiles in internal/sync with tests
2026-03-12 16:45:02 +08:00
Willie 1b8940a630 fix(extras): copy-mode idempotency and display mode label
- Add contentEqual() byte comparison for copy-mode idempotency check:
  re-running sync extras no longer marks identical copies as conflicts
- Restore mode default in CLI handler so display shows "(merge)"
  instead of "()" for targets with no explicit mode
2026-03-04 12:16:32 +08:00
Willie 55bc5289c6 refactor(extras): simplify after code review
- Fix bug: pass `rest` (not `args`) to cmdSyncExtras in --all path
- Return error from cmdSyncExtras when totalErrors > 0
- Remove empty if-block dead code in syncOneExtraFile
- Remove redundant mode default (SyncExtra already defaults to merge)
- Consolidate capitalize/capitalizeFirst into single Unicode-safe helper
- Remove trivial copyExtraFile wrapper, call copyFile directly
- Warn when --all is used in project mode (extras are global only)
- Cache os.UserHomeDir() at package level for shortenPath
- Use source file set instead of per-file os.Stat in pruneExtraOrphans
2026-03-04 12:16:32 +08:00
Willie fbccdb9628 feat(sync): add extras sync engine — walk, symlink/copy, prune 2026-03-04 12:16:32 +08:00