Skip to content

fix(skills): a link-only install refuses the skill's own library folder instead of deleting it - #266

Open
connorburgess wants to merge 3 commits into
spacesheep-dev:mainfrom
connorburgess:fix/skills-link-only-self
Open

connorburgess wants to merge 3 commits into
spacesheep-dev:mainfrom
connorburgess:fix/skills-link-only-self

Conversation

@connorburgess

@connorburgess connorburgess commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Updated against v0.8.18 / main d16a2c01 on 2026-12-05. Current validation and refresh details.

What

A link-only install (POST /api/ui/skills/install with linkOnly and overwrite) no longer deletes a skill when its source is that skill's own library folder. A source that is the library folder (~/.agents/skills/<slug>), a folder inside it, or a harness link to it (~/.claude/skills/<slug>, as linking a skill makes) is refused with refusing to link skill "<slug>" to itself: …; link a folder outside the library, returned as a 400 skill_error, and nothing on disk changes. A source that holds the whole skills library is refused too. A link-only install from a harness folder (or a folder inside one) with forceHarnesses no longer deletes that folder when it links the skill back into the same harness, and a later unlink or remove no longer deletes it either. Link-only installs from a folder outside the library work as before.

Why

installLocalSkillFromDir in server/ui/skillsCore.ts handles linkOnly by removing the existing library entry (rmSync(dest, { recursive: true, force: true })) and then linking it to the source path as typed. Nothing checked where the source resolves to. When the source was the library folder, or a harness link to it, removing the entry removed the source: the call returned 200, every file of the skill was gone, and the library entry was left as a link to itself (or a loop through the harness link), so the skill dropped out of the list.

The fix compares real paths before anything is removed. It uses realpathSync.native, so on macOS and Windows a source spelled ~/.agents/skills/FOO still matches foo:

  • A source that holds the skills library is refused (linking it would put a folder inside itself; on main this deleted the library entry and then failed with ELOOP).
  • A source that resolves to the library folder or into it is refused when that entry is a real folder.
  • When the library entry is already a link (an earlier link-only install), removing it deletes no files. If the source goes through that link, the entry is relinked to the source's real folder instead of a path that leads back through the entry. On main this case also left a loop.

The same call then links the skill into the chosen harnesses with linkLocalSkill. When the source was a real harness folder (~/.claude/skills/foo) and forceHarnesses was set, linkLocalSkill saw a real folder where it wanted a link, removed it, and linked it to the library entry, which by then linked to that same folder: the files were gone and the two entries looped. linkLocalSkill skipped an entry that already resolves to the library folder only when the entry was a link; it now skips it whenever both resolve to the same real folder, and skips a real harness folder when the library entry links to a folder inside it (~/.claude/skills/foo/inner), so it never removes the folder the library entry links to. It compares the native real paths, like the install check, so a source typed as ~/.Claude/skills/foo still matches on macOS. When it skips a real folder that way, it also drops a managed-copy record for that harness, so a later unlink does not delete the folder as if it were a copy.

unlinkLocalSkill (which removeLocalSkill calls for every harness) removed a harness entry when it was a link to the library folder or when the state file recorded a managed copy for that harness. A managed-copy record can outlive the copy: one from before this change, or one for a harness that was not in the install's harness list (a link-only install from ~/.claude/skills/foo with harnesses ["cursor"] keeps an old claude-code record). Unlinking Claude Code, or removing the skill, then deleted ~/.claude/skills/foo, the folder the library entry links to. It now keeps a real harness folder that the library entry resolves to, or that holds it, and drops the record. When a harness skills folder is itself a link to the library folder (~/.claude/skills -> ~/.agents/skills), its entry is the library entry: on main unlinking that harness removed the library entry when it was a link, and deleted the library folder when a managed-copy record for that harness was left; it is now skipped.

adoptLocalSkill compared the plain real paths, and only for equality. After a link-only install from ~/.Claude/skills/foo, or from ~/.claude/skills/foo/inner, adopting the claude-code folder with force did not see that it already was (or held) the library's source, copied the validated files into the library and deleted the folder, losing anything the scan leaves out (a .git folder, for one). It now compares the native real paths and treats a folder the library entry resolves to or into as already in the library.

