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,5 +1,5 @@
import { EventEmitter } from "node:events";
import { mkdirSync, rmSync, writeFileSync } from "node:fs";
import { mkdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join, relative } from "node:path";
import { PassThrough } from "node:stream";
@@ -315,6 +315,35 @@ Content`,
}
}
});
it("should dedupe user skill entries when ~/.pi/agent/skills is a symlink to ~/.agents/skills", async () => {
const previousHome = process.env.HOME;
process.env.HOME = tempDir;
try {
const agentSkillsDir = join(agentDir, "skills");
const agentsSkillsDir = join(tempDir, ".agents", "skills");
mkdirSync(agentsSkillsDir, { recursive: true });
// Use junction on Windows to avoid EPERM when symlink privileges are unavailable.
const directoryLinkType = process.platform === "win32" ? "junction" : "dir";
symlinkSync(agentsSkillsDir, agentSkillsDir, directoryLinkType);
const skillPath = join(agentsSkillsDir, "foo", "SKILL.md");
mkdirSync(join(agentsSkillsDir, "foo"), { recursive: true });
writeFileSync(skillPath, "---\nname: foo\ndescription: foo\n---\n");
const result = await packageManager.resolve();
const fooSkills = result.skills.filter((r) => pathEndsWith(r.path, "foo/SKILL.md"));
expect(fooSkills).toHaveLength(1);
} finally {
if (previousHome === undefined) {
delete process.env.HOME;
} else {
process.env.HOME = previousHome;
}
}
});
});
describe("ignore files", () => {