@@ -50,7 +50,7 @@ import { McpServerManager } from "../../services/mcp/McpServerManager"
5050import { ShadowCheckpointService } from "../../services/checkpoints/ShadowCheckpointService"
5151import { CodeIndexManager } from "../../services/code-index/manager"
5252import type { IndexProgressUpdate } from "../../services/code-index/interfaces/manager"
53- import { fileExistsAtPath } from "../../utils/fs"
53+ import { fileExistsAtPath , safeReadFile } from "../../utils/fs"
5454import { setTtsEnabled , setTtsSpeed } from "../../utils/tts"
5555import { ContextProxy } from "../config/ContextProxy"
5656import { ProviderSettingsManager } from "../config/ProviderSettingsManager"
@@ -988,6 +988,16 @@ export class ClineProvider
988988 await this . initClineWithHistoryItem ( { ...historyItem , rootTask, parentTask } )
989989 }
990990
991+ // Settings Directory
992+
993+ async ensureSettingsDirectoryExists ( ) : Promise < string > {
994+ const { getSettingsDirectoryPath } = await import ( "../../utils/storage" )
995+ const globalStoragePath = this . contextProxy . globalStorageUri . fsPath
996+ return getSettingsDirectoryPath ( globalStoragePath )
997+ }
998+
999+ // Custom Instructions
1000+
9911001 async updateCustomInstructions ( instructions ?: string ) {
9921002 const settingsDirPath = await this . ensureSettingsDirectoryExists ( )
9931003 const customInstructionsFilePath = path . join ( settingsDirPath , GlobalFileNames . customInstructions )
@@ -1017,17 +1027,14 @@ export class ClineProvider
10171027 }
10181028
10191029 async refreshCustomInstructions ( ) : Promise < void > {
1030+ const content = await this . readCustomInstructionsFromFile ( )
1031+ await this . updateCustomInstructions ( content )
1032+ }
1033+
1034+ private async readCustomInstructionsFromFile ( ) : Promise < string | undefined > {
10201035 const settingsDirPath = await this . ensureSettingsDirectoryExists ( )
10211036 const customInstructionsFilePath = path . join ( settingsDirPath , GlobalFileNames . customInstructions )
1022- let content : string | undefined = undefined
1023- try {
1024- content = await fs . readFile ( customInstructionsFilePath , "utf-8" )
1025- } catch ( error ) {
1026- if ( ( error as NodeJS . ErrnoException ) . code !== "ENOENT" ) {
1027- throw error
1028- }
1029- }
1030- await this . updateCustomInstructions ( content )
1037+ return await safeReadFile ( customInstructionsFilePath )
10311038 }
10321039
10331040 // MCP
@@ -1055,27 +1062,6 @@ export class ClineProvider
10551062 return mcpServersDir
10561063 }
10571064
1058- async ensureSettingsDirectoryExists ( ) : Promise < string > {
1059- const { getSettingsDirectoryPath } = await import ( "../../utils/storage" )
1060- const globalStoragePath = this . contextProxy . globalStorageUri . fsPath
1061- return getSettingsDirectoryPath ( globalStoragePath )
1062- }
1063-
1064- private async readCustomInstructionsFromFile ( ) : Promise < string | undefined > {
1065- const settingsDirPath = await this . ensureSettingsDirectoryExists ( )
1066- const customInstructionsFilePath = path . join ( settingsDirPath , GlobalFileNames . customInstructions )
1067-
1068- if ( await fileExistsAtPath ( customInstructionsFilePath ) ) {
1069- try {
1070- return await fs . readFile ( customInstructionsFilePath , "utf-8" )
1071- } catch ( error ) {
1072- this . log ( `Error reading custom instructions file: ${ error } ` )
1073- return undefined
1074- }
1075- }
1076- return undefined
1077- }
1078-
10791065 // OpenRouter
10801066
10811067 async handleOpenRouterCallback ( code : string ) {
0 commit comments