nanocoder
nanocoder copied to clipboard
[Feature] Load the VS Code websocket server (ws) only when --vscode is used
Summary
App.tsx imports useVSCodeServer, which imports the whole vscode module graph and the ws package. The server only starts when --vscode is passed, but the modules load on every start.
Steps to reproduce
pnpm run build- From the repo root run:
node --input-type=module -e "
import {registerHooks} from 'node:module';
const seen = new Set();
registerHooks({load(url, ctx, next) { seen.add(url); return next(url, ctx); }});
await import('ink');
await import('./dist/app/index.js');
console.log('ws modules:', [...seen].filter(u => /node_modules\/ws\//.test(u)).length);"
Expected behaviour
ws is not loaded unless the VS Code mode is enabled.
Actual behaviour
ws modules: 14
Import chain: app/App.js -> hooks/useVSCodeServer.js -> vscode/index.js -> vscode/vscode-server.js -> ws. Blocking the dist/vscode/ subtree removes 19 modules from the startup graph.
Environment
- OS: Windows 11 (10.0.26300)
- Node: 22.22.3
- Nanocoder: 1.31.0 (main at be428fc7)
Suggested fix
source/hooks/useVSCodeServer.tsx:3: replace the staticimport {getVSCodeServer, VSCodeServer} from '@/vscode/index'with a dynamicimport()inside the effect that already runs only whenenabledis true (line 97). Keep the hook call unconditional.source/vscode/vscode-server.ts:7importsws; keeping it inside the lazily loaded module is enough.- Tests:
source/hooks/useVSCodeServer.spec.tsx.
if no one is working on this would be happy to take this on @addyCooks