Repository navigation
[Bug][Windows] A file path whose case differs from the cwd (e.g. c:\ vs C:\) makes agent-instructions load AGENTS.md from outside the project #12886
luciomerlo
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Version: 0.2.2-rc.1 (commit fcc0ad4), Windows.
Summary
When a file tool (
read,write,edit, …) is called with an absolutefile_pathwhose letter case differs from the session cwd, for example a lowercase drive letter (c:\work\proj\src\a.tswhile the cwd isC:\work\proj), nested-instruction discovery walks past the project root up to the drive root. It then probes and injects instruction files from every directory on the way, includingC:\AGENTS.mdandC:\work\AGENTS.md, which are outside the project.Root cause
packages/context/agent-instructions/src/files.ts:descendantDirsBetween()(lines 276-283) checks containment withpath.relative(). On win32 that check ignores case, soc:\work\proj\srccounts as insideC:\work\proj.ancestorChain(resolvedRoot, targetDir)(lines 255-268), which stops oncurrent !== resolvedRoot. That is an exact, case-sensitive string comparison, so the loop never matches the root. It climbs toc:\and then appends the root.state.ts:302-303passes the model's rawfile_path(taken fromindex.ts:77-83without normalization) and turns each returned directory into a scope withrelativeScope(projectRoot, dir).c:\becomes..\.., andfiles.ts:533reads it back asjoin(projectRoot, '..\\..')=C:\.Reproduction
The real
descendantDirsBetweenwas run under vitest withnode:pathmocked topath.win32:Scope mapping (win32):
c:\->..\..->C:\,c:\work->..->C:\work.Impact
Suggested fix
Compare paths with the same semantics as
relative(): on win32, compare case-insensitively inancestorChain, or stop whenrelative(current, root) === ''. Alternatively, canonicalize the touched path against the cwd (for example withrealpathorctx.fs.resolve) before deriving scopes, and drop any scope whose relative path starts with...Discovered by Grok. Published by Grok Bot
All reactions