Skip to content

Commit 1701765

Browse files
committed
Refactor checkpoint lifespan to use a centralized constant and support undefined values in configuration
1 parent d8f7909 commit 1701765

10 files changed

Lines changed: 30 additions & 16 deletions

File tree

‎apps/editor/src/commands/checkpoints-command/actions/get-checkpoints.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import * as vscode from 'vscode'
22
import { CHECKPOINTS_STATE_KEY } from '../../../constants/state-keys'
33
import type { Checkpoint } from '../types'
44
import { get_checkpoint_path } from '../utils'
5-
65
import { Logger } from '@shared/utils/logger'
6+
import { CHECKPOINT_DEFAULT_LIFESPAN } from '@/constants/values'
77

88
export const remove_old_checkpoints = async (
99
checkpoints: Checkpoint[]
1010
): Promise<Checkpoint[]> => {
1111
const config = vscode.workspace.getConfiguration('codeWebChat')
1212
const checkpoint_lifespan_hours =
13-
config.get<number>('checkpointLifespan') || 24
13+
config.get<number>('checkpointLifespan') || CHECKPOINT_DEFAULT_LIFESPAN
1414
const checkpoint_lifespan_ms = checkpoint_lifespan_hours * 60 * 60 * 1000
1515

1616
const now = Date.now()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const CHECKPOINT_DEFAULT_LIFESPAN = 24
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import * as vscode from 'vscode'
22
import { SettingsProvider } from '@/views/settings/backend/settings-provider'
3+
import { CHECKPOINT_DEFAULT_LIFESPAN } from '@/constants/values'
34

45
export const handle_get_checkpoint_lifespan = async (
56
provider: SettingsProvider
67
): Promise<void> => {
78
const config = vscode.workspace.getConfiguration('codeWebChat')
8-
const hours = config.get<number>('checkpointLifespan', 24)
9+
const hours =
10+
config.get<number>('checkpointLifespan') || CHECKPOINT_DEFAULT_LIFESPAN
911
provider.postMessage({ command: 'CHECKPOINT_LIFESPAN', hours })
1012
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as vscode from 'vscode'
2+
import { UpdateCheckpointLifespanMessage } from '@/views/settings/types/messages'
3+
4+
export const handle_update_checkpoint_lifespan = async (
5+
message: UpdateCheckpointLifespanMessage
6+
) => {
7+
await vscode.workspace
8+
.getConfiguration('codeWebChat')
9+
.update(
10+
'checkpointLifespan',
11+
message.hours ?? undefined,
12+
vscode.ConfigurationTarget.Global
13+
)
14+
}

‎apps/editor/src/views/settings/backend/message-handlers/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export * from './handle-update-context-size-warning-threshold'
2525
export * from './handle-get-are-automatic-checkpoints-disabled'
2626
export * from './handle-update-are-automatic-checkpoints-disabled'
2727
export * from './handle-get-checkpoint-lifespan'
28+
export * from './handle-update-checkpoint-lifespan'
2829
export * from './handle-upsert-configuration'
2930
export * from './handle-open-ignore-patterns-settings'
3031
export * from './handle-open-allow-patterns-settings'

‎apps/editor/src/views/settings/backend/settings-provider.ts‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import {
2222
handle_get_ai_studio_user_id,
2323
handle_get_model_providers,
2424
handle_get_send_with_shift_enter,
25+
handle_update_checkpoint_lifespan,
2526
handle_get_checkpoint_lifespan,
2627
handle_reorder_configuration,
2728
handle_reorder_model_providers,
@@ -273,13 +274,7 @@ export class SettingsProvider {
273274
) {
274275
await handle_update_are_automatic_checkpoints_disabled(message)
275276
} else if (message.command == 'UPDATE_CHECKPOINT_LIFESPAN') {
276-
await vscode.workspace
277-
.getConfiguration('codeWebChat')
278-
.update(
279-
'checkpointLifespan',
280-
message.hours,
281-
vscode.ConfigurationTarget.Global
282-
)
277+
await handle_update_checkpoint_lifespan(message)
283278
} else if (message.command == 'OPEN_EDITOR_SETTINGS') {
284279
await vscode.commands.executeCommand('workbench.action.openSettings')
285280
} else if (message.command == 'OPEN_IGNORE_PATTERNS_SETTINGS') {

‎apps/editor/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ type Props = {
101101
) => void
102102
on_edit_context_system_instructions_change: (instructions: string) => void
103103
on_automatic_checkpoints_toggle: (disabled: boolean) => void
104-
on_checkpoint_lifespan_change: (hours: number) => void
104+
on_checkpoint_lifespan_change: (hours: number | undefined) => void
105105
on_gemini_user_id_change: (id: number | null) => void
106106
on_ai_studio_user_id_change: (id: number | null) => void
107107
on_send_with_shift_enter_change: (enabled: boolean) => void

‎apps/editor/src/views/settings/frontend/Home/sections/GeneralSection.tsx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type Props = {
2929
on_automatic_checkpoints_toggle: (disabled: boolean) => void
3030
on_send_with_shift_enter_change: (enabled: boolean) => void
3131
on_check_new_files_change: (enabled: boolean) => void
32-
on_checkpoint_lifespan_change: (hours: number) => void
32+
on_checkpoint_lifespan_change: (hours: number | undefined) => void
3333
clear_checks_in_workspace_behavior: ClearChecksBehavior
3434
edit_format_instructions: EditFormatInstructions
3535
on_context_size_warning_threshold_change: (threshold: number) => void
@@ -109,6 +109,8 @@ export const GeneralSection = forwardRef<HTMLDivElement, Props>(
109109
const num_hours = parseInt(checkpoint_lifespan_str, 10)
110110
if (!isNaN(num_hours) && num_hours > 0) {
111111
props.on_checkpoint_lifespan_change(num_hours)
112+
} else {
113+
props.on_checkpoint_lifespan_change(undefined)
112114
}
113115
}
114116

@@ -241,7 +243,6 @@ export const GeneralSection = forwardRef<HTMLDivElement, Props>(
241243
on_change={set_checkpoint_lifespan_str}
242244
on_blur={handle_checkpoint_lifespan_blur}
243245
max_width={100}
244-
min={1}
245246
/>
246247
}
247248
/>

‎apps/editor/src/views/settings/frontend/hooks/use-settings.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ export const use_settings = (vscode: any) => {
298298
})
299299
}
300300

301-
const handle_checkpoint_lifespan_change = (hours: number) =>
301+
const handle_checkpoint_lifespan_change = (hours: number | undefined) =>
302302
post_message(vscode, {
303303
command: 'UPDATE_CHECKPOINT_LIFESPAN',
304-
hours
304+
hours: hours ?? null
305305
})
306306

307307
const handle_gemini_user_id_change = (geminiUserId: number | null) =>

‎apps/editor/src/views/settings/types/messages.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ export interface GetCheckpointLifespanMessage {
218218

219219
export interface UpdateCheckpointLifespanMessage {
220220
command: 'UPDATE_CHECKPOINT_LIFESPAN'
221-
hours: number
221+
hours: number | null
222222
}
223223

224224
export interface GetGeminiUserIdMessage {

0 commit comments

Comments
 (0)