@@ -4,7 +4,7 @@ import { PromptInfo } from './promptTreeProvider';
44import { FileSystemManager } from '../utils/fileSystem' ;
55import { Logger } from '../utils/logger' ;
66import { ConfigManager } from '../configManager' ;
7- import { encodeRepositorySlug } from '../storage/repositoryStorage' ;
7+ import { encodeRepositorySlug , getRepositoryStorageDirectory } from '../storage/repositoryStorage' ;
88
99export class PromptDetailsWebviewProvider implements vscode . WebviewViewProvider {
1010 public static readonly viewType = 'promptitude.details' ;
@@ -13,13 +13,16 @@ export class PromptDetailsWebviewProvider implements vscode.WebviewViewProvider
1313 private _currentPrompt ?: PromptInfo ;
1414 private fileSystem : FileSystemManager ;
1515 private logger : Logger ;
16+ private context ?: vscode . ExtensionContext ;
1617
1718 constructor (
1819 private readonly _extensionUri : vscode . Uri ,
19- private readonly config : ConfigManager
20+ private readonly config : ConfigManager ,
21+ context ?: vscode . ExtensionContext
2022 ) {
2123 this . fileSystem = new FileSystemManager ( ) ;
2224 this . logger = Logger . get ( 'PromptDetailsWebviewProvider' ) ;
25+ this . context = context ;
2326 }
2427
2528 public resolveWebviewView (
@@ -76,9 +79,11 @@ export class PromptDetailsWebviewProvider implements vscode.WebviewViewProvider
7679 }
7780
7881 try {
82+ this . logger . info ( `showPrompt called for: ${ prompt . name } , active: ${ prompt . active } , repositoryUrl: ${ prompt . repositoryUrl } ` ) ;
83+
7984 // Compute the actual file path
8085 const actualPath = this . getActualFilePath ( prompt ) ;
81- this . logger . debug ( `Reading prompt from : ${ actualPath } `) ;
86+ this . logger . info ( `Actual path resolved to : ${ actualPath } `) ;
8287
8388 const content = await this . fileSystem . readFileContent ( actualPath ) ;
8489 const metadata = await this . getPromptMetadata ( prompt ) ;
@@ -105,34 +110,49 @@ export class PromptDetailsWebviewProvider implements vscode.WebviewViewProvider
105110 private getActualFilePath ( prompt : PromptInfo ) : string {
106111 const fs = require ( 'fs' ) ;
107112
108- this . logger . debug ( `Getting actual path - active: ${ prompt . active } , repositoryUrl: ${ prompt . repositoryUrl } , path: ${ prompt . path } ` ) ;
113+ this . logger . debug ( `Getting actual path - active: ${ prompt . active } , repositoryUrl: ${ prompt . repositoryUrl } , path: ${ prompt . path } , name: ${ prompt . name } ` ) ;
109114
110- // First, check if the workspace path exists (for active prompts)
111- if ( fs . existsSync ( prompt . path ) ) {
112- this . logger . debug ( `File exists at workspace path: ${ prompt . path } ` ) ;
113- return prompt . path ;
114- }
115-
116- // If workspace path doesn't exist and we have a repository URL, try repository storage
117- if ( prompt . repositoryUrl ) {
118- // Get prompts directory and compute repository storage directory
119- const promptsDir = this . config . getPromptsDirectory ( ) ;
120- const repoStorageDir = path . join ( path . dirname ( promptsDir ) , 'repos' ) ;
115+ // For inactive prompts with a repository URL, go directly to repository storage
116+ if ( ! prompt . active && prompt . repositoryUrl ) {
117+ // Get repository storage directory using the helper function
118+ const repoStorageDir = getRepositoryStorageDirectory ( this . context ) ;
121119
122120 // Encode repository URL using the same logic as SyncManager
123121 const encodedUrl = encodeRepositorySlug ( prompt . repositoryUrl ) ;
124122
125- // Build path to repository storage
123+ // Build path to repository storage using the original filename
126124 const repoStoragePath = path . join ( repoStorageDir , encodedUrl , prompt . name ) ;
127125
126+ this . logger . debug ( `Repo storage dir: ${ repoStorageDir } ` ) ;
127+ this . logger . debug ( `Encoded URL: ${ encodedUrl } ` ) ;
128+ this . logger . debug ( `Looking for inactive prompt at repository storage: ${ repoStoragePath } ` ) ;
129+
128130 if ( fs . existsSync ( repoStoragePath ) ) {
129- this . logger . debug ( `File exists at repository storage: ${ repoStoragePath } ` ) ;
131+ this . logger . debug ( `File found at repository storage: ${ repoStoragePath } ` ) ;
130132 return repoStoragePath ;
131133 } else {
132134 this . logger . warn ( `File not found at repository storage: ${ repoStoragePath } ` ) ;
135+ // Try to list files in the encoded directory to help debug
136+ const encodedDir = path . join ( repoStorageDir , encodedUrl ) ;
137+ if ( fs . existsSync ( encodedDir ) ) {
138+ try {
139+ const files = fs . readdirSync ( encodedDir ) ;
140+ this . logger . debug ( `Files in repository directory: ${ files . join ( ', ' ) } ` ) ;
141+ } catch ( err ) {
142+ this . logger . debug ( `Could not list files in repository directory: ${ err } ` ) ;
143+ }
144+ } else {
145+ this . logger . warn ( `Repository directory does not exist: ${ encodedDir } ` ) ;
146+ }
133147 }
134148 }
135149
150+ // For active prompts or when repository lookup failed, check workspace path
151+ if ( fs . existsSync ( prompt . path ) ) {
152+ this . logger . debug ( `File exists at workspace path: ${ prompt . path } ` ) ;
153+ return prompt . path ;
154+ }
155+
136156 // Fallback to the original path (will likely fail, but at least we tried)
137157 this . logger . warn ( `File not found anywhere, returning original path: ${ prompt . path } ` ) ;
138158 return prompt . path ;
0 commit comments