Skip to content

feat: add workspace add-dir support#812

Open
liruifengv wants to merge 5 commits into
mainfrom
feat/add-dir-workspace
Open

feat: add workspace add-dir support#812
liruifengv wants to merge 5 commits into
mainfrom
feat/add-dir-workspace

Conversation

@liruifengv

Copy link
Copy Markdown
Collaborator

Related Issue

No linked issue.

Problem

Kimi Code did not have a built-in way to add extra workspace directories during a session, persist remembered directories per project, or pass multiple startup additional directories from the CLI.

What changed

  • Added /add-dir with a confirmation dialog for session-only use, remembering the directory in project-local config, or canceling.
  • Added support for multiple additional workspace directories in runtime state, project-local config, tool path guards, manual write/edit approval, and @file mentions.
  • Added /add-dir directory argument completion, including /, ~/, and ../, while filtering dot directories.
  • Added repeat --add-dir CLI startup support.
  • Kept runtime /add-dir additions from immediately refreshing the current system prompt or inserting an add-dir reminder; remembered directories are rendered again for new/resumed sessions.
  • Added tests for config loading, RPC/session behavior, permissions, file mentions, slash command behavior, CLI parsing, and editor autocomplete refresh.
  • Added a changeset.

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.

Verification

  • pnpm vitest run packages/agent-core/test/config/workspace-local.test.ts packages/agent-core/test/session/subagent-host.test.ts packages/agent-core/test/harness/runtime.test.ts packages/agent-core/test/tools/path-guard.test.ts packages/agent-core/test/agent/permission.test.ts packages/node-sdk/test/create-session-transport.test.ts apps/kimi-code/test/tui/components/editor/file-mention-provider.test.ts apps/kimi-code/test/tui/commands/add-dir.test.ts apps/kimi-code/test/tui/commands/registry.test.ts apps/kimi-code/test/tui/commands/resolve.test.ts apps/kimi-code/test/cli/options.test.ts apps/kimi-code/test/cli/run-shell.test.ts apps/kimi-code/test/cli/run-prompt.test.ts
  • pnpm --filter @moonshot-ai/agent-core run typecheck
  • pnpm --filter @moonshot-ai/kimi-code-sdk run typecheck
  • pnpm --filter @moonshot-ai/kimi-code run typecheck
  • pnpm -C apps/kimi-code run build
  • pnpm -C apps/kimi-code run smoke
  • git diff --check

@changeset-bot

changeset-bot Bot commented Jun 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8663f50

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

This PR includes changesets to release 5 packages
Name Type
@moonshot-ai/agent-core Minor
@moonshot-ai/kimi-code-sdk Minor
@moonshot-ai/kimi-code Minor
@moonshot-ai/acp-adapter Patch
@moonshot-ai/migration-legacy 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 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: 1823aa02ba

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

): Promise<WorkspaceAdditionalDirsLoadResult> {
const projectRoot = await findProjectRoot(kaos, workDir);
const configPath = getWorkspaceLocalConfigPath(projectRoot);
const additionalDir = await resolveAdditionalDir(kaos, projectRoot, inputPath);

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 Resolve add-dir input from the current workdir

When Kimi is launched from a subdirectory of a git worktree, the /add-dir argument and TUI completions are cwd-relative, but this resolves the user-supplied path against projectRoot. For example, from /repo/packages/app, /add-dir ../shared is validated as /repo/shared instead of /repo/packages/shared, so a valid selected directory can fail to add or the wrong root can be persisted. Resolve interactive/CLI input against workDir and only interpret stored local.toml entries relative to the project root.

Useful? React with 👍 / 👎.

Comment on lines +94 to +95
await mkdir(dirname(configPath), { recursive: true, mode: 0o700 });
await writeFileAtomicDurable(configPath, `${stringifyToml(file.raw)}\n`);

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 Persist workspace config through the session Kaos

In SDK sessions backed by a non-local/custom Kaos (SSH/ACP/test harness), projectRoot was discovered and the directory was validated through kaos, but these writes go to the host filesystem path instead. remember can therefore fail or create .kimi-code/local.toml in an unrelated local path while the workspace never sees it (and readWorkspaceLocalToml has the same local-FS assumption). Use the provided Kaos/persistence abstraction consistently for the project-local config.

Useful? React with 👍 / 👎.

Comment on lines +552 to +554
if (this.state.appState.additionalDirs.length > 0) {
createSessionOptions.additionalDirs = [...this.state.appState.additionalDirs];
}

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 Honor --add-dir when resuming sessions

These startup dirs are only copied into createSessionOptions, but the resume branches below call harness.resumeSession(...) and then syncAdditionalDirs replaces app state from session.summary?.additionalDirs. As a result, kimi -r <id> --add-dir /tmp/extra or kimi -C --add-dir /tmp/extra silently ignores the flag unless a new session is created; either apply the dirs after resume or reject the combination.

Useful? React with 👍 / 👎.

Add multi-directory /add-dir management with session-only or project-remembered persistence, directory completion, confirmation UI, and runtime workspace/permission wiring.
Pass CLI additional directories through shell and prompt resume paths, resolve caller-relative dirs against workDir, and add regression coverage.
Load only user-level and cwd AGENTS.md by default, while preserving additional directory listings in the prompt context.
Add a session appendUserMessage RPC and use it after /add-dir so the command result is recorded as a normal user message and surfaced in the transcript.
Document the add-dir / local-command-stdout research findings and the follow-up tasks for stdout wrapping, slash file completion, and hints.
@liruifengv liruifengv force-pushed the feat/add-dir-workspace branch from 1823aa0 to 8663f50 Compare June 16, 2026 09:51
@pkg-pr-new

pkg-pr-new Bot commented Jun 16, 2026

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

commit: 8663f50

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