Skip to content

Commit 89b6284

Browse files
committed
Use constants to replace magic values ​​and modify some i18n
1 parent 453a5c9 commit 89b6284

File tree

12 files changed

+91
-49
lines changed

12 files changed

+91
-49
lines changed

packages/types/src/global-settings.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ export const DEFAULT_WRITE_DELAY_MS = 1000
2929
*/
3030
export const DEFAULT_TERMINAL_OUTPUT_CHARACTER_LIMIT = 50_000
3131

32+
/**
33+
* Minimum checkpoint timeout in seconds.
34+
*/
35+
export const MIN_CHECKPOINT_TIMEOUT_SECONDS = 10
36+
37+
/**
38+
* Maximum checkpoint timeout in seconds.
39+
*/
40+
export const MAX_CHECKPOINT_TIMEOUT_SECONDS = 60
41+
42+
/**
43+
* Default checkpoint timeout in seconds.
44+
*/
45+
export const DEFAULT_CHECKPOINT_TIMEOUT_SECONDS = 15
46+
3247
/**
3348
* GlobalSettings
3449
*/
@@ -97,7 +112,12 @@ export const globalSettingsSchema = z.object({
97112
cachedChromeHostUrl: z.string().optional(),
98113

99114
enableCheckpoints: z.boolean().optional(),
100-
checkpointTimeout: z.number().optional(),
115+
checkpointTimeout: z
116+
.number()
117+
.int()
118+
.min(MIN_CHECKPOINT_TIMEOUT_SECONDS)
119+
.max(MAX_CHECKPOINT_TIMEOUT_SECONDS)
120+
.optional(),
101121

102122
ttsEnabled: z.boolean().optional(),
103123
ttsSpeed: z.number().optional(),

src/core/task/Task.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
isInteractiveAsk,
3636
isResumableAsk,
3737
QueuedMessage,
38+
DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
3839
} from "@roo-code/types"
3940
import { TelemetryService } from "@roo-code/telemetry"
4041
import { CloudService, BridgeOrchestrator } from "@roo-code/cloud"
@@ -304,7 +305,7 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
304305
apiConfiguration,
305306
enableDiff = false,
306307
enableCheckpoints = true,
307-
checkpointTimeout = 15,
308+
checkpointTimeout = DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
308309
enableBridge = false,
309310
fuzzyMatchThreshold = 1.0,
310311
consecutiveMistakeLimit = DEFAULT_CONSECUTIVE_MISTAKE_LIMIT,

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
DEFAULT_WRITE_DELAY_MS,
4141
ORGANIZATION_ALLOW_ALL,
4242
DEFAULT_MODES,
43+
DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
4344
} from "@roo-code/types"
4445
import { TelemetryService } from "@roo-code/telemetry"
4546
import { CloudService, BridgeOrchestrator, getRooCodeApiUrl } from "@roo-code/cloud"
@@ -1832,7 +1833,7 @@ export class ClineProvider
18321833
ttsSpeed: ttsSpeed ?? 1.0,
18331834
diffEnabled: diffEnabled ?? true,
18341835
enableCheckpoints: enableCheckpoints ?? true,
1835-
checkpointTimeout: checkpointTimeout ?? 15,
1836+
checkpointTimeout: checkpointTimeout ?? DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
18361837
shouldShowAnnouncement:
18371838
telemetrySetting !== "unset" && lastShownAnnouncementId !== this.latestAnnouncementId,
18381839
allowedCommands: mergedAllowedCommands,
@@ -2053,7 +2054,7 @@ export class ClineProvider
20532054
ttsSpeed: stateValues.ttsSpeed ?? 1.0,
20542055
diffEnabled: stateValues.diffEnabled ?? true,
20552056
enableCheckpoints: stateValues.enableCheckpoints ?? true,
2056-
checkpointTimeout: stateValues.checkpointTimeout ?? 15,
2057+
checkpointTimeout: stateValues.checkpointTimeout ?? DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
20572058
soundVolume: stateValues.soundVolume,
20582059
browserViewportSize: stateValues.browserViewportSize ?? "900x600",
20592060
screenshotQuality: stateValues.screenshotQuality ?? 75,

src/core/webview/__tests__/ClineProvider.spec.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import Anthropic from "@anthropic-ai/sdk"
44
import * as vscode from "vscode"
55
import axios from "axios"
66

7-
import { type ProviderSettingsEntry, type ClineMessage, ORGANIZATION_ALLOW_ALL } from "@roo-code/types"
7+
import {
8+
type ProviderSettingsEntry,
9+
type ClineMessage,
10+
ORGANIZATION_ALLOW_ALL,
11+
DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
12+
} from "@roo-code/types"
813
import { TelemetryService } from "@roo-code/telemetry"
914

1015
import { ExtensionMessage, ExtensionState } from "../../../shared/ExtensionMessage"
@@ -557,7 +562,7 @@ describe("ClineProvider", () => {
557562
remoteControlEnabled: false,
558563
taskSyncEnabled: false,
559564
featureRoomoteControlEnabled: false,
560-
checkpointTimeout: 15,
565+
checkpointTimeout: DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
561566
}
562567

563568
const message: ExtensionMessage = {

src/core/webview/webviewMessageHandler.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
type TelemetrySetting,
1313
TelemetryEventName,
1414
UserSettingsConfig,
15+
DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
1516
} from "@roo-code/types"
1617
import { CloudService } from "@roo-code/cloud"
1718
import { TelemetryService } from "@roo-code/telemetry"
@@ -1260,7 +1261,7 @@ export const webviewMessageHandler = async (
12601261
await provider.postStateToWebview()
12611262
break
12621263
case "checkpointTimeout":
1263-
const checkpointTimeout = message.value ?? 15
1264+
const checkpointTimeout = message.value ?? DEFAULT_CHECKPOINT_TIMEOUT_SECONDS
12641265
await updateGlobalState("checkpointTimeout", checkpointTimeout)
12651266
await provider.postStateToWebview()
12661267
break

src/i18n/locales/en/common.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"git_not_installed": "Git is required for the checkpoints feature. Please install Git to enable checkpoints.",
3232
"nested_git_repos_warning": "Checkpoints are disabled because a nested git repository was detected at: {{path}}. To use checkpoints, please remove or relocate this nested git repository.",
3333
"wait_checkpoint_long_time": "Checkpoint initialization is taking longer than expected. This may indicate a large repository or slow Git operations.",
34-
"init_checkpoint_fail_long_time": "Checkpoint initialization failed after taking long time. Checkpoints have been disabled for this task. You can disable checkpoints entirely or increase the timeout in settings.",
34+
"init_checkpoint_fail_long_time": "Checkpoint initialization failed after taking a long time. Checkpoints have been disabled for this task. You can disable checkpoints entirely or increase the timeout in settings.",
3535
"no_workspace": "Please open a project folder first",
3636
"update_support_prompt": "Failed to update support prompt",
3737
"reset_support_prompt": "Failed to reset support prompt",

src/i18n/locales/hi/common.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/src/components/chat/CheckpointWarning.tsx

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,48 @@
11
import { Trans } from "react-i18next"
22
import { VSCodeLink } from "@vscode/webview-ui-toolkit/react"
3-
import { useMemo } from "react"
43

54
interface CheckpointWarningProps {
65
text?: string
76
}
87

98
export const CheckpointWarning = ({ text }: CheckpointWarningProps) => {
10-
const warningText = useMemo(() => {
11-
return text || "chat:checkpoint.initializingWarning"
12-
}, [text])
9+
const settingsLink = (
10+
<VSCodeLink
11+
href="#"
12+
onClick={(e) => {
13+
e.preventDefault()
14+
window.postMessage(
15+
{
16+
type: "action",
17+
action: "settingsButtonClicked",
18+
values: { section: "checkpoints" },
19+
},
20+
"*",
21+
)
22+
}}
23+
className="inline px-0.5"
24+
/>
25+
)
26+
1327
return (
1428
<div className="flex items-center p-3 my-3 bg-vscode-inputValidation-warningBackground border border-vscode-inputValidation-warningBorder rounded">
1529
<span className="codicon codicon-loading codicon-modifier-spin mr-2" />
1630
<span className="text-vscode-foreground">
17-
<Trans
18-
i18nKey={warningText}
19-
components={{
20-
settingsLink: (
21-
<VSCodeLink
22-
href="#"
23-
onClick={(e) => {
24-
e.preventDefault()
25-
window.postMessage(
26-
{
27-
type: "action",
28-
action: "settingsButtonClicked",
29-
values: { section: "checkpoints" },
30-
},
31-
"*",
32-
)
33-
}}
34-
className="inline px-0.5"
35-
/>
36-
),
37-
}}
38-
/>
31+
{text ? (
32+
<Trans
33+
components={{
34+
settingsLink,
35+
}}>
36+
{text}
37+
</Trans>
38+
) : (
39+
<Trans
40+
i18nKey="chat:checkpoint.initializingWarning"
41+
components={{
42+
settingsLink,
43+
}}
44+
/>
45+
)}
3946
</span>
4047
</div>
4148
)

webview-ui/src/components/marketplace/__tests__/MarketplaceView.spec.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { vscode } from "@/utils/vscode"
55

66
import { MarketplaceView } from "../MarketplaceView"
77
import { MarketplaceViewStateManager } from "../MarketplaceViewStateManager"
8+
import { DEFAULT_CHECKPOINT_TIMEOUT_SECONDS } from "@roo-code/types"
89

910
vi.mock("@/utils/vscode", () => ({
1011
vscode: {
@@ -66,7 +67,7 @@ describe("MarketplaceView", () => {
6667
setFollowupAutoApproveTimeoutMs: vi.fn(),
6768
profileThresholds: {},
6869
setProfileThresholds: vi.fn(),
69-
checkpointTimeout: 15,
70+
checkpointTimeout: DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
7071
// ... other required context properties
7172
}
7273
})
@@ -87,7 +88,7 @@ describe("MarketplaceView", () => {
8788
mockExtensionState = {
8889
...mockExtensionState,
8990
organizationSettingsVersion: 2,
90-
checkpointTimeout: 15,
91+
checkpointTimeout: DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
9192
}
9293

9394
// Re-render with updated context

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import { Slider } from "@/components/ui"
99
import { SetCachedStateField } from "./types"
1010
import { SectionHeader } from "./SectionHeader"
1111
import { Section } from "./Section"
12+
import {
13+
DEFAULT_CHECKPOINT_TIMEOUT_SECONDS,
14+
MAX_CHECKPOINT_TIMEOUT_SECONDS,
15+
MIN_CHECKPOINT_TIMEOUT_SECONDS,
16+
} from "@roo-code/types"
1217

1318
type CheckpointSettingsProps = HTMLAttributes<HTMLDivElement> & {
1419
enableCheckpoints?: boolean
@@ -59,19 +64,19 @@ export const CheckpointSettings = ({
5964
</label>
6065
<div className="flex items-center gap-2">
6166
<Slider
62-
min={10}
63-
max={60}
67+
min={MIN_CHECKPOINT_TIMEOUT_SECONDS}
68+
max={MAX_CHECKPOINT_TIMEOUT_SECONDS}
6469
step={1}
65-
defaultValue={[checkpointTimeout ?? 15]}
70+
defaultValue={[checkpointTimeout ?? DEFAULT_CHECKPOINT_TIMEOUT_SECONDS]}
6671
onValueChange={([value]) => {
67-
if (value >= 10 && value <= 60) {
68-
setCachedStateField("checkpointTimeout", value)
69-
}
72+
setCachedStateField("checkpointTimeout", value)
7073
}}
7174
className="flex-1"
7275
data-testid="checkpoint-timeout-slider"
7376
/>
74-
<span className="w-12 text-center">{checkpointTimeout ?? 15}</span>
77+
<span className="w-12 text-center">
78+
{checkpointTimeout ?? DEFAULT_CHECKPOINT_TIMEOUT_SECONDS}
79+
</span>
7580
</div>
7681
<div className="text-vscode-descriptionForeground text-sm mt-1">
7782
{t("settings:checkpoints.timeout.description")}

0 commit comments

Comments
 (0)