Skip to content

feat(kap-server): add global fs:mkdir endpoint - #2281

Merged
sailist merged 3 commits into
MoonshotAI:mainfrom
sailist:feat/kap-server-fs-mkdir
Jul 28, 2026
Merged

feat(kap-server): add global fs:mkdir endpoint#2281
sailist merged 3 commits into
MoonshotAI:mainfrom
sailist:feat/kap-server-fs-mkdir

Conversation

@sailist

@sailist sailist commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue — the problem is explained below.

Problem

The global (non-session) filesystem surface under /api/v1 can browse directories (fs:browse) and read any host file (fs:content), but there is no way to create a directory. A folder-picker style UI that lets users choose a workspace root therefore cannot offer a "new folder" action: creating a directory today only works inside a session's workspace via the session-scoped fs:mkdir action, which requires an existing session and is confined to that session's work dir.

What changed

  • Added POST /api/v1/fs:mkdir (source path /fs::mkdir, served single-colon on the wire like the other fs: routes) accepting { path }, which creates a directory by absolute path on the host filesystem. Like fs:content, the global bearer auth is the only access gate.
  • Implemented directly on node:fs/promises.mkdir in the transport layer for now, since the engine deliberately has no "unconfined write" domain Service (mirroring the read side, where fs:content also lives in the transport layer on host fs primitives). The route is deliberately non-recursive: a missing parent surfaces as an error instead of silently creating a deep tree the caller may have mistyped.
  • Wire errors map onto the existing fs.* codes: non-absolute path → 40001 validation.failed, existing target (file or directory) → 40919 fs.already_exists, missing parent → 40409 fs.path_not_found, EACCES/EPERM40411 fs.permission_denied. Success returns { path }.
  • Added route tests covering creation (verified via fs:browse), relative path, existing directory/file, missing parent, and the double-colon URL 404 parity guard.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Add POST /api/v1/fs:mkdir to create a directory on the host filesystem
by absolute path, backing the folder picker's "new folder" action.
Implemented directly on node:fs/promises.mkdir in the transport layer
for now, non-recursive by design, with wire errors mapped to the
existing fs.* codes (40001/40409/40411/40919).
@changeset-bot

changeset-bot Bot commented Jul 28, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fb9085d

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 28, 2026

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

commit: fb9085d

@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: 5f459a0947

ℹ️ 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 mkdirRoute = defineRoute(
{
method: 'POST',
path: '/fs::mkdir',

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Update the API surface snapshot for fs:mkdir

Adding this documented POST route changes /openapi.json, but packages/kap-server/test/apiSurface.snapshot.test.ts derives the route table from that document and the checked-in snapshot still only contains the existing fs:browse, fs:content, and fs:home entries. In CI, that snapshot assertion will fail until the new POST /api/v1/fs:mkdir route is recorded intentionally.

Useful? React with 👍 / 👎.

sailist added 2 commits July 28, 2026 10:18
The export download tests reused pooled undici keep-alive connections,
so afterEach's server.close() could wait out fastify's 72s default
keepAliveTimeout and die on the 10s hook timeout (flaky on CI). Send
connection: close on the streamed export requests, matching the
fs:content tests.
@sailist
sailist merged commit 7e30add into MoonshotAI:main Jul 28, 2026
14 checks passed
7723qqq pushed a commit to 7723qqq/kimi-code that referenced this pull request Aug 15, 2026
* feat(kap-server): add global fs:mkdir endpoint

Add POST /api/v1/fs:mkdir to create a directory on the host filesystem
by absolute path, backing the folder picker's "new folder" action.
Implemented directly on node:fs/promises.mkdir in the transport layer
for now, non-recursive by design, with wire errors mapped to the
existing fs.* codes (40001/40409/40411/40919).

* test(kap-server): update api surface snapshot for fs:mkdir

* test(kap-server): stop export tests from holding server.close() open

The export download tests reused pooled undici keep-alive connections,
so afterEach's server.close() could wait out fastify's 72s default
keepAliveTimeout and die on the 10s hook timeout (flaky on CI). Send
connection: close on the streamed export requests, matching the
fs:content tests.
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