Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 18894da

Browse files
committed
fix: address mrubens review on retention types and settings navigation
1 parent 56ac6ef commit 18894da

6 files changed

Lines changed: 34 additions & 35 deletions

File tree

packages/types/src/global-settings.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,7 @@ export const globalSettingsSchema = z.object({
190190
enhancementApiConfigId: z.string().optional(),
191191
includeTaskHistoryInEnhance: z.boolean().optional(),
192192
// Auto-delete task history on extension reload.
193-
// Note: we accept `number` for backwards compatibility with older persisted state.
194-
taskHistoryRetention: z.union([z.enum(TASK_HISTORY_RETENTION_OPTIONS), z.number()]).optional(),
193+
taskHistoryRetention: z.enum(TASK_HISTORY_RETENTION_OPTIONS).optional(),
195194
// Calculated task history storage size info for the Settings > About page
196195
taskHistorySize: z
197196
.object({

src/activate/registerCommands.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
105105
return openClineInNewTab({ context, outputChannel })
106106
},
107107
openInNewTab: () => openClineInNewTab({ context, outputChannel }),
108-
settingsButtonClicked: () => {
108+
settingsButtonClicked: (section?: string) => {
109109
const visibleProvider = getVisibleProviderOrLog(outputChannel)
110110

111111
if (!visibleProvider) {
@@ -114,7 +114,11 @@ const getCommandsMap = ({ context, outputChannel, provider }: RegisterCommandOpt
114114

115115
TelemetryService.instance.captureTitleButtonClicked("settings")
116116

117-
visibleProvider.postMessageToWebview({ type: "action", action: "settingsButtonClicked" })
117+
visibleProvider.postMessageToWebview({
118+
type: "action",
119+
action: "settingsButtonClicked",
120+
values: section ? { section } : undefined,
121+
})
118122
// Also explicitly post the visibility message to trigger scroll reliably
119123
visibleProvider.postMessageToWebview({ type: "action", action: "didBecomeVisible" })
120124
},

src/extension.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
import { initializeI18n } from "./i18n"
4646
import { flushModels, initializeModelCacheRefresh, refreshModels } from "./api/providers/fetchers/modelCache"
4747
import { startBackgroundRetentionPurge } from "./utils/task-history-retention"
48+
import { TASK_HISTORY_RETENTION_OPTIONS, type TaskHistoryRetentionSetting } from "@roo-code/types"
4849

4950
/**
5051
* Built using https://github.com/microsoft/vscode-webview-ui-toolkit
@@ -392,14 +393,11 @@ export async function activate(context: vscode.ExtensionContext) {
392393
// By this point, provider is fully initialized and ready to handle deletions
393394
{
394395
const retentionValue = contextProxy.getValue("taskHistoryRetention")
395-
const retention =
396-
retentionValue === "90" ||
397-
retentionValue === "60" ||
398-
retentionValue === "30" ||
399-
retentionValue === "7" ||
400-
retentionValue === "3"
401-
? retentionValue
402-
: "never"
396+
const retention: TaskHistoryRetentionSetting = TASK_HISTORY_RETENTION_OPTIONS.includes(
397+
retentionValue as TaskHistoryRetentionSetting,
398+
)
399+
? (retentionValue as TaskHistoryRetentionSetting)
400+
: "never"
403401
startBackgroundRetentionPurge({
404402
globalStoragePath: contextProxy.globalStorageUri.fsPath,
405403
log: (m) => outputChannel.appendLine(m),

src/utils/task-history-retention.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,13 @@ import * as path from "path"
33
import * as fs from "fs/promises"
44
import type { Dirent } from "fs"
55

6+
import { TASK_HISTORY_RETENTION_OPTIONS, type TaskHistoryRetentionSetting } from "@roo-code/types"
7+
68
import { getStorageBasePath } from "./storage"
79
import { GlobalFileNames } from "../shared/globalFileNames"
810
import { 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

2214
export type PurgeResult = {
2315
purgedCount: number
@@ -280,7 +272,7 @@ export async function purgeOldTasks(
280272
*/
281273
function 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
}

webview-ui/src/components/settings/About.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HTMLAttributes, useState, useCallback, useEffect } from "react"
1+
import { HTMLAttributes, useState, useCallback, useEffect, useRef } from "react"
22
import { useAppTranslation } from "@/i18n/TranslationContext"
33
import { Trans } from "react-i18next"
44
import {
@@ -58,6 +58,7 @@ export const About = ({
5858
const { t } = useAppTranslation()
5959
const [isRefreshing, setIsRefreshing] = useState(false)
6060
const [cachedSize, setCachedSize] = useState<TaskHistorySize | undefined>(taskHistorySize)
61+
const didRequestInitialSize = useRef(false)
6162

6263
// Update cached size when taskHistorySize changes and reset refreshing state
6364
useEffect(() => {
@@ -67,6 +68,13 @@ export const About = ({
6768
}
6869
}, [taskHistorySize])
6970

71+
// Trigger initial task history size calculation when this tab mounts
72+
useEffect(() => {
73+
if (didRequestInitialSize.current) return
74+
didRequestInitialSize.current = true
75+
vscode.postMessage({ type: "refreshTaskHistorySize" })
76+
}, [])
77+
7078
const handleRefreshStorageSize = useCallback(() => {
7179
setIsRefreshing(true)
7280
vscode.postMessage({ type: "refreshTaskHistorySize" })

webview-ui/src/components/settings/SettingsView.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, t
429429
includeCurrentTime: includeCurrentTime ?? true,
430430
includeCurrentCost: includeCurrentCost ?? true,
431431
maxGitStatusFiles: maxGitStatusFiles ?? 0,
432-
taskHistoryRetention: normalizedTaskHistoryRetention,
432+
taskHistoryRetention: normalizedTaskHistoryRetention,
433433
profileThresholds,
434434
imageGenerationProvider,
435435
openRouterImageApiKey,
@@ -566,13 +566,6 @@ taskHistoryRetention: normalizedTaskHistoryRetention,
566566
scrollToActiveTab()
567567
}, [activeTab, scrollToActiveTab])
568568

569-
// Effect to trigger task history size calculation when About tab is opened
570-
useEffect(() => {
571-
if (activeTab === "about") {
572-
vscode.postMessage({ type: "refreshTaskHistorySize" })
573-
}
574-
}, [activeTab])
575-
576569
// Effect to scroll when the webview becomes visible
577570
useLayoutEffect(() => {
578571
const handleMessage = (event: MessageEvent) => {

0 commit comments

Comments
 (0)