File tree Expand file tree Collapse file tree 4 files changed +22
-0
lines changed
Expand file tree Collapse file tree 4 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ export const historyItemSchema = z.object({
1616 totalCost : z . number ( ) ,
1717 size : z . number ( ) . optional ( ) ,
1818 workspace : z . string ( ) . optional ( ) ,
19+ mode : z . string ( ) . optional ( ) ,
1920} )
2021
2122export type HistoryItem = z . infer < typeof historyItemSchema >
Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ export type TaskMetadataOptions = {
1818 taskNumber : number
1919 globalStoragePath : string
2020 workspace : string
21+ mode ?: string
2122}
2223
2324export async function taskMetadata ( {
@@ -26,6 +27,7 @@ export async function taskMetadata({
2627 taskNumber,
2728 globalStoragePath,
2829 workspace,
30+ mode,
2931} : TaskMetadataOptions ) {
3032 const taskDir = await getTaskDirectoryPath ( globalStoragePath , taskId )
3133
@@ -92,6 +94,7 @@ export async function taskMetadata({
9294 totalCost : tokenUsage . totalCost ,
9395 size : taskDirSize ,
9496 workspace,
97+ mode,
9598 }
9699
97100 return { historyItem, tokenUsage }
Original file line number Diff line number Diff line change @@ -405,12 +405,17 @@ export class Task extends EventEmitter<ClineEvents> {
405405 globalStoragePath : this . globalStoragePath ,
406406 } )
407407
408+ const provider = this . providerRef . deref ( )
409+ const state = await provider ?. getState ( )
410+ const currentMode = state ?. mode
411+
408412 const { historyItem, tokenUsage } = await taskMetadata ( {
409413 messages : this . clineMessages ,
410414 taskId : this . taskId ,
411415 taskNumber : this . taskNumber ,
412416 globalStoragePath : this . globalStoragePath ,
413417 workspace : this . cwd ,
418+ mode : currentMode ,
414419 } )
415420
416421 this . emit ( "taskTokenUsageUpdated" , this . taskId , tokenUsage )
Original file line number Diff line number Diff line change @@ -578,6 +578,11 @@ export class ClineProvider
578578 public async initClineWithHistoryItem ( historyItem : HistoryItem & { rootTask ?: Task ; parentTask ?: Task } ) {
579579 await this . removeClineFromStack ( )
580580
581+ // If the history item has a saved mode, restore it
582+ if ( historyItem . mode ) {
583+ await this . updateGlobalState ( "mode" , historyItem . mode )
584+ }
585+
581586 const {
582587 apiConfiguration,
583588 diffEnabled : enableDiff ,
@@ -807,6 +812,14 @@ export class ClineProvider
807812 if ( cline ) {
808813 TelemetryService . instance . captureModeSwitch ( cline . taskId , newMode )
809814 cline . emit ( "taskModeSwitched" , cline . taskId , newMode )
815+
816+ // Update the task history with the new mode
817+ const history = this . getGlobalState ( "taskHistory" ) ?? [ ]
818+ const taskHistoryItem = history . find ( ( item ) => item . id === cline . taskId )
819+ if ( taskHistoryItem ) {
820+ taskHistoryItem . mode = newMode
821+ await this . updateTaskHistory ( taskHistoryItem )
822+ }
810823 }
811824
812825 await this . updateGlobalState ( "mode" , newMode )
You can’t perform that action at this time.
0 commit comments