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
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…t land yet

Both need multi-root workspace registration (MoonshotAI#4336): the REST create and
update schemas carry only `root` and `name`, so there is no
`additional_dirs` field to pass through or to de-duplicate. MoonshotAI#4511's fs
half is already in place — resolveWorkspaceFs forwards
ws.additionalDirs — so it stays in_progress with that note rather than
being closed or signed off.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…MoonshotAI#4513

MoonshotAI#4336 is in_progress: d07cc07 adds managed creation with retry-safe
ids and 0390f64 puts source folders on the REST and wire surfaces.
MoonshotAI#4513 lands on top of that in 718a3ae and is closed against a route
probe.

MoonshotAI#4511 keeps its fs-side forwarding, but its route-level cross-folder
search test is still missing, so it stays in_progress with a manual
probe rather than borrowing the workspace-creation case as evidence.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026


The fuzzy search path now covers every registered source folder, pinned
by the fsService case added with 14ba59e. The row stays in_progress
because two pieces are still absent: the empty-query listing only sees
the work directory (it needs a per-root list anchor, since resolveWithin
refuses absolute paths by design), and upstream's route-level test is
not ported.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
…obes

Both halves of the cross-folder search are in place: the fuzzy walk
(14ba59e) and the empty-query listing, which now anchors an absolute
path at the nearest registered root (a14144d). Upstream's route-level
test is not ported, and the evidence says so, but the route forwarding it
covers has been in place since MoonshotAI#4527's work.

Ledger: closed 36 -> 37, remaining 62.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Port of upstream MoonshotAI/kimi-code bfdfde1's route-level tests and
the workspace-scoped `fs::list` they exercise (MoonshotAI#4511).

The tests create a workspace with a source folder and drive the three
workspace-scoped routes plus a session-scoped search, which is the
end-to-end proof that a registered folder reaches the filesystem layer:
search and suggest see files in both roots with root-specific paths, a
cold session search finds a file that lives only in the source folder,
`list` respects the folder boundary and refuses a path outside it, and a
`PATCH` that replaces the folder list takes effect on the next call.

The `fs::list` route is new here: this fork only had `search` and
`suggest` on `/api/v1/workspace/fs:<action>`, so a caller could search a
workspace without a session but not list it. The route mirrors the
`search` one, reusing its body-schema extension and runtime-scope
release, and it is the boundary-refusal case that pins the anchoring
introduced in a14144d.

Removing `additionalDirs` from the workspace scope makes the cross-folder
search case fail, so the forwarding is covered rather than incidental.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Port of upstream MoonshotAI/kimi-code 0772396 (MoonshotAI#4568).

IAgentGoalService.editGoalObjective changes only the objective of the current
goal: goalId, status, stats and budget are untouched, and goal.updated
notifies clients. A running turn is not interrupted, and the tool cannot
finish the goal before the agent sees the new objective: an edit bumps an
objective revision, each turn records the revision it started under, and
UpdateGoal's complete/blocked path refuses a stale revision at execution
time, which also covers an edit made while the call waited for approval.
CreateGoal replace clears the recorded revisions, so a same-turn replacement
goal stays finishable.

Surfaces: PATCH /api/v1/sessions/{session_id}/goal, Session#editGoalObjective
with the SDKRpcClientBase/V2 pair, and the vis context projector folding the
new goal.update objective field.

Local-form adaptations, because this fork's goal state differs from upstream:
- GoalState carries updatedAt and the transition tracks a changed flag; an
  objective edit sets it so the snapshot's updatedAt moves. Upstream's
  transition has neither.
- The fork rejects non-strict request bodies at route definition, so
  editSessionGoalRequestSchema is .strict().
- The route reuses the local ensureMainAgent helper, which returns the agent
  handle and localizes the not-found message, instead of upstream's
  ensureMainAgent + handleOf(AGENT_NOT_FOUND) pair.
- The complete-status test dispatches GoalUpdate directly because the fork's
  markComplete clears the goal and cannot leave one in complete status.

Also updates the api-surface snapshot, which was still missing
POST /api/v1/workspace/fs:list from MoonshotAI#4511; that batch never ran this gate.

Verified: agent-core-v2 goal 126 pass, fold 18, goal injection 25; kap-server
goal routes 7 and the api-surface snapshot; node-sdk 305; agent-core-v2,
kap-server, apps/kimi-code and vis server typechecks clean; agent-core-v2
bun run build and check:no-comments clean. Reverse checks: short-circuiting
the execution-time check reddens the two stale-edit cases, and dropping the
transition's objective assignment reddens four cases including this route's.

No changeset: the CLI does not expose the edit yet, so users of the published
package cannot perceive it.
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