@@ -46,6 +46,7 @@ import { Terminal } from "../../integrations/terminal/Terminal"
4646import { downloadTask } from "../../integrations/misc/export-markdown"
4747import { getTheme } from "../../integrations/theme/getTheme"
4848import WorkspaceTracker from "../../integrations/workspace/WorkspaceTracker"
49+ import { getHistoryItem , setHistoryItems , deleteHistoryItem } from "../task-persistence/taskHistory"
4950import { McpHub } from "../../services/mcp/McpHub"
5051import { McpServerManager } from "../../services/mcp/McpServerManager"
5152import { MarketplaceManager } from "../../services/marketplace"
@@ -1128,8 +1129,8 @@ export class ClineProvider
11281129 uiMessagesFilePath : string
11291130 apiConversationHistory : Anthropic . MessageParam [ ]
11301131 } > {
1131- const history = this . getGlobalState ( "taskHistory" ) ?? [ ]
1132- const historyItem = history . find ( ( item ) => item . id === id )
1132+ // Get the history item from the file-based storage
1133+ const historyItem = await getHistoryItem ( id )
11331134
11341135 if ( historyItem ) {
11351136 const { getTaskDirectoryPath } = await import ( "../../utils/storage" )
@@ -1155,10 +1156,9 @@ export class ClineProvider
11551156 }
11561157 }
11571158
1158- // if we tried to get a task that doesn't exist, remove it from state
1159- // FIXME: this seems to happen sometimes when the json file doesnt save to disk for some reason
1160- await this . deleteTaskFromState ( id )
1161- throw new Error ( "Task not found" )
1159+ // If we tried to get a task that doesn't exist, delete it from storage
1160+ await deleteHistoryItem ( id )
1161+ throw new Error ( `Task not found, removed from index: ${ id } ` )
11621162 }
11631163
11641164 async showTaskWithId ( id : string ) {
@@ -1241,9 +1241,7 @@ export class ClineProvider
12411241 }
12421242
12431243 async deleteTaskFromState ( id : string ) {
1244- const taskHistory = this . getGlobalState ( "taskHistory" ) ?? [ ]
1245- const updatedTaskHistory = taskHistory . filter ( ( task ) => task . id !== id )
1246- await this . updateGlobalState ( "taskHistory" , updatedTaskHistory )
1244+ await deleteHistoryItem ( id )
12471245 await this . postStateToWebview ( )
12481246 }
12491247
@@ -1387,7 +1385,6 @@ export class ClineProvider
13871385 ttsSpeed,
13881386 diffEnabled,
13891387 enableCheckpoints,
1390- taskHistory,
13911388 soundVolume,
13921389 browserViewportSize,
13931390 screenshotQuality,
@@ -1472,12 +1469,9 @@ export class ClineProvider
14721469 autoCondenseContextPercent : autoCondenseContextPercent ?? 100 ,
14731470 uriScheme : vscode . env . uriScheme ,
14741471 currentTaskItem : this . getCurrentCline ( ) ?. taskId
1475- ? ( taskHistory || [ ] ) . find ( ( item : HistoryItem ) => item . id === this . getCurrentCline ( ) ? .taskId )
1472+ ? await getHistoryItem ( this . getCurrentCline ( ) ! . taskId )
14761473 : undefined ,
14771474 clineMessages : this . getCurrentCline ( ) ?. clineMessages || [ ] ,
1478- taskHistory : ( taskHistory || [ ] )
1479- . filter ( ( item : HistoryItem ) => item . ts && item . task )
1480- . sort ( ( a : HistoryItem , b : HistoryItem ) => b . ts - a . ts ) ,
14811475 soundEnabled : soundEnabled ?? false ,
14821476 ttsEnabled : ttsEnabled ?? false ,
14831477 ttsSpeed : ttsSpeed ?? 1.0 ,
@@ -1645,7 +1639,6 @@ export class ClineProvider
16451639 allowedMaxRequests : stateValues . allowedMaxRequests ,
16461640 autoCondenseContext : stateValues . autoCondenseContext ?? true ,
16471641 autoCondenseContextPercent : stateValues . autoCondenseContextPercent ?? 100 ,
1648- taskHistory : stateValues . taskHistory ,
16491642 allowedCommands : stateValues . allowedCommands ,
16501643 deniedCommands : stateValues . deniedCommands ,
16511644 soundEnabled : stateValues . soundEnabled ?? false ,
@@ -1725,17 +1718,11 @@ export class ClineProvider
17251718 }
17261719
17271720 async updateTaskHistory ( item : HistoryItem ) : Promise < HistoryItem [ ] > {
1728- const history = ( this . getGlobalState ( "taskHistory" ) as HistoryItem [ ] | undefined ) || [ ]
1729- const existingItemIndex = history . findIndex ( ( h ) => h . id === item . id )
1721+ await setHistoryItems ( [ item ] )
17301722
1731- if ( existingItemIndex !== - 1 ) {
1732- history [ existingItemIndex ] = item
1733- } else {
1734- history . push ( item )
1735- }
1736-
1737- await this . updateGlobalState ( "taskHistory" , history )
1738- return history
1723+ // Return all history items for the current workspace
1724+ const { getHistoryItemsForSearch } = await import ( "../task-persistence/taskHistory" )
1725+ return await getHistoryItemsForSearch ( { workspacePath : this . cwd } )
17391726 }
17401727
17411728 // ContextProxy
0 commit comments