Skip to content

fix(vscode): respect configured cwd across extension operations - #1743

Merged
addyCooks merged 3 commits into
Nano-Collective:mainfrom
Srinidhi444:fix/vscode-cwd-consistency
Oct 15, 2026
Merged

addyCooks merged 3 commits into
Nano-Collective:mainfrom
Srinidhi444:fix/vscode-cwd-consistency

Conversation

@Srinidhi444

Copy link
Copy Markdown
Contributor

Fixes #1720

Ensures the VS Code extension consistently respects the configured nanocoder.cwd instead of defaulting to the first workspace folder.

Introduces a shared resolveExtensionCwd() helper and uses it across ACP process startup, session initialization, settings operations, and @ mention file searches.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Changeset

  • Added a changeset (pnpm changeset) describing this change for the changelog

No changeset added, as nanocoder-vscode is excluded from Changesets in .changeset/config.json.

Testing

Automated Tests

  • New features include passing tests in .spec.ts/tsx files (N/A — bug fix)
  • All existing tests pass (pnpm test:all completes successfully)
  • Tests cover both success and error scenarios

Additional checks performed:

  • pnpm run test:types:vscode — Passed
  • git diff --check — Passed
  • pnpm --filter ./plugins/vscode build:ext

Manual Testing

  • Tested with Ollama
  • Tested with OpenRouter
  • Tested with OpenAI-compatible API
  • Tested MCP integration (if applicable)

Checklist

  • If this was for an open issue, I was assigned to it
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (if needed)
  • No breaking changes (or clearly documented)
  • Appropriate logging added using structured logging see CONTRIBUTING.md)

Additional Notes

The @ mention search now uses the configured CWD as its search root. One edge case that may need further handling is when nanocoder.cwd points outside the currently opened VS Code workspace, since vscode.workspace.findFiles() may not search external directories as expected. This scenario has not yet been verified.

@github-actions

Copy link
Copy Markdown
Contributor

No changeset found

This PR does not add a changeset, so it will not appear in the changelog or trigger a release.

If the change is user-facing, add one:

pnpm changeset

