[Bug] File context attachments read directly from disk, ignoring unsaved editor buffers
Description
When expanding context attachments (e.g. @[file] path/to/file), readCappedFile() reads the file from the filesystem using Node's fs.statSync and fs.readSync. If the user has made unsaved edits in an active VS Code editor, those changes are completely ignored and the LLM receives outdated disk contents.
Environment
- OS: Linux (reviewed); macOS / Windows potentially affected
- Node version: >= 22.0.0
- Nanocoder version: 1.31.0
Steps to Reproduce
- Open a file in VS Code and make edits without saving.
- In the Nanocoder chat box, type
@filename, select the matching file from the completion dropdown, then submit a question about the unsaved contents. - Observe the response.
Expected Behavior
The extension should check vscode.workspace.textDocuments first. If an open document matches the file path, its in-memory buffer (doc.getText()) should be used (subject to the same byte cap), falling back to disk only if the document is not open in VS Code.
Actual Behavior
The extension reads directly from the filesystem, sending the unedited file content to the model.
Additional Context
- [x] No matching open issue found in issue search performed on 2026-10-12
- [x] Relevant code paths inspected at commit
d5ff9c37
Implementation Notes (optional)
- Files:
plugins/vscode/src/chat-webview-provider.ts:796-825plugins/vscode/src/context-attachment.ts:38-65
- Prioritize
vscode.workspace.textDocuments.find(d => d.uri.fsPath === filePath)?.getText()overreadCappedFile. - Apply the same
MAX_CONTEXT_FILE_BYTEScap to the in-memory buffer content.
hey @akramcodez @addyCooks , would like to work on this could you please assign this to me.