Skip to content

feat: add workspace add-dir support - #812

Merged
liruifengv merged 20 commits into
mainfrom
feat/add-dir-workspace
Jun 22, 2026
Merged

feat: add workspace add-dir support#812
liruifengv merged 20 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: 9d3862e

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

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

Comment thread packages/agent-core/src/config/workspace-local.ts Outdated
Comment thread packages/agent-core/src/config/workspace-local.ts Outdated
Comment thread apps/kimi-code/src/tui/kimi-tui.ts
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@9d3862e
npx https://pkg.pr.new/@moonshot-ai/kimi-code@9d3862e

commit: 9d3862e

Insert the /add-dir result as a user-role <local-command-stdout> record with an injection origin directly inside Session.addAdditionalDir. It enters the model context on the next turn but does not start a turn, and stays out of the live and resumed transcript; the transient status toast is kept for immediate feedback. --add-dir is unaffected since it bypasses addAdditionalDir.

Remove the now-unused appendUserMessage RPC and SDK method.
Generalize the slash-argument completion reopen so it fires whenever the text before the cursor ends with '/', not only when the literal '/' key is typed. After Tab-accepting a directory (or auto-applying a single-child dir), the next level's completion list reappears automatically, so repeated Tab keeps drilling down into subdirectories. '@' file mention is unaffected.
Extend the path completion reopen so it also fires for '@' file mentions. After Tab-accepting a directory in an '@' mention, the next level's completion list reappears automatically, matching the '/add-dir' continuous-Tab behavior.
Render a dim ghost-text argument hint inside the input box after a slash command that takes arguments, replacing the popup-only hint that was easy to miss. The hint appears once the command is typed and disappears as soon as an argument is entered, and is truncated to fit the box width. Add argument hints for /compact, /swarm, /goal and /title; /add-dir already had one.
The subagent-host test still asserted that an additional directory's AGENTS.md content appears in the agent system prompt, but additional-dirs AGENTS.md has been intentionally excluded from the default context since an earlier commit (covered by context.test.ts). Drop the stale assertion.
Merge origin/main into feat/add-dir-workspace. Resolved conflicts in 6 files by keeping both sides' independent additions: .gitignore, dispatch.ts imports, agent/index.ts (kept additionalDirs, dropped the field main's logging refactor removed), core-api.ts / types.ts payloads, core-impl.ts imports and the createSession return (kept both the new telemetry and withAdditionalDirs).
@liruifengv

Copy link
Copy Markdown
Collaborator Author

@codex

@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: 47e2bf0c69

ℹ️ 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/agent-core/src/config/workspace-local.ts Outdated
Comment thread packages/agent-core/src/config/workspace-local.ts Outdated
Comment thread packages/agent-core/src/session/index.ts
Comment thread packages/agent-core/src/profile/context.ts
Resolve user-supplied /add-dir paths against the current workdir instead of the project root, so launching from a subdirectory behaves like the CLI --add-dir flag. Also route the local.toml read/write through the kaos abstraction instead of host fs, so the remember path works for non-local sessions.
The /add-dir completer emits ~/... values, but the core treated ~/foo as a relative path because pathe isAbsolute('~/foo') is false, producing <workDir>/~/foo. Expand ~ and ~/ to the home directory (via kaos.gethome()) before resolving.
These were working notes (research and follow-up todos) that don't belong in the PR.
FileSystemAgentRecordPersistence.append buffers records and flushes asynchronously, so readMainWire can read the wire before the local-command-stdout record lands. Flush the main agent's records explicitly in the two add-dir runtime tests to make them deterministic.
@liruifengv
liruifengv merged commit c0eeca2 into main Jun 22, 2026
8 checks passed
@liruifengv
liruifengv deleted the feat/add-dir-workspace branch June 22, 2026 11:42
@github-actions github-actions Bot mentioned this pull request Jun 22, 2026
@ikrivosheev

Copy link
Copy Markdown

@liruifengv hello! Can you look an issue: #988?)

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.

2 participants