Skip to content

Commit 8d1ae7d

Browse files
fix: improve logging and apply suggested improvements
1 parent d81aab5 commit 8d1ae7d

7 files changed

Lines changed: 39 additions & 44 deletions

File tree

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@
7878
},
7979
"promptitude.syncInstructions": {
8080
"type": "boolean",
81-
"default": true,
82-
"description": "Sync instruction prompts",
81+
"default": false,
82+
"description": "Sync instructions",
8383
"order": 3
8484
},
8585
"promptitude.syncPrompt": {

src/configManager.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { GitProvider } from './utils/gitProvider';
44
import { Logger } from './utils/logger';
55
import * as os from 'os';
66
import * as path from 'path';
7-
import * as fs from 'fs';
87

98
export interface SyncFrequency {
109
startup: number;
@@ -61,7 +60,7 @@ export class ConfigManager {
6160
`Removed ${repository.length - uniqueArray.length} duplicate repository URL(s) from configuration.`
6261
);
6362
}, (error) => {
64-
this.logger.error('Failed to update repositories configuration', error);
63+
this.logger.error('Failed to update repositories configuration', error instanceof Error ? error : undefined);
6564
vscode.window.showWarningMessage(
6665
`Found ${repository.length - uniqueArray.length} duplicate repository URL(s) but failed to update configuration. Please remove duplicates manually.`
6766
);

src/storage/repositoryStorage.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,11 @@ export function getRepositoryStorageDirectory(context?: vscode.ExtensionContext)
4949
}
5050

5151
// Fallback: use platform-specific globalStorage path
52-
const extensionId = 'logientnventive.promptitude-extension';
52+
const packageJson = require('../../package.json') as { publisher?: string; name?: string };
53+
const extensionId =
54+
packageJson?.publisher && packageJson?.name
55+
? `${packageJson.publisher}.${packageJson.name}`
56+
: 'logientnventive.promptitude-extension';
5357
let globalStoragePath: string;
5458

5559
switch (process.platform) {

src/syncManager.ts

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as vscode from 'vscode';
22
import * as path from 'path';
3-
import * as os from 'os';
43
import { ConfigManager } from './configManager';
54
import { StatusBarManager, SyncStatus } from './statusBarManager';
65
import { Logger } from './utils/logger';
@@ -811,7 +810,7 @@ export class SyncManager {
811810
this.logger.debug(`Attempting to create symlink...`);
812811
// On Windows, use 'file' type; on Unix, type parameter is optional but 'file' works
813812
await fs.symlink(sourcePath, targetPath, 'file');
814-
this.logger.info(`✅ Created symlink: ${sourcePath} -> ${targetPath}`);
813+
this.logger.debug(`✅ Created symlink: ${sourcePath} -> ${targetPath}`);
815814
} catch (symlinkError: any) {
816815
this.logger.debug(`Symlink creation failed with code: ${symlinkError?.code}`);
817816
// Symlink creation failed (likely Windows without admin/dev mode)
@@ -855,11 +854,11 @@ export class SyncManager {
855854

856855
if (stats.isSymbolicLink()) {
857856
await vscode.workspace.fs.delete(vscode.Uri.file(targetPath));
858-
this.logger.info(`✅ Removed symlink: ${targetPath}`);
857+
this.logger.debug(`✅ Removed symlink: ${targetPath}`);
859858
} else if (process.platform === 'win32') {
860859
// On Windows, we may have copied files instead of symlinks
861860
await vscode.workspace.fs.delete(vscode.Uri.file(targetPath));
862-
this.logger.info(`✅ Removed file copy (Windows fallback): ${targetPath}`);
861+
this.logger.debug(`✅ Removed file copy (Windows fallback): ${targetPath}`);
863862
} else {
864863
this.logger.warn(`File exists but is not a symlink: ${targetPath}`);
865864
}
@@ -972,7 +971,7 @@ export class SyncManager {
972971
await fs.unlink(fullPath);
973972
await this.createPromptSymlink(newSourcePath, fullPath);
974973
fixedCount++;
975-
this.logger.info(`Fixed broken symlink: ${entry.name}`);
974+
this.logger.debug(`Fixed broken symlink: ${entry.name}`);
976975
} else {
977976
this.logger.warn(`Cannot fix broken symlink ${entry.name}: source file not found at ${newSourcePath}`);
978977
}
@@ -1079,13 +1078,13 @@ export class SyncManager {
10791078

10801079
try {
10811080
const repoPath = this.getRepositoryPath(repositoryUrl);
1082-
this.logger.info(`Repository storage path: ${repoPath}`);
1081+
this.logger.debug(`Repository storage path: ${repoPath}`);
10831082

10841083
const sourcePath = this.fileSystem.joinPath(repoPath, promptPath);
1085-
this.logger.info(`Source file path: ${sourcePath}`);
1084+
this.logger.debug(`Source file path: ${sourcePath}`);
10861085

10871086
const sourceExists = await this.fileSystem.fileExists(sourcePath);
1088-
this.logger.info(`Source file exists: ${sourceExists}`);
1087+
this.logger.debug(`Source file exists: ${sourceExists}`);
10891088

10901089
if (!sourceExists) {
10911090
const errorMsg = `Source file does not exist: ${sourcePath}`;
@@ -1095,13 +1094,13 @@ export class SyncManager {
10951094

10961095
// Generate unique workspace name if there are conflicts
10971096
const workspaceName = await this.getUniqueWorkspaceName(promptPath, repositoryUrl);
1098-
this.logger.info(`Workspace name: ${workspaceName}`);
1097+
this.logger.debug(`Workspace name: ${workspaceName}`);
10991098

11001099
// Create target path directly in User/prompts/ (no subdirectories)
11011100
const promptsDir = this.config.getPromptsDirectory();
1102-
this.logger.info(`Prompts directory: ${promptsDir}`);
1101+
this.logger.debug(`Prompts directory: ${promptsDir}`);
11031102
const targetPath = this.fileSystem.joinPath(promptsDir, workspaceName);
1104-
this.logger.info(`Target path: ${targetPath}`);
1103+
this.logger.debug(`Target path: ${targetPath}`);
11051104

11061105
await this.createPromptSymlink(sourcePath, targetPath);
11071106
this.logger.info(`✅ Successfully activated prompt: ${promptPath} as ${workspaceName}`);
@@ -1120,24 +1119,6 @@ export class SyncManager {
11201119
}
11211120
}
11221121

1123-
/**
1124-
* Determine prompt type from filename
1125-
*/
1126-
private determinePromptType(fileName: string): 'agents' | 'instructions' | 'prompts' {
1127-
const lowerName = fileName.toLowerCase();
1128-
1129-
// Support both 'agents' and legacy 'chatmode' naming
1130-
if (lowerName.includes('agent') || lowerName.includes('chatmode') || lowerName.includes('chat-mode')) {
1131-
return 'agents';
1132-
}
1133-
1134-
if (lowerName.includes('instruction') || lowerName.includes('guide')) {
1135-
return 'instructions';
1136-
}
1137-
1138-
return 'prompts';
1139-
}
1140-
11411122
/**
11421123
* Deactivate a prompt by removing its symlink
11431124
* @param promptPath The workspace filename (may include repository identifier)
@@ -1154,7 +1135,9 @@ export class SyncManager {
11541135
this.logger.error(`Failed to deactivate prompt: ${promptPath}`, error instanceof Error ? error : undefined);
11551136
throw error;
11561137
}
1157-
} /**
1138+
}
1139+
1140+
/**
11581141
* Clean up orphaned regular files in prompts directory that should be symlinks
11591142
* Regular files that exist in repository storage should be removed from workspace
11601143
*/
@@ -1211,7 +1194,10 @@ export class SyncManager {
12111194
// On Windows, check if this is actually an active prompt (even if not a symlink)
12121195
if (process.platform === 'win32' && this.treeProvider) {
12131196
const allPrompts = this.treeProvider.getAllPrompts();
1214-
const isActive = allPrompts.some(p => p.name === entry.name && p.active);
1197+
// Check both p.name and p.workspaceName to handle disambiguated files (e.g., prompt@org-repo.md)
1198+
const isActive = allPrompts.some(p =>
1199+
(p.name === entry.name || p.workspaceName === entry.name) && p.active
1200+
);
12151201
if (isActive) {
12161202
this.logger.debug(`Keeping active Windows file copy: ${entry.name}`);
12171203
continue;

src/ui/promptCardsWebview.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export class PromptCardsWebviewProvider implements vscode.WebviewViewProvider {
182182
--vscode-descriptionForeground: var(--vscode-descriptionForeground);
183183
184184
/* Category colors */
185+
--agents-color: #4CAF50;
185186
--chatmode-color: #4CAF50;
186187
--instructions-color: #2196F3;
187188
--prompts-color: #FF9800;
@@ -982,7 +983,7 @@ export class PromptCardsWebviewProvider implements vscode.WebviewViewProvider {
982983
983984
function renderPromptCard(prompt) {
984985
const typeIcon = getTypeIcon(prompt.type);
985-
// Escape backslashes in paths for JavaScript strings (Windows compatibility)
986+
// Escape characters in paths for JavaScript single-quoted strings (Windows compatibility)
986987
const escapedPath = prompt.path.replace(/\\\\/g, '\\\\\\\\');
987988
return \`
988989
<div class="prompt-card \${prompt.type} \${prompt.active ? 'active' : ''}" onclick="viewPrompt('\${escapedPath}')">
@@ -1012,7 +1013,7 @@ export class PromptCardsWebviewProvider implements vscode.WebviewViewProvider {
10121013
10131014
function getTypeIcon(type) {
10141015
switch(type) {
1015-
case 'chatmode': return '💬';
1016+
case 'agents': return '💬';
10161017
case 'instructions': return '📖';
10171018
case 'prompts': return '⚡';
10181019
default: return '📄';

src/ui/promptDetailsWebview.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,11 @@ export class PromptDetailsWebviewProvider implements vscode.WebviewViewProvider
7979
}
8080

8181
try {
82-
this.logger.info(`showPrompt called for: ${prompt.name}, active: ${prompt.active}, repositoryUrl: ${prompt.repositoryUrl}`);
82+
this.logger.debug(`showPrompt called for: ${prompt.name}, active: ${prompt.active}, repositoryUrl: ${prompt.repositoryUrl}`);
8383

8484
// Compute the actual file path
8585
const actualPath = this.getActualFilePath(prompt);
86-
this.logger.info(`Actual path resolved to: ${actualPath}`);
86+
this.logger.debug(`Actual path resolved to: ${actualPath}`);
8787

8888
const content = await this.fileSystem.readFileContent(actualPath);
8989
const metadata = await this.getPromptMetadata(prompt);

src/ui/promptTreeProvider.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as path from 'path';
33
import * as fs from 'fs';
4-
import * as os from 'os';
54
import { ConfigManager } from '../configManager';
65
import { FileSystemManager } from '../utils/fileSystem';
76
import { Logger } from '../utils/logger';
@@ -409,8 +408,14 @@ export class PromptTreeDataProvider implements vscode.TreeDataProvider<PromptTre
409408
isActive = normalizedTarget === normalizedRepoPath;
410409
} else if (process.platform === 'win32') {
411410
// On Windows, it might be a file copy (fallback when symlinks aren't available)
412-
// Consider it active if the file exists in workspace and matches this repository
413-
isActive = true;
411+
// Verify content matches to ensure it's actually from this repository
412+
try {
413+
const workspaceContent = await this.fileSystem.readFileContent(workspacePath);
414+
isActive = workspaceContent === content;
415+
} catch (error) {
416+
this.logger.debug(`Failed to read workspace file for comparison: ${workspaceName}`);
417+
isActive = false;
418+
}
414419
}
415420
} catch (error) {
416421
this.logger.debug(`Failed to check if prompt is active: ${workspaceName}`);
@@ -588,7 +593,7 @@ export class PromptTreeDataProvider implements vscode.TreeDataProvider<PromptTre
588593

589594
// If the file is in the prompts directory, check all repo storage for a matching file
590595
if (normalizedFilePath.startsWith(normalizedPromptsDir)) {
591-
this.logger.debug(`Windows: Checking if ${fileName} is an active copy in prompts directory`);
596+
this.logger.debug(`Windows: File ${fileName} found in workspace prompts directory, checking against repository storage`);
592597
// Note: This prompt is in the workspace directory
593598
// It will be marked as active if we can find it in any repository storage
594599
// The repository URL will remain undefined if not found

0 commit comments

Comments
 (0)