acpmux: _acpmux/set_directories gives a running chat new folders

Merged
TE
2d ago
+133-3

Leo asked for chats that can see any folders and files, before or during a chat, on any harness:

"but like also being able to have chatgpt (and in this case, any harnesses) see whatever folders/files would be cool"

This builds on #32811 (folders at start, merged as 09242cc65c5). Follow-ups from that PR are in #32935. It adds _acpmux/set_directories {sessionId, additionalDirectories}, which replaces a running chat's folders. An empty list clears them.

  • When the change takes effect. The chat's agent restarts on the new folders and resumes the same conversation, the same way _acpmux/set_tools does:
    • now when no turn is running,
    • afterTurn when a turn is running,
    • nextStart when no agent is running.
  • What each harness gets. Claude Code restarts with the new --add-dir list. An ACP harness reloads the session (session/load) with the new additionalDirectories.
  • Same list twice. Sending the same list again answers unchanged and restarts nothing.
  • Watchers. Every change is recorded as a mux record of kind directories.
  • Validation and security. The folders are checked the same way session/new checks them.
    • A WebSocket (Web) caller's folders must sit inside the web roots (remote_guard.rs folder fields), whatever chat they name.
    • The app's request for a chat on a peer goes to that peer unchanged, and the peer checks the folders on its own disk, as it already does for acp.trust.set.
    • The folder-trust gate covers this method the same way it covers set_tools.
  • Protocol. The method is registered in the protocol IR (spec/acpmux-protocol.json), and the web types are regenerated.

Not in this PR: the Swift pane relay allowlist (AcpmuxPaneMethods) and the web UI that calls this method. Those come in a follow-up.

Changelog

none (no UI yet)

Tests

  • Red first: the test commit acpmux test: a running chat takes new folders through _acpmux/set_directories (red).
  • cmux-ci test -- cargo test -p acpmux --lib --test additional_directories ...: results in a comment below.

Observed / Not run

See the test comment. Not run: a live Claude Code run.

Agent session: agent session

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Adds _acpmux/set_directories so any harness can see new folders mid-chat, not just at session start. The method replaces a chat's additionalDirectories (an empty list clears them) and restarts its agent on the new folders, resuming the same conversation.

  • Applies like set_tools: now between turns, after a running turn, or at the next start; sending the same list again returns unchanged without a restart, and the turn-end race is closed the same way restart_harnesses closes it.
  • Applies the same folder checks as session/new: Web callers' folders must stay inside web roots, peer chat requests are forwarded unchanged for the peer to validate, and the folder-trust gate covers this method.
  • Tests cover chats that start with folders and chats that take new folders mid-chat, and the method is in the request-stack table.
  • Registers the method in the protocol IR and regenerates the web types; the Swift pane relay allowlist and web UI follow in a later PR.