fix(server): skip home directory in workspace prefix matching

When resolving a workspace for a given cwd, the prefix matching loop
would match the user's home directory (~) as a prefix for any path
under it. This caused new projects created under the home directory
to be incorrectly associated with the home workspace instead of
getting their own independent workspace.

Added a check to skip the home directory (homedir()) during prefix
matching. Exact matches for the home directory still work fine.

Fixes #BUG

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
hissincn
2026-04-25 13:54:55 +08:00
parent 2b37276577
commit e92f084727

View File

@@ -6010,8 +6010,10 @@ export class Session {
return exact.workspaceId; return exact.workspaceId;
} }
const userHome = homedir();
let bestMatch: PersistedWorkspaceRecord | null = null; let bestMatch: PersistedWorkspaceRecord | null = null;
for (const workspace of workspaces) { for (const workspace of workspaces) {
if (workspace.cwd === userHome) continue;
const prefix = workspace.cwd.endsWith(sep) ? workspace.cwd : `${workspace.cwd}${sep}`; const prefix = workspace.cwd.endsWith(sep) ? workspace.cwd : `${workspace.cwd}${sep}`;
if (!normalizedCwd.startsWith(prefix)) { if (!normalizedCwd.startsWith(prefix)) {
continue; continue;