-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy path_chat.settings.tsx
More file actions
1348 lines (1299 loc) · 54.8 KB
/
_chat.settings.tsx
File metadata and controls
1348 lines (1299 loc) · 54.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { createFileRoute } from "@tanstack/react-router";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { ChevronDownIcon, PlusIcon, RotateCcwIcon, Undo2Icon, XIcon } from "lucide-react";
import { type ReactNode, useCallback, useEffect, useState } from "react";
import {
type ProjectId,
type ProviderKind,
DEFAULT_GIT_TEXT_GENERATION_MODEL,
} from "@okcode/contracts";
import { getModelOptions, normalizeModelSlug } from "@okcode/shared/model";
import {
getAppModelOptions,
getCustomModelsForProvider,
MAX_CUSTOM_MODEL_LENGTH,
MODEL_PROVIDER_SETTINGS,
patchCustomModels,
useAppSettings,
} from "../appSettings";
import { APP_VERSION } from "../branding";
import { Button } from "../components/ui/button";
import { Collapsible, CollapsibleContent } from "../components/ui/collapsible";
import { EnvironmentVariablesEditor } from "../components/EnvironmentVariablesEditor";
import { Input } from "../components/ui/input";
import {
Select,
SelectItem,
SelectPopup,
SelectTrigger,
SelectValue,
} from "../components/ui/select";
import { SidebarTrigger } from "../components/ui/sidebar";
import { Switch } from "../components/ui/switch";
import { SidebarInset } from "../components/ui/sidebar";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../components/ui/tooltip";
import { resolveAndPersistPreferredEditor } from "../editorPreferences";
import { isElectron } from "../env";
import { useTheme, COLOR_THEMES, FONT_FAMILIES } from "../hooks/useTheme";
import {
environmentVariablesQueryKeys,
globalEnvironmentVariablesQueryOptions,
projectEnvironmentVariablesQueryOptions,
} from "../lib/environmentVariablesReactQuery";
import { serverConfigQueryOptions } from "../lib/serverReactQuery";
import { cn } from "../lib/utils";
import { ensureNativeApi, readNativeApi } from "../nativeApi";
import { useStore } from "../store";
const THEME_OPTIONS = [
{
value: "system",
label: "System",
description: "Match your OS appearance setting.",
},
{
value: "light",
label: "Light",
description: "Always use the light theme.",
},
{
value: "dark",
label: "Dark",
description: "Always use the dark theme.",
},
] as const;
const TIMESTAMP_FORMAT_LABELS = {
locale: "System default",
"12-hour": "12-hour",
"24-hour": "24-hour",
} as const;
type InstallBinarySettingsKey = "claudeBinaryPath" | "codexBinaryPath";
type InstallProviderSettings = {
provider: ProviderKind;
title: string;
binaryPathKey: InstallBinarySettingsKey;
binaryPlaceholder: string;
binaryDescription: ReactNode;
homePathKey?: "codexHomePath";
homePlaceholder?: string;
homeDescription?: ReactNode;
};
const INSTALL_PROVIDER_SETTINGS: readonly InstallProviderSettings[] = [
{
provider: "codex",
title: "Codex",
binaryPathKey: "codexBinaryPath",
binaryPlaceholder: "Codex binary path",
binaryDescription: (
<>
Leave blank to use <code>codex</code> from your PATH. Authentication normally uses{" "}
<code>codex login</code> unless your Codex config points at a custom model provider.
</>
),
homePathKey: "codexHomePath",
homePlaceholder: "CODEX_HOME",
homeDescription: "Optional custom Codex home and config directory.",
},
{
provider: "claudeAgent",
title: "Anthropic",
binaryPathKey: "claudeBinaryPath",
binaryPlaceholder: "Claude binary path",
binaryDescription: (
<>
Leave blank to use <code>claude</code> from your PATH. Authentication uses{" "}
<code>claude auth login</code>.
</>
),
},
];
function SettingsSection({ title, children }: { title: string; children: ReactNode }) {
return (
<section className="space-y-3">
<h2 className="text-[11px] font-medium uppercase tracking-[0.14em] text-muted-foreground">
{title}
</h2>
<div className="relative overflow-hidden rounded-2xl border bg-card not-dark:bg-clip-padding text-card-foreground shadow-xs/5 before:pointer-events-none before:absolute before:inset-0 before:rounded-[calc(var(--radius-2xl)-1px)] before:shadow-[0_1px_--theme(--color-black/4%)] dark:before:shadow-[0_-1px_--theme(--color-white/6%)]">
{children}
</div>
</section>
);
}
function SettingsRow({
title,
description,
status,
resetAction,
control,
children,
onClick,
}: {
title: string;
description: string;
status?: ReactNode;
resetAction?: ReactNode;
control?: ReactNode;
children?: ReactNode;
onClick?: () => void;
}) {
return (
<div
className="border-t border-border px-4 py-4 first:border-t-0 sm:px-5"
data-slot="settings-row"
>
<div
className={cn(
"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",
onClick && "cursor-pointer",
)}
onClick={onClick}
>
<div className="min-w-0 flex-1 space-y-1">
<div className="flex min-h-5 items-center gap-1.5">
<h3 className="text-sm font-medium text-foreground">{title}</h3>
<span className="inline-flex h-5 w-5 shrink-0 items-center justify-center">
{resetAction}
</span>
</div>
<p className="text-xs text-muted-foreground">{description}</p>
{status ? <div className="pt-1 text-[11px] text-muted-foreground">{status}</div> : null}
</div>
{control ? (
<div className="flex w-full shrink-0 items-center gap-2 sm:w-auto sm:justify-end">
{control}
</div>
) : null}
</div>
{children}
</div>
);
}
function SettingResetButton({ label, onClick }: { label: string; onClick: () => void }) {
return (
<Tooltip>
<TooltipTrigger
render={
<Button
size="icon-xs"
variant="ghost"
aria-label={`Reset ${label} to default`}
className="size-5 rounded-sm p-0 text-muted-foreground hover:text-foreground"
onClick={(event) => {
event.stopPropagation();
onClick();
}}
>
<Undo2Icon className="size-3" />
</Button>
}
/>
<TooltipPopup side="top">Reset to default</TooltipPopup>
</Tooltip>
);
}
function getErrorMessage(error: unknown): string {
if (error instanceof Error && error.message.trim().length > 0) {
return error.message;
}
if (typeof error === "string" && error.trim().length > 0) {
return error;
}
return "Unknown error";
}
function SettingsRouteView() {
const { theme, setTheme, colorTheme, setColorTheme, fontFamily, setFontFamily } = useTheme();
const { settings, defaults, updateSettings, resetSettings } = useAppSettings();
const serverConfigQuery = useQuery(serverConfigQueryOptions());
const queryClient = useQueryClient();
const projects = useStore((state) => state.projects);
const [selectedProjectId, setSelectedProjectId] = useState<ProjectId | null>(
() => projects[0]?.id ?? null,
);
const [isOpeningKeybindings, setIsOpeningKeybindings] = useState(false);
const [openKeybindingsError, setOpenKeybindingsError] = useState<string | null>(null);
const [openInstallProviders, setOpenInstallProviders] = useState<Record<ProviderKind, boolean>>({
codex: Boolean(settings.codexBinaryPath || settings.codexHomePath),
claudeAgent: Boolean(settings.claudeBinaryPath),
});
const [selectedCustomModelProvider, setSelectedCustomModelProvider] =
useState<ProviderKind>("codex");
const [customModelInputByProvider, setCustomModelInputByProvider] = useState<
Record<ProviderKind, string>
>({
codex: "",
claudeAgent: "",
});
const [customModelErrorByProvider, setCustomModelErrorByProvider] = useState<
Partial<Record<ProviderKind, string | null>>
>({});
const [showAllCustomModels, setShowAllCustomModels] = useState(false);
const globalEnvironmentVariablesQuery = useQuery(globalEnvironmentVariablesQueryOptions());
const activeProjectId = selectedProjectId ?? projects[0]?.id ?? null;
const selectedProject = projects.find((project) => project.id === activeProjectId) ?? null;
const selectedProjectEnvironmentVariablesQuery = useQuery(
projectEnvironmentVariablesQueryOptions(activeProjectId),
);
useEffect(() => {
if (projects.length === 0) {
if (selectedProjectId !== null) {
setSelectedProjectId(null);
}
return;
}
if (!selectedProjectId || !projects.some((project) => project.id === selectedProjectId)) {
setSelectedProjectId(projects[0]?.id ?? null);
}
}, [projects, selectedProjectId]);
const codexBinaryPath = settings.codexBinaryPath;
const codexHomePath = settings.codexHomePath;
const claudeBinaryPath = settings.claudeBinaryPath;
const keybindingsConfigPath = serverConfigQuery.data?.keybindingsConfigPath ?? null;
const availableEditors = serverConfigQuery.data?.availableEditors;
const gitTextGenerationModelOptions = getAppModelOptions(
"codex",
settings.customCodexModels,
settings.textGenerationModel,
);
const currentGitTextGenerationModel =
settings.textGenerationModel ?? DEFAULT_GIT_TEXT_GENERATION_MODEL;
const defaultGitTextGenerationModel =
defaults.textGenerationModel ?? DEFAULT_GIT_TEXT_GENERATION_MODEL;
const isGitTextGenerationModelDirty =
currentGitTextGenerationModel !== defaultGitTextGenerationModel;
const selectedGitTextGenerationModelLabel =
gitTextGenerationModelOptions.find((option) => option.slug === currentGitTextGenerationModel)
?.name ?? currentGitTextGenerationModel;
const selectedCustomModelProviderSettings = MODEL_PROVIDER_SETTINGS.find(
(providerSettings) => providerSettings.provider === selectedCustomModelProvider,
)!;
const selectedCustomModelInput = customModelInputByProvider[selectedCustomModelProvider];
const selectedCustomModelError = customModelErrorByProvider[selectedCustomModelProvider] ?? null;
const totalCustomModels = settings.customCodexModels.length + settings.customClaudeModels.length;
const activeProjectEnvironmentVariables = selectedProjectEnvironmentVariablesQuery.data?.entries;
const savedCustomModelRows = MODEL_PROVIDER_SETTINGS.flatMap((providerSettings) =>
getCustomModelsForProvider(settings, providerSettings.provider).map((slug) => ({
key: `${providerSettings.provider}:${slug}`,
provider: providerSettings.provider,
providerTitle: providerSettings.title,
slug,
})),
);
const visibleCustomModelRows = showAllCustomModels
? savedCustomModelRows
: savedCustomModelRows.slice(0, 5);
const isInstallSettingsDirty =
settings.claudeBinaryPath !== defaults.claudeBinaryPath ||
settings.codexBinaryPath !== defaults.codexBinaryPath ||
settings.codexHomePath !== defaults.codexHomePath;
const changedSettingLabels = [
...(theme !== "system" ? ["Theme"] : []),
...(colorTheme !== "default" ? ["Color theme"] : []),
...(fontFamily !== "inter" ? ["Font"] : []),
...(settings.timestampFormat !== defaults.timestampFormat ? ["Time format"] : []),
...(settings.diffWordWrap !== defaults.diffWordWrap ? ["Diff line wrapping"] : []),
...(settings.enableAssistantStreaming !== defaults.enableAssistantStreaming
? ["Assistant output"]
: []),
...(settings.openLinksExternally !== defaults.openLinksExternally
? ["Open links externally"]
: []),
...(settings.defaultThreadEnvMode !== defaults.defaultThreadEnvMode ? ["New thread mode"] : []),
...(settings.confirmThreadDelete !== defaults.confirmThreadDelete
? ["Delete confirmation"]
: []),
...(isGitTextGenerationModelDirty ? ["Git writing model"] : []),
...(settings.customCodexModels.length > 0 || settings.customClaudeModels.length > 0
? ["Custom models"]
: []),
...(isInstallSettingsDirty ? ["Provider installs"] : []),
];
const openKeybindingsFile = useCallback(() => {
if (!keybindingsConfigPath) return;
setOpenKeybindingsError(null);
setIsOpeningKeybindings(true);
const api = ensureNativeApi();
const editor = resolveAndPersistPreferredEditor(availableEditors ?? []);
if (!editor) {
setOpenKeybindingsError("No available editors found.");
setIsOpeningKeybindings(false);
return;
}
void api.shell
.openInEditor(keybindingsConfigPath, editor)
.catch((error) => {
setOpenKeybindingsError(
error instanceof Error ? error.message : "Unable to open keybindings file.",
);
})
.finally(() => {
setIsOpeningKeybindings(false);
});
}, [availableEditors, keybindingsConfigPath]);
const saveGlobalEnvironmentVariables = useCallback(
async (entries: ReadonlyArray<{ key: string; value: string }>) => {
const api = ensureNativeApi();
const result = await api.server.saveGlobalEnvironmentVariables({ entries });
queryClient.setQueryData(environmentVariablesQueryKeys.global(), result);
return result.entries;
},
[queryClient],
);
const saveProjectEnvironmentVariables = useCallback(
async (entries: ReadonlyArray<{ key: string; value: string }>) => {
if (!selectedProject) {
throw new Error("Select a project before saving project variables.");
}
const api = ensureNativeApi();
const result = await api.server.saveProjectEnvironmentVariables({
projectId: selectedProject.id,
entries,
});
queryClient.setQueryData(environmentVariablesQueryKeys.project(selectedProject.id), result);
return result.entries;
},
[queryClient, selectedProject],
);
const addCustomModel = useCallback(
(provider: ProviderKind) => {
const customModelInput = customModelInputByProvider[provider];
const customModels = getCustomModelsForProvider(settings, provider);
const normalized = normalizeModelSlug(customModelInput, provider);
if (!normalized) {
setCustomModelErrorByProvider((existing) => ({
...existing,
[provider]: "Enter a model slug.",
}));
return;
}
if (getModelOptions(provider).some((option) => option.slug === normalized)) {
setCustomModelErrorByProvider((existing) => ({
...existing,
[provider]: "That model is already built in.",
}));
return;
}
if (normalized.length > MAX_CUSTOM_MODEL_LENGTH) {
setCustomModelErrorByProvider((existing) => ({
...existing,
[provider]: `Model slugs must be ${MAX_CUSTOM_MODEL_LENGTH} characters or less.`,
}));
return;
}
if (customModels.includes(normalized)) {
setCustomModelErrorByProvider((existing) => ({
...existing,
[provider]: "That custom model is already saved.",
}));
return;
}
updateSettings(patchCustomModels(provider, [...customModels, normalized]));
setCustomModelInputByProvider((existing) => ({
...existing,
[provider]: "",
}));
setCustomModelErrorByProvider((existing) => ({
...existing,
[provider]: null,
}));
},
[customModelInputByProvider, settings, updateSettings],
);
const removeCustomModel = useCallback(
(provider: ProviderKind, slug: string) => {
const customModels = getCustomModelsForProvider(settings, provider);
updateSettings(
patchCustomModels(
provider,
customModels.filter((model) => model !== slug),
),
);
setCustomModelErrorByProvider((existing) => ({
...existing,
[provider]: null,
}));
},
[settings, updateSettings],
);
async function restoreDefaults() {
if (changedSettingLabels.length === 0) return;
const api = readNativeApi();
const confirmed = await (api ?? ensureNativeApi()).dialogs.confirm(
["Restore default settings?", `This will reset: ${changedSettingLabels.join(", ")}.`].join(
"\n",
),
);
if (!confirmed) return;
setTheme("system");
setColorTheme("default");
setFontFamily("inter");
resetSettings();
setOpenInstallProviders({
codex: false,
claudeAgent: false,
});
setSelectedCustomModelProvider("codex");
setCustomModelInputByProvider({
codex: "",
claudeAgent: "",
});
setCustomModelErrorByProvider({});
}
return (
<SidebarInset className="h-dvh min-h-0 overflow-hidden overscroll-y-none bg-background text-foreground isolate">
<div className="flex min-h-0 min-w-0 flex-1 flex-col bg-background text-foreground">
{!isElectron && (
<header className="border-b border-border px-3 py-2 sm:px-5">
<div className="flex items-center gap-2">
<SidebarTrigger className="size-7 shrink-0 md:hidden" />
<span className="text-sm font-medium text-foreground">Settings</span>
<div className="ms-auto flex items-center gap-2">
<Button
size="xs"
variant="outline"
disabled={changedSettingLabels.length === 0}
onClick={() => void restoreDefaults()}
>
<RotateCcwIcon className="size-3.5" />
Restore defaults
</Button>
</div>
</div>
</header>
)}
{isElectron && (
<div className="drag-region flex h-[52px] shrink-0 items-center border-b border-border px-5">
<span className="text-xs font-medium tracking-wide text-muted-foreground/70">
Settings
</span>
<div className="ms-auto flex items-center gap-2">
<Button
size="xs"
variant="outline"
disabled={changedSettingLabels.length === 0}
onClick={() => void restoreDefaults()}
>
<RotateCcwIcon className="size-3.5" />
Restore defaults
</Button>
</div>
</div>
)}
<div className="flex-1 overflow-y-auto p-6">
<div className="mx-auto flex w-full max-w-2xl flex-col gap-6">
<SettingsSection title="General">
<SettingsRow
title="Theme"
description="Choose how OK Code looks across the app."
resetAction={
theme !== "system" ? (
<SettingResetButton label="theme" onClick={() => setTheme("system")} />
) : null
}
control={
<Select
value={theme}
onValueChange={(value) => {
if (value !== "system" && value !== "light" && value !== "dark") return;
setTheme(value);
}}
>
<SelectTrigger className="w-full sm:w-40" aria-label="Theme preference">
<SelectValue>
{THEME_OPTIONS.find((option) => option.value === theme)?.label ?? "System"}
</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
{THEME_OPTIONS.map((option) => (
<SelectItem hideIndicator key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectPopup>
</Select>
}
/>
<SettingsRow
title="Color theme"
description="Pick a color palette for light and dark modes."
resetAction={
colorTheme !== "default" ? (
<SettingResetButton
label="color theme"
onClick={() => setColorTheme("default")}
/>
) : null
}
control={
<Select
value={colorTheme}
onValueChange={(value) => {
const match = COLOR_THEMES.find((t) => t.id === value);
if (!match) return;
setColorTheme(match.id);
}}
>
<SelectTrigger className="w-full sm:w-40" aria-label="Color theme">
<SelectValue>
{COLOR_THEMES.find((t) => t.id === colorTheme)?.label ?? "Default"}
</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
{COLOR_THEMES.map((t) => (
<SelectItem hideIndicator key={t.id} value={t.id}>
{t.label}
</SelectItem>
))}
</SelectPopup>
</Select>
}
/>
<SettingsRow
title="Font"
description="Choose the typeface for the interface."
resetAction={
fontFamily !== "inter" ? (
<SettingResetButton label="font" onClick={() => setFontFamily("inter")} />
) : null
}
control={
<Select
value={fontFamily}
onValueChange={(value) => {
const match = FONT_FAMILIES.find((f) => f.id === value);
if (!match) return;
setFontFamily(match.id);
}}
>
<SelectTrigger className="w-full sm:w-40" aria-label="Font family">
<SelectValue>
{FONT_FAMILIES.find((f) => f.id === fontFamily)?.label ?? "Inter"}
</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
{FONT_FAMILIES.map((f) => (
<SelectItem hideIndicator key={f.id} value={f.id}>
{f.label}
</SelectItem>
))}
</SelectPopup>
</Select>
}
/>
<SettingsRow
title="Window opacity"
description="Adjust the transparency of the entire application window."
resetAction={
settings.windowOpacity !== defaults.windowOpacity ? (
<SettingResetButton
label="window opacity"
onClick={() => {
updateSettings({ windowOpacity: defaults.windowOpacity });
if (isElectron && window.desktopBridge) {
void window.desktopBridge.setWindowOpacity(defaults.windowOpacity);
}
}}
/>
) : null
}
control={
<div className="flex items-center gap-2">
<input
type="range"
min={30}
max={100}
value={Math.round(settings.windowOpacity * 100)}
onChange={(e) => {
const value = Number(e.target.value) / 100;
updateSettings({ windowOpacity: value });
if (isElectron && window.desktopBridge) {
void window.desktopBridge.setWindowOpacity(value);
}
}}
className="h-1.5 w-24 cursor-pointer appearance-none rounded-full bg-muted accent-foreground sm:w-28"
aria-label="Window opacity"
/>
<span className="w-9 text-right text-xs tabular-nums text-muted-foreground">
{Math.round(settings.windowOpacity * 100)}%
</span>
</div>
}
/>
<SettingsRow
title="Sidebar opacity"
description="Adjust the transparency of the side panel and project list."
resetAction={
settings.sidebarOpacity !== defaults.sidebarOpacity ? (
<SettingResetButton
label="sidebar opacity"
onClick={() => updateSettings({ sidebarOpacity: defaults.sidebarOpacity })}
/>
) : null
}
control={
<div className="flex items-center gap-2">
<input
type="range"
min={30}
max={100}
value={Math.round(settings.sidebarOpacity * 100)}
onChange={(e) => {
const value = Number(e.target.value) / 100;
updateSettings({ sidebarOpacity: value });
}}
className="h-1.5 w-24 cursor-pointer appearance-none rounded-full bg-muted accent-foreground sm:w-28"
aria-label="Sidebar opacity"
/>
<span className="w-9 text-right text-xs tabular-nums text-muted-foreground">
{Math.round(settings.sidebarOpacity * 100)}%
</span>
</div>
}
/>
<SettingsRow
title="Time format"
description="System default follows your browser or OS clock preference."
resetAction={
settings.timestampFormat !== defaults.timestampFormat ? (
<SettingResetButton
label="time format"
onClick={() =>
updateSettings({
timestampFormat: defaults.timestampFormat,
})
}
/>
) : null
}
control={
<Select
value={settings.timestampFormat}
onValueChange={(value) => {
if (value !== "locale" && value !== "12-hour" && value !== "24-hour") {
return;
}
updateSettings({
timestampFormat: value,
});
}}
>
<SelectTrigger className="w-full sm:w-40" aria-label="Timestamp format">
<SelectValue>{TIMESTAMP_FORMAT_LABELS[settings.timestampFormat]}</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
<SelectItem hideIndicator value="locale">
{TIMESTAMP_FORMAT_LABELS.locale}
</SelectItem>
<SelectItem hideIndicator value="12-hour">
{TIMESTAMP_FORMAT_LABELS["12-hour"]}
</SelectItem>
<SelectItem hideIndicator value="24-hour">
{TIMESTAMP_FORMAT_LABELS["24-hour"]}
</SelectItem>
</SelectPopup>
</Select>
}
/>
<SettingsRow
title="Diff line wrapping"
description="Set the default wrap state when the diff panel opens. The in-panel wrap toggle only affects the current diff session."
resetAction={
settings.diffWordWrap !== defaults.diffWordWrap ? (
<SettingResetButton
label="diff line wrapping"
onClick={() =>
updateSettings({
diffWordWrap: defaults.diffWordWrap,
})
}
/>
) : null
}
control={
<Switch
checked={settings.diffWordWrap}
onCheckedChange={(checked) =>
updateSettings({
diffWordWrap: Boolean(checked),
})
}
aria-label="Wrap diff lines by default"
/>
}
/>
<SettingsRow
title="Assistant output"
description="Show token-by-token output while a response is in progress."
resetAction={
settings.enableAssistantStreaming !== defaults.enableAssistantStreaming ? (
<SettingResetButton
label="assistant output"
onClick={() =>
updateSettings({
enableAssistantStreaming: defaults.enableAssistantStreaming,
})
}
/>
) : null
}
control={
<Switch
checked={settings.enableAssistantStreaming}
onCheckedChange={(checked) =>
updateSettings({
enableAssistantStreaming: Boolean(checked),
})
}
aria-label="Stream assistant messages"
/>
}
/>
<SettingsRow
title="Open links externally"
description="Open terminal URLs in your default browser instead of the embedded preview panel."
resetAction={
settings.openLinksExternally !== defaults.openLinksExternally ? (
<SettingResetButton
label="open links externally"
onClick={() =>
updateSettings({
openLinksExternally: defaults.openLinksExternally,
})
}
/>
) : null
}
control={
<Switch
checked={settings.openLinksExternally}
onCheckedChange={(checked) =>
updateSettings({
openLinksExternally: Boolean(checked),
})
}
aria-label="Open links externally"
/>
}
/>
<SettingsRow
title="New threads"
description="Pick the default workspace mode for newly created draft threads."
resetAction={
settings.defaultThreadEnvMode !== defaults.defaultThreadEnvMode ? (
<SettingResetButton
label="new threads"
onClick={() =>
updateSettings({
defaultThreadEnvMode: defaults.defaultThreadEnvMode,
})
}
/>
) : null
}
control={
<Select
value={settings.defaultThreadEnvMode}
onValueChange={(value) => {
if (value !== "local" && value !== "worktree") return;
updateSettings({
defaultThreadEnvMode: value,
});
}}
>
<SelectTrigger className="w-full sm:w-44" aria-label="Default thread mode">
<SelectValue>
{settings.defaultThreadEnvMode === "worktree" ? "New worktree" : "Local"}
</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
<SelectItem hideIndicator value="local">
Local
</SelectItem>
<SelectItem hideIndicator value="worktree">
New worktree
</SelectItem>
</SelectPopup>
</Select>
}
/>
<SettingsRow
title="Delete confirmation"
description="Ask before deleting a thread and its chat history."
resetAction={
settings.confirmThreadDelete !== defaults.confirmThreadDelete ? (
<SettingResetButton
label="delete confirmation"
onClick={() =>
updateSettings({
confirmThreadDelete: defaults.confirmThreadDelete,
})
}
/>
) : null
}
control={
<Switch
checked={settings.confirmThreadDelete}
onCheckedChange={(checked) =>
updateSettings({
confirmThreadDelete: Boolean(checked),
})
}
aria-label="Confirm thread deletion"
/>
}
/>
</SettingsSection>
<SettingsSection title="Environment">
<SettingsRow
title="Global variables"
description="Available to every provider session, terminal, Git command, and health check launched on this machine."
status={
globalEnvironmentVariablesQuery.isError ? (
<span className="block text-destructive">
Failed to load saved variables:{" "}
{getErrorMessage(globalEnvironmentVariablesQuery.error)}
</span>
) : globalEnvironmentVariablesQuery.isFetching ? (
<span className="block">Loading saved variables...</span>
) : globalEnvironmentVariablesQuery.data?.entries.length ? (
<span className="block">
{globalEnvironmentVariablesQuery.data.entries.length} saved variables
</span>
) : (
<span className="block">No global variables saved yet.</span>
)
}
>
<EnvironmentVariablesEditor
description="Global values are encrypted locally and merged into every runtime environment."
entries={globalEnvironmentVariablesQuery.data?.entries ?? []}
emptyMessage={
globalEnvironmentVariablesQuery.isFetching
? "Loading global variables..."
: "No global variables saved yet."
}
saveButtonLabel="Save global"
addButtonLabel="Add variable"
onSave={saveGlobalEnvironmentVariables}
disabled={
globalEnvironmentVariablesQuery.isFetching ||
globalEnvironmentVariablesQuery.isError
}
/>
</SettingsRow>
<SettingsRow
title="Project variables"
description="Saved per project and merged on top of the global set when that project launches a provider, terminal, or helper command."
status={
selectedProject ? (
<span className="block break-all font-mono text-[11px] text-foreground">
{selectedProject.name} · {selectedProject.cwd}
</span>
) : (
<span className="block">Open a project to edit project variables.</span>
)
}
control={
projects.length > 0 ? (
<Select
value={activeProjectId ?? ""}
onValueChange={(value) => {
setSelectedProjectId(value as ProjectId);
}}
>
<SelectTrigger className="w-full sm:w-64" aria-label="Project selector">
<SelectValue>
{selectedProject ? selectedProject.name : "Select project"}
</SelectValue>
</SelectTrigger>
<SelectPopup align="end" alignItemWithTrigger={false}>
{projects.map((project) => (
<SelectItem hideIndicator key={project.id} value={project.id}>
<div className="flex min-w-0 flex-col">
<span className="truncate">{project.name}</span>
<span className="truncate text-[11px] text-muted-foreground">
{project.cwd}
</span>
</div>
</SelectItem>
))}
</SelectPopup>
</Select>
) : (
<span className="text-xs text-muted-foreground">No projects available.</span>
)
}
>
<EnvironmentVariablesEditor
key={selectedProject?.id ?? "no-project"}
description={
selectedProject
? `Project values override global values for ${selectedProject.name}.`
: "Open or create a project to edit project variables."
}
entries={activeProjectEnvironmentVariables ?? []}
emptyMessage={
selectedProjectEnvironmentVariablesQuery.isFetching
? "Loading project variables..."
: selectedProject
? "No project variables saved yet."
: "Open or create a project to edit project variables."
}
saveButtonLabel="Save project"
addButtonLabel="Add variable"
onSave={saveProjectEnvironmentVariables}
disabled={
!selectedProject ||
selectedProjectEnvironmentVariablesQuery.isFetching ||
selectedProjectEnvironmentVariablesQuery.isError
}
/>
</SettingsRow>
</SettingsSection>
<SettingsSection title="Models">
<SettingsRow
title="Git writing model"
description="Used for generated commit messages, PR titles, and branch names."
resetAction={
isGitTextGenerationModelDirty ? (
<SettingResetButton
label="git writing model"
onClick={() =>
updateSettings({
textGenerationModel: defaults.textGenerationModel,