diff --git a/sdk/src/__tests__/list-project-files.test.ts b/sdk/src/__tests__/list-project-files.test.ts index 9fa6a6f36a..28cf55880a 100644 --- a/sdk/src/__tests__/list-project-files.test.ts +++ b/sdk/src/__tests__/list-project-files.test.ts @@ -163,6 +163,23 @@ describe('listProjectFilesWithRipgrep', () => { expect(await listWithRipgrep(root)).toEqual(walked) }) + it('honors agent re-includes of default-ignored directories', async () => { + const root = project({ + '.gitignore': 'ignored.ts\n', + '.codebuffignore': '!node_modules\n!node_modules/**\nblocked.ts\n', + 'node_modules/pkg/index.ts': 'export const dependency = true\n', + 'node_modules/pkg/blocked.ts': '', + 'ignored.ts': '', + 'src/index.ts': '', + }) + const walked = await walkEverything(root) + expect(walked).toContain('node_modules/pkg/index.ts') + expect(walked).not.toContain('node_modules/pkg/blocked.ts') + expect(walked).not.toContain('ignored.ts') + + expect(await listWithRipgrep(root)).toEqual(walked) + }) + for (const agentDir of ['', 'packages/web/']) { it(`re-includes what .gitignore excluded when ${agentDir || 'the root'}'s .codebuffignore says so`, async () => { const root = project({ diff --git a/sdk/src/tools/list-project-files.ts b/sdk/src/tools/list-project-files.ts index 642f0ee571..555d3f1447 100644 --- a/sdk/src/tools/list-project-files.ts +++ b/sdk/src/tools/list-project-files.ts @@ -74,8 +74,8 @@ export async function listProjectFiles(params: { * `!.env.example` there still re-includes, as in the walker. * - It cannot read `.codebuffignore` or `.manicodeignore`. When one of those * re-includes with `!`, possibly something `.gitignore` excluded, the - * listing is redone without `.gitignore` pruning. Such a file is found only - * where something else is listed beside or below it. + * listing is redone without Git or built-in directory pruning. Such a file + * is found only where something else is listed beside or below it. * The chain is per path, so it runs after `select`: a narrow glob pays for * its matches, not for the whole project. Undefined when ripgrep cannot run; * the caller then walks. A cancelled `signal` rejects with its reason instead, @@ -203,10 +203,14 @@ async function listCandidates( '--no-ignore-parent', // `ignore` matches case-insensitively by default. '--ignore-file-case-insensitive', - // Lowest precedence, below every .gitignore, as the walker's defaults - // are. + ] + // Lowest precedence, below every .gitignore, as the walker's defaults are. + const pruned = [ + ...args, ...(defaultsFile ? ['--ignore-file', defaultsFile] : []), ] + // Agent rules may re-include built-in exclusions too. The final ignore + // chain decides which of these candidates the caller can see. const unpruned = [...args, '--no-ignore-vcs'] const run = (rgArgs: string[]) => runRipgrepFiles(rgPath, rgArgs, projectRoot, signal) @@ -217,7 +221,7 @@ async function listCandidates( ...AGENT_IGNORE_FILES, ]) if (reincludesAtRoot) return run(unpruned) - const listing = await run(args) + const listing = await run(pruned) if (!listing) return undefined // Whether a nested agent ignore file re-includes needs every ignore file, // not just those above the paths a caller selects.