Repository navigation
refactor(acp): load project config per session folder via SessionContext - #2100
Merged
Merged
Conversation
Generalise the AsyncLocalStorage scope in session-cwd.ts into a SessionContext module (services/session-context.ts). Config loaders (loadHierarchicalConfig and every loader behind loadAppConfig, loadAllProviderConfigs, loadAllMCPConfigs, getClosestConfigFile, loadDefaultMode) now take an explicit cwd, defaulting to the active session's folder or process.cwd() outside one. getAppConfig caches config per canonical root; a session in the launch folder shares the launch config object. ACP requests that act on a session (new, load, resume, prompt, set mode, set config option) now run inside the session's context, so a session in another folder reads that project's agents.config.json. TUI and --plain run outside any context and behave as before. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
|
nc-review could not produce a verdict this run (agent exit |
The roots are the launch folder or a session folder that already passed the trust check, as for the existing project-config joins. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This was referenced Nov 11, 2026
jay23606
added a commit
to jay23606/nanocoder
that referenced
this pull request
Nov 12, 2026
…ext (Nano-Collective#2100) * refactor(acp): load project config per session folder via SessionContext Generalise the AsyncLocalStorage scope in session-cwd.ts into a SessionContext module (services/session-context.ts). Config loaders (loadHierarchicalConfig and every loader behind loadAppConfig, loadAllProviderConfigs, loadAllMCPConfigs, getClosestConfigFile, loadDefaultMode) now take an explicit cwd, defaulting to the active session's folder or process.cwd() outside one. getAppConfig caches config per canonical root; a session in the launch folder shares the launch config object. ACP requests that act on a session (new, load, resume, prompt, set mode, set config option) now run inside the session's context, so a session in another folder reads that project's agents.config.json. TUI and --plain run outside any context and behave as before. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> * chore(config): mark session-root config joins for semgrep The roots are the launch folder or a session folder that already passed the trust check, as for the existing project-config joins. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> --------- 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.
First step of moving per-session state out of process globals so one ACP process can serve sessions in different folders correctly.
What was wrong
nanocoder --acpis one process hosting many sessions, and each session names its own folder (cwdinsession/new). Since #1707 its tools, bash, path boundary, system prompt andAGENTS.mdfollow that folder, but every config loader readprocess.cwd(). So a session opened in project B, from an agent spawned in project A, ran B's tools under A'salwaysAllow,disabledTools, lifecycle hooks, formatters,sandbox,firewall,autoCommit, auto-compact / retry limits,systemPrompt, tune and provider list.Concrete case: A has
alwaysAllow: ["write_file"], B hasalwaysAllow: ["read_file"]. A session in B advertised and applied["write_file"].The change
services/session-context.ts(new):SessionContextheld in AsyncLocalStorage. This is the scope thatsession-cwd.tsalready had (projectRoot,sessionCwd), moved into its own module so later steps can add more per-session state to it.session-cwd.tskeeps its getters and setters and reads the context. Renames:SessionCwdScope→SessionContext,createSessionCwdScope→createSessionContext,runInSessionCwdScope→runInSessionContext,AcpSession.cwdScope→AcpSession.context.cwd:loadHierarchicalConfigand all the loaders behindloadAppConfig, plusloadAllProviderConfigs,loadAllMCPConfigs,loadProjectMCPConfig,getClosestConfigFileandloadDefaultMode. The public ones default togetConfigRoot(), which is the active session's folder, orprocess.cwd()outside a session.getAppConfig()keeps the launch-directory config exactly as before. Inside a session context it returns that folder's config, cached per canonical root (realpath, so/var/...and/private/var/...are the same folder). A session in the launch folder shares the launch config object.reloadAppConfig/clearAppConfigdrop the per-root entries too.session/new,load,resume,prompt,set_mode,set_config_option) now runs inside that session's context. Each public method is a thin wrapper around the old body, which moved into a private method. The trust check (fix(acp): check directory trust for each session's cwd #2071) still runs before the context is entered.acp-conversation.tschanges only at its one call site (import plusrunInSessionContext(options.session.context, …)). It does not conflict with the loop-engine refactor.Behaviour
--plain, daemon: no change. They never enter a context, so every loader still readsprocess.cwd(), and the launch config is cached and reloaded as before.agents.config.json. Still set up once from the launch folder: the starting provider/model,.mcp.jsonserver connections, custom tools, commands and skills. These are documented indocs/features/acp.mdand are follow-ups.Most of the
config/index.tsline count is biome re-wrapping theloadHierarchicalConfig(cwd, …)calls.git diff -wshows 177+/79-.Tests
config/session-root-config.spec.ts: a session reads its own folder's providers / MCP / alwaysAllow / defaultMode /getClosestConfigFile; the launch config is unchanged outside a session; a session in the launch folder (including through a symlink) shares the object; concurrent sessions in two folders keep their own; clearing drops session roots.alwaysAllow.acp-agent.spec.tstests mutated the launch config but opened sessions at the placeholdercwd: '/tmp'. They now open sessions in the launch dir (testConfigDir). These are thewithProviderstests, the approval-policy test, the disabled-tools test andSESSION_CWD.acp-conversation.spec.tsauto-commit test now enablesautoCommitin the session repo's ownagents.config.json, not on the launch config. It asserts the same commit message.config-schema.spec.ts: the loader scraper now matches the leadingcwd,argument. The sanity assertions are unchanged.tsc --noEmit, biome,knip(both passes), AVA forsource/acp,source/config,source/services,source/plain,source/models,tools/git,utils/prompt-builder, plus the full AVA suite. The only failures were the CLI integration specs (needdist/) andapp-container"narrow boot summary places branch on its own line". That one fails onorigin/maintoo when the branch name is this long, so it is unrelated.Next in the sequence
session-override,tuneAggressiveCompact/compressionBackup,lastBuiltPrompt, the subagent executor's cwd,NANOCODER_SESSION_ID..envload inconfig/index.tswith an explicit bootstrap.session/resumeright aftersession/newreturns "not found", because a new session isn't written to disk until its first turn ends.🤖 Generated with Claude Code