@@ -3,21 +3,13 @@ import * as path from "path"
33import * as fs from "fs/promises"
44import type { Dirent } from "fs"
55
6+ import { TASK_HISTORY_RETENTION_OPTIONS , type TaskHistoryRetentionSetting } from "@roo-code/types"
7+
68import { getStorageBasePath } from "./storage"
79import { GlobalFileNames } from "../shared/globalFileNames"
810import { t } from "../i18n"
911
10- /**
11- * Allowed retention day values (as numbers).
12- */
13- export type RetentionDays = 90 | 60 | 30 | 7 | 3
14-
15- /**
16- * Supported values for the retention setting.
17- * - "never" or 0 disables purging
18- * - "90" | "60" | "30" | "7" | "3" (string) or 90 | 60 | 30 | 7 | 3 (number) specify days
19- */
20- export type RetentionSetting = "never" | "0" | `${RetentionDays } ` | RetentionDays | 0
12+ export type RetentionSetting = TaskHistoryRetentionSetting
2113
2214export type PurgeResult = {
2315 purgedCount : number
@@ -280,7 +272,7 @@ export async function purgeOldTasks(
280272 */
281273function normalizeDays ( value : RetentionSetting ) : number {
282274 if ( value === "never" ) return 0
283- const n = typeof value === "number" ? value : parseInt ( String ( value ) , 10 )
275+ const n = parseInt ( value , 10 )
284276 return Number . isFinite ( n ) && n > 0 ? Math . trunc ( n ) : 0
285277}
286278
@@ -314,11 +306,16 @@ export function startBackgroundRetentionPurge(options: BackgroundPurgeOptions):
314306 void ( async ( ) => {
315307 try {
316308 // Skip if retention is disabled
317- if ( retention === "never" || retention === "0" || retention === 0 ) {
309+ if ( retention === "never" ) {
318310 log ( "[Retention] Background purge skipped: retention is set to 'never'" )
319311 return
320312 }
321313
314+ if ( ! TASK_HISTORY_RETENTION_OPTIONS . includes ( retention ) ) {
315+ log ( `[Retention] Background purge skipped: invalid retention value '${ retention } '` )
316+ return
317+ }
318+
322319 log ( `[Retention] Starting background purge: setting=${ retention } ` )
323320
324321 const result = await purgeOldTasks ( retention , globalStoragePath , log , false , deleteTaskById )
@@ -340,7 +337,7 @@ export function startBackgroundRetentionPurge(options: BackgroundPurgeOptions):
340337 vscode . window . showInformationMessage ( message , viewSettingsLabel , dismissLabel ) . then ( ( action ) => {
341338 if ( action === viewSettingsLabel ) {
342339 // Navigate to Roo Code settings About tab
343- vscode . commands . executeCommand ( "roo-cline.settingsButtonClicked" )
340+ vscode . commands . executeCommand ( "roo-cline.settingsButtonClicked" , "about" )
344341 }
345342 } )
346343 }
0 commit comments