Skip to content

Commit b96984a

Browse files
avivsinaiclaude
andauthored
fix: include workspace info in generated prompts for Apply & Review (#59)
The Apply & Review feature expects LLMs to output <workspace_name> and <workspace_root> 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 <noreply@anthropic.com>
1 parent 6915bca commit b96984a

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# workspace-info-fix preset
2+
# Generated: 2025-12-01T15:01:17.153Z
3+
# Source: files optimized (6 → 5 patterns)
4+
# Optimization: balanced
5+
# Optimized: 4 files → 5 patterns (saved 0)
6+
# Applied rules:
7+
# - almost-all-exclusion: packages/core/src/types (exclude 1)
8+
9+
packages/core/src/types/**
10+
prompts/xml-outputs.md
11+
src/promptGenerator.ts
12+
src/webview/mergeTab.js
13+
!packages/core/src/types/index.ts
14+
!**/node_modules/**
15+
!**/dist/**
16+
!**/build/**

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [Unreleased]
6+
7+
### Fixed
8+
- **Apply & Review Workspace Resolution**: Generated prompts now include workspace info (name and root path) for each file, enabling LLMs to correctly output `<workspace_name>` and `<workspace_root>` tags. This fixes Apply & Review functionality in multi-root workspace scenarios. ([#58](https://github.com/cogflows/promptcode-vscode/issues/58))
9+
510
## [0.9.0] - 2025-11-19
611

712
### Added

src/promptGenerator.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,16 +294,23 @@ export async function generatePrompt(
294294
log(`Adding content for ${selectedFiles.length} selected files...`);
295295
finalPromptText += '<file_contents>\n';
296296
for (const file of selectedFiles) {
297+
// Defensive fallback for missing workspace info
298+
const workspaceName = file.workspaceFolderName || 'workspace';
299+
const workspacePath = file.workspaceFolderRootPath || workspaceRoot;
300+
297301
try {
298302
const fileContent = file.content ?? await readFileContent(file.absolutePath);
299-
const relativePath = path.relative(file.workspaceFolderRootPath, file.absolutePath);
300-
finalPromptText += `File: ${relativePath} (${file.tokenCount} tokens)\n`;
303+
const relativePath = path.relative(workspacePath, file.absolutePath);
304+
finalPromptText += `File: ${relativePath} (${file.tokenCount} tokens)\n`;
305+
finalPromptText += `Workspace: ${workspaceName} (${workspacePath})\n`;
301306
finalPromptText += '```\n';
302307
finalPromptText += fileContent;
303308
finalPromptText += '\n```\n\n';
304309
} catch (error) {
305310
log(`Error adding file content for ${file.absolutePath}:`, error);
306-
finalPromptText += `File: ${file.path}\n<!-- Error reading file content: ${(error as Error).message} -->\n\n`;
311+
finalPromptText += `File: ${file.path}\n`;
312+
finalPromptText += `Workspace: ${workspaceName} (${workspacePath})\n`;
313+
finalPromptText += `<!-- Error reading file content: ${(error as Error).message} -->\n\n`;
307314
}
308315
}
309316
finalPromptText += '</file_contents>\n\n';

0 commit comments

Comments
 (0)