start: restore original CWD before importing server bundle#924
Conversation
|
Hey @mattst88! 👋 Thanks for tracking this down — the diagnosis is correct, the fix placement is right, and the ESM-resolution reasoning is sound. Two things needed before we can merge: Required: wrap the restore in try/catch // Before:
process.chdir(originalCwd);
// After:
try { process.chdir(originalCwd); } catch { /* best effort — restore cwd for VTE tab inheritance */ }Without this, if Recommended: add a Vitest test The The fix logic is solid — just these two changes and this is good to go. Thanks again! |
Restore process.cwd() to the pre-launch directory after chdir(__dirname) so VTE-based terminals (gnome-terminal) open new tabs in the project directory rather than the plugin cache directory. Wrap the restore in try/catch so a missing or unmounted directory (network FS, container, cleaned-up temp dir) doesn't crash the server on launch. Add static-analysis tests pinning the restore ordering and defensive try/catch invariants. Fixes: mksglu#923
5907fc2 to
f4511ac
Compare
|
Done, thanks! |
Fixes #923.
start.mjscallsprocess.chdir(__dirname)early in startup for self-heal path operations, but never restores the original working directory. This causes VTE-based terminals (gnome-terminal, etc.) to open new tabs in the plugin cache directory instead of the user's project directory.VTE determines the "open new tab here" directory by reading
/proc/<pid>/cwdof the foreground process group. The MCP server subprocess inherits the terminal's process group, so its CWD is what the terminal sees.ES module
import()resolves relative toimport.meta.url, notprocess.cwd(), so restoring the original CWD before the server bundle import is safe. The project directory env vars (CLAUDE_PROJECT_DIR,CONTEXT_MODE_PROJECT_DIR) are already set fromoriginalCwdbefore this point, so server behavior is unaffected.