Skip to content

LLM cannot provide workspace root in Apply & Review because it's not included in generated prompt #58

@inter1965

Description

@inter1965

Summary

The Apply & Review feature expects LLM to output workspace root information in XML tags, but the workspace root is never provided to the LLM during the Generate Prompt phase. This creates a fundamental design flaw where the system requests information that the LLM cannot possibly know.

Current Behavior

In the Generate Prompt phase, the system:

  • Retrieves workspace root internally for path calculations 1
  • Only outputs relative paths in the final prompt 2
  • Does not include workspace root information in the prompt sent to LLM

In the Apply & Review phase, the system:

  • Expects LLM to output <workspace_name> and <workspace_root> XML tags 3
  • Uses these values to locate the correct workspace folder for file operations 4

The Problem

The LLM has no way of knowing the actual workspace root path because:

  1. The generated prompt only contains relative file paths
  2. No workspace context or root path information is provided to the LLM
  3. The system asks the LLM to output information it was never given

This forces users to manually provide workspace root information or causes the Apply & Review feature to fail when the LLM cannot provide accurate workspace details.

Suggested Solution

Include workspace root information in the generated prompt. The SelectedFile objects already contain the necessary data 5 :

  • workspaceFolderRootPath
  • workspaceFolderName

This information should be added to the prompt, either:

  1. In the instructions section:
<user_instructions>
[User instructions]

Workspace: /absolute/path/to/workspace
Workspace Name: my-project
</user_instructions>
  1. Or as part of the file tree section:
<file_tree>
/workspace_root/
  file1.ts
  dir/file2.ts
</file_tree>

Impact

This change would:

  • Allow LLM to accurately output workspace information
  • Improve reliability of Apply & Review feature
  • Reduce user friction by eliminating manual workspace root input
  • Maintain prompt portability while providing necessary context

Notes

The workspace root information is already available in the system - it just needs to be included in the prompt sent to the LLM rather than being used only for internal calculations.

Citations

File: src/promptGenerator.ts (L219-225)

    const workspaceFolders = vscode.workspace.workspaceFolders;
    if (!workspaceFolders || workspaceFolders.length === 0) {
        log('No workspace folders found. Aborting prompt generation.');
        return 'No workspace folders available.';
    }
    const workspaceRoot = workspaceFolders[0].uri.fsPath;
    log('Workspace root:', { workspaceRoot });

File: src/promptGenerator.ts (L299-300)

                const relativePath = path.relative(file.workspaceFolderRootPath, file.absolutePath);
                finalPromptText += `File: ${relativePath} (${file.tokenCount} tokens)\n`; 

File: src/webview/mergeTab.js (L253-254)

        const workspaceName = getElementTextContent(fileEl, 'workspace_name');
        const workspaceRoot = getElementTextContent(fileEl, 'workspace_root');

File: src/extension.ts (L444-464)

			// Find the workspace folder for this file
			let targetWorkspaceFolder: vscode.WorkspaceFolder | undefined;

			if (workspaceName && workspaceRoot) {
				// Try to find the workspace folder by name and root path
				targetWorkspaceFolder = vscode.workspace.workspaceFolders?.find(folder =>
					folder.name === workspaceName && folder.uri.fsPath === workspaceRoot
				);
			}

			if (!targetWorkspaceFolder && filePath) {
                // Fallback: Find workspace folder containing the file path if provided
                // Ensure filePath is treated as relative to some workspace root if workspaceRoot is provided
                const potentialUri = vscode.Uri.file(path.join(workspaceRoot || '', filePath));
                targetWorkspaceFolder = vscode.workspace.getWorkspaceFolder(potentialUri);
            }

            // If still no workspace folder, try finding based on just workspaceRoot if available
            if (!targetWorkspaceFolder && workspaceRoot) {
                targetWorkspaceFolder = vscode.workspace.workspaceFolders?.find(folder => folder.uri.fsPath === workspaceRoot);
            }

File: src/extension.ts (L1708-1715)

	// Convert to SelectedFile format expected by core
	const coreSelectedFiles: SelectedFile[] = selectedFiles.map(file => ({
		path: file.path,
		absolutePath: file.absolutePath || path.join(file.workspaceFolderRootPath || '', file.path),
		tokenCount: file.tokenCount,
		workspaceFolderRootPath: file.workspaceFolderRootPath || '',
		workspaceFolderName: file.workspaceFolderName || ''
	}));

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions