Skip to content

feat(opencode): add session workspace directories and searchable add-directory UX.#14244

Open
adampoit wants to merge 1 commit intoanomalyco:devfrom
adampoit:add-directory
Open

feat(opencode): add session workspace directories and searchable add-directory UX.#14244
adampoit wants to merge 1 commit intoanomalyco:devfrom
adampoit:add-directory

Conversation

@adampoit
Copy link

Implement session-scoped workspace directory support behind /add-directory, persist external-directory permissions on the session, and include added directories in file discovery/autocomplete. Reuse the existing inline autocomplete surface for directory selection and update system prompt environment metadata so assistants can accurately report searchable directories.

Issue for this PR

Closes #1543.

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

  • Adds a session-scoped workspace directory flow:
    • POST /session/:sessionID/workspace/directory
    • Stores external_directory allow rules on the session permission set
  • Extends file discovery so workspace directories are included in:
    • find.files
    • TUI @ autocomplete
    • App-side file search/autocomplete
  • Implements /add-directory in TUI prompt flow and reuses the existing inline autocomplete panel
  • Updates system prompt environment metadata so <directories> includes both:
    • Current working directory
    • Session workspace directories

How did you verify your code works?

  • nix develop -c bun run typecheck (from packages/opencode)
  • Added and ran tests:
    • test/session/workspace-directory.test.ts
    • test/file/search-external-directory.test.ts
    • test/server/session-workspace-directory.test.ts
  • Manual TUI checks:
    • /add-directory <path> works with and without an active session
    • @ autocomplete includes files from added workspace directories
    • /add-directory ../ and token fuzzy (iden) suggestion behavior
    • ~/... directory submission succeeds
    • Assistant scope question now reflects workspace directories in system context

Screenshots / recordings

asciicast

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI review requested due to automatic review settings February 19, 2026 06:39
@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on my search, I found a potentially related PR:

Related PR:

  • feat: /add-dir command #8943 - feat: /add-dir command
    • This PR implements a similar /add-dir command feature, which overlaps with the current PR's /add-directory implementation for adding workspace directories.

The current PR (14244) is a more comprehensive implementation that builds upon earlier directory-related features. The search results also show several external_directory permission-related PRs (#5905, #5841, #6714) that provide context for the permission model being used.

However, no exact duplicate PRs were found - PR #14244 appears to be a new consolidated feature that combines session workspace directory support with improved UX for the /add-directory flow and file discovery integration.

@adampoit
Copy link
Author

adampoit commented Feb 19, 2026

I somehow missed that this was implemented in #8943. I'm happy to close this out if we like the approach taken in the other PR.

I can address Copilot's feedback if we choose to move forward.

Copy link
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

Adds session-scoped “workspace directory” support so users can allow and search additional (external) directories per session, and surfaces this in both TUI and app autocomplete/file discovery plus system prompt metadata.

Changes:

  • Introduces POST /session/:sessionID/workspace/directory and a Session.addWorkspaceDirectory flow that persists an external_directory allow rule on the session.
  • Extends file discovery (find.files, TUI @ autocomplete, app file search) to include session workspace directories when sessionID is provided.
  • Adds /add-directory UX (with inline directory autocomplete) and updates system prompt <directories> metadata to include workspace directories.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/sdk/js/src/v2/gen/types.gen.ts Adds new API/types for session workspace directory and sessionID support on find.files.
packages/sdk/js/src/v2/gen/sdk.gen.ts Adds generated session.workspaceDirectory() client method and sessionID query for find.files.
packages/opencode/test/session/workspace-directory.test.ts Unit tests for Session.addWorkspaceDirectory behavior (tilde, symlink canonicalization, duplicates, invalid paths).
packages/opencode/test/server/session-workspace-directory.test.ts Endpoint tests for adding a workspace directory and basic body validation.
packages/opencode/test/file/search-external-directory.test.ts Tests that external directories are only searched when sessionID is provided + permitted.
packages/opencode/test/cli/tui/prompt-directory.test.ts Tests directory path formatting for slash directory autocomplete display/value.
packages/opencode/src/session/system.ts Updates system prompt environment metadata to list working + workspace directories from permissions.
packages/opencode/src/session/prompt.ts Ensures system prompt env uses current session permissions (re-fetches session in loop).
packages/opencode/src/session/index.ts Implements addWorkspaceDirectory and response schema.
packages/opencode/src/server/routes/session.ts Adds POST /:sessionID/workspace/directory route.
packages/opencode/src/server/routes/file.ts Adds optional sessionID query to /find/file and passes through to File.search.
packages/opencode/src/file/index.ts Extends File.search to merge in files/dirs from permitted external directories for a session.
packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx Implements /add-directory submission flow (creates session if needed, calls API, shows toast).
packages/opencode/src/cli/cmd/tui/component/prompt/directory.ts Adds helper for formatting directory suggestion values (absolute vs relative vs tilde).
packages/opencode/src/cli/cmd/tui/component/prompt/autocomplete.tsx Reuses inline autocomplete surface to suggest directories for /add-directory and includes sessionID in file search.
packages/opencode/src/cli/cmd/tui/component/dialog-tag.tsx Threads sessionID into dialog tag file search.
packages/app/src/pages/session/use-session-commands.tsx Adds “Add workspace directory” session command (dialog + API call + toasts).
packages/app/src/i18n/en.ts Adds i18n strings for the new session command and toasts.
packages/app/src/context/file.tsx Includes sessionID when searching files so session workspace dirs are discoverable in app search.

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

Comment on lines +441 to +442
if (!stat) throw new Error(`Directory not found: ${input.path}`)
if (!stat.isDirectory()) throw new Error(`Path is not a directory: ${input.path}`)
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

addWorkspaceDirectory throws plain Error for missing/non-directory paths. In the server this will be converted into a 500 response (since only NamedError / HTTPException are mapped), which contradicts the OpenAPI/SDK contract advertising 400/404 and will surface as an internal error to clients for invalid input. Please return a 4xx here (e.g., throw a HTTPException(400, ...), or introduce a typed NamedError and map it to 400) and consider adding a server test asserting invalid paths return 400.

Suggested change
if (!stat) throw new Error(`Directory not found: ${input.path}`)
if (!stat.isDirectory()) throw new Error(`Path is not a directory: ${input.path}`)
if (!stat) throw new NotFoundError(`Directory not found: ${input.path}`)
if (!stat.isDirectory()) throw new NotFoundError(`Path is not a directory: ${input.path}`)

Copilot uses AI. Check for mistakes.
Comment on lines +84 to +87
if (input === "~") return process.env.HOME ?? input
if (input.startsWith("~/")) {
const home = process.env.HOME
if (!home) return input
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

expand() handles ~/... but not the Windows-style ~\... form, even though other parts of this change (e.g. Session.addWorkspaceDirectory and directoryPath) explicitly support ~\\. This will make /add-directory ~\... directory suggestions behave incorrectly on Windows. Consider updating expand() (and any other path expansion helpers here) to also expand ~\\ when HOME is set.

Suggested change
if (input === "~") return process.env.HOME ?? input
if (input.startsWith("~/")) {
const home = process.env.HOME
if (!home) return input
const home = process.env.HOME
if (input === "~") return home ?? input
if (home && (input.startsWith("~/") || input.startsWith("~\\"))) {

Copilot uses AI. Check for mistakes.
Comment on lines +621 to +623
const root = await state().then((x) => x.files())
const extra = await external(input.sessionID)
const files = extra.files.length ? Array.from(new Set([...root.files, ...extra.files])) : root.files
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

File.search() now calls external(sessionID) on every invocation. That helper does a DB lookup (Session.get) and then walks each allowed external directory via Ripgrep.files, which can be very expensive during autocomplete (many calls per keystroke) and may cause noticeable latency on large directories. Consider caching external directory file/dir lists per session (keyed by permission set + maybe a short TTL), or precomputing them when a workspace directory is added, so search remains fast.

Copilot uses AI. Check for mistakes.
…directory UX

Implement session-scoped workspace directory support behind `/add-directory`, persist external-directory permissions on the session, and include added directories in file discovery/autocomplete. Reuse the existing inline autocomplete surface for directory selection and update system prompt environment metadata so assistants can accurately report searchable directories.
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.

[Feature Request] Adding directories / creating workspaces

1 participant

Comments