Repository navigation
fix(skills): a link-only install refuses the skill's own library folder instead of deleting it - #266
connorburgess wants to merge 3 commits into
Conversation
…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>
|
The link-only skill source-preservation fix still applies to SessionPipe GUI v0.8.18. Merged current Added the previously deferred Unreleased changelog entry. Validation on this head, macOS / Node 22.23.2:
GitHub CI run 47453785808 for head 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. |
Updated against v0.8.18 / main
d16a2c01on 2026-12-05. Current validation and refresh details.What
A link-only install (
POST /api/ui/skills/installwithlinkOnlyandoverwrite) 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 withrefusing to link skill "<slug>" to itself: …; link a folder outside the library, returned as a 400skill_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) withforceHarnessesno 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
installLocalSkillFromDirinserver/ui/skillsCore.tshandleslinkOnlyby 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/FOOstill matchesfoo:mainthis deleted the library entry and then failed with ELOOP).mainthis 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) andforceHarnesseswas set,linkLocalSkillsaw 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.linkLocalSkillskipped 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/foostill 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(whichremoveLocalSkillcalls 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/foowith harnesses["cursor"]keeps an oldclaude-coderecord). 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: onmainunlinking 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.adoptLocalSkillcompared the plain real paths, and only for equality. After a link-only install from~/.Claude/skills/foo, or from~/.claude/skills/foo/inner, adopting theclaude-codefolder withforcedid 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.gitfolder, 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 withoverwritea source inside the library folder still replaces that folder with its own contents, and files the scan leaves out are dropped; that is howmainbehaves and is not changed here.SkillsPage.tsxdoes not sendlinkOnlytoday, 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 inserver/ui/skills.test.ts.On this branch (
npx vitest run server/ui/skills.linkonly.test.ts server/ui/skills.test.ts --reporter verbose):The new tests with
server/ui/skillsCore.tsfrommain(1a475e8):On
mainthe first adopt test already fails at the install, which deletes the folder first. With only theadoptLocalSkillchange undone, each adopt test fails on its own: the harness folder is replaced by a link and its.gitfolder is gone (AssertionError: expected true to be false). With only thelinkLocalSkillline that drops the managed-copy record removed, "drops an old managed-copy record …" fails (expected 'x' to be undefined). With the plainrealpathSyncin 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 onmain, 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 branchTest 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 unmodifiedmain1a475e8 (Tests 2 failed | 3365 passed | 2 skipped (3369): the same test with the same 15000 ms timeout, andserver/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).realpathSync.nativeand onlstatreporting 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:
main),realpathSync.nativedoes 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.unmanaged, as it already did.forcereplaces the library entry with that copy and then relinks every detected harness withforce, which replaces a real harness folder the old library entry linked to.forceasks for that replacement.This shares
server/ui/skillsCore.tswith my open #265 (the symlink-loop fix inscanSkillDir); they change different functions, and this branch keeps its tests in a new file soserver/ui/skills.test.ts, which #265 also changes, is untouched here.git merge-tree --write-treefinds no conflict between this branch andmain, 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
git commit -s): the DCO is the only paperwork.npm run typecheck && npm run lint && npm testpass;npm run test:e2efor a UI change. (Not a UI change. The last fullnpm testpassed; an earlier run's one timeout also fails onmain, see Proof.)// SPDX-License-Identifier: Apache-2.0. (server/ui/skills.linkonly.test.ts.)--demo).shared/*names the wire-contract change in the description. (Noshared/*change.)CHANGELOG.md.