Skip to content

feat(acp): support additional workspace directories - #52524

Merged
nexxeln merged 4 commits into
v2from
acp-extra-dirs
Oct 1, 2026
Merged

nexxeln merged 4 commits into
v2from
acp-extra-dirs

Conversation

@nexxeln

@nexxeln nexxeln commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

#35457

Why the change

ACP clients can now give a session extra workspace roots with additionalDirectories, and opencode tools can work in those roots without asking for outside-directory approval each time.

Special things to note

  • The session metadata key opencode.acp.additionalDirectories is the source of truth. Rules are derived from it, and a session rule is ACP's only if it exactly equals a rule derived from the stored list. Load, resume and fork replace those rules and keep every other rule and metadata key. Each root is granted under both its written spelling and its real path, because tools compare paths without following symlinks.
  • Grants persist on the server session. They also apply when the session is used from the TUI, and child sessions copy them when they are created, so a child created earlier keeps roots its parent later dropped. Session rules are checked after config rules, so a config external_directory deny inside a granted root is overridden. read, edit and shell rules still apply.
  • Entries must be absolute and must not contain * or ?, because the permission matcher has no escaping. Anything else is rejected with -32602. The ACP SDK (1.2.1) silently drops entries that are not strings and turns a value that is not an array into [] before the agent sees it, which fails toward a smaller scope. Discovery, the Location root, and telling the model about the roots are deferred core work.

Change outline

Each lifecycle request maps to a session change through the existing session API:

 session/new      { cwd, additionalDirectories }
+  parse → session.create({ location, permissions: rules(dirs), metadata: { [key]: dirs } })   # no field → neither
 session/load     { sessionId, cwd, additionalDirectories }
 session/resume   { sessionId, cwd, additionalDirectories }
+  parse → getSession → activate(session, dirs) → attach
 session/fork     { sessionId, cwd, additionalDirectories }
+  parse → fork → activate(forked, dirs)        # forks copy rules and metadata, so inherited grants are replaced
 session/list
+  SessionInfo.additionalDirectories = metadata[key]
 initialize
+  sessionCapabilities.additionalDirectories = {}

How a root becomes rules and how activate reconciles them:

// parse: path.resolve without following symlinks; drop duplicates and roots whose real path is cwd's
"/tmp/shared" → [
  { action: "external_directory", resource: "/tmp/shared/*", effect: "allow" },
  { action: "external_directory", resource: "/private/tmp/shared/*", effect: "allow" }, // real path, when different
]

// activate: one PATCH, only for the fields that changed
owned       = rules(metadata[key])
permissions = [...rules(dirs), ...session.permissions.filter((rule) => !owned.includes(rule))]
metadata    = { ...session.metadata without key, ...(dirs.length ? { [key]: dirs } : {}) }

ACP rules go first so the session's other rules, including denies, keep precedence for the same paths. FileAccess asks for <parent dir>/* on any path outside the session directory. Core takes the last rule that matches, and * in a pattern also matches /. So /abs/root/* allows anything under the root, but not /abs/rootx/* or /abs/*.

@nexxeln
nexxeln merged commit 7bb3fbf into v2 Oct 1, 2026
11 of 13 checks passed
@nexxeln
nexxeln deleted the acp-extra-dirs branch October 1, 2026 18:17
Ichinose-Kazuki pushed a commit to Ichinose-Kazuki/opencode that referenced this pull request Oct 7, 2026
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.

1 participant