Skip to content

fix(cli): relink dangling agent instruction symlinks instead of crashing - #3544

Merged
fengmk2 merged 2 commits into
voidzero-dev:mainfrom
thejesh23:fix/agent-dangling-symlink
Nov 23, 2026
Merged

fengmk2 merged 2 commits into
voidzero-dev:mainfrom
thejesh23:fix/agent-dangling-symlink

Conversation

@thejesh23

Copy link
Copy Markdown
Contributor

vp migrate --agent agents,claude (and vp create with the same targets) crashes with an uncaught EEXIST when CLAUDE.md is a dangling symlink, for example one that points at a shared file that isn't checked out:

$ ln -s ../shared/CLAUDE.md CLAUDE.md          # target missing
$ vp migrate --no-interactive --agent agents,claude --no-editor --no-hooks
    at async writeAgentInstructions (.../vite-plus/dist/agent-Bdqqkb0O.js:303:8)
    at async main (.../vite-plus/dist/migration/bin.js:5619:4) {
  errno: -17,
  code: 'EEXIST',
  syscall: 'symlink',
  path: 'AGENTS.md',
  dest: '.../CLAUDE.md'
}
exit=1

getExistingPathKind in packages/cli/src/utils/agent.ts checks fs.existsSync first. existsSync follows symlinks, so a dangling link counts as missing. tryLinkTargetToAgents then calls fsPromises.symlink() over the existing link, and only EPERM is caught.

This PR uses lstat instead, so a dangling link takes the existing symlink branch: it is unlinked and relinked to AGENTS.md, the same as a link that points somewhere else.

The in-memory fs in agent.spec.ts didn't match node:fs here: its existsSync didn't follow links and its symlink() silently overwrote an existing path. It now follows links in existsSync, throws EEXIST from symlink() over an existing path, and sets code: 'ENOENT' on its not-found errors. The new test "relinks a dangling agent file symlink to AGENTS.md" fails with EEXIST before the fix and passes after it. I also ran writeAgentInstructions against a real temp directory with a dangling CLAUDE.md link: before the fix it throws EEXIST, after it CLAUDE.md links to AGENTS.md.

Validation (macOS arm64, Node 24.22.3). I couldn't build the monorepo locally (no Rust toolchain, rolldown/vite not synced), so I ran the checks with the published vite-plus@1.7.0 toolchain against this checkout:

  • vp test run packages/cli/src: no new failures. The failing files are the same as on unmodified main in this setup, because of missing workspace builds (for example @voidzero-dev/vite-task-client) and vi.spyOn on the npm build of @voidzero-dev/vite-plus-prompts. Those failures are unrelated to this change.
  • vp fmt --check and vp lint --type-aware --type-check on the changed files: clean.

🤖 Generated with Claude Code

@fengmk2 fengmk2 self-assigned this Nov 23, 2026

@fengmk2 fengmk2 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@thejesh23 Thanks!

@fengmk2 fengmk2 added test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: create-e2e Run `vp create` e2e tests labels Nov 23, 2026
thejesh23 and others added 2 commits November 23, 2026 13:59
getExistingPathKind used fs.existsSync, which follows symlinks, so a
dangling CLAUDE.md symlink was reported as missing. tryLinkTargetToAgents
then called symlink() over it and vp migrate/create crashed with an
uncaught EEXIST. Use lstat so the dangling link takes the existing
symlink branch and is relinked to AGENTS.md.

The in-memory fs in agent.spec.ts now follows symlinks in existsSync,
throws EEXIST from symlink() over an existing path and sets error codes,
matching node:fs.
@fengmk2
fengmk2 force-pushed the fix/agent-dangling-symlink branch from 42d80d4 to 56cbf75 Compare November 23, 2026 06:03
@fengmk2
fengmk2 merged commit a9b6a32 into voidzero-dev:main Nov 23, 2026
118 of 120 checks passed
@fengmk2 fengmk2 mentioned this pull request Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test: create-e2e Run `vp create` e2e tests test: e2e Auto run e2e tests test: install-e2e run vite install e2e test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants