Skip to content

feat: support symlinked directories in file tree - #4457

Merged
liruifengv merged 11 commits into
mainfrom
feat/file-tree-symlink-directories
Oct 27, 2026
Merged

liruifengv merged 11 commits into
mainfrom
feat/file-tree-symlink-directories

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Requirement or Bug

The file tree should expand symlinked directories, including links whose targets are outside the workspace.

Bug Reproduction Steps

N/A

Root Cause

N/A

Code Changes

 fs:list
+  optionally follow symlinks outside the workspace
+  return is_directory for symlink directories
+  recurse into them and keep per-branch realpath ancestors to stop cycles
+  sort symlink directories as directories

 fs:read
+  optionally read through symlinks outside the workspace

 kap-server
+  POST /api/v1/workspace/fs:list
  • allow_external_symlinks is opt-in and defaults to off, so existing callers keep the current confinement behavior.
  • The session-backed and session-less file trees both use the new option.
  • The new is_directory entry field is additive; kind: "symlink" is unchanged.

Behavior Changes and Affected Users

Behavior Before After Who relies on the old behavior Escape hatch
Symlink directory entries in fs:list Always kind: "symlink", never recursed Directory targets also return is_directory: true and recurse when requested File tree clients that treated every symlink as a leaf; API clients reading kind only Existing fields and kind are unchanged
Symlinks outside the workspace Listing or reading through them returns 41304 Allowed when allow_external_symlinks: true Desktop/web clients and other API consumers relying on strict confinement Omit the option to keep the old behavior
Symlink directory ordering Sorted with files Sorted with directories File tree users sensitive to ordering None; ordering follows the existing type_first semantics
Session-less workspace listing Only search and suggest endpoints existed New POST /api/v1/workspace/fs:list No existing caller; this is additive N/A

Affected modules:

  • agent-core-v2 filesystem service: unit coverage in fsService.test.ts for internal, external, broken and cyclic symlinks, including read and recursion behavior.
  • kap-server filesystem routes: route coverage in fs.test.ts for session and session-less listing, external access, and default rejection; API surface snapshot updated for the new endpoint.
  • No prompt text, CLI output, provider behavior, or existing default changes.

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.

Copilot AI balanced review requested due to automatic review settings October 27, 2026 05:12
@changeset-bot

changeset-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b8be4f9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 7 packages
Name Type
@moonshot-ai/agent-core-v2 Minor
@moonshot-ai/kap-server Minor
@moonshot-ai/acp-server Patch
@moonshot-ai/klient Patch
@moonshot-ai/migration-legacy Patch
@moonshot-ai/kimi-code-product Patch
@moonshot-ai/remote-control Patch

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 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-27T06:38:35.906392Z b8be4f9 Manual request
ℹ️ 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 27, 2026 •

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

commit: b8be4f9

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.

🟡 Changes recommended

Recursive alias traversal lacks a request-wide budget, and ignored-descendant probing can hide explicitly allowed external-symlink content.

2 open issues
What changed in this PR

This PR adds filesystem API support for expanding symlinked directories, including opt-in access to targets outside the workspace, and introduces session-less workspace listing.

Changes:

  • Add symlink-directory metadata, recursive traversal, cycle detection, and directory-first sorting.
  • Add optional external-symlink access for listing and reading, preserving default confinement.
  • Extend route coverage, API snapshots, bilingual documentation, and release metadata.
File Description
packages/​kap-server/​test/​fs.test.ts Test session and workspace symlink listing and external access.
packages/​kap-server/​test/​__snapshots__/​apiSurface.snapshot.test.ts.snap Record the workspace listing endpoint.
packages/​kap-server/​src/​routes/​fs.ts Register session-less workspace listing.
packages/​agent-core-v2/​test/​workspace/​workspaceFs/​fsService.test.ts Extend filesystem mocks and symlink regression coverage.
packages/​agent-core-v2/​src/​workspace/​workspaceFs/​fsService.ts Implement symlink traversal, cycle checks, and optional external reads.
packages/​agent-core-v2/​src/​workspace/​workspaceFs/​fs.ts Extend request and response schemas.
docs/​zh/​reference/​server-api.md Document the API additions in Chinese.
docs/​en/​reference/​server-api.md Document the API additions in English.
.changeset/​file-tree-symlink-directories.md Add release metadata for symlink support.