Pick a bump (patch / minor / major) and write the changelog entry in our usual voice ("Added X... Thanks to @you. Closes #123."), then commit the generated .changeset/*.md file.

If this PR is docs-only or a chore that needs no release note, you can ignore this — or run pnpm changeset --empty to record that intentionally.

@github-actions github-actions Bot added the area:vscode VS Code extension and host integration label Oct 13, 2026
@Srinidhi444
Srinidhi444 marked this pull request as ready for review October 13, 2026 14:16

@addyCooks addyCooks left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Srinidhi444, this covers the call sites from the issue and the helper is a good shape.
I checked the precedence (setting, then workspace folder, then home) and it behaves as intended. A few things before it can merge:

  1. acp-client.ts:476 (resumeSession) still sends workspaceFolders[0] as the cwd. Now that the agent honours the session cwd, a resumed session would run in a different directory from where it started. Please use resolveExtensionCwd() there too.
  2. extension.ts:120 has its own copy of the same logic. Please switch it to the helper so there's one source of truth. (startCli() at :376 is optional.)
  3. Please add a small spec for resolveExtensionCwd. The vscode stub in test-stubs supports it: setting wins over folder, an empty setting counts as unset, and no folder falls back to home.

No changeset is needed, since nanocoder-vscode is in the ignore list. I'd also like to see the nanocoder.cwd-outside-workspace case checked by hand if you can, since findFiles may behave differently there.

@github-actions

Copy link
Copy Markdown
Contributor

nc-review: comments — 2 important, 2 nits

@Srinidhi444 — a few things worth a look, none blocking.

PR #1743 introduces a shared resolveExtensionCwd() helper and routes seven hardcoded workspaceFolders?.[0]?.uri.fsPath || process.cwd() expressions in the VS Code extension through it, matching the resolution chain already used in acp-process-manager.ts and extension.ts's openConfig. The change is correct, well-scoped to the file list in issue #1720, and the changeset exemption for nanocoder-vscode is real. The unresolved concerns are: no test for the new helper (the project rubric asks for a regression test with a bug fix), and the @-mention search now builds a RelativePattern from a Uri.file(resolveExtensionCwd()) unconditionally — when nanocoder.cwd points outside the open workspace the previous code passed the workspace folder (always in-scope) and the new code may not, which the author acknowledges but does not guard.

🟠 important · tests · plugins/vscode/src/workspace-utils.ts

The new resolveExtensionCwd() helper is the only behavioural change in this PR, and it has no spec file. The helper is pure (only vscode.workspace.getConfiguration, vscode.workspace.workspaceFolders, os.homedir, and process.cwd()) and trivially unit-testable by stubbing those four — the same pattern mention-search.spec.ts already uses. A regression test asserting (a) nanocoder.cwd wins over a workspace folder, (b) empty/missing nanocoder.cwd falls back to the first workspace folder, and (c) absent workspace folder falls back through homedir / process.cwd would have caught any future drift in the resolution chain, and would have locked in the order so a future re-order cannot silently change the public contract for cwd. Without it, the change relies entirely on the type checker and the type checker is not exercised.

🟠 important · correctness · plugins/vscode/src/chat-webview-provider.ts:747

In _mentionSearchDeps() the diff replaces the previous vscode.workspace.workspaceFolders?.[0] (which is always a real workspace folder, so RelativePattern is always in-scope) with vscode.Uri.file(resolveExtensionCwd()) and passes that to vscode.workspace.findFiles(new vscode.RelativePattern(searchRoot, glob), …) unconditionally. When the user sets nanocoder.cwd to a path outside the currently opened VS Code workspace, searchRoot is no longer a workspace folder and findFiles is documented to search only workspace folders — the call may return no results, throw, or behave inconsistently across VS Code versions. The old code had the same RelativePattern guard (workspaceFolder ? … : glob) that silently degraded to an unscoped glob when there was no folder; the new code drops that guard. Either keep the workspace-folder branch and only change the workspaceRoot (string) used for relative-path display, or guard the RelativePattern against out-of-workspace roots and fall back to the bare glob — the same pattern the surrounding code already used. The author's PR description flags this as unverified, which is the right instinct; the code should not ship without the guard.

⚪ nit · correctness · plugins/vscode/src/chat-webview-provider.ts:747

Related to the previous finding: the diff changes _mentionExcludeGlob(workspaceFolder?.uri) to _mentionExcludeGlob(searchRoot). When nanocoder.cwd is outside the workspace, the user's files.exclude / search.exclude settings are now read with the configured cwd as the scope instead of the workspace folder, so workspace-level exclude rules silently stop applying. Worth a comment noting that the exclude scope intentionally tracks the search root, or — preferably — passing both scopes (workspace folder for the user's excludes, cwd for the always-excludes) so a configured cwd does not regress exclusion behaviour.

⚪ nit · completeness · plugins/vscode/src/acp-client.ts:476

acp-client.resumeSession() still reads vscode.workspace.workspaceFolders?.[0]?.uri.fsPath || process.cwd() and is therefore out of sync with the new resolveExtensionCwd() helper. The issue body is explicit that this inconsistency is the bug; resuming a session against a different cwd than the one used to create it will likely surface as a session-not-found or wrong-working-directory error. Out of scope for the diff but worth a follow-up issue so the helper stays the single source of truth.


🔴 blocking · 🟠 a reviewer would ask for a change · ⚪ optional

Automated code review — correctness, security, design, tests, plus duplicates and scope. A human still decides; this is not a substitute for review and is not exhaustive. The required status checks separately cover lint, formatting, types, unused dependencies, the test suite and the build. This bot never merges. Maintainers can rerun with /re-review.

@github-actions github-actions Bot added the agent:comments nc-review left non-blocking findings label Oct 14, 2026
@Srinidhi444

Srinidhi444 commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Hey @addyCooks , I've addressed the requested changes and added the regression tests for resolveExtensionCwd().
I also manually verified the nanocoder.cwd outside-workspace scenario on Windows. I opened Project B in VS Code while explicitly setting nanocoder.cwd to Project A.

The @ mention autocomplete correctly suggested files from Project A and did not suggest files from Project B, confirming that the search respects the configured CWD in this setup.

The changes have been pushed to the PR. Let me know if anything else needs adjustment!
Also please check this: #1720 (comment)

With no folder open and no nanocoder.cwd set, the new cwd fallback is the home directory, so @ mention search started crawling it where it used to find nothing. Search only the configured cwd or the first workspace folder; sessions still fall back to home. Add resolveProjectCwd for that distinction, test the search root, and update the nanocoder.cwd description in package.json, the README and the extension docs, which still said it only set the CLI's working directory.
@github-actions github-actions Bot added the area:docs Documentation label Oct 15, 2026

@addyCooks addyCooks left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @Srinidhi444, this covers everything from my review. I checked it: resumeSession now sends the configured nanocoder.cwd (main sends the first workspace folder), openConfig uses the helper, and the new spec covers the three cases.

I pushed one small commit on top (9fd1b40) for the follow-ups I'd noted:

  • @ mention search no longer falls back to your home directory: with no folder open and no nanocoder.cwd set it finds nothing, as before. Sessions still fall back to home. Added resolveProjectCwd() for that distinction, plus tests for the search root.
  • Updated the nanocoder.cwd description in package.json, the README and docs/features/vscode-extension.md.

CI is green on it.
Approving 🎉

@addyCooks
addyCooks merged commit ea67faf into Nano-Collective:main Oct 15, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:comments nc-review left non-blocking findings area:docs Documentation area:vscode VS Code extension and host integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] VS Code extension inconsistently applies nanocoder.cwd to new sessions, settings, and mention search

2 participants