Skip to content

feat(workspace): support additional directories via --add-dir and /add-dir#1271

Merged
RealKai42 merged 12 commits intomainfrom
kaiyi/add-dir-capability
Feb 27, 2026
Merged

feat(workspace): support additional directories via --add-dir and /add-dir#1271
RealKai42 merged 12 commits intomainfrom
kaiyi/add-dir-capability

Conversation

@RealKai42
Copy link
Copy Markdown
Collaborator

@RealKai42 RealKai42 commented Feb 27, 2026

This PR adds support for expanding the workspace scope with additional directories.

What changed

  • Added CLI flag --add-dir (repeatable) to include extra directories in session workspace state.
  • Added /add-dir slash command to list/add directories at runtime.
  • Persisted additional_dirs in session state and prune stale paths on runtime restore.
  • Introduced is_within_workspace(...) and updated file tools (glob, read, read_media, write, replace) to allow paths under either work_dir or configured additional dirs.
  • Included additional directory context in system prompt args so agents are aware of accessible paths.
  • Ensured fixed/dynamic subagents share the same additional-dir workspace view.

Tests

  • Added tests for session-state persistence/backward compatibility.
  • Added utility tests for workspace path checks.
  • Added file-tool behavior tests for access inside/outside additional dirs and dynamic updates.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue, if any.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have run make gen-changelog to update the changelog.
  • I have run make gen-docs to update the user documentation.

Open with Devin

Copilot AI review requested due to automatic review settings February 27, 2026 08:11
@RealKai42 RealKai42 changed the title feat: add support for additional directories in workspace management feat(workspace): support additional directories via --add-dir and /add-dir Feb 27, 2026
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 6 additional findings.

Open in Devin Review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for additional directories in workspace management, allowing users to extend the agent's file access scope beyond the primary working directory. This addresses use cases where projects need to access shared libraries or modules located outside the main project directory.

Changes:

  • Added is_within_workspace() utility function that checks path containment within work_dir or additional directories
  • Introduced /add-dir slash command and --add-dir CLI flag for adding directories to workspace
  • Updated all file tools (Glob, ReadFile, WriteFile, StrReplaceFile, ReadMediaFile) to respect additional directories
  • Added additional_dirs field to session state for persistence across sessions
  • Updated Runtime to manage and share additional directories with subagents

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/kimi_cli/utils/path.py Adds is_within_workspace() helper that checks if path is within work_dir or any additional directory
src/kimi_cli/tools/file/glob.py Updates Glob tool to accept paths in additional directories and changes error messages to refer to "workspace"
src/kimi_cli/tools/file/read.py Updates ReadFile to support reading from additional directories
src/kimi_cli/tools/file/write.py Updates WriteFile to support writing to additional directories
src/kimi_cli/tools/file/replace.py Updates StrReplaceFile to support editing files in additional directories
src/kimi_cli/tools/file/read_media.py Updates ReadMediaFile to support reading media from additional directories
src/kimi_cli/soul/agent.py Adds additional_dirs management to Runtime including restoration from session state, pruning stale entries, and formatting for system prompt
src/kimi_cli/soul/slash.py Implements /add-dir slash command with validation and redundancy checks
src/kimi_cli/session_state.py Adds additional_dirs field to SessionState for persistence
src/kimi_cli/cli/init.py Adds --add-dir CLI option and processes it during session initialization
src/kimi_cli/agents/default/system.md Updates system prompt template to include additional directories information
tests/utils/test_is_within_workspace.py Comprehensive tests for the new is_within_workspace utility function including prefix attack tests
tests/tools/test_additional_dirs.py Integration tests covering all file tools with additional directories and dynamic mutation behavior
tests/test_additional_dirs_state.py Tests for session state serialization and backward compatibility
tests/tools/test_glob.py Updates error message assertions to match new "workspace" terminology
tests/conftest.py Updates test fixtures to use Runtime instead of BuiltinSystemPromptArgs
tests/core/test_kimisoul_retry_recovery.py Adds additional_dirs to Runtime reconstruction in test helper
tests/core/test_kimisoul_ralph_loop.py Adds additional_dirs to Runtime reconstruction in test helper

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

for d in local_add_dirs:
dir_str = str(KaosPath.unsafe_from_local_path(d).canonical())
# Skip dirs within work_dir (already accessible)
if dir_str == work_dir_str or dir_str.startswith(work_dir_str + "/"):
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

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

The path comparison using hardcoded "/" as separator is not Windows-compatible. On Windows, path separators are backslashes. Use the is_within_directory helper function which properly handles path hierarchy checks using PurePath.relative_to(), which works correctly across platforms.

Copilot uses AI. Check for mistakes.
devin-ai-integration[bot]

This comment was marked as resolved.

@RealKai42 RealKai42 merged commit f27b450 into main Feb 27, 2026
14 checks passed
@RealKai42 RealKai42 deleted the kaiyi/add-dir-capability branch February 27, 2026 10:39
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