feat: add workspace add-dir support#812
Conversation
🦋 Changeset detectedLatest commit: 8663f50 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
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 |
There was a problem hiding this comment.
💡 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); |
There was a problem hiding this comment.
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 👍 / 👎.
| await mkdir(dirname(configPath), { recursive: true, mode: 0o700 }); | ||
| await writeFileAtomicDurable(configPath, `${stringifyToml(file.raw)}\n`); |
There was a problem hiding this comment.
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 👍 / 👎.
| if (this.state.appState.additionalDirs.length > 0) { | ||
| createSessionOptions.additionalDirs = [...this.state.appState.additionalDirs]; | ||
| } |
There was a problem hiding this comment.
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.
1823aa0 to
8663f50
Compare
commit: |
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
/add-dirwith a confirmation dialog for session-only use, remembering the directory in project-local config, or canceling.@filementions./add-dirdirectory argument completion, including/,~/, and../, while filtering dot directories.--add-dirCLI startup support./add-diradditions from immediately refreshing the current system prompt or inserting an add-dir reminder; remembered directories are rendered again for new/resumed sessions.Checklist
gen-changesetsskill, or this PR needs no changeset.gen-docsskill, 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.tspnpm --filter @moonshot-ai/agent-core run typecheckpnpm --filter @moonshot-ai/kimi-code-sdk run typecheckpnpm --filter @moonshot-ai/kimi-code run typecheckpnpm -C apps/kimi-code run buildpnpm -C apps/kimi-code run smokegit diff --check