@@ -32,6 +32,7 @@ import {
3232 rmSync ,
3333 statSync ,
3434 symlinkSync ,
35+ unlinkSync ,
3536} from "node:fs" ;
3637import { homedir } from "node:os" ;
3738import { basename , dirname , isAbsolute , join , relative , resolve , sep } from "node:path" ;
@@ -237,6 +238,23 @@ function mirrorInto(
237238 return { mirrored : true } ;
238239}
239240
241+ /**
242+ * Unlink symlinks an earlier mirror left in `targetDir` (they resolve to the same source skill).
243+ * Real dirs and Windows copies carry no ownership proof, so they stay.
244+ */
245+ function removeMirrorLinks ( targetDir : string , source : string , skills : string [ ] ) : void {
246+ for ( const skill of skills ) {
247+ const targetSkill = join ( targetDir , skill ) ;
248+ try {
249+ if ( ! lstatSync ( targetSkill ) . isSymbolicLink ( ) ) continue ;
250+ if ( realpathSync ( targetSkill ) !== realpathSync ( join ( source , skill ) ) ) continue ;
251+ unlinkSync ( targetSkill ) ;
252+ } catch {
253+ // absent or dangling: nothing of ours to remove
254+ }
255+ }
256+ }
257+
240258/**
241259 * Mirror the global Claude store into every installed agent's global skills
242260 * dir. Best-effort and idempotent: a no-op when the store is absent, and per
@@ -283,7 +301,11 @@ export function mirrorGlobalSkills(opts: {
283301 for ( const { agent, base, sub } of AGENT_GLOBAL_DIRS ) {
284302 const targetDir = join ( bases [ base ] , ...sub . split ( "/" ) . filter ( Boolean ) ) ;
285303 if ( targetDir === source || targetDir === universalStore ) continue ; // install-owned
286- if ( UNIVERSAL_STORE_READERS . has ( agent ) ) continue ; // already reads the universal store (#3294)
304+ if ( UNIVERSAL_STORE_READERS . has ( agent ) ) {
305+ // Already reads the universal store (#3294); drop links an older version mirrored here.
306+ removeMirrorLinks ( targetDir , source , skills ) ;
307+ continue ;
308+ }
287309 if ( ! existsSync ( dirname ( targetDir ) ) ) continue ; // agent not installed (no marker)
288310 const attempt = mirrorInto ( targetDir , source , skills , platform , ( ) =>
289311 targetSafety ( targetDir , resolvedProtectedPaths ) ,
0 commit comments