fix(coding-agent): avoid duplicate symlinked skills in pi config (#3417)

- dedupe resolved skill entries by canonical path (realpathSync) with raw-path fallback matching loadSkills()

- preserve precedence by applying skill dedupe after resource precedence sorting (first winner retained)

- add tests to verify expected behavior

- closes #3405
This commit is contained in:
Ramiz Wachtler
2026-04-20 13:23:00 +02:00
committed by GitHub
parent cbe0e8304f
commit 2b45243817
3 changed files with 64 additions and 3 deletions

View File

@@ -1,6 +1,15 @@
import { type ChildProcess, type ChildProcessByStdio, spawn, spawnSync } from "node:child_process";
import { createHash } from "node:crypto";
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
import {
existsSync,
mkdirSync,
readdirSync,
readFileSync,
realpathSync,
rmSync,
statSync,
writeFileSync,
} from "node:fs";
import { homedir, tmpdir } from "node:os";
import { basename, dirname, join, relative, resolve, sep } from "node:path";
import type { Readable } from "node:stream";
@@ -2190,9 +2199,28 @@ export class DefaultPackageManager implements PackageManager {
return resolved;
};
const seenCanonicalSkillPaths = new Set<string>();
const resolvedSkills = toResolved(accumulator.skills).filter((entry) => {
let canonicalPath: string;
try {
// Resolve symlink aliases to detect duplicate files.
canonicalPath = realpathSync(entry.path);
} catch {
// Fallback to raw path to match loadSkills() behavior.
canonicalPath = entry.path;
}
if (seenCanonicalSkillPaths.has(canonicalPath)) {
return false;
}
seenCanonicalSkillPaths.add(canonicalPath);
return true;
});
return {
extensions: toResolved(accumulator.extensions),
skills: toResolved(accumulator.skills),
skills: resolvedSkills,
prompts: toResolved(accumulator.prompts),
themes: toResolved(accumulator.themes),
};