From da4befea43117d1896bd5dabe2ca3aac184c0c0d Mon Sep 17 00:00:00 2001 From: avivsinai Date: Mon, 1 Dec 2025 17:07:09 +0200 Subject: [PATCH] fix: include workspace info in generated prompts for Apply & Review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Apply & Review feature expects LLMs to output and XML tags, but this information was never provided in the generated prompt. The LLM had no way to know the workspace root path since only relative file paths were included. Changes: - Add workspace name and root path after each file header in prompts - Add defensive fallback for missing workspace metadata - Include workspace info in error path for consistent format Fixes #58 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .promptcode/presets/workspace-info-fix.patterns | 16 ++++++++++++++++ CHANGELOG.md | 5 +++++ src/promptGenerator.ts | 13 ++++++++++--- 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 .promptcode/presets/workspace-info-fix.patterns diff --git a/.promptcode/presets/workspace-info-fix.patterns b/.promptcode/presets/workspace-info-fix.patterns new file mode 100644 index 0000000..5ec7359 --- /dev/null +++ b/.promptcode/presets/workspace-info-fix.patterns @@ -0,0 +1,16 @@ +# workspace-info-fix preset +# Generated: 2025-12-01T15:01:17.153Z +# Source: files optimized (6 → 5 patterns) +# Optimization: balanced +# Optimized: 4 files → 5 patterns (saved 0) +# Applied rules: +# - almost-all-exclusion: packages/core/src/types (exclude 1) + +packages/core/src/types/** +prompts/xml-outputs.md +src/promptGenerator.ts +src/webview/mergeTab.js +!packages/core/src/types/index.ts +!**/node_modules/** +!**/dist/** +!**/build/** diff --git a/CHANGELOG.md b/CHANGELOG.md index b3ca931..123697a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## [Unreleased] + +### Fixed +- **Apply & Review Workspace Resolution**: Generated prompts now include workspace info (name and root path) for each file, enabling LLMs to correctly output `` and `` tags. This fixes Apply & Review functionality in multi-root workspace scenarios. ([#58](https://github.com/cogflows/promptcode-vscode/issues/58)) + ## [0.9.0] - 2025-11-19 ### Added diff --git a/src/promptGenerator.ts b/src/promptGenerator.ts index 415e077..80ff2a6 100644 --- a/src/promptGenerator.ts +++ b/src/promptGenerator.ts @@ -294,16 +294,23 @@ export async function generatePrompt( log(`Adding content for ${selectedFiles.length} selected files...`); finalPromptText += '\n'; for (const file of selectedFiles) { + // Defensive fallback for missing workspace info + const workspaceName = file.workspaceFolderName || 'workspace'; + const workspacePath = file.workspaceFolderRootPath || workspaceRoot; + try { const fileContent = file.content ?? await readFileContent(file.absolutePath); - const relativePath = path.relative(file.workspaceFolderRootPath, file.absolutePath); - finalPromptText += `File: ${relativePath} (${file.tokenCount} tokens)\n`; + const relativePath = path.relative(workspacePath, file.absolutePath); + finalPromptText += `File: ${relativePath} (${file.tokenCount} tokens)\n`; + finalPromptText += `Workspace: ${workspaceName} (${workspacePath})\n`; finalPromptText += '```\n'; finalPromptText += fileContent; finalPromptText += '\n```\n\n'; } catch (error) { log(`Error adding file content for ${file.absolutePath}:`, error); - finalPromptText += `File: ${file.path}\n\n\n`; + finalPromptText += `File: ${file.path}\n`; + finalPromptText += `Workspace: ${workspaceName} (${workspacePath})\n`; + finalPromptText += `\n\n`; } } finalPromptText += '\n\n';