Skip to content

Install skill references from the package root and record installed files - #3397

Merged
mstomar125 merged 3 commits into
mainfrom
issue-3368-skill-install-record
Sep 30, 2026
Merged

mstomar125 merged 3 commits into
mainfrom
issue-3368-skill-install-record

Conversation

@mstomar125

@mstomar125 mstomar125 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Closes #3368

What changed

The skill installer no longer takes its reference files from a hand-kept list. It installs every references/*.md in the skill it runs from (the staged resources/skill/, or packages/skill/ in a source checkout), and records what it wrote so uninstall and reinstall can remove exactly that.

  • agents.ts: no agent's shims names a references/ path any more. Antigravity's shims is now just SKILL.md.
  • installer.ts
    • New listReferenceFiles(packageRoot): the sorted *.md files directly under <packageRoot>/references/ (not recursive), as references/<name> paths; [] when the directory is absent. Any other read error is rethrown, so an unreadable directory never reads as "no references" (which would make a reinstall delete every installed reference).
    • install() copies the shims and every reference, deletes each file the previous record named that the new set does not contain (pruning references/ if it ends up empty), then writes <installDir>/.nodespace-install.json ({ "files": [...sorted relative paths] }). A stale file that cannot be deleted stays in the record and is reported on stderr instead of aborting the install.
    • A package with no SKILL.md installs nothing and leaves an existing install and its record alone (a skill is discovered by SKILL.md; a folder without one is not a skill).
    • uninstall(targetAgents, packageRoot = PACKAGE_ROOT) removes exactly the recorded files and the record, then prunes only the directories those files leave empty, and the install directory once it is empty (fail-soft if that directory is a symlink). checkInstalled is unchanged.
    • Deletion only ever touches a recorded path that is a regular file or a symlink whose parent directory really lies inside the real install directory. A symlink entry is unlinked, never followed. Absolute paths, .. entries, directories, and files reached through a symlinked directory that leads outside are ignored.
  • install.ts: uninstall now gets the --resource-root the CLI already parses. The Claude Code plugin reconciliation (uninstall(['claude-code']) inside install) passes its own packageRoot.
  • scripts/publish-skill-repo.ts: sharedShimPaths() is the shared shims (now only SKILL.md) plus listReferenceFiles(packages/skill), so the public repository is derived the same way. readSkillSource() returns the references as a map. The script does not read any extension input.
  • packages/skill/README.md describes the install record. types.ts documents that shims no longer lists references.

Behaviour change to note

SKILL.md's "Work tracking" line links references/jira-playbook.md, linear-playbook.md and spec-driven-playbook.md, but no agent's shims listed them, so both the installed skill and the public repository linked to files that were not there. Taking the list from the directory means those three playbooks are now installed and published (six references instead of three). The PTY-session embed in packages/agent already wrote all six.

Reviewer decision: installs without a record (option A chosen)

Most installs predate the record (skill_installed makes the first-launch install run once), so I took the recommended option A: a missing record is read as the files the pre-record installer wrote (SKILL.md, the agent's harness shim, and the exported PRE_RECORD_REFERENCES: cli.md, shared-workspaces.md, graph-authored-guidance.md). The constant's doc says it covers installs made before the record existed and can be deleted once those are gone. If you prefer option B, delete PRE_RECORD_REFERENCES, preRecordFiles, and the four tests that name them.

One extension beyond the issue text, worth a look: I applied the same reading on reinstall, not only on uninstall. Without it, a reinstall over a record-less install writes a record that omits a legacy reference the new skill no longer ships (say shared-workspaces.md), leaving that file behind for good; a later uninstall would then keep references/ and strand the install directory, the case the record exists to prevent. With it, the first reinstall cleans the legacy file. This is under option A only.

Deviations from the issue and the code as found

  • listReferenceFiles returns references/<name> paths rather than bare names, so install, the record, PRE_RECORD_REFERENCES and the publish list all share one spelling.
  • installedName() is deleted. With no references/ shims, basename(shim) is the whole rule, and the record replaces the install/uninstall-must-agree problem it documented. Directory pruning now walks up from each deleted file (leaf-upward), which also retires the "deeper shim strands references/" caveat in the old comment.
  • A package with no SKILL.md installs nothing and leaves the existing install and its record alone instead of diffing against a partial set: a broken package root must not wipe or half-replace a working install.
  • Stale detection compares resolved paths, so a differently spelled record entry (./SKILL.md) can never delete a file the same install just wrote.
  • README.md in packages/skill had a sentence saying the public repository gets only references/cli.md; updated, plus a short note on the record.
  • The ADRs (081 R3, 082 §5) are not merged yet. Per the standing decision I implemented ahead of them. If R3 lands as "keep the guidance reworded in core", this issue closes as not planned.

Ratchet

bun run scripts/check-pro-boundary.ts exits 0, and the count table on this branch is identical to the table on its merge-base (checked against a checkout of the merge-base itself): 271 / 368 / 95 / 81 / 54 / 104 / 203 / 0 / 72 / 463 / 275 / 18 in marker order (proCommands through proNamedFiles). This PR adds and removes no marker, and BASELINES is untouched. (Several counts are below their baselines because other PRs have lowered them; the final tightening issue owns that.)

Tests

bun run test:changed (skill, scripts and Rust tiers) passed on the final head, including the Rust workspace under nextest. Skill package: 131 tests. Scripts: 970 tests. tsc for packages/skill (src and shims) and scripts/ is clean.

New tests in packages/skill/src/tests/installer.test.ts, each mutation-checked by reverting the matching installer.ts change and confirming it fails:

Issue test Test Reverted change
1 copies every references/*.md, including one no agent config names reference discovery in install
2 writes a record listing exactly the files it wrote (and does not list or report itself) record write / record naming itself
3 a reinstall from a package missing a reference deletes it and updates the record (plus: prunes references/ when none remain; leaves a user's own file alone) stale deletion; directory pruning
4 uninstall with a record removes exactly the recorded files (including one neither shims nor the package names) and the record, leaving no directory record ignored by uninstall; record not removed
5 uninstall keeps a user's own file in references/, so references/ and the install directory stay pruning made recursive
6 a record entry such as ../outside.md (also an absolute path, a directory, and a path through a symlinked directory) is never deleted, on uninstall and on reinstall containment/regular-file/real-path checks, each dropped separately
7 option A: uninstall without a record removes the pre-record references, including one the package no longer ships, and prunes the directory pre-record list dropped

Added after review: a failed stale delete stays recorded and warns (mocked rmSync); an emptied symlinked install directory does not crash uninstall or skip the next agent; a recorded symlink is unlinked and its target survives; a package without SKILL.md leaves the install alone; recorded files deleted by hand still get their directories pruned; a record-less uninstall survives an unreadable package references/ and says the cleanup was partial; pruning never removes a symlinked directory (Windows rmdir semantics emulated).

Also added: listReferenceFiles cases (sorted under a reversed readdir, non-recursive, .md only, missing/non-directory, read errors rethrown with installed references left in place); reinstall over a record-less install (the option A extension); an install that writes nothing leaves the install alone; a differently spelled record entry is not treated as stale; malformed or non-string records fall back to no record; record-less uninstall also removes references the package root ships; the plugin-managed cleanup passes packageRoot; a record-only directory is not "installed"; installing from the real packages/skill puts every reference in place and every references/... link in the installed SKILL.md resolves; and install.test.ts spawns the real CLI with a scratch HOME to prove uninstall receives --resource-root.

In scripts/publish-skill-repo.test.ts: the expected lists are now SKILL.md plus the six references, every reference is copied verbatim, and every references/... link in the published SKILL.md resolves to a published file.

Mutation results: 42 mutations run (installer.ts, agents.ts, package.json, install.ts and publish-skill-repo.ts, several variants per guard). 41 are caught by the tests named above. The one that is not is an equivalent mutant: dropping the explicit Array.isArray check on the record's files still yields "no record", because the surrounding try/catch already turns .filter on a non-array into "no usable record".

Verified against the real installer

Built with bun run scripts/build-skill.ts and ran the compiled nodespace-skill-installer against the staged resources/skill with a scratch HOME (env -i, nothing under the real ~/.claude, ~/.codex or ~/.gemini was touched):

  • The staged resources/skill/references/ is identical to packages/skill/references/ (six files, unchanged by this PR).
  • install put all six references plus the shim in each of claude-code, codex and antigravity, and wrote the record.
  • A reinstall from a resource root missing jira-playbook.md deleted it and updated the record.
  • uninstall removed the recorded files and the record, kept a user's references/my-notes.md and its directories.
  • A hand-built pre-record codex install was fully removed and pruned by uninstall --resource-root <root that ships no references>.

bun run skill:check (the cargo gen_skill_md --check) was not run separately: SKILL.md is not modified.

Risks and rollback

  • Users who reinstall get three more reference files. Intended: SKILL.md already links them.
  • A new dotfile appears in each skill directory. Harnesses discover a skill by SKILL.md, so it is inert there.
  • Revert the PR to roll back. An older installer ignores the record, so after a rollback an uninstall leaves .nodespace-install.json behind and keeps the install directory; delete that file by hand if needed.

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review Type: Initial Review

Requirements Check (issue #3368)

  • agents.ts names no references/ path. Antigravity's shims is ['SKILL.md']. A config test pins it.
  • Installing from a package root installs every references/*.md (six), and every references/... link in the installed SKILL.md resolves. Covered by the seeded-root test (it includes extra-playbook.md, which no agent names) and by an install from the real packages/skill.
  • Each install writes a record listing exactly what it wrote. A reinstall from a skill missing one reference deletes it and updates the record.
  • Uninstall with a record leaves no install dir. A user's own file in references/ survives, and so do references/ and the install dir.
  • A record entry pointing outside the install dir is ignored (.., absolute, directory, symlinked directory), on uninstall and on reinstall.
  • The public file list is SKILL.md plus every references/*.md (sharedShimPaths / readSkillSource). The published-links test is added.
  • The PR description names the three-playbook behaviour change and option A. It also names the reinstall extension.
  • Ratchet: scripts/check-pro-boundary.ts exits 0 and --changed reports 0 hits in this diff. BASELINES is untouched. The below-baseline notices come from main, not from this PR.
  • Scope and Tests: install.ts passes resourceRoot, checkInstalled is unchanged (with a record-only-dir test), and all seven listed installer tests exist. Note that ADR-081 R3 / ADR-082 §5 are not merged. The PR states it went ahead per the standing decision. If R3 lands as "keep the guidance reworded in core", this becomes a no-op cleanup.

I ran bun run test:skill (124 pass), bun test scripts/publish-skill-repo.test.ts (28 pass) and the ratchet. I also ran the real installer under env -i with a scratch HOME, and mutation-checked the guards in a scratch copy of packages/skill. git status in the worktree is clean.

Code Review Findings

Critical

None. The deletion logic holds up. removeInstalledFile is sound:

  • lstat().isFile() plus isWithin(realpath(installDir), realpath(dirname(target))) covers .., absolute entries, symlinked directories and the install dir itself (not a regular file).
  • A NUL byte makes lstat throw into the catch. On Windows, cross-drive relative() returns an absolute path, which isAbsolute rejects. resolve normalizes backslashes there, and relative compares case-insensitively.
  • TOCTOU between the check and rmSync is not a privilege boundary. The installer runs as the user against their own home, and the .pkg postinstall never invokes it. Do not add more machinery for this.

I mutation-checked in a scratch copy:

  • Dropping the isFile check is caught, but only because rmSync throws EISDIR.
  • Dropping the realpath containment fails 3 tests.
  • Lexical-only containment fails the symlinked-directory test, so that test isolates the realpath guard.
  • Swapping lstat for stat survives all 79 tests (see Improvement 3).

Improvements

  1. A failed stale delete during install() loses the file from the record for good. installer.ts:216-229 and :296.

    • The new record is written before the stale deletes. rmSync(target) at :296 is outside the try, so an EACCES/EBUSY/EPERM (a read-only dir, or a locked file on Windows) throws out of install().
    • That also skips every remaining agent. The record no longer lists the file, so it is orphaned. A later uninstall then strands references/ and the install dir, which is the exact case the record exists to prevent.
    • Reproduced: after chmod 555 references/, a reinstall that drops b.md throws EACCES. The record then lists only a.md, and uninstall leaves references/b.md behind.
    • Suggestion: catch the rmSync error per file, and write the record once, after the stale pass, as wrote ∪ {stale entries that could not be deleted}. The crash window then becomes copy-then-record. It converges on the next install, unlike record-then-delete, which never recovers. This is a small change.
    • Principle: failure atomicity and fail-soft cleanup.
    • Uninstall is fine: the record is removed last, so a rerun works.
  2. uninstall crashes when the install dir is a symlink that ends up empty. installer.ts:373-375.

    • Some users have a dotfile manager that links ~/.claude/skills/nodespace to a repo directory. After the recorded files are removed, readdirSync(root).length === 0 holds and rmdirSync(root) throws ENOTDIR on POSIX.
    • Reproduced: the process crashes with a stack trace after deleting everything.
    • The old code used rmSync(installDir, {recursive: true}), which unlinks a symlink. This is a regression in a plausible setup.
    • Suggestion: wrap that final rmdirSync in try/catch, as pruneEmptyParents already does. Leaving an empty dir is the smaller failure, per the file's own principle.
    • Principle: fail-soft and uninstall must not abort the remaining agents.
  3. Symlink policy is undecided and untested. installer.ts:288.

    • A record entry that is a symlink inside the install dir is refused. Reproduced with a symlinked SKILL.md: uninstall prints "nothing to remove", the symlink stays, and the skill remains discoverable. The old code unlinked it.
    • Unlinking a symlink never touches its target, and the realpath check on the parent still guards it.
    • Either accept isFile() || isSymbolicLink(), or keep the refusal and add a test that pins it. Right now the PR's "symlinks are ignored" claim has no test: the lstat→stat mutant survives.
    • Principle: tests must pin every claimed guard.
  4. The "install that wrote nothing" guard is keyed on the wrong thing. installer.ts:216.

    • It checks wrote.length > 0, but checkInstalled (and the harnesses) key on SKILL.md.
    • Reproduced: a package with references and a shim but no SKILL.md reinstalls over a working install. The stale pass deletes SKILL.md and rewrites the record without it. That leaves a "malformed skill folder", the state the author set out to avoid.
    • Suggestion: if (wrote.includes('SKILL.md')), or the equivalent existence check on the package's SKILL.md.

Nits

  • Case-insensitive filesystems (installer.ts:223-227). The stale comparison is by resolved string. A case-only rename (CLI.md in the old record, cli.md shipped now) on APFS or NTFS deletes the file the install just wrote and prunes references/, while the record still lists it. Reproduced on this Mac. It is unlikely for kebab-case names. It is cheap to fix by comparing dev:ino via statSync, or by deleting stale entries before copying.
  • A record that names itself. If the previous record lists .nodespace-install.json, the stale pass deletes the record just written (reproduced). Add resolve(root, INSTALL_RECORD) to kept. It needs a hand-edited record, so it is very low risk.
  • Doc over-claim (installer.ts:273-283). "a file reached through a symlinked directory" is ignored only when the directory leads outside the install dir. A symlinked directory that resolves inside it is accepted, and the file there is deleted if a record names it. That is fine behaviour, but the comment and the PR text overstate it.
  • Pruning only follows deleted files (installer.ts:227,367). If the user already deleted every recorded file from references/, removeInstalledFile returns undefined and the empty references/ is never pruned. That leaves a stranded empty directory and install dir. Calling pruneEmptyParents for a missing-but-contained target would close it. The old code pruned empty owned dirs unconditionally.
  • Uninstall reads the package root through listReferenceFiles (installer.ts:361). Its rethrow of non-ENOENT errors is right for install, where an unreadable directory would otherwise delete everything. For a record-less uninstall it aborts cleanup that the pre-record list alone could have done. Consider catching there.
  • Stale comment: .github/workflows/release.yml:865-866 still says the script reads SKILL.md and references/cli.md.
  • Naming. sharedShimPaths() now returns references too. That is fine for the issue's contract, but the name has drifted.

Answers to the specific questions

  • Reinstall reading a missing record as the pre-record set (the extension): justified and bounded. The read is limited to the three named references plus shim basenames, and the shim basenames are always in the new set. So the most a reinstall can delete beyond the record is cli.md, shared-workspaces.md or graph-authored-guidance.md, and only if the new skill drops them. It is what makes the later Pro-guidance removal clean on the many installs with no record. I would keep it.
  • Uninstall over-deletion: none found. PRE_RECORD_REFERENCES plus listReferenceFiles is bounded by name. pruneEmptyParents uses a non-recursive rmdirSync, only walks up from a just-deleted file and excludes the install dir. The final rmdirSync(root) is non-recursive too, which is strictly safer than the old rmSync recursive, apart from Improvement 2.
  • listReferenceFiles: staged Tauri resources and git checkouts hold regular files (git ls-files -s shows 100644, find -type l is empty, and build-skill copies files rather than links), so Dirent.isFile is fine.
  • Compiled-binary story: no gap.
    • The script path is resources/skill/dist/install.js, so PACKAGE_ROOT is resources/skill, which holds references/ (STAGED_ENTRIES). The debug path gives packages/skill.
    • compiled_installer_command always passes --resource-root for install, uninstall and status.
    • The CLI test proves the flag reaches uninstall. It is meaningful: without the plumbing, only-in-this-skill.md survives and the dir stays.
  • publish-skill-repo.ts importing installer.ts: acceptable coupling.
    • installer.ts imports only node builtins and ./agents.js, which the script already imports. The sync-skill-repo job needs no bun install, and bun resolves .js to .ts.
    • Sharing listReferenceFiles is the point of the issue. Moving it to its own tiny module would only avoid loading child_process, which is optional.
  • Tests:
    • The sorting test wraps readdirSync in reverse, so it is not tied to macOS ordering. The vi.doMock('node:fs') tests unmock and reset modules in afterEach.
    • Per-pid TMP dirs are removed in afterEach, and the CLI test uses its own scratch HOME with CLAUDE_CONFIG_DIR stripped. spawnSync('bun') is fine in CI because the suite runs under bunx.
    • The hardcoded REFERENCES list in the publish test is an intentional pin. It will need a one-line edit when the shared-workspaces file is removed later.
  • Other user-visible changes:
    • The installed N file(s) count goes from 5 to 8 (Claude Code; 4 to 7 for Antigravity). Rust parse_installer_output matches only the ✓ <agent> marker and never reads the count, so nothing breaks.
    • The README is updated, and the new dotfile and the three playbooks are covered by the PR body.
    • Reinstall now silently deletes dropped references, which is the intended behaviour.
  • CLAUDE.md: no issue numbers in the new code or comments, no lint suppression, no any, and no Pro-boundary markers added (--changed shows 0 hits). PRE_RECORD_REFERENCES is a documented, deletable installer-hygiene constant, sanctioned by the issue's option A.

Recommendation: APPROVE. There are no blockers and this is a clear net improvement. The deletion guard is sound and well tested. Improvements 1 and 2 are cheap robustness fixes worth making in this PR or a fast follow-up. Improvements 3 and 4 are one-liners plus a test.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review: APPROVE (posted as a comment, GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary (round 1)

Review verdict was APPROVE with no blockers. Commit 06fdd553 addresses the improvements and most of the nits. Every behaviour change has a test that fails when the change is reverted (mutation-checked, 12 new mutations; details below).

Addressed

# Finding Change Test
Imp 1 A failed stale delete lost the file from the record and aborted the install The stale pass catches per file: the file stays in the record, a WARNING goes to stderr, and the install carries on for this agent and the rest. The record is now written once, after the stale pass. reinstall with rmSync failing on one stale file (mocked fs): install finishes, the file stays recorded, a later uninstall leaves nothing behind
Imp 2 uninstall crashed when the install directory was an emptied symlink The final rmdirSync is fail-soft; an empty linked directory is left in place. symlinked install dir: no crash, the next agent is still processed
Imp 3 Symlink policy undecided (a recorded symlink was refused, the old code unlinked it) A recorded symlink is unlinked, never followed (verified rmSync on a link leaves the target alone in both Bun and Node). A symlinked parent leading outside is still refused. Doc comment corrected. symlinked file and symlinked directory entries are unlinked, targets survive (also kills the reviewer's lstat→stat mutant)
Imp 4 "Wrote nothing" guard keyed on the wrong thing A package without SKILL.md now installs nothing at all and leaves the existing install and record alone (stronger than guarding only the cleanup: no unrecorded files are dropped beside it either). package with references and a shim but no SKILL.md over a working install
Nit Pruning only followed deleted files removeRecordedFile prunes the parents even when the file was already gone. user deleted every recorded file by hand, uninstall leaves no directory
Nit Record-less uninstall aborted on an unreadable package references/ Treated as shipping none; the pre-record list still applies. mocked readdirSync failure
Nit Doc over-claim on symlinked directories Comment rewritten (Imp 3). -

The two reproductions in the review were re-run against the real CLI with a scratch HOME after the fix: a read-only references/ during a reinstall now warns, keeps b.md recorded, converges on the next install and uninstalls cleanly; a symlinked install directory uninstalls without a crash.

Skipped, with reasons

  • Case-only rename on a case-insensitive filesystem (CLI.md recorded, cli.md shipped). It needs a case-only rename of a shipped reference name, which kebab-case names make very unlikely, and the fix (comparing dev:ino, with fail-safe handling where a filesystem reports inode 0) cannot be tested on the case-sensitive Linux CI. Revisit if a reference is ever renamed by case alone.
  • Record naming itself. No longer reachable with the new ordering: the record is written last, after the stale pass, so a hand-edited record listing itself cannot delete the record that was just written. (I had added a guard for it, then removed it because no test could distinguish it.)
  • release.yml comment (lines 865-866). Touching .github/ is an unrecognized path to test:changed's scoping and would run every tier (including the browser tier) for a one-line comment. The comment is incomplete, not wrong. Fix it the next time the workflow is edited.
  • sharedShimPaths() naming. The issue's contract names it, and renaming widens the diff for no behaviour change.

Verification

test:changed is re-running on the new commit (skill 130 tests locally: pass; Rust tier queued). Ratchet: no marker added or removed relative to the merge-base (checked against a checkout of the merge-base itself); BASELINES untouched. PR description updated with corrected numbers.

Re-Review Decision

Decision: RE-REVIEW NEEDED

Rationale: Imp 1, 3 and 4 change install/uninstall behaviour (record write order, symlink policy, the SKILL.md guard) in deletion logic, so a second pair of eyes on commit 06fdd553 is warranted.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Review Type: Re-Review

Previous Review Summary: 4 improvements and 7 nits in the previous review. All 4 improvements are addressed correctly. Of the nits, 4 are addressed in code and 3 are skipped with reasons I accept (case-only rename on a case-insensitive filesystem, the release.yml comment, the sharedShimPaths() name). The "record that names itself" nit is moot with the new ordering. New issues found: 0 critical, 0 improvements, 3 optional nits.

Verified: bunx vitest run in a scratch copy of packages/skill passes 130/130, tsc --noEmit is clean for both tsconfigs, and the ratchet --changed reports 0 hits. The new lines add no issue numbers, lint suppression, any, or Pro-boundary words. I ran the real installer under env -i with a scratch HOME and never touched a real harness config. git status in the worktree is clean, and all mutation work was done in a copy.

Status of each previous finding

# Finding Verdict
Imp 1 Failed stale delete lost from the record, aborted the install Addressed. Reproduced with a real chmod 555 references/: the reinstall warns on stderr, keeps b.md recorded, finishes the install and the following agent (codex). After chmod 755 the next install deletes it and drops it from the record.
Imp 2 Uninstall crash on an emptied symlinked install dir Addressed. rmdirSync(root) is in a try/catch and the test also checks the next agent is still processed.
Imp 3 Symlink policy undecided Addressed: unlink, never follow. Probed on macOS: a recorded symlink to an outside file, a symlink to an outside directory and a dangling link are all unlinked and the targets survive. rmSync on a symlink-to-directory only unlinks it under both Bun and Node (checked, since the compiled installer runs under Bun).
Imp 4 "Wrote nothing" guard keyed on the wrong thing Addressed, and stronger than asked.
Nit Prune only followed deleted files Addressed (see nit 2 for a Windows-only footnote).
Nit Record-less uninstall aborted on an unreadable package references/ Addressed. Swallowing is right here (see below).
Nit Doc over-claim on symlinked directories Addressed. The new comment matches behaviour.
Nit Case-only rename on a case-insensitive FS Skipped, accepted. Kebab-case names make it very unlikely, and the author states when to revisit.
Nit Record that names itself Moot. The record is now written after the stale pass, so an old record listing itself cannot delete the fresh one.
Nit release.yml comment, sharedShimPaths() name Skipped, accepted. Neither is behavioural.

Findings

Critical

None.

Improvements

None. The changes I checked hold up.

Answers to the specific questions

  • New write ordering (copy, stale pass, then one record write).
    • The record is only ever a superset of what will be gone or a description of what was written. An entry can now leave the record only when its file is gone or was never containable, so orphaning via a failed delete is closed.
    • An entry cannot be in both wrote and undeleted. undeleted only holds entries whose resolved path is not in keep, so a string that equals a wrote entry is always kept.
    • The crash window is copy-done, record-not-written. New files are then unrecorded, and an uninstall driven by the old record would strand a newly added reference plus references/ and the install dir. The window is milliseconds wide, needs a process kill in it, and converges on the next install. The previous ordering had the same window, and a torn record (non-atomic writeFileSync) fails safe: unparsable JSON reads as "no record" and falls back to the pre-record list. Acceptable, no extra machinery needed.
    • Pruning cannot damage new files. Copy happens before the stale pass, so any directory holding a new file is non-empty and rmdirSync refuses it.
  • No SKILL.md installs nothing.
    • Every agent config lists SKILL.md first in shims (all five in agents.ts), so the guard cannot trip for a well-formed package.
    • The CLI already prints the exact right line for installed: [] with no skipReason: "detected but no files to install (package may be incomplete)".
    • skill_setup.rs parses only the ✓ and ⚠ agent: reason markers from stdout. It maps ⚠ to agents_skipped and never reads the file count. Nothing depends on the old "install the shim anyway" behaviour, and the guard runs before any mkdirSync, so it leaves no empty directories.
  • Symlink unlink safety. The containment check is on realpath(dirname(target)), unchanged. Probed on macOS with a scratch HOME:
    • Parent symlink to an outside directory: refused, and the outside directory and the link both survive (rmdirSync on a symlink fails ENOTDIR on POSIX).
    • Parent symlink to a directory inside the install dir: deletes the file in that inside directory only.
    • Hostile record entries (../emptydir/x.md, references/../../emptydir/x.md, .., ../.., ., references, ../../../../.., /tmp): nothing outside the install dir is touched. A sibling empty directory survives.
    • Install dir itself a symlink (dotfile manager): install, reinstall dropping a reference, and uninstall all work, with the record removed and no crash.
    • Deleting the recorded files in the real directory behind such a link is consistent with the installer having written them there.
  • Pruning when nothing was deleted. pruneEmptyParents only walks parents of the entry, stops at the install dir, and uses non-recursive rmdirSync. It is bounded by isWithin(installDir, dir), so references/../../x starts at a dir outside the install dir and does nothing. The worst case is an empty directory inside the install dir being removed because a record entry sits beneath it. Harmless.
  • filesWithoutRecord swallowing. Right for uninstall (it only reads, and the pre-record list is still worth removing), and rightly different from install, where a failed read would delete everything installed earlier. See nit 3.

Nits

  1. Duplicate record entries persist (installer.ts:241). A hand-edited record with references/b.md listed three times, while b.md is undeletable, is rewritten with three copies and warns three times on every install. Real records never contain duplicates, so this is cosmetic. A new Set in writeInstallRecord fixes it. (Principle: keep state canonical.)
  2. Prune with nothing deleted vs a symlinked parent on Windows (installer.ts:343-347). Not verified, and I could not run it here. On POSIX a symlinked parent is safe (rmdirSync on a link gives ENOTDIR, confirmed). On Windows rmdirSync on a directory symlink or junction removes the link itself. The new "prune even if nothing was deleted" path can now reach an outside-pointing symlinked references whose delete was refused. It would remove only the link, never the target, and only for a user who symlinked references/. If you want it closed, pruneEmptyParents can return when lstatSync(dir).isSymbolicLink(). Optional.
  3. A swallowed listReferenceFiles failure is silent (installer.ts:281-291). The uninstall then reports "removed N" with no hint that shipped-but-unlisted references may remain. A one-line WARNING on stderr, like the install path, would make the partial cleanup visible. Optional.

Two smaller observations, no action needed:

  • removeInstalledFile's catch treats any lstat/realpath error (for example a mode-000 parent directory) as "already gone". During install that entry would be dropped from the record. It needs a directory the user made unreadable and is far rarer than the failure Imp 1 fixed.
  • The mocked-rmSync test proves the "kept in the record, uninstall cleans up" path. The reinstall half ("the next install converges") is covered only by the composition of existing tests and by my manual run. Not worth a new test.

Test quality

I mutated a scratch copy of installer.ts and ran installer.test.ts for each mutant. Nine mutants, each killed by exactly the intended test and no other:

Mutant Killed by
undeleted.push removed "keeps a stale file it could not delete in the record"
catch rethrows same test
final rmdirSync uncaught "install directory is a symlink"
symlink refused "unlinks a recorded symlink"
lstat swapped for stat same
SKILL.md guard changed to present.length === 0 "installs nothing ... no SKILL.md"
prune only when removed "prunes ... deleted by hand"
filesWithoutRecord rethrows "package references cannot be read"
lexical-only containment "symlinked directory that leads outside"
  • Leakage: the top-level afterEach does doUnmock and resetModules. That affects only later dynamic imports, since the static imports are already bound, and vitest isolates per file. failingOn simulates the error instead of relying on permissions, so it is safe as root and on CI. The symlink tests are skipIf(win32), and the path checks use endsWith so they hold with backslashes.
  • Assertions: none are vacuous. Each new test asserts on the on-disk end state, not just "did not throw".

Recommendation: APPROVE

No blockers. The deletion logic is sound and every behaviour change is pinned by a test that fails when it is reverted. Nits 1 to 3 are optional and can ride along or be dropped.

@mstomar125 mstomar125 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated pragmatic-code-review (re-review): APPROVE (posted as a comment, GitHub blocks self-approval). Full findings in the review comment above.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Address-review summary (round 2)

The re-review of 06fdd553 came back APPROVE: 0 critical, 0 improvements, 3 optional nits. Commit 2573da27 takes two of them.

Addressed

Nit Change Test (fails when the change is reverted)
Pruning could remove a symlinked directory on Windows (rmdir removes the link even when the target is not empty) pruneEmptyParents returns at a symlinked directory. An uninstall whose references is a symlink to an outside directory, run against a rmdirSync that emulates the Windows behaviour, leaves the link and its target alone.
A swallowed package-read failure in a record-less uninstall was silent It now writes a one-line WARNING to stderr saying the cleanup is partial. The existing unreadable-package test now asserts the warning.

Skipped

  • Duplicate entries in a hand-edited record are rewritten as they were. Real records never contain duplicates (they are written from a set of distinct paths), so this only shows up after someone hand-edits the file, and the cost is a repeated warning. Revisit if a record is ever merged from more than one source.
  • The two "no action needed" observations (an lstat/realpath error on an unreadable parent reads as "already gone"; the reinstall half of the undeletable-file scenario is covered by composition and the manual run). Both need a directory the user made unreadable, and the second was verified by hand with a real chmod 555.

Verification

  • bun run test:changed passed on the pushed head 2573da27: skill package, scripts, and the Rust workspace (nextest).
  • Skill package: 131 tests. Scripts: 970 tests. tsc is clean for packages/skill (src and shims) and scripts/.
  • Both new behaviours were mutation-checked, and the whole mutation set was re-run on the final code: 42 mutations, 41 caught by their intended tests, 1 equivalent mutant (dropping the explicit Array.isArray check on the record still yields "no record" through the surrounding try/catch).
  • Ratchet: the count table on this branch equals the table on its merge-base (271 / 368 / 95 / 81 / 54 / 104 / 203 / 0 / 72 / 463 / 275 / 18); no marker added or removed; BASELINES untouched.

Re-Review Decision

Decision: NO RE-REVIEW NEEDED

Rationale: The reviewer approved with no critical findings or improvements. Both changes in 2573da27 only make the installer delete less (a symlink guard) or say more (a warning), and each is pinned by a test that fails when reverted. Nothing is pushed after this comment. The PR is ready for the merge gate; the branch is issue-3368-skill-install-record at 2573da27, based on 0d82377b (main has since moved on two commits with no overlapping files).

mstomar125 and others added 3 commits September 30, 2026 14:49
…iles (closes #3368)

Install every references/*.md in the skill being installed instead of naming
references in each agent's shims. Each install writes .nodespace-install.json
in the agent's install directory, listing exactly the files it wrote. Uninstall
removes the files the record names; a reinstall removes any recorded file the
new skill no longer ships. Entries are deleted only when they are regular files
that resolve inside the install directory.

An install with no record is read as the files installers wrote before records
existed (PRE_RECORD_REFERENCES plus SKILL.md and the harness shim), for both
uninstall and reinstall. uninstall takes the package root, and the CLI passes
its --resource-root.

The public skill repository's file list comes from the same directory, so the
work-tracking playbooks SKILL.md links to are now installed and published.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…s, key installs on SKILL.md

- A stale file that cannot be deleted during a reinstall stays in the record
  and is reported on stderr; the install carries on instead of aborting. The
  record is written once, after the stale pass.
- A package without SKILL.md installs nothing and leaves an existing install
  and its record alone (previously only a package with no files at all did).
- A recorded symlink is unlinked, never followed; a symlinked parent that
  leads outside the install directory is still refused.
- Uninstall no longer crashes when the install directory is an emptied
  symlink, and prunes the directories of recorded files already deleted by
  hand.
- A record-less uninstall no longer aborts when the package's references/
  directory cannot be read.

Not changed: a case-only rename of a shipped reference on a case-insensitive
filesystem, and the stale comment in the release workflow (touching it would
run every test tier for a comment).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…record-less uninstall

- pruneEmptyParents leaves a symlinked directory alone. On Windows rmdir would
  remove the link itself even though the directory behind it is not empty.
- A record-less uninstall that cannot read the package's references/ still
  removes the pre-record files, and now says on stderr that the cleanup is
  partial.

Not changed: duplicate entries in a hand-edited record are rewritten as they
were (cosmetic; real records never contain them).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@mstomar125
mstomar125 force-pushed the issue-3368-skill-install-record branch from 2573da2 to e7677c0 Compare September 30, 2026 12:49
@mstomar125
mstomar125 merged commit 358882c into main Sep 30, 2026
@mstomar125
mstomar125 deleted the issue-3368-skill-install-record branch September 30, 2026 12:49
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.

Install skill references from the staged directory and record installed files

1 participant