@@ -38,9 +38,7 @@ import { deleteFromContextDirectory } from "../../utils/delete-helper"
3838import delay from "delay"
3939import { AutoApprovalSettings , DEFAULT_AUTO_APPROVAL_SETTINGS } from "../../shared/AutoApprovalSettings"
4040import { HaiBuildDefaults } from "../../shared/haiDefaults"
41- import chokidar , { FSWatcher } from "chokidar"
4241import { buildEmbeddingHandler } from "../../embedding"
43- import { existsSync } from "fs"
4442
4543/*
4644https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
@@ -801,13 +799,19 @@ export class ClineProvider implements vscode.WebviewViewProvider {
801799 await fs . writeFile ( filePath , fileInstruction . content , "utf8" ) ;
802800 }
803801 }
802+ vscode . window . showInformationMessage ( `${ message . fileInstructions . length } files uploaded successfully` ) ;
804803 }
805804 break ;
806805 case "deleteInstruction" :
807806 const dir = path . join ( this . vsCodeWorkSpaceFolderFsPath , HaiBuildDefaults . defaultInstructionsDirectory ) ;
808807 if ( message . text ) {
809808 try {
810809 const filePath = path . join ( dir , message . text ) ;
810+ let doesFileExist = await fileExistsAtPath ( filePath ) ;
811+ if ( ! doesFileExist ) {
812+ vscode . window . showErrorMessage ( `${ message . text } does not exist.` ) ;
813+ break ;
814+ }
811815 await fs . unlink ( filePath ) ;
812816 vscode . window . showInformationMessage ( message . text + " has been deleted." ) ;
813817 } catch ( error ) {
@@ -1038,43 +1042,16 @@ export class ClineProvider implements vscode.WebviewViewProvider {
10381042 await this . postStateToWebview ( )
10391043 }
10401044
1041- async removeFromFileInstructions ( deletedFiles : string [ ] ) {
1042- const fileInstructions = await this . customGetState ( "fileInstructions" ) as HaiInstructionFile [ ] ;
1043- const deletedFileNames = deletedFiles . map ( path => path . split ( '/' ) . pop ( ) ) ;
1044- const updatedFileInstructions = fileInstructions ?. filter (
1045- ( instruction ) => ! deletedFileNames . includes ( instruction . name )
1046- ) ;
1047- this . updateFileInstructions ( updatedFileInstructions ) ;
1048- }
1049-
1050- async addFileInstruction ( filePaths : string [ ] ) {
1051- const fileInstructions = await this . customGetState ( "fileInstructions" ) as HaiInstructionFile [ ] ;
1052- const newInstructions = await Promise . all ( filePaths . map ( async ( filePath ) => ( {
1053- name : filePath . split ( "/" ) . pop ( ) ,
1054- enabled : false ,
1055- } ) ) ) ;
1056-
1057- newInstructions . forEach ( ( instruction ) => {
1058- if ( instruction . name ) {
1059- fileInstructions ?. push ( instruction as HaiInstructionFile ) ;
1060- }
1061- } ) ;
1062- await this . updateFileInstructions ( fileInstructions ) ;
1063- }
1064-
10651045 async checkInstructionFilesFromFileSystem ( ) {
10661046 const workspaceFolder = this . getWorkspacePath ( ) ;
10671047 if ( ! workspaceFolder ) { return ; }
10681048 const instructionsPath = path . join ( workspaceFolder , HaiBuildDefaults . defaultInstructionsDirectory ) ;
10691049 try {
10701050 const files = await fs . readdir ( instructionsPath ) ;
1071- const filesInSystemSet = new Set ( files . filter ( file => file . endsWith ( '.md' ) ) ) ;
1072-
1073- const currentState = await this . getState ( ) ;
1074- const fileInstructions = currentState . fileInstructions || [ ] ;
1075-
1051+ const filesInSystemSet = new Set ( files . filter ( file => file . endsWith ( '.md' ) ) ) ;
1052+ const fileInstructions = await this . customGetState ( "fileInstructions" ) as HaiInstructionFile [ ] ;
10761053 const existingInstructionsMap = new Map (
1077- fileInstructions . map ( instruction => [ instruction . name , instruction . enabled ] )
1054+ fileInstructions ? .map ( instruction => [ instruction . name , instruction . enabled ] )
10781055 ) ;
10791056
10801057 const updatedInstructions = Array . from ( filesInSystemSet , name => ( {
@@ -1798,12 +1775,6 @@ export class ClineProvider implements vscode.WebviewViewProvider {
17981775 await this . context . globalState . update ( key , undefined )
17991776 }
18001777
1801- let workspaceName = this . getWorkspacePath ( )
1802- if ( workspaceName ) {
1803- let instructionsDir = path . join ( workspaceName , HaiBuildDefaults . defaultInstructionsDirectory )
1804- fs . rmdir ( instructionsDir , { recursive : true } )
1805- }
1806-
18071778 const secretKeys : SecretKey [ ] = [
18081779 "apiKey" ,
18091780 "openRouterApiKey" ,
@@ -1829,6 +1800,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
18291800 this . cline = undefined
18301801 }
18311802 vscode . window . showInformationMessage ( "State reset" )
1803+ await this . checkInstructionFilesFromFileSystem ( )
18321804 await this . postStateToWebview ( )
18331805 await this . postMessageToWebview ( { type : "action" , action : "chatButtonClicked" } )
18341806 }
0 commit comments