@@ -36,6 +36,7 @@ import { telemetryService } from "../../services/telemetry/TelemetryService"
3636import { TelemetrySetting } from "../../shared/TelemetrySetting"
3737import { cleanupLegacyCheckpoints } from "../../integrations/checkpoints/CheckpointMigration"
3838import CheckpointTracker from "../../integrations/checkpoints/CheckpointTracker"
39+ import { getTotalTasksSize } from "../../utils/storage"
3940
4041/*
4142https://github.com/microsoft/vscode-webview-ui-toolkit-samples/blob/main/default/weather-webview/src/providers/WeatherViewProvider.ts
@@ -816,6 +817,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
816817 }
817818 break
818819 }
820+ case "requestTotalTasksSize" : {
821+ this . refreshTotalTasksSize ( )
822+ break
823+ }
819824 case "restartMcpServer" : {
820825 try {
821826 await this . mcpHub ?. restartConnection ( message . text ! )
@@ -917,6 +922,7 @@ export class ClineProvider implements vscode.WebviewViewProvider {
917922 case "clearAllTaskHistory" : {
918923 await this . deleteAllTaskHistory ( )
919924 await this . postStateToWebview ( )
925+ this . refreshTotalTasksSize ( )
920926 this . postMessageToWebview ( { type : "relinquishControl" } )
921927 break
922928 }
@@ -1788,46 +1794,56 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
17881794 // await this.postStateToWebview()
17891795 }
17901796
1797+ async refreshTotalTasksSize ( ) {
1798+ getTotalTasksSize ( this . context . globalStorageUri . fsPath )
1799+ . then ( ( newTotalSize ) => {
1800+ this . postMessageToWebview ( {
1801+ type : "totalTasksSize" ,
1802+ totalTasksSize : newTotalSize ,
1803+ } )
1804+ } )
1805+ . catch ( ( error ) => {
1806+ console . error ( "Error calculating total tasks size:" , error )
1807+ } )
1808+ }
1809+
17911810 async deleteTaskWithId ( id : string ) {
17921811 console . info ( "deleteTaskWithId: " , id )
17931812
1794- if ( id === this . cline ?. taskId ) {
1795- await this . clearTask ( )
1796- console . debug ( "cleared task" )
1797- }
1813+ try {
1814+ if ( id === this . cline ?. taskId ) {
1815+ await this . clearTask ( )
1816+ console . debug ( "cleared task" )
1817+ }
17981818
1799- const { taskDirPath, apiConversationHistoryFilePath, uiMessagesFilePath } = await this . getTaskWithId ( id )
1819+ const { taskDirPath, apiConversationHistoryFilePath, uiMessagesFilePath } = await this . getTaskWithId ( id )
18001820
1801- // Delete checkpoints
1802- console . info ( "deleting checkpoints" )
1803- const taskHistory = ( ( await this . getGlobalState ( "taskHistory" ) ) as HistoryItem [ ] | undefined ) || [ ]
1804- const historyItem = taskHistory . find ( ( item ) => item . id === id )
1805- //console.log("historyItem: ", historyItem)
1806- // if (historyItem) {
1807- // try {
1808- // await CheckpointTracker.deleteCheckpoints(id, historyItem, this.context.globalStorageUri.fsPath)
1809- // } catch (error) {
1810- // console.error(`Failed to delete checkpoints for task ${id}:`, error)
1811- // }
1812- // }
1821+ const updatedTaskHistory = await this . deleteTaskFromState ( id )
18131822
1814- await this . deleteTaskFromState ( id )
1823+ // Delete the task files
1824+ const apiConversationHistoryFileExists = await fileExistsAtPath ( apiConversationHistoryFilePath )
1825+ if ( apiConversationHistoryFileExists ) {
1826+ await fs . unlink ( apiConversationHistoryFilePath )
1827+ }
1828+ const uiMessagesFileExists = await fileExistsAtPath ( uiMessagesFilePath )
1829+ if ( uiMessagesFileExists ) {
1830+ await fs . unlink ( uiMessagesFilePath )
1831+ }
1832+ const legacyMessagesFilePath = path . join ( taskDirPath , "claude_messages.json" )
1833+ if ( await fileExistsAtPath ( legacyMessagesFilePath ) ) {
1834+ await fs . unlink ( legacyMessagesFilePath )
1835+ }
18151836
1816- // Delete the task files
1817- const apiConversationHistoryFileExists = await fileExistsAtPath ( apiConversationHistoryFilePath )
1818- if ( apiConversationHistoryFileExists ) {
1819- await fs . unlink ( apiConversationHistoryFilePath )
1820- }
1821- const uiMessagesFileExists = await fileExistsAtPath ( uiMessagesFilePath )
1822- if ( uiMessagesFileExists ) {
1823- await fs . unlink ( uiMessagesFilePath )
1824- }
1825- const legacyMessagesFilePath = path . join ( taskDirPath , "claude_messages.json" )
1826- if ( await fileExistsAtPath ( legacyMessagesFilePath ) ) {
1827- await fs . unlink ( legacyMessagesFilePath )
1837+ await fs . rmdir ( taskDirPath ) // succeeds if the dir is empty
1838+
1839+ if ( updatedTaskHistory . length === 0 ) {
1840+ await this . deleteAllTaskHistory ( )
1841+ }
1842+ } catch ( error ) {
1843+ console . debug ( `Error deleting task:` , error )
18281844 }
18291845
1830- await fs . rmdir ( taskDirPath ) // succeeds if the dir is empty
1846+ this . refreshTotalTasksSize ( )
18311847 }
18321848
18331849 async deleteTaskFromState ( id : string ) {
@@ -1838,6 +1854,8 @@ Here is the project's README to help you get started:\n\n${mcpDetails.readmeCont
18381854
18391855 // Notify the webview that the task has been deleted
18401856 await this . postStateToWebview ( )
1857+
1858+ return updatedTaskHistory
18411859 }
18421860
18431861 async postStateToWebview ( ) {
0 commit comments