@@ -51,8 +51,7 @@ import { McpServerManager } from "../../services/mcp/McpServerManager"
5151import { ShadowCheckpointService } from "../../services/checkpoints/ShadowCheckpointService"
5252import { CodeIndexManager } from "../../services/code-index/manager"
5353import type { IndexProgressUpdate } from "../../services/code-index/interfaces/manager"
54- import { fileExistsAtPath , safeReadFile } from "../../utils/fs"
55- import { openFile } from "../../integrations/misc/open-file"
54+ import { fileExistsAtPath } from "../../utils/fs"
5655import { setTtsEnabled , setTtsSpeed } from "../../utils/tts"
5756import { ContextProxy } from "../config/ContextProxy"
5857import { ProviderSettingsManager } from "../config/ProviderSettingsManager"
@@ -67,6 +66,7 @@ import { webviewMessageHandler } from "./webviewMessageHandler"
6766import { WebviewMessage } from "../../shared/WebviewMessage"
6867import { EMBEDDING_MODEL_PROFILES } from "../../shared/embeddingModels"
6968import { ProfileValidator } from "../../shared/ProfileValidator"
69+ import { ContentManager } from "../../services/content/ContentManager"
7070
7171/**
7272 * https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
@@ -103,6 +103,7 @@ export class ClineProvider
103103 return this . _workspaceTracker
104104 }
105105 protected mcpHub ?: McpHub // Change from private to protected
106+ public contentManager : ContentManager // Declare private member
106107
107108 public isViewLaunched = false
108109 public settingsImportedAt ?: number
@@ -149,6 +150,14 @@ export class ClineProvider
149150 . catch ( ( error ) => {
150151 this . log ( `Failed to initialize MCP Hub: ${ error } ` )
151152 } )
153+
154+ // Instantiate ContentManager
155+ this . contentManager = new ContentManager ( {
156+ log : this . log . bind ( this ) ,
157+ postMessageToWebview : this . postMessageToWebview . bind ( this ) ,
158+ postStateToWebview : this . postStateToWebview . bind ( this ) ,
159+ globalStorageUriFsPath : this . contextProxy . globalStorageUri . fsPath ,
160+ } )
152161 }
153162
154163 // Adds a new Cline instance to clineStack, marking the start of a new task.
@@ -1009,62 +1018,6 @@ export class ClineProvider
10091018 }
10101019 }
10111020
1012- // Content
1013-
1014- async openContent ( contentId : string ) : Promise < void > {
1015- const filePath = await this . getContentPath ( contentId )
1016-
1017- if ( ! filePath ) {
1018- this . log ( `File path could not be determined for contentId: ${ contentId } ` )
1019- return
1020- }
1021-
1022- await openFile ( filePath , { create : true } )
1023- await vscode . commands . executeCommand ( "workbench.action.files.revert" )
1024- }
1025-
1026- async refreshContent ( contentId : string ) : Promise < void > {
1027- const content = await this . readContent ( contentId )
1028- await this . updateContent ( contentId , content )
1029- this . postMessageToWebview ( {
1030- type : "contentRefreshed" ,
1031- contentId : contentId ,
1032- success : true , // Assuming success for now
1033- } )
1034- }
1035-
1036- async updateContent ( contentId : string , content ?: string ) {
1037- const filePath = await this . getContentPath ( contentId )
1038-
1039- if ( ! filePath ) {
1040- this . log ( `File path could not be determined for contentId: ${ contentId } ` )
1041- return
1042- }
1043-
1044- if ( content && content . trim ( ) ) {
1045- await fs . writeFile ( filePath , content . trim ( ) , "utf-8" )
1046- this . log ( `Updated content file: ${ filePath } ` )
1047- } else {
1048- try {
1049- await fs . unlink ( filePath )
1050- this . log ( `Deleted content file: ${ filePath } ` )
1051- } catch ( error ) {
1052- if ( error . code !== "ENOENT" ) {
1053- this . log ( `Error deleting content file: ${ error . message } ` )
1054- throw error
1055- }
1056- }
1057- }
1058- // Update the webview state
1059- await this . postStateToWebview ( )
1060- }
1061-
1062- private async readContent ( contentId : string ) : Promise < string > {
1063- const filePath = await this . getContentPath ( contentId )
1064-
1065- return filePath ? ( ( await safeReadFile ( filePath ) ) ?? "" ) : ""
1066- }
1067-
10681021 // MCP
10691022
10701023 async ensureMcpServersDirectoryExists ( ) : Promise < string > {
@@ -1539,7 +1492,7 @@ export class ClineProvider
15391492 return {
15401493 apiConfiguration : providerSettings ,
15411494 lastShownAnnouncementId : stateValues . lastShownAnnouncementId ,
1542- customInstructions : await this . readContent ( GlobalContentIds . customInstructions ) ,
1495+ customInstructions : await this . contentManager . readContent ( GlobalContentIds . customInstructions ) ,
15431496 apiModelId : stateValues . apiModelId ,
15441497 alwaysAllowReadOnly : stateValues . alwaysAllowReadOnly ?? false ,
15451498 alwaysAllowReadOnlyOutsideWorkspace : stateValues . alwaysAllowReadOnlyOutsideWorkspace ?? false ,
0 commit comments