Review effort: Balanced

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ce85ce5b51

ℹ️ 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".

Comment thread packages/kap-server/src/routes/fs.ts Resolved
Comment thread packages/kap-server/src/routes/fs.ts Resolved
@@ -31,6 +31,7 @@ export const fsEntrySchema = z.object({
mime: z.string().optional(),
language_id: z.string().optional(),
is_binary: z.boolean().optional(),
is_directory: z.boolean().optional(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Ship client support for the symlink directory marker

The committed web bundle still maps filesystem entries in QH without is_directory, and its file-tree component only expands entries whose kind === "directory"; listDirectory also has no way to send allow_external_symlinks. Consequently the shipped CLI/web file tree discards this new marker and continues treating every kind: "symlink" entry as a leaf, so the feature described by this change is unavailable to its primary users. Update the code-app client and sync the resulting dist-web bundle in this change.

AGENTS.md reference: AGENTS.md:L17-L18

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Intentionally out of scope for this PR per product decision; the client change is tracked in MoonshotAI/kimi-code-app#997.

@liruifengv

Copy link
Copy Markdown
Collaborator Author

Addressed the review findings in f734dc9:

  • added a request-wide output budget for recursive listings and set truncated when exhausted
  • passed allow_external_symlinks through ignored-descendant probing
  • declared FS_PATH_NOT_FOUND for the workspace list endpoint and documented 40409
  • kept the Pino error under err for open-in launch failures

The dist-web bundle sync is intentionally out of scope for this PR.

@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f734dc9714

ℹ️ 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".

Comment thread packages/kap-server/src/routes/fs.ts Resolved
Comment thread packages/kap-server/src/routes/fs.ts Resolved
Comment thread packages/kap-server/src/routes/fs.ts Resolved
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8f243f2057

ℹ️ 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".

@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 58787f7ff7

ℹ️ 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".

Comment thread packages/kap-server/src/routes/fs.ts Resolved
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9e34b5bf54

ℹ️ 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".

@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c9036fae06

ℹ️ 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".

@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c964d120a9

ℹ️ 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".

@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

Reviewed commit: b8be4f982f

ℹ️ 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".

@liruifengv
liruifengv merged commit e2ad1dc into main Oct 27, 2026
16 checks passed
@liruifengv
liruifengv deleted the feat/file-tree-symlink-directories branch October 27, 2026 08:49
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
Engine slice of upstream MoonshotAI/kimi-code e2ad1dc (MoonshotAI#4457).

A symlinked directory appeared as an inert `symlink` entry: the walk never
descended into it, so a project whose folders are links listed as empty.
Listing now resolves a symlink's target, marks the entry with
`is_directory`, and queues it with its real path as an ancestor so a cycle
stops instead of recursing. Entries reached through a symlink share a
10,000-record budget; a symlink whose target is outside the workspace is
still not followed unless the caller passes `allow_external_symlinks`,
which `resolveWithin` now honours.

Three cases pin it: an in-workspace link expands and carries the flag, an
external target does not expand by default, and the same target does
expand with the flag. Removing either the marking or the external guard
turns them red.

Test fixtures needed two additions to model a real filesystem: `readdir`
follows a symlinked path, and `lstat` rewrites a symlinked parent prefix
before the lookup.

Not yet ported from the same commit: the REST `allow_external_symlinks`
flag on the fs routes, the workspace `fs:list` documentation, and the
download route's flag.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
REST slice of upstream MoonshotAI/kimi-code e2ad1dc (MoonshotAI#4457).

`fs:read` and the download route now accept `allow_external_symlinks`,
so a caller that deliberately points at a link outside the workspace can
read it, while the default still refuses. The entry documentation gains
`is_directory` and the 10,000-record budget for symlink-expanded
entries, in both locales.

The route case extends the existing escape test: the same path that is
refused by default now reads and downloads with the flag. Dropping the
flag from the download route turns it red.
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Nov 4, 2026
cd7936a lists symlinked directories with `is_directory` and an
ancestor-based cycle guard, and 5d30e43 exposes
`allow_external_symlinks` on read and download with both locales
documenting the entry shape and the 10,000-record budget.

Ledger: closed 43 -> 44, remaining 55.
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