Skip to content

fix(kap-server): search all workspace source folders - #4511

Merged
liruifengv merged 1 commit into
mainfrom
fix/workspace-fs-additional-dirs
Oct 29, 2026
Merged

liruifengv merged 1 commit into
mainfrom
fix/workspace-fs-additional-dirs

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Requirement or Bug

Fix workspace file search and completion so they include every registered source folder in multi-folder projects.

Related review discussion: #4336 (comment)

Bug Reproduction Steps

  1. Create a project with primary directory A and additional directory B, without creating a session.
  2. Add a uniquely named file to B and files with the same name to both A and B.
  3. Search by workspace ID through POST /api/v1/workspace/fs:suggest or POST /api/v1/workspace/fs:search.
  4. Only primary-directory candidates are returned. Empty queries also omit B's top-level entries, and a cold session-form search has the same problem.

Root Cause

resolveWorkspaceFs resolved the workspace metadata but constructed the filesystem scope with only ws.root. The downstream WorkspaceFsService already supports merging multiple roots, but never received ws.additionalDirs.

This is a fundamental fix: the resolver now passes the current registered root + additionalDirs snapshot through the existing acquire, runtime mapping, and lease-release path. No request or response schema changes are introduced.

Code Changes

 resolveWorkspaceFs(ref)
-  roots = { workDir: ws.root }
+  roots = { workDir: ws.root, additionalDirs: ws.additionalDirs }
   acquireWorkspaceFs(core, ws.id, roots, runtimeId, required)
  • Reuse the existing multi-root search, deduplication, ranking, limits, and path mapping in WorkspaceFsService.
  • Preserve primary-relative and additional-root-absolute result paths.
  • Add four route-level tests covering suggest, search, empty queries, cold session references, directory updates after materialization, and list boundaries.
  • Confirm that unregistered external paths remain rejected.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Workspace fs:suggest and fs:search Searched only the primary root Searches the primary root and all currently registered additional roots Desktop and web file mentions; workspace filesystem API consumers Not applicable; this restores the expected project scope
Cold session-form fs:search resolved by workspace reference Returned only primary-root matches Returns matches from every registered source folder Clients that use a workspace ID or root as the session reference Not applicable
Workspace-ID fs:list Rejected absolute paths under additional roots Allows paths under registered additional roots while still rejecting unregistered external paths Session-less workspace file browsers and filesystem consumers Not applicable
Single-root workspaces and generic POST /fs:suggest Existing relative/absolute path behavior Unchanged Single-folder projects and file-tree searches scoped to one root Existing behavior and tests are preserved

Test coverage:

  • pnpm --filter @moonshot-ai/kap-server exec vitest run test/fs.test.ts: 65 passed, including the four new regression tests. All four failed before the production fix and passed afterward.
  • pnpm --filter @moonshot-ai/kap-server run typecheck: passed.
  • pnpm --filter @moonshot-ai/kap-server run build: passed.
  • pnpm lint: passed with 0 errors.
  • pnpm test: 17,915 tests passed and 3 unrelated tests failed. Two failures passed when rerun in isolation. agent-core-v2/test/tool/tool.test.ts > returns the spawned agent id when a foreground subagent times out still timed out independently; this PR does not modify that module.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related review discussion.
  • I have added tests that prove my feature works.
  • The behavior-change table above is complete; no behavior is removed and no default is flipped.
  • Ran gen-changesets skill; no changeset was added at the author's explicit request.
  • This PR needs no user-documentation update because it restores the existing filesystem contract without changing its shape or usage.

Copilot AI balanced review requested due to automatic review settings October 29, 2026 06:50
@changeset-bot

changeset-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 53829aa

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-29T06:51:35.899859Z 53829aa 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 Oct 29, 2026

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

commit: 53829aa

@liruifengv
liruifengv merged commit bfdfde1 into main Oct 29, 2026
17 checks passed
@liruifengv
liruifengv deleted the fix/workspace-fs-additional-dirs branch October 29, 2026 07:00
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.

3 participants