From d4e457a809e2464548e82dc2516674182bfb9809 Mon Sep 17 00:00:00 2001 From: Bender-0 Date: Sun, 14 Sep 2025 20:23:07 +0200 Subject: [PATCH] fix: Improve workspace detection logic This commit improves the workspace detection logic by first trying to get the workspace from the active text editor. This is more reliable when multiple workspaces are open. It also sets the working directory to the workspace root instead of the .superdesign directory. --- src/services/customAgentService.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/customAgentService.ts b/src/services/customAgentService.ts index 64b3b7b2..be8bb88f 100644 --- a/src/services/customAgentService.ts +++ b/src/services/customAgentService.ts @@ -33,8 +33,13 @@ export class CustomAgentService implements AgentService { private async setupWorkingDirectory(): Promise { try { - // Try to get workspace root first - const workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath; + // Try to get workspace root first from the active text editor + let workspaceRoot = vscode.window.activeTextEditor ? vscode.workspace.getWorkspaceFolder(vscode.window.activeTextEditor.document.uri)?.uri.fsPath : undefined; + + if (!workspaceRoot) { + workspaceRoot = vscode.workspace.workspaceFolders?.[0]?.uri.fsPath; + } + this.outputChannel.appendLine(`Workspace root detected: ${workspaceRoot}`); if (workspaceRoot) { @@ -50,7 +55,7 @@ export class CustomAgentService implements AgentService { this.outputChannel.appendLine(`.superdesign directory already exists: ${superdesignDir}`); } - this.workingDirectory = superdesignDir; + this.workingDirectory = workspaceRoot; this.outputChannel.appendLine(`Working directory set to: ${this.workingDirectory}`); } else { this.outputChannel.appendLine('No workspace root found, using fallback');