Copy installs (no linkOnly) are unchanged. They read the files before replacing the folder, so the source's validated files survive, but with overwrite a source inside the library folder still replaces that folder with its own contents, and files the scan leaves out are dropped; that is how main behaves and is not changed here. SkillsPage.tsx does not send linkOnly today, so this is reachable through the API.

Original proof (before the v0.8.18 refresh)

New tests in server/ui/skills.linkonly.test.ts (skillsCore link-only install onto the library copy). They are skipped on Windows, where creating symlinks needs extra rights, like the other symlink tests. The three tests that spell a folder in another case run only on a case-insensitive disk (macOS default) and skip themselves elsewhere. They live in their own file so this branch does not conflict with #265 in server/ui/skills.test.ts.

On this branch (npx vitest run server/ui/skills.linkonly.test.ts server/ui/skills.test.ts --reporter verbose):

 ✓ skillsCore local library > installs, discovers, inspects, links/unlinks, adopts without clobbering, packs, and manages collections
 ✓ registerSkills HTTP routes > enforces loopback-only for local mutations and supports full demo mode lifecycle
 ✓ skillsCore link-only install onto the library copy > refuses the library folder itself and keeps its files
 ✓ skillsCore link-only install onto the library copy > refuses a harness link that points at the library folder
 ✓ skillsCore link-only install onto the library copy > refuses a folder inside the library folder
 ✓ skillsCore link-only install onto the library copy > refuses the library folder spelled in another case on a case-insensitive disk
 ✓ skillsCore link-only install onto the library copy > links the real folder when the library entry is already a link and the source goes through it
 ✓ skillsCore link-only install onto the library copy > refuses a source that holds the skills library
 ✓ skillsCore link-only install onto the library copy > keeps a harness folder that the library entry links to when harnesses are forced
 ✓ skillsCore link-only install onto the library copy > matches a harness folder typed in another case, and unlinking it later keeps its files
 ✓ skillsCore link-only install onto the library copy > drops an old managed-copy record for the harness folder it links to, so unlinking keeps its files
 ✓ skillsCore link-only install onto the library copy > keeps the harness folder it links to when that harness is not linked and the skill is removed
 ✓ skillsCore link-only install onto the library copy > keeps the library folder when a harness skills folder is a link to the library
 ✓ skillsCore link-only install onto the library copy > keeps a harness skill folder that holds the linked source, when linking and when removing
 ✓ skillsCore link-only install onto the library copy > keeps a library link when a harness skills folder is a link to the library
 ✓ skillsCore link-only install onto the library copy > adopting a harness folder linked in another case keeps the folder
 ✓ skillsCore link-only install onto the library copy > adopting a harness folder that holds the linked source keeps the folder
 ✓ skillsCore link-only install onto the library copy > still replaces a library folder with a link to a folder outside it
      Tests  18 passed (18)

The new tests with server/ui/skillsCore.ts from main (1a475e8):

 × … > refuses the library folder itself and keeps its files
 × … > refuses a harness link that points at the library folder
 × … > refuses a folder inside the library folder
 × … > refuses the library folder spelled in another case on a case-insensitive disk
 × … > links the real folder when the library entry is already a link and the source goes through it
 × … > refuses a source that holds the skills library
 × … > keeps a harness folder that the library entry links to when harnesses are forced
 × … > matches a harness folder typed in another case, and unlinking it later keeps its files
 × … > drops an old managed-copy record for the harness folder it links to, so unlinking keeps its files
 × … > keeps the harness folder it links to when that harness is not linked and the skill is removed
 × … > keeps the library folder when a harness skills folder is a link to the library
 × … > keeps a harness skill folder that holds the linked source, when linking and when removing
 × … > keeps a library link when a harness skills folder is a link to the library
 × … > adopting a harness folder linked in another case keeps the folder
 × … > adopting a harness folder that holds the linked source keeps the folder
 ✓ … > still replaces a library folder with a link to a folder outside it
AssertionError: expected [Function] to throw an error   (×4)
AssertionError: expected [Function] to throw error matching /holds the skills library/ but got 'ELOOP: too many symbolic links encoun…'
AssertionError: expected true to be false // Object.is equality   (×2)
Error: ELOOP: too many symbolic links encountered, open '…/.agents/skills/foo/notes.md'
Error: ELOOP: too many symbolic links encountered, open '…/.claude/skills/foo/inner/notes.md'
Error: ELOOP: too many symbolic links encountered, open '…/.claude/skills/foo/notes.md'   (×2)
Error: ENOENT: no such file or directory, lstat '…/.agents/skills/foo'   (×2)
Error: ENOENT: no such file or directory, open '…/.claude/skills/foo/notes.md'
Error: skill "foo" not found in any harness
      Tests  15 failed | 1 passed (16)

On main the first adopt test already fails at the install, which deletes the folder first. With only the adoptLocalSkill change undone, each adopt test fails on its own: the harness folder is replaced by a link and its .git folder is gone (AssertionError: expected true to be false). With only the linkLocalSkill line that drops the managed-copy record removed, "drops an old managed-copy record …" fails (expected 'x' to be undefined). With the plain realpathSync in place of the native call, only the case test fails (expected [Function] to throw an error), which is why the comparison uses the native spelling.

Checks on macOS, Node 22:

  • npm run typecheck: passes.
  • npm run lint: exit 0. It reports 135 warnings, the same count as on main, and none in the changed files (npx biome check server/ui/skills.linkonly.test.ts server/ui/skillsCore.ts: no diagnostics).
  • npm test: on this branch Test Files 249 passed (249), Tests 3383 passed | 2 skipped (3385). An earlier full run of the branch had one failure, server/control/remote.parity.test.ts ("machines, sends, refusals, jobs, … row for row": TestTimeoutError: Test timed out in 15000ms), which also fails in a full run on unmodified main 1a475e8 (Tests 2 failed | 3365 passed | 2 skipped (3369): the same test with the same 15000 ms timeout, and server/runfile.test.ts "stops cleanly on SIGHUP after its output has gone away", which passed on this branch). Run on its own, the parity file passes on both (Tests 11 passed (11)).
  • npm run test:e2e: not run (server-only change, no UI).
  • Windows: not run. The new tests skip there; the check relies on realpathSync.native and on lstat reporting the junction an earlier link-only install made as a link, as the existing code already does.

Left as they are in this pull request:

  • On Linux (as on main), realpathSync.native does not fold case, so on a case-insensitive Linux folder (ext4 casefold, vfat, an NTFS mount) a source spelled in another case is not caught.
  • A link-only install links the source path as typed (unless it goes through the library entry). When that path is itself a harness link to an outside folder, the library entry links through the harness link, and unlinking that harness leaves the library entry dangling. No files are lost.
  • Unlinking a harness whose folder is the library's source now leaves it in place and returns the snapshot as before; the skill list shows that entry as unmanaged, as it already did.
  • Discovery's status check still compares the plain real paths; it only decides what the list shows.
  • Adopting a copy from another harness with force replaces the library entry with that copy and then relinks every detected harness with force, which replaces a real harness folder the old library entry linked to. force asks for that replacement.

This shares server/ui/skillsCore.ts with my open #265 (the symlink-loop fix in scanSkillDir); they change different functions, and this branch keeps its tests in a new file so server/ui/skills.test.ts, which #265 also changes, is untouched here. git merge-tree --write-tree finds no conflict between this branch and main, or between this branch and #265's head.

An entry is now included under Unreleased in CHANGELOG.md. Other open PRs also add release notes; those entries may need combining as the PRs land.

Checklist

  • Every commit is signed off (git commit -s): the DCO is the only paperwork.
  • npm run typecheck && npm run lint && npm test pass; npm run test:e2e for a UI change. (Not a UI change. The last full npm test passed; an earlier run's one timeout also fails on main, see Proof.)
  • New source files start with // SPDX-License-Identifier: Apache-2.0. (server/ui/skills.linkonly.test.ts.)
  • No secret, real address, hostname or home path in code, fixtures or screenshots (screenshots come from --demo).
  • A change to shared/* names the wire-contract change in the description. (No shared/* change.)
  • A line under Unreleased in CHANGELOG.md.

…er instead of deleting it

Symptom: a link-only install (POST /api/ui/skills/install with
linkOnly and overwrite) whose source was the skill's library folder
(~/.agents/skills/<slug>), a folder inside it, or a harness link to it
(~/.claude/skills/<slug>, as linkLocalSkill makes) reported success, but
deleted every file of the skill and left the library entry as a link to
itself (or a loop through the harness link). The skill vanished from the
list. When the library entry was already a link, the same install
deleted no files but still left a loop, and a source that holds the
whole library (a SKILL.md in ~/.agents) lost the library folder and
failed with ELOOP. A link-only install from a harness folder
(~/.claude/skills/<slug>) with forceHarnesses deleted that folder too:
linking the skill back into the same harness replaced it with a link
to the library entry, which links to it.

Cause: installLocalSkillFromDir's linkOnly branch removed the library
entry with rmSync and then linked it to the source path as typed,
without checking where the source resolves to.

Fix: compare real paths first (realpathSync.native, so on macOS and
Windows a name spelled in another case still matches). A source that
holds the skills library is refused. A source that resolves to the
library folder or into it is refused when that folder is a real folder
(`refusing to link skill "<slug>" to itself ...`), and nothing is
touched; the route returns it as a 400 skill_error. When the library
entry is already a link, it is relinked to the source's real folder,
not to a path that leads back through the entry.

linkLocalSkill now leaves a harness entry alone whenever it resolves
to the same real folder as the library entry, not only when it is a
link, and leaves a real harness folder alone when the library entry
links to a folder inside it, so it never removes the folder the library
entry links to.
It compares the native real paths, like the install check, so a source
typed in another case still matches, and it drops a managed-copy record
left for that harness (a copy made when linking failed), so a later
unlink does not delete the folder the library entry links to.

unlinkLocalSkill (and removeLocalSkill, which calls it for every
harness) applies the same rule: a real harness folder that the library
entry resolves to, or that holds it, is the skill itself, not a copy,
so it is kept and a managed-copy record left for it is dropped. This
covers a harness that was not in the install's harness list and records
written before this change. A harness skills folder that is itself a
link to the library folder is skipped, since its entry is the library
entry. adoptLocalSkill compares the native real paths too, and treats a
harness folder that the library entry resolves to or into as already
in the library, so adopting it (under another case, or when the
library links to a folder inside it) no longer copies it and deletes
the original.

Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
@connorburgess

Copy link
Copy Markdown
Contributor Author

The link-only skill source-preservation fix still applies to SessionPipe GUI v0.8.18. Merged current main (d16a2c01) into this branch; the refreshed head is 3ac5d673. The affected files have not changed upstream, and the original change is preserved.

Added the previously deferred Unreleased changelog entry.

Validation on this head, macOS / Node 22.23.2:

  • npm run typecheck, npm run lint, and npm run build passed. Lint has the same 135 warnings and one informational diagnostic as current main, with no errors.
  • npx vitest run --maxWorkers=2 server/ui/skills.linkonly.test.ts server/ui/skills.test.ts: 18 tests passed.

GitHub CI run 47453785808 for head 3ac5d673 passed: typecheck · lint · unit · build, all three desktop e2e shards, e2e (phone · duo), e2e (control channel), and the aggregate typecheck · lint · unit · build · e2e gate.

Also checked the combined source/test changes from all 19 refreshed PRs on the same main: no source conflicts; typecheck, lint and build passed; all 252 unit-test files passed (3,439 tests, two skipped). This was a local integration check, separate from the individual PR run above. Release-note entries may still need combining as PRs land.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant