Skip to content

Commit 3ad7a2d

Browse files
committed
fix: simplify symlink resolution for AGENTS.md to fix Windows compatibility
- Remove duplicate resolveSymlinkPath function as suggested by @mrubens - Use simpler inline symlink resolution in loadAgentRulesFile - Update tests to match simplified implementation - This should fix the failing Windows unit tests while maintaining functionality
1 parent 8bdf36a commit 3ad7a2d

File tree

2 files changed

+14
-43
lines changed

2 files changed

+14
-43
lines changed

src/core/prompts/sections/__tests__/custom-instructions.spec.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,11 +674,6 @@ describe("addCustomInstructions", () => {
674674
return Promise.resolve({
675675
isSymbolicLink: vi.fn().mockReturnValue(true),
676676
})
677-
} else if (pathStr.endsWith("actual-agents-file.md")) {
678-
// The resolved target is not a symlink
679-
return Promise.resolve({
680-
isSymbolicLink: vi.fn().mockReturnValue(false),
681-
})
682677
}
683678
return Promise.reject({ code: "ENOENT" })
684679
})

src/core/prompts/sections/custom-instructions.ts

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,6 @@ async function safeReadFile(filePath: string): Promise<string> {
2626
}
2727
}
2828

29-
/**
30-
* Resolve a symlink to its target path
31-
*/
32-
async function resolveSymlinkPath(symlinkPath: string, depth: number = 0): Promise<string> {
33-
// Avoid cyclic symlinks
34-
if (depth > MAX_DEPTH) {
35-
throw new Error(`Maximum symlink depth exceeded for ${symlinkPath}`)
36-
}
37-
38-
try {
39-
// Check if the path is a symlink
40-
const stats = await fs.lstat(symlinkPath)
41-
if (!stats.isSymbolicLink()) {
42-
// Not a symlink, return the original path
43-
return symlinkPath
44-
}
45-
46-
// Get the symlink target
47-
const linkTarget = await fs.readlink(symlinkPath)
48-
// Resolve the target path (relative to the symlink location)
49-
const resolvedTarget = path.resolve(path.dirname(symlinkPath), linkTarget)
50-
51-
// Check if the resolved target is also a symlink (handle nested symlinks)
52-
const targetStats = await fs.lstat(resolvedTarget)
53-
if (targetStats.isSymbolicLink()) {
54-
// Recursively resolve nested symlinks
55-
return resolveSymlinkPath(resolvedTarget, depth + 1)
56-
}
57-
58-
return resolvedTarget
59-
} catch (err) {
60-
// If we can't resolve the symlink, return the original path
61-
return symlinkPath
62-
}
63-
}
64-
6529
/**
6630
* Check if a directory exists
6731
*/
@@ -258,8 +222,20 @@ export async function loadRuleFiles(cwd: string): Promise<string> {
258222
async function loadAgentRulesFile(cwd: string): Promise<string> {
259223
try {
260224
const agentsPath = path.join(cwd, "AGENTS.md")
261-
// Resolve symlinks if necessary
262-
const resolvedPath = await resolveSymlinkPath(agentsPath)
225+
let resolvedPath = agentsPath
226+
227+
// Check if the file is a symlink and resolve it if necessary
228+
try {
229+
const stats = await fs.lstat(agentsPath)
230+
if (stats.isSymbolicLink()) {
231+
const linkTarget = await fs.readlink(agentsPath)
232+
resolvedPath = path.resolve(path.dirname(agentsPath), linkTarget)
233+
}
234+
} catch (err) {
235+
// If we can't check symlink status, just use the original path
236+
resolvedPath = agentsPath
237+
}
238+
263239
// Read the file content
264240
const content = await safeReadFile(resolvedPath)
265241
if (content) {

0 commit comments

Comments
 (0)