11 Commits
Author SHA1 Message Date
Willie 8e9ef1c806 test(sync): make the tests pass on Windows and run them in CI
Ten tests assumed POSIX behaviour:

- Five asserted os.ModeSymlink, but Windows links with a junction;
  check utils.IsLinkMode instead.
- Two used `/abs/...` as an absolute path, which has no volume on
  Windows; give the fixtures one.
- Windows has no permission bits to preserve, so the 0600 check is
  skipped there.
- Reading a file as a directory reports not-exist on Windows, which
  prune ignores, so that prune-error test is skipped there.
- A single-file extension relies on the shebang and the executable bit,
  so ListExtensions finds only directory extensions on Windows, as the
  extras docs describe.

Add ./internal/sync and ./internal/trash to the windows-test package
list so they stay green.

Refs #344
2026-10-06 09:40:50 +08:00
Willie a2d75300f6 fix(sync): prune only agent copies skillshare wrote in copy mode
Copy and extension modes pruned every unexpected .md (or output-extension)
file in the agents target, so agent files a user kept there were deleted
on the next sync, unlike skills copy mode, which prunes only manifest
entries.

Copy and transform outputs are now tracked with the same checksum
manifest the merge fallback already uses, and prune removes only tracked
copies the user has not edited. Existing copies are adopted while their
agent is still synced, and an untracked pre-transform .md that still
matches its agent is treated as a stale copy, so switching to an
extension keeps cleaning it up. Copies already orphaned before upgrading
are kept and must be removed by hand.

copyTracker.pruneOrphans now continues past a failed removal and joins
the errors, so one locked file no longer leaves the other orphans behind.
2026-10-01 22:10:08 +08:00
Willie 097d2c0257 fix(sync): keep unreadable links and report failed agent prune removals
prunableLink treated any stat failure as a broken link, so a live link
whose referent was temporarily unreadable (for example permission denied)
was deleted as if it pointed nowhere. Only a missing referent now counts
as broken.

PruneOrphanAgentLinks and PruneOrphanAgentCopies ignored os.Remove errors
and still listed the entry as removed, so sync reported a prune that did
not happen. Failed removals are now returned as errors, which the agent
runner already surfaces as warnings.
2026-10-01 21:55:41 +08:00
Willie bdd1fcf286 fix(sync): keep links to other locations when pruning agents and extras
Merge-mode pruning for agents and extras removed any link whose name was
not expected, so links a user made to agent or extra files outside the
source were deleted on the next sync or `extras --remove-target --prune`.

Agents and extras do not record their links in a manifest, so the #315
provenance check cannot be reused. Prune now removes a link only when it
is broken or resolves inside the source. Relative links are resolved from
the real parent directory, matching how createLink writes them, so
orphans under a symlinked target directory are still found.
2026-10-01 21:23:30 +08:00
Willie cb2bcec948 feat(agents): convert agents with a target extension
Tools disagree on agent frontmatter and some need another format entirely,
so an agent written for Claude is misread elsewhere. An `extension` on a
target's agents block reuses the extras transform mechanism to convert each
agent during sync.

Converted targets hold transformed output, so collect never pulls them back
into the source. Leftover symlinks from merge or symlink mode are removed
rather than written through, and a failed conversion drops the old output
so an unconverted agent never stays active.

The bundled opencode-agents extension keeps only fields OpenCode documents
and refuses agents that restrict their tools, since dropping those fields
would widen the agent's access.

Refs #267
Refs #241
2026-09-21 13:31:38 +08:00
Willie 51656e9cb3 fix(sync): keep project agent symlinks stable across syncs on symlinked paths
Project-mode agent sync re-reported every agent as updated on the second
sync when the project lived under a symlinked ancestor (e.g. macOS temp
dirs under /var -> /private/var), failing idempotency on macOS CI.

Two interacting causes:

- shouldUseRelative was unstable: on the first sync the target directory
  does not exist yet, so evalOrClean fell back to a non-resolved path and
  the under-project-root check failed, producing an absolute link; on the
  second sync the directory existed and resolved, so it wanted a relative
  link and reformatted the existing one. evalOrClean now resolves the
  deepest existing ancestor and re-appends the missing tail, so the answer
  is the same whether or not the leaf exists.
- The existing-symlink comparison only did a direct string compare, so a
  stable relative link whose resolved target carried the unresolved alias
  prefix looked like it pointed elsewhere. It now canonicalizes both sides
  via EvalSymlinks on the slow path, mirroring isSymlinkToSource.

Adds a regression test that reproduces the symlinked-ancestor case on any
platform.
2026-06-11 01:18:05 +08:00
Willie 2b08bdf400 fix: use relative project symlinks for agents 2026-06-10 23:39:45 +08:00
Willie 081348d39b refactor(collect): unify skills/agents flow with collectPlan + generics
Replace duplicated runCollectSkills/runCollectAgents (~110 lines of 95%
identical code) with a single runCollectPlan function driven by a
collectPlan struct + toCollectResources[T] generic converter.

Key changes:

- Add collectPlan/collectResources types and runCollectPlan unified flow
- Add toCollectResources[T] generic to bridge typed slices into the
  shared pipeline (scan → display → dry-run → confirm → pull → render)
- Replace fragile err.Error() == "already exists in source" string
  matching with ErrAlreadyExists sentinel error + errors.Is()
- Move os.MkdirAll from per-agent PullAgent to PullAgents (call once)
- Add FindLocalAgents/PullAgent/PullAgents to match FindLocalSkills API
- Add target selection, --force/--dry-run/--json support for agent collect
- Add integration tests for agent collect (target filter, dry-run, force,
  JSON, oplog, project mode)
- Update collect.md, agents.md, ui.md docs for agent collect support
2026-04-09 00:36:39 +08:00
Willie 4426ca5db7 fix: resolve macOS /var → /private/var symlink in agent sync test
TestSyncAgents_MergeMode_NestedSameBasename_IsStable compared raw
symlink targets against t.TempDir() paths without EvalSymlinks, causing
false failures on macOS where /var is a symlink to /private/var.
2026-04-08 22:43:50 +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 9a4fbdc18f feat(sync): add agent sync engine with merge, symlink, and copy modes
Add SyncAgents() dispatcher supporting all three sync modes:
- merge: per-file symlinks with local file preservation
- symlink: whole directory symlink to agent source
- copy: file copy with content-diff detection

Add CheckAgentCollisions() to detect agents that flatten to the same
filename from different subdirectories.

Add PruneOrphanAgentLinks() for merge mode and PruneOrphanAgentCopies()
for copy mode to clean up stale agent files in targets.

Add CollectAgents() to copy non-symlinked .md files from target back
to agent source directory.

18 tests covering all modes, collision detection, pruning, and collect.
2026-04-07 18:05:40 +08:00