Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions sdk/src/__tests__/list-project-files.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
14 changes: 9 additions & 5 deletions sdk/src/tools/list-project-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand Down
Loading