Skip to content

Commit ef142ac

Browse files
committed
Add toggler UI and backend logic to enable disabling automatic checkpoint creation
1 parent 3af00ca commit ef142ac

14 files changed

Lines changed: 209 additions & 1 deletion

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
.toggler {
2+
position: relative;
3+
display: inline-block;
4+
width: 36px;
5+
height: 20px;
6+
}
7+
8+
.toggler input {
9+
opacity: 0;
10+
width: 0;
11+
height: 0;
12+
}
13+
14+
.slider {
15+
position: absolute;
16+
cursor: pointer;
17+
top: 0;
18+
left: 0;
19+
right: 0;
20+
bottom: 0;
21+
background-color: var(--vscode-input-background);
22+
border: 1px solid var(--cwc-border-color);
23+
-webkit-transition: 0.4s;
24+
transition: 0.4s;
25+
border-radius: 20px;
26+
}
27+
28+
.slider:before {
29+
position: absolute;
30+
content: '';
31+
height: 12px;
32+
width: 12px;
33+
left: 3px;
34+
bottom: 3px;
35+
background-color: var(--vscode-input-foreground);
36+
-webkit-transition: 0.4s;
37+
transition: 0.4s;
38+
border-radius: 50%;
39+
}
40+
41+
input:checked + .slider {
42+
background-color: var(--vscode-button-background);
43+
}
44+
45+
input:focus + .slider {
46+
box-shadow: 0 0 1px var(--vscode-focusBorder);
47+
}
48+
49+
input:checked + .slider:before {
50+
-webkit-transform: translateX(16px);
51+
-ms-transform: translateX(16px);
52+
transform: translateX(16px);
53+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import styles from './Toggler.module.scss'
2+
3+
type Props = {
4+
is_on: boolean
5+
on_toggle: (is_on: boolean) => void
6+
id?: string
7+
}
8+
9+
export const Toggler: React.FC<Props> = (props) => {
10+
const handle_change = (e: React.ChangeEvent<HTMLInputElement>) => {
11+
props.on_toggle(e.target.checked)
12+
}
13+
14+
return (
15+
<label className={styles.toggler} htmlFor={props.id}>
16+
<input
17+
id={props.id}
18+
type="checkbox"
19+
checked={props.is_on}
20+
onChange={handle_change}
21+
/>
22+
<span className={styles.slider}></span>
23+
</label>
24+
)
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Toggler'

‎packages/vscode/src/commands/checkpoints-command/actions/create-checkpoint.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as vscode from 'vscode'
22
import {
33
CHECKPOINTS_STATE_KEY,
44
TEMPORARY_CHECKPOINT_STATE_KEY,
5-
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY
5+
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY,
6+
ARE_AUTOMATIC_CHECKPOINTS_DISABLED_STATE_KEY
67
} from '../../../constants/state-keys'
78
import { WorkspaceProvider } from '../../../context/providers/workspace-provider'
89
import type { Checkpoint, CheckpointTab } from '../types'
@@ -34,6 +35,22 @@ export const create_checkpoint = async (
3435
description?: string
3536
): Promise<Checkpoint | undefined> => {
3637
try {
38+
const are_automatic_checkpoints_disabled =
39+
context.workspaceState.get<boolean>(
40+
ARE_AUTOMATIC_CHECKPOINTS_DISABLED_STATE_KEY
41+
) ?? false
42+
43+
const is_automatic_checkpoint = title !== 'Created by user'
44+
45+
if (are_automatic_checkpoints_disabled && is_automatic_checkpoint) {
46+
Logger.info({
47+
function_name: 'create_checkpoint',
48+
message: 'Automatic checkpoint creation is disabled. Skipping.',
49+
data: { title }
50+
})
51+
return undefined
52+
}
53+
3754
const operation_in_progress = context.workspaceState.get<number>(
3855
CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY
3956
)

‎packages/vscode/src/constants/state-keys.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,13 @@ export const LAST_CONTEXT_MERGE_REPLACE_OPTION_STATE_KEY =
2626
export const LAST_REFACTOR_INSTRUCTION_SOURCE_STATE_KEY =
2727
'last-refactor-instruction-source'
2828
export const LAST_REFACTOR_INSTRUCTION_STATE_KEY = 'last-refactor-instruction'
29+
2930
export const CHECKPOINTS_STATE_KEY = 'checkpoints'
3031
export const TEMPORARY_CHECKPOINT_STATE_KEY = 'temporary-checkpoint'
3132
export const CHECKPOINT_OPERATION_IN_PROGRESS_STATE_KEY =
3233
'checkpoint-operation-in-progress'
34+
export const ARE_AUTOMATIC_CHECKPOINTS_DISABLED_STATE_KEY =
35+
'are_automatic_checkpoints_disabled'
3336

3437
export const DUPLICATE_WORKSPACE_CONTEXT_STATE_KEY =
3538
'duplicate-workspace-context'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { SettingsProvider } from '../settings-provider'
2+
import { ARE_AUTOMATIC_CHECKPOINTS_DISABLED_STATE_KEY } from '@/constants/state-keys'
3+
4+
export async function handle_get_are_automatic_checkpoints_disabled(
5+
settings_provider: SettingsProvider
6+
) {
7+
const disabled =
8+
settings_provider.context.workspaceState.get<boolean>(
9+
ARE_AUTOMATIC_CHECKPOINTS_DISABLED_STATE_KEY
10+
) ?? false
11+
12+
settings_provider.postMessage({
13+
command: 'ARE_AUTOMATIC_CHECKPOINTS_DISABLED',
14+
disabled
15+
})
16+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import * as vscode from 'vscode'
2+
import { UpdateAreAutomaticCheckpointsDisabledMessage } from '@/views/settings/types/messages'
3+
import { ARE_AUTOMATIC_CHECKPOINTS_DISABLED_STATE_KEY } from '@/constants/state-keys'
4+
5+
export async function handle_update_are_automatic_checkpoints_disabled(
6+
message: UpdateAreAutomaticCheckpointsDisabledMessage,
7+
context: vscode.ExtensionContext
8+
) {
9+
await context.workspaceState.update(
10+
ARE_AUTOMATIC_CHECKPOINTS_DISABLED_STATE_KEY,
11+
message.disabled
12+
)
13+
}

‎packages/vscode/src/views/settings/backend/message-handlers/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,6 @@ export * from './handle-get-gemini-user-id'
3737
export * from './handle-update-gemini-user-id'
3838
export * from './handle-get-context-size-warning-threshold'
3939
export * from './handle-update-context-size-warning-threshold'
40+
export * from './handle-get-are-automatic-checkpoints-disabled'
41+
export * from './handle-update-are-automatic-checkpoints-disabled'
4042
export * from './handle-get-checkpoint-lifespan'

‎packages/vscode/src/views/settings/backend/settings-provider.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
handle_delete_model_provider,
1414
handle_edit_custom_model_provider,
1515
handle_get_clear_checks_in_workspace_behavior,
16+
handle_get_are_automatic_checkpoints_disabled,
1617
handle_get_code_completions_configurations,
1718
handle_get_commit_message_instructions,
1819
handle_get_commit_message_auto_accept_after,
@@ -38,6 +39,7 @@ import {
3839
handle_upsert_edit_context_configuration,
3940
handle_upsert_intelligent_update_configuration,
4041
handle_update_clear_checks_in_workspace_behavior,
42+
handle_update_are_automatic_checkpoints_disabled,
4143
handle_update_commit_message_instructions,
4244
handle_update_commit_message_auto_accept_after,
4345
handle_update_context_size_warning_threshold,
@@ -217,6 +219,18 @@ export class SettingsProvider {
217219
await handle_update_gemini_user_id(message)
218220
} else if (message.command == 'GET_CHECKPOINT_LIFESPAN') {
219221
await handle_get_checkpoint_lifespan(this)
222+
} else if (
223+
message.command == 'GET_ARE_AUTOMATIC_CHECKPOINTS_DISABLED'
224+
) {
225+
await handle_get_are_automatic_checkpoints_disabled(this)
226+
} else if (
227+
message.command == 'UPDATE_ARE_AUTOMATIC_CHECKPOINTS_DISABLED'
228+
) {
229+
await handle_update_are_automatic_checkpoints_disabled(
230+
message,
231+
this.context
232+
)
233+
await handle_get_are_automatic_checkpoints_disabled(this)
220234
} else if (message.command == 'UPDATE_CHECKPOINT_LIFESPAN') {
221235
await vscode.workspace
222236
.getConfiguration('codeWebChat')
@@ -247,6 +261,7 @@ export class SettingsProvider {
247261
void handle_get_commit_message_instructions(this)
248262
void handle_get_commit_message_auto_accept_after(this)
249263
void handle_get_clear_checks_in_workspace_behavior(this)
264+
void handle_get_are_automatic_checkpoints_disabled(this)
250265
void handle_get_checkpoint_lifespan(this)
251266
void handle_get_gemini_user_id(this)
252267
}

‎packages/vscode/src/views/settings/frontend/Home/Home.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type Props = {
7878
commit_message_auto_accept_after: number | null
7979
context_size_warning_threshold: number
8080
gemini_user_id: number | null
81+
are_automatic_checkpoints_disabled: boolean
8182
checkpoint_lifespan: number
8283
edit_format_instructions: EditFormatInstructions
8384
clear_checks_in_workspace_behavior: 'ignore-open-editors' | 'uncheck-all'
@@ -95,6 +96,7 @@ type Props = {
9596
instructions: EditFormatInstructions
9697
) => void
9798
on_edit_context_system_instructions_change: (instructions: string) => void
99+
on_automatic_checkpoints_toggle: (disabled: boolean) => void
98100
on_checkpoint_lifespan_change: (hours: number) => void
99101
on_gemini_user_id_change: (id: number | null) => void
100102
on_clear_checks_in_workspace_behavior_change: (
@@ -294,6 +296,12 @@ export const Home: React.FC<Props> = (props) => {
294296
on_edit_format_instructions_change={
295297
props.on_edit_format_instructions_change
296298
}
299+
are_automatic_checkpoints_disabled={
300+
props.are_automatic_checkpoints_disabled
301+
}
302+
on_automatic_checkpoints_toggle={
303+
props.on_automatic_checkpoints_toggle
304+
}
297305
checkpoint_lifespan={props.checkpoint_lifespan}
298306
on_checkpoint_lifespan_change={props.on_checkpoint_lifespan_change}
299307
on_open_editor_settings={props.on_open_editor_settings}

0 commit comments

Comments
 (0)