Skip to content

Conversation

aryasaatvik
Copy link
Contributor

Implements workspace-based multi-directory access control, allowing opencode to work with files across multiple directories.

Changes

Core Module

  • New Workspace module manages directory allowlist with defaults (cwd, worktree) + configurable directories
  • PathValidation module unifies workspace checks with permission system
  • Config schema extended with workspace.directories field

API & CLI

  • REST endpoints: GET/POST/DELETE /workspace/directories
  • CLI commands: opencode workspace add|remove|list|clear
  • TUI: /add-dir command (requires SDK regeneration)

Security

  • All file tools (read, write, edit, patch, bash) now use unified workspace validation
  • Paths outside workspace trigger permission prompts
  • Fixed: Read tool now uses Instance.directory instead of process.cwd()

Usage

# CLI
opencode workspace add ../related-project
opencode workspace list
# Config (opencode.json)
{
  "workspace": {
    "directories": ["../other-dir", "/absolute/path"]
  }
}

Breaking Changes

File operations outside workspace now require explicit permission approval.

Notes

TUI /add-dir command requires SDK regeneration to function (placeholder implemented).

Introduces workspace-based multi-directory access control:
- Workspace module manages allowed directories allowlist
- Always includes cwd and worktree as defaults
- Supports additional directories via opencode.json config
- PathValidation module unifies workspace + permission checks
- Adds workspace.directories field to config schema
Adds three new endpoints:
- GET /workspace/directories - List allowed workspace directories
- POST /workspace/directories - Add directory to workspace
- DELETE /workspace/directories - Remove directory from workspace

All endpoints use Workspace module for directory management and
return structured WorkspaceInfo responses.
Implements `opencode workspace` command with subcommands:
- add <directory> - Add directory to workspace
- remove <directory> - Remove from workspace
- list - Show all allowed directories
- clear - Reset to defaults only

Supports both absolute and relative paths (relative to worktree).
Updates all file operation tools to use PathValidation.validate():
- Read tool: Fixed to use Instance.directory instead of process.cwd()
- Write, Edit, Patch tools: Replace Filesystem.contains with validation
- Bash tool: Validates file operation commands (cd, rm, cp, mv, etc.)

Path validation now checks workspace allowlist first, then requests
permission for paths outside workspace. Provides unified security model.
Implements /add-dir slash command in TUI:
- Command registry with "add-dir" trigger
- Editor special handling for directory argument input
- Message passing via AddWorkspaceDir type
- Handler ready with SDK placeholder

NOTE: Requires SDK regeneration to enable actual API calls.
Currently shows error message prompting SDK regeneration.
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