Repository navigation
fix(agent-core-v2): honor .gitignore in fd file suggestions outside git - #5452
Merged
Merged
Conversation
fd applies .gitignore files only inside a git repository unless it is given --no-require-git, while the ripgrep and filesystem strategies apply them everywhere. With fd installed, a suggestion request that follows .gitignore in a plain directory listed ignored files. Pass --no-require-git, and when fd rejects its arguments, as releases before 8.7 do, fall back to the other strategies and stop using that fd for the session instead of returning no results.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
commit: |
5 of 6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requirement or Bug
文件建议在非 git 目录里,会因为本机有没有
fd而给出不同的结果。本机装了fd时,调用方要求遵守.gitignore(follow_gitignore: true),被忽略的文件照样会出现;没有fd、走 ripgrep 或文件系统遍历时则不会。node-sdk 的serves suggestFiles through the workspace handler fs service在装了fd的机器上稳定失败,CI 上没有fd,所以一直通过。Bug Reproduction Steps
.gitignore(内容为ignored-app.ts)、ignored-app.ts和src/app.ts。~/.kimi-code/bin里有fd(10.x)的机器上,用follow_gitignore: true请求app的文件建议(SDK 的suggestFiles默认就是这样)。ignored-app.ts。去掉fd后再请求,结果只有src/app.ts。Root Cause
fd默认只在 git 仓库里读取.gitignore,要在仓库外也读取,必须加--no-require-git。ripgrep 策略早就加了这个参数,文件系统遍历本来就读.gitignore,只有fd策略漏了。Code Changes
fdSuggest.ts:每次调用fd都加--no-require-git。fd会以退出码 2 拒绝参数,而原来的代码把任何非零退出都当成「没有结果」,文件建议会悄悄变空。现在退出码 2 会抛出FdArgumentsRejectedError,fsService接住后退回 ripgrep 或文件系统遍历,并在这个会话里不再使用这个fd。其他非零退出的处理不变。关键决策
.gitignore--no-require-git,说明这是有意的行为;改fd一处影响最小fdfd --version只对 8.7 以上加参数Behavior Changes and Affected Users
.gitignore的文件建议(VS Code 扩展的@补全,SDK 的suggestFiles默认)fd时列出被忽略的文件fd时一致followGitignore: false即可包含被忽略的文件@补全、桌面端和 Web 的输入框)fd时,被忽略的文件和普通文件混排fd(拒绝参数时)fdchangeset:
@moonshot-ai/agent-core-v2(技术条目),CLI、VS Code 扩展、桌面端各一条。验证
只在 macOS 上验证过,Linux 交给 CI,Windows 没有验证。
fd的参数和退出码在各平台相同,这个改动不涉及路径处理。packages/agent-core-v2/test/project/projectFs:156 条通过。新增的两条用例在还原产品代码后都失败:一条断言每次调用fd都带--no-require-git,一条模拟以退出码 2 拒绝参数的旧版fd,断言结果退回遵守.gitignore的策略、第二次请求不再调用fd。suggestFiles用例修复前稳定失败,修复后通过。packages/kap-server/test/fs.test.ts、packages/app-core/test/daemon-client.test.ts、apps/kimi-code/test/tui/kimi-tui-startup.test.ts共 328 条通过。pnpm lint通过。Checklist
/approve).gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.