Skip to content

fix(agent-core-v2): honor .gitignore in fd file suggestions outside git - #5452

Merged
RealKai42 merged 2 commits into
mainfrom
fix/fd-suggest-gitignore-outside-git
Nov 25, 2026
Merged

RealKai42 merged 2 commits into
mainfrom
fix/fd-suggest-gitignore-outside-git

Conversation

@RealKai42

Copy link
Copy Markdown
Collaborator

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

  1. 在一个不是 git 仓库的目录里放 .gitignore(内容为 ignored-app.ts)、ignored-app.ts 和 src/app.ts。
  2. 在 PATH 或 ~/.kimi-code/bin 里有 fd(10.x)的机器上,用 follow_gitignore: true 请求 app 的文件建议(SDK 的 suggestFiles 默认就是这样)。
  3. 结果里有 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 8.7 才有的(Debian 12 的 fd-find 是 8.6,Ubuntu 22.04 是 8.3)。旧版 fd 会以退出码 2 拒绝参数,而原来的代码把任何非零退出都当成「没有结果」,文件建议会悄悄变空。现在退出码 2 会抛出 FdArgumentsRejectedError,fsService 接住后退回 ripgrep 或文件系统遍历,并在这个会话里不再使用这个 fd。其他非零退出的处理不变。

关键决策

决策 选择 没选 理由
仓库外是否遵守 .gitignore 遵守,和 ripgrep、文件系统遍历一致 让三种策略都只在仓库内遵守 ripgrep 策略显式加了 --no-require-git,说明这是有意的行为;改 fd 一处影响最小
旧版 fd 按退出码 2 识别参数被拒,退回其他策略 解析 fd --version 只对 8.7 以上加参数 退出码 2 是 fd 用来报告参数错误的固定约定,不必维护版本表;也顺带覆盖了更老的 fd 不认其他参数的情况

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
非 git 目录、遵守 .gitignore 的文件建议(VS Code 扩展的 @ 补全,SDK 的 suggestFiles 默认) 装了 fd 时列出被忽略的文件 不列出,和没有 fd 时一致 无:这是一个策略相关的不一致 调用方传 followGitignore: false 即可包含被忽略的文件
非 git 目录、包含被忽略文件的文件建议(CLI 的 @ 补全、桌面端和 Web 的输入框) 装了 fd 时,被忽略的文件和普通文件混排 被忽略的文件排在同等匹配的普通文件之后,和 git 仓库内一致 无 —
旧版 fd(拒绝参数时) 文件建议为空 退回 ripgrep 或文件系统遍历,本会话不再用这个 fd 无 —

changeset:@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。
  • 真实入口:本机装有 fd 10.4.2,node-sdk 的 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 条通过。
  • 用本机的 fd 10.4.2 核对过退出码:没有匹配是 0,正则错误是 1,参数错误是 2。
  • 类型检查:agent-core-v2 通过。pnpm lint 通过。

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue (external PRs: issue must have a maintainer's /approve).
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete, and every removed behavior or flipped default is named in the changeset and either has an escape hatch or was explicitly approved by a maintainer in this PR.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T17:25:22.822617Z 1eb1d5c PR opened
🔒 Security Review ✅ Completed 2026-11-25T17:26:37.512422Z 1eb1d5c PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@1eb1d5c
npx https://pkg.pr.new/@moonshot-ai/kimi-code@1eb1d5c

commit: 1eb1d5c

@RealKai42
RealKai42 merged commit 90c3ca6 into main Nov 25, 2026
22 checks passed
@RealKai42
RealKai42 deleted the fix/fd-suggest-gitignore-outside-git branch November 25, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant