Repository navigation
fix(acp): check directory trust for each session's cwd - #2071
Merged
Merged
Conversation
Contributor
|
nc-review could not produce a verdict this run (agent exit |
will-lamerton
force-pushed
the
fix/acp-session-cwd-trust
branch
from
November 11, 2026 15:07
64c8f48 to
457fb77
Compare
acp-server.ts checks trust only for the directory the server starts in.
newSession, loadSession and resumeSession then accepted any cwd an editor
sent, so a session in an untrusted folder ran tools and bash there and
put its AGENTS.md in the prompt.
Sessions in any folder other than the launch directory are now refused
unless that folder is trusted. The refusal is a RequestError with code
-32003 and nanocoder/trustRequired {cwd, status} data, so a client can
run `nanocoder trust --status/--grant` there and retry. The launch
directory keeps the server's own check, --trust-directory included.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
will-lamerton
force-pushed
the
fix/acp-session-cwd-trust
branch
from
November 11, 2026 15:07
457fb77 to
367f347
Compare
jay23606
added a commit
to jay23606/nanocoder
that referenced
this pull request
Nov 12, 2026
…ve#2071) acp-server.ts checks trust only for the directory the server starts in. newSession, loadSession and resumeSession then accepted any cwd an editor sent, so a session in an untrusted folder ran tools and bash there and put its AGENTS.md in the prompt. Sessions in any folder other than the launch directory are now refused unless that folder is trusted. The refusal is a RequestError with code -32003 and nanocoder/trustRequired {cwd, status} data, so a client can run `nanocoder trust --status/--grant` there and retry. The launch directory keeps the server's own check, --trust-directory included. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
acp-server.tschecks directory trust forprocess.cwd(), the foldernanocoder --acpstarts in. After that,newSession(params.cwd),loadSession(params.cwd)andresumeSession(the savedworkingDirectory) accepted any folder the editor sent. A session in an untrusted folder then:execute_bashthere (turns run insiderunInSessionCwdScope(session.cwd));None of that went through the trust prompt. (Project plugins were already gated per folder by
withTrustedProjectPlugins.)Fix (this PR)
AcpInitContext.launchDirectoryis set by the server once its own trust check has passed.newSession,loadSession(when it registers from disk) andresumeSessioncallassertDirectoryTrusted(cwd)before registering a session:--trust-directoryincluded;ensureDirectoryTrust, soNANOCODER_TRUST_DIRECTORY=1works as it does for the server.RequestErrorwith code-32003(ACP_TRUST_REQUIRED_ERROR_CODE, the per-session form of the server's exit code 3). Its data is{"nanocoder/trustRequired": {cwd, status}}, withstatusworded asnanocoder trust --statuswords it. A client can runnanocoder trust --status --json/--grant <fingerprint>in that folder and retry, the same flow it uses for exit code 3.docs/features/acp.mddocuments the error.Not fixed here (phase 2)
Project-level config is still read from the launch directory, not the session's cwd.
getAppConfig()is a process-wide singleton built fromprocess.cwd(). That covers:loadHierarchicalConfiginconfig/index.ts;mcp-config-loader.ts(.mcp.jsonandagents.config.json);getClosestConfigFileinconfig/paths.ts;.envloaded at import time.So a session in folder B still gets folder A's providers, hooks, MCP servers,
alwaysAllow, sandbox and retry limits, while its prompt and AGENTS.md come from B. A real fix needs:cwd, andloadAppConfig(cwd)is cached per project root.getAppConfig()resolves through the session-cwdAsyncLocalStoragescope that ACP turns already run in, falling back to the process config outside it..envis handled.prompt()readsalwaysAllowinside the session scope.That reaches into every
getAppConfig()caller and MCP lifecycle, so I left it out of this PR. Trust-checking the session folder first is the prerequisite: once folder B is required to be trusted, loading B's config is safe.Testing
New
acp-agent.spec.tstests:-32003and thetrustRequireddata, while the launch folder starts without a trust entry. Fails onmain.loadandresumerefuse a saved session whose folder is no longer trusted, and register nothing. Fails onmain.The full
acp-agent.spec.tsandacp-capabilities.spec.tspass (137 tests).tsc --noEmitandbiome checkpass. Existing tests build the agent withoutlaunchDirectory, which skips the check.🤖 Generated with Claude Code