Repository navigation
feat: include gitignored files in file suggestions - #4752
Conversation
🦋 Changeset detectedLatest commit: a8cd5f4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
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: |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e58e8ad93c
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| 100, | ||
| options.signal, | ||
| undefined, | ||
| true, |
There was a problem hiding this comment.
Avoid capping the ignored fd pass before exact matches
When more than 100 ordinary paths match the query, this supplemental fd invocation can exhaust --max-results 100 before emitting an exact gitignored file, so the feature still omits the best ignored match. For example, with 150 tracked weak-zzz-*.ts files and an ignored file named zzz, the no-ignore invocation returns 100 weak files and never returns zzz; deduplication then adds nothing. The ignored pass needs to avoid being consumed by already-seen ordinary results or search deeply enough to select the global top 20.
AGENTS.md reference: packages/pi-tui/AGENTS.md:L3-L5
Useful? React with 👍 / 👎.
| if (!query.followGitignore && (matched <= cap || top.worst?.tier !== 3) && !signal.aborted && Date.now() < deadline) { | ||
| await runPass(true); |
There was a problem hiding this comment.
Preserve time for the ignored fallback scan
In an environment without ripgrep, a large or slow workspace can consume the entire 10-second deadline during the ordinary first pass, making this condition false and preventing the no-ignore pass from running at all. This regresses explicit follow_gitignore: false callers: the old single no-ignore walk could return an ignored entry encountered early, while the new path always spends the budget excluding it first. Split or interleave the budget so ignored candidates remain reachable before the shared deadline.
AGENTS.md reference: AGENTS.md:L125-L127
Useful? React with 👍 / 👎.
| if (preview.items.length === 0) { | ||
| this.autocompleteList = undefined; | ||
| } else { |
There was a problem hiding this comment.
Keep autocomplete controls active for an empty preview
When appended text filters the preview to zero items, this removes the list but leaves autocompleteState active until the trailing request completes. During that interval, the input handler skips both the list-control branch and the !autocompleteState Tab branch, so Tab is silently ignored and Escape cannot cancel the picker; for a slow remote request this can last seconds rather than only the 80 ms debounce. Clear the autocomplete state with the list or teach the no-list pending state to handle these controls.
AGENTS.md reference: packages/pi-tui/AGENTS.md:L11-L15
Useful? React with 👍 / 👎.
| if (signal.aborted) break; | ||
| const git = resolveCommandPath('git', root); | ||
| if (git === undefined) continue; | ||
| const result = spawnSync(git, ['check-ignore', '--no-index', '--stdin', '-z'], { |
There was a problem hiding this comment.
Do not block the TUI while classifying ignored files
Whenever fd is unavailable, every authoritative @ completion now runs git check-ignore through spawnSync on the editor's event-loop thread. The call can block for its full one-second timeout for each workspace root, cannot react to the autocomplete abort signal, and the initial bare @ request runs immediately, so a slow repository or several additional roots freeze input and rendering for multiple seconds. Use an asynchronous child process or cached classification instead.
Useful? React with 👍 / 👎.
| if (!seenDirs.has(dirKey)) { | ||
| seenDirs.add(dirKey); | ||
| const candidate = evaluateSuggestCandidate(dir, 'directory', query); | ||
| const candidate = evaluateSuggestCandidate(dir, 'directory', query, ignored); | ||
| if (candidate !== null) { |
There was a problem hiding this comment.
Classify derived directories independently from ignored children
In the ripgrep path, every directory derived during the supplemental pass inherits ignored: true from the child file, even when only the contents are ignored. For example, with .gitignore containing build/* and only build/generated.js present, the ordinary pass emits nothing under build, while the no-ignore pass derives build here and ranks it as ignored although the directory itself is not ignored. Under a tight result cap, ordinary exact matches can therefore displace this directory; before the change, the single no-ignore pass ranked it normally. Determine the directory's own ignore status rather than inheriting the pass label.
AGENTS.md reference: AGENTS.md:L125-L127
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e9aa27d3d5
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (!(await this.hostFs.stat(candidate)).isDirectory) continue; | ||
| scoped.push({ ...root, baseDir: root.dir, dir: candidate, scanBase, scoped: true }); |
There was a problem hiding this comment.
Reject external symlinks before narrowing search roots
When a slash-containing query names a symlink to a directory outside the workspace, stat() follows the link and this code promotes it to a search root. Both the explicit ripgrep path and the Node walk then enumerate the external target; for example, link/secret can reveal filenames under an out-of-workspace directory even though normal filesystem operations reject external symlinks unless explicitly allowed. Validate the candidate's real path against the configured roots before scoping to it.
AGENTS.md reference: AGENTS.md:L125-L127
Useful? React with 👍 / 👎.
| const candidate = this.path.resolve(root.dir, scanBase); | ||
| try { | ||
| if (!(await this.hostFs.stat(candidate)).isDirectory) continue; | ||
| scoped.push({ ...root, baseDir: root.dir, dir: candidate, scanBase, scoped: true }); |
There was a problem hiding this comment.
Preserve parent ignore rules in scoped fallback scans
When ripgrep is unavailable or fails, a slash query that resolves to an existing subdirectory changes the Node walk root here, so the later walkIgnoreFor(root.dir) reads only that subdirectory's .gitignore. With a root rule such as build/**, follow_gitignore: true plus query build/generated now returns build/generated.js, whereas the previous root-level walk filtered it; keep ignore matching anchored to baseDir while scanning the narrower directory.
AGENTS.md reference: AGENTS.md:L125-L127
Useful? React with 👍 / 👎.
| const candidate = this.path.resolve(root.dir, scanBase); | ||
| try { | ||
| if (!(await this.hostFs.stat(candidate)).isDirectory) continue; | ||
| scoped.push({ ...root, baseDir: root.dir, dir: candidate, scanBase, scoped: true }); |
There was a problem hiding this comment.
Preserve workspace-wide fuzzy path matching
When the first query segment happens to name an existing directory, this scopes the scan to that directory even though path queries are fuzzy subsequence matches rather than anchored prefixes. For example, if apps/ exists but the valid match is examples/apps/demo.ts, querying apps/de previously found that file through matchSuggestPath; the scoped scan now searches only apps/ and can return nothing. Keep the workspace-wide fallback or merge it with scoped results so an optimization does not narrow the accepted query semantics.
AGENTS.md reference: AGENTS.md:L125-L127
Useful? React with 👍 / 👎.
| for (let length = segments.length; length >= 1; length -= 1) { | ||
| const scanBase = segments.slice(0, length).join('/'); | ||
| const candidate = this.path.resolve(root.dir, scanBase); | ||
| try { | ||
| if (!(await this.hostFs.stat(candidate)).isDirectory) continue; |
There was a problem hiding this comment.
Bound prefix probing by the suggestion deadline
For a slash-containing query with many nonexistent suffix segments, this loop performs one awaited stat per progressively shorter prefix and per workspace root, while the 10-second deadline is not created until after scopeSuggestRoots returns. On remote filesystems each probe is an RPC, so a long pasted or API-supplied path can keep fs:suggest running far beyond its advertised timeout. Start the deadline before probing and abort or cap these sequential lookups.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5c477e35d1
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| let capped = false; | ||
| for (const root of roots) { | ||
| const matcher = req.follow_gitignore ? await this.matcherFor(root.dir) : undefined; | ||
| const matcher = await this.matcherFor(root.dir); |
There was a problem hiding this comment.
Avoid caching ignore rules during unignored requests
When a long-lived workspace first makes a request with follow_gitignore: false, this unconditional matcher lookup now populates gitignoreCache; if .gitignore is then edited, a subsequent explicit follow_gitignore: true request reuses the stale rules and silently returns newly ignored paths. Before this change, unignored requests used WALK_DEFAULT_IGNORE without populating that cache. The same new behavior occurs in the non-empty search and Node suggestion passes, so either invalidate/version the cache when .gitignore changes or avoid caching rules merely to classify an unfiltered scan.
AGENTS.md reference: AGENTS.md:L109-L111
Useful? React with 👍 / 👎.
| if (signal.aborted) break; | ||
| const git = resolveCommandPath('git', root); | ||
| if (git === undefined) continue; | ||
| const result = spawnSync(git, ['check-ignore', '--no-index', '--stdin', '-z'], { |
There was a problem hiding this comment.
Classify ignored files outside Git repositories
When fd is unavailable in a non-Git workspace that still has a .gitignore, git check-ignore --no-index exits 128 because it requires a repository, and this branch consequently leaves every candidate marked as non-ignored. Equal-quality ignored paths are then ordered alphabetically with ordinary paths and can displace them from the 50-item fallback result, contradicting the newly documented behavior for non-Git directories. Use an ignore classifier that can read .gitignore without requiring a .git directory.
Useful? React with 👍 / 👎.
| }) || inventoryTruncated; | ||
| const runPass = async (ignored: boolean): Promise<void> => { | ||
| for (const root of roots) { | ||
| const ignoreRules = ignored ? WALK_DEFAULT_IGNORE : await this.walkIgnoreFor(root.dir); |
There was a problem hiding this comment.
Apply nested ignore files in Node fallback ordering
When an ignored file is covered by a descendant rule such as a/.gitignore rather than the workspace-root .gitignore, this ordinary pass still emits and labels it as non-ignored because walkIgnoreFor(root.dir) only loads the root file. For example, equal-quality a/foo.ts (ignored by a/.gitignore) and z/foo.ts are sorted with a/foo.ts first, contrary to the new ordinary-before-ignored contract; this affects every fs:search request and fs:suggest when ripgrep is unavailable. Compose per-directory ignore rules or use an authoritative ignore-aware scanner for classification.
Useful? React with 👍 / 👎.
| if (VCS_METADATA_DIRS.has(queryLower.replace(/\/+$/, ''))) { | ||
| return { items: [], truncated: false }; |
There was a problem hiding this comment.
Preserve fuzzy matches for VCS-like query names
When the fuzzy query is exactly .git (or another configured VCS directory name), this new query-level short circuit returns no results at all, suppressing legitimate candidates such as .gitignore, .gitattributes, .gitkeep, and .github; remote TUI users therefore get an empty picker for @.git. Candidate-level filtering already excludes paths whose segment is actually .git, so retain that filtering without rejecting the entire fuzzy query. The same regression is present in search().
AGENTS.md reference: AGENTS.md:L109-L111
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1c8fe10c2
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| if (target.fdQuery.includes('/')) args.push('--full-path'); | ||
| if (target.fdQuery) args.push(fdPathQuery(target.fdQuery)); |
There was a problem hiding this comment.
Preserve fuzzy matching before filtering with fd
When fd is available, passing fdPathQuery(target.fdQuery) to fd filters the inventory using a contiguous regex before the existing fuzzy scorer sees it. An established subsequence query such as rdm previously matched README.md through evaluateSuggestCandidate, but fd emits no candidate for that query, so the same fs:suggest request now silently returns no result depending on whether fd is installed. Translate each query segment into the same subsequence semantics or avoid using the query to prefilter fd output.
AGENTS.md reference: AGENTS.md:L109-L111
Useful? React with 👍 / 👎.
| for (const binary of ['fd', 'fdfind']) { | ||
| const result = await probe.exec([binary, '--version']).catch(() => ({ exitCode: -1 })); | ||
| if (result.exitCode === 0) return { path: binary, source: 'system-path' }; |
There was a problem hiding this comment.
Resolve fd probes outside the workspace on Windows
On Windows, when the requested workspace contains an fd.exe or fdfind.exe, probing these bare command names with the workspace as cwd can execute that file before falling back to the managed binary. This is reachable from the new fs:suggest path, including its absolute-root endpoint, so merely requesting suggestions for an untrusted checkout can run repository-controlled code. Resolve PATH hits to trusted absolute paths, or run the probe from a directory that cannot be controlled by the workspace.
Useful? React with 👍 / 👎.
| '--base-directory', target.baseDir, | ||
| '--max-results', '100', | ||
| '--type', 'f', | ||
| '--type', 'd', | ||
| '--hidden', |
There was a problem hiding this comment.
Honor show_hidden in fd-backed suggestions
When fd is available, this unconditional --hidden makes show_hidden: false ineffective for every non-dot query, so a request such as query: "env", show_hidden: false can now return .env or files below hidden directories even though the same request still filters them in the ripgrep and Node paths. Because managed fd availability determines which behavior callers receive, preserve the existing option by passing the effective hidden setting into this backend rather than always enabling it.
AGENTS.md reference: AGENTS.md:L109-L111
Useful? React with 👍 / 👎.
| if (result.exitCode !== 0 || result.stdout.length === 0 || options.signal.aborted) { | ||
| return { target, entries: [], capped: false }; | ||
| } |
There was a problem hiding this comment.
Fall back when fd exits with an error
If an installed fd exits nonzero—for example because the selected root is unreadable or the installed version rejects one of these flags—this converts the error into an empty group, and suggestWithFdEvents then emits a successful empty final response. The surrounding suggest() fallback only runs when the fd path throws, so affected users silently lose all suggestions instead of reaching the existing ripgrep/Node implementation; propagate nonzero exits while retaining the empty-success handling for a genuine zero-exit no-match.
AGENTS.md reference: AGENTS.md:L125-L127
Useful? React with 👍 / 👎.
| if (stream) { | ||
| await sendSuggestStream(environmentFs, suggestRequest, reply, req.id); | ||
| } else { | ||
| const data = await environmentFs.fs.suggest(suggestRequest); | ||
| reply.send(okEnvelope(data, req.id)); |
There was a problem hiding this comment.
Describe the NDJSON response in the route contract
For stream: true, this branch hijacks the reply and returns application/x-ndjson, but the route still declares only success: { data: fsSuggestResponseSchema }, so /openapi.json advertises the ordinary JSON envelope for the newly exposed streaming input. External desktop/web clients generated or validated from that contract can consequently try to parse the multi-record body as one JSON response; expose the streaming media type and event schema in the route contract, or use a separately described streaming endpoint.
AGENTS.md reference: AGENTS.md:L121-L123
Useful? React with 👍 / 👎.
| } | ||
| yield { phase: 'final', response: await this.suggest(req, externalSignal) }; | ||
| } finally { |
There was a problem hiding this comment.
Reuse the original timeout in streamed fallback
When fd is unavailable or fails before the outer 10-second timer expires, this calls suggest() with externalSignal rather than the already deadline-bound signal; suggest() then starts a fresh 10-second timer. On a slow remote environment, the initial fd probes can therefore consume several seconds and the ripgrep/Node fallback can consume another full timeout, making a streamed suggestion request run well beyond the intended shared budget. Pass the combined outer signal or the original absolute deadline into the fallback.
Useful? React with 👍 / 👎.
| "@moonshot-ai/kimi-code": minor | ||
| --- | ||
|
|
||
| Align `fs:suggest` with local fd completion, using bounded scans and at most 20 results with optional streamed previews, while including hidden and gitignored paths by default and placing regular files first at equal match quality. |
There was a problem hiding this comment.
Name the fs:search default loss in the changeset
HTTP clients that omit follow_gitignore from fs:search previously filtered ignored paths and now include them, with explicit follow_gitignore: true as the escape hatch, but this changeset only names fs:suggest. As a result the release changelog gives existing search clients no warning that their default result set expands; update the user-facing sentence to name the lost filtering behavior and its explicit-true escape hatch.
AGENTS.md reference: AGENTS.md:L113-L115
Useful? React with 👍 / 👎.
- default file-search requests to include gitignored files while preserving explicit filtering - prioritize exact and prefix matches and reveal dot-prefixed queries - add release notes for the CLI and autocomplete changes
Short-circuit exact VCS queries and scope path searches to existing prefixes with fuzzy fallback. Push subsequence globs into ignored ripgrep passes while preserving hidden paths and ignore semantics.
e1c8fe1 to
ab0999a
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab0999a2eb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| const args = [ | ||
| options.fdBinary, | ||
| '--base-directory', target.baseDir, | ||
| '--max-results', '100', | ||
| '--type', 'f', | ||
| '--type', 'd', | ||
| '--hidden', | ||
| ]; |
There was a problem hiding this comment.
Enable fd gitignore filtering outside Git repositories
When fs:suggest runs in a non-Git directory that still has a .gitignore, this ordinary fd pass includes the ignored paths because it never passes --no-require-git; they are then recorded as ordinary candidates, so follow_gitignore: true does not filter them and false cannot rank them after regular files. Checked fdfind --help, which documents --no-require-git as the mode that respects Git ignore rules regardless of whether the search is inside a repository; the fd invocation in packages/pi-tui/src/autocomplete.ts has the same omission. Preserve the old Node-backed behavior by enabling that mode for the ordinary pass.
AGENTS.md reference: AGENTS.md:L125-L127
Useful? React with 👍 / 👎.
| '--type', 'f', | ||
| '--type', 'd', | ||
| '--hidden', |
There was a problem hiding this comment.
Include symlinks in fd-backed suggestions
When fd is available, these filters request only files and directories, so symlinks disappear from suggestions; this is especially visible for an empty query, which previously used suggestTopLevel() and returned top-level entries with kind: 'symlink'. Checked fdfind --help, which documents symlinks as a separate --type symlink category, so neither --type file nor --type directory includes them. Add the symlink type and preserve its kind so bare @ completion does not silently lose existing links.
AGENTS.md reference: AGENTS.md:L125-L127
Useful? React with 👍 / 👎.
Requirement or Bug
Kimi Code CLI 的
@文件补全和 kap-server 文件搜索调用方需要引用被.gitignore排除的构建产物、临时目录等文件。当前这些候选默认被过滤,即使显式纳入,也可能因排序和limit截断而找不到精确匹配;本 PR 让本地/远程补全与搜索能够返回这些文件,并保持高相关结果优先。Bug Reproduction Steps
N/A
Root Cause
N/A
Code Changes
核心思路是在候选选取阶段区分普通文件与忽略文件,而不是在最终响应上重排。各搜索路径先扫描普通候选,仅在启用忽略文件且现有结果仍可能包含更优匹配时补充 no-ignore 扫描,再去重并执行 Top-N;匹配质量始终是第一排序键,ignored 只是同一匹配质量内的次级键,因此精确的忽略目录不会被大量普通弱匹配挤出结果。
flowchart LR A[文件搜索或 @ 补全] --> B[普通候选扫描] B --> C{包含忽略文件且仍需补充?} C -- 否 --> F[排序并截取 Top-N] C -- 是 --> D[no-ignore 补充扫描] D --> E[去重并标记 ignored] E --> F F --> G[匹配质量优先,同质量普通文件优先]补充扫描复用原 deadline 和 abort signal。显式要求遵守
.gitignore的调用不会增加第二次扫描,响应结构也没有新增字段。fs:search与fs:suggest省略follow_gitignore时默认包含忽略文件,显式true仍过滤。ripgrep、Node fallback、空查询和多 root 共用相同的分组语义;非空搜索按 exact / prefix / weak 分层,点开头的 suggest 查询自动启用隐藏项匹配。@补全:本地 fd 路径通过默认关闭的includeGitignoredFiles扩展点补扫,Kimi 入口显式开启;无 fd 时在 Git 工作树内批量调用git check-ignore --no-index分类,失败时保留原有补全可用性。远程 TUI 显式请求包含忽略文件并保留服务端顺序,.git始终排除。SuggestFilesInput新增可选followGitignore。SDK 调用方省略时仍默认true,只有显式传false才包含忽略文件,避免扩大服务端默认值变化的影响面。@连续输入使用 80ms debounce,严格追加查询时先筛选上一轮权威结果,尾随搜索始终执行并替换预览;首次@和显式 Tab 仍立即请求,其他 provider 保持 20ms 和无预览行为。建议先读
packages/agent-core-v2/src/workspace/workspaceFs/fsService.ts理解两阶段选取,再读packages/pi-tui/src/autocomplete.ts和apps/kimi-code/src/tui/components/editor/file-mention-provider.ts看本地补全如何复用同一排序原则;packages/pi-tui/src/components/editor.ts只负责调度与预览。SDK 参数透传、中英文文档和测试可随后阅读。Screenshots / Recordings
在本机 fd 路径上,对同一个中性 Git fixture 分别运行基线与 PR 代码。以下是真实输出:基线只返回普通弱匹配,PR 将精确的忽略目录
@.tmp/排在首位。Input: @.tmp@weak-one.tmp.ts@weak-two.tmp.ts@weak-three.tmp.tsInput: @.tmp@.tmp/@weak-one.tmp.ts@weak-two.tmp.ts@weak-three.tmp.tsBehavior Changes and Affected Users
fs:search/fs:suggest省略follow_gitignoretrue,过滤忽略文件false,包含忽略文件并可能执行一次补充扫描follow_gitignore: true,保留单次过滤扫描false的 HTTP 调用方,以及远程 Kimi@补全truncated形状不变show_hidden: true才能匹配隐藏路径show_hidden默认值不变.tmp等点开头查询的 HTTP 与补全用户suggestFilesfollow_gitignore: truefollowGitignore?: boolean;省略仍为true,显式false才包含true即保持旧行为@文件补全.git仍排除.ignore与.fdignore@为 80ms,其他 provider 默认不变受影响模块与覆盖:
limit/truncated和补扫跳过条件。.git排除。验证结果与未覆盖范围
main@origin后,在 m0-dev 运行 5 个相关 Vitest 文件:487 passed / 3 skipped。node --test:1149 passed / 2 skipped。kimi-code-docs的 VitePress 构建通过;仅有既有的ES2024target 与 chunk 大小警告。Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, or this PR needs no doc update.