Open History to see the last commit
1import { msg } from "gt-react";
2import { managedCapabilityDenial } from "@t3tools/client-runtime/contract-labels";
3import { useAuth } from "@clerk/react";
4import { Link } from "@tanstack/react-router";
5import {
6 AgentFeedbackMode,
7 DEFAULT_WORKFLOW_SKIPPED_RUNS_KEPT,
8 MAX_WORKFLOW_SKIPPED_RUNS_KEPT,
9} from "@t3tools/contracts";
10import { T, useGT, useMessages } from "gt-react";
11
12import { hasCloudPublicConfig } from "~/cloud/publicConfig";
13import { useT3ConnectAuthPrompt } from "../clerk/useT3ConnectAuthPrompt";
14import { Button } from "../ui/button";
15import { NumberField, NumberFieldGroup, NumberFieldInput } from "../ui/number-field";
16import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
17import { Switch } from "../ui/switch";
18import { commitNumberFieldOnEnter } from "./commitNumberFieldOnEnter";
19import { ScopedSwitch } from "./ScopedSwitch";
20import {
21 SettingResetButton,
22 SettingsPageContainer,
23 SettingsRow,
24 SettingsSection,
25} from "./settingsLayout";
26import { useSearchableSetting } from "./settingsSearch";
27import {
28 useScopedSettings,
29 useScopedSettingsMixed,
30 useUpdateScopedSettings,
31} from "./useScopedSettings";
32import { useOptionalSettingsScope, useSettingsScope } from "./SettingsScopeContext";
33import { firstManagedDenial, usePrimaryManagedPolicy } from "~/state/managedPolicy";
34
35/** Features still settling in. */
36export function LabsSettingsPanel() {
37 const gt = useGT();
38 return (
39 <SettingsPageContainer>
40 <SettingsSection id="beta" title={gt`Beta`}>
41 <BoringSidebarRow />
42 {/* Clerk is only mounted when this build has T3 Connect. */}
43 {hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />}
44 <LinkedEnvironmentsRow />
45 <WorkflowsRow />
46 <WorkflowSkippedRunsRow />
47 <PromptSuggestionsRow />
48 <SimlockHostsRow />
49 <FastWorktreeCheckoutRow />
50 <AgentFeedbackRow />
51 </SettingsSection>
52 </SettingsPageContainer>
53 );
54}
55
56function BoringSidebarRow() {
57 const searchableSetting = useSearchableSetting();
58 const settings = useScopedSettings();
59 const updateSettings = useUpdateScopedSettings();
60 const gt = useGT();
61 return (
62 <SettingsRow
63 {...searchableSetting("boring-sidebar")}
64 devicePreference
65 description={gt`Group sidebar threads into project folders. Pinned threads stay on top, and Snoozed and Settled stay below the folders.`}
66 control={
67 <Switch
68 checked={settings.boringSidebarEnabled}
69 onCheckedChange={(checked) => updateSettings({ boringSidebarEnabled: Boolean(checked) })}
70 aria-label={gt`Boring sidebar (group by project)`}
71 />
72 }
73 >
74 {settings.boringSidebarEnabled ? (
75 <div className="mt-2 mb-2 border-l-2 border-border/60 ps-3">
76 <BoringSidebarMultilineRow />
77 </div>
78 ) : null}
79 </SettingsRow>
80 );
81}
82
83function BoringSidebarMultilineRow() {
84 const searchableSetting = useSearchableSetting();
85 const settings = useScopedSettings();
86 const updateSettings = useUpdateScopedSettings();
87 const gt = useGT();
88 return (
89 <SettingsRow
90 {...searchableSetting("boring-sidebar-multiline")}
91 devicePreference
92 className="px-0 py-2 sm:px-0"
93 description={gt`Show folder threads on two lines: the title, then the items you place on the sidebar thread card in Appearance.`}
94 control={
95 <Switch
96 checked={settings.boringSidebarMultilineRows}
97 onCheckedChange={(checked) =>
98 updateSettings({ boringSidebarMultilineRows: Boolean(checked) })
99 }
100 aria-label={gt`Two-line folder rows`}
101 />
102 }
103 />
104 );
105}
106
107/** Signed out of T3 Connect, the row offers to sign in instead of its switch. */
108function GuestLinksRowWithSignIn() {
109 const searchableSetting = useSearchableSetting();
110 const gt = useGT();
111 const { isSignedIn } = useAuth();
112 const { openAuthPrompt } = useT3ConnectAuthPrompt();
113 // `isSignedIn` is undefined until Clerk loads.
114 if (isSignedIn !== false) return <GuestLinksRow />;
115 return (
116 <SettingsRow
117 {...searchableSetting("guest-links")}
118 description={gt`Share a thread with a guest who watches it live in a browser and sends messages you approve. Sign in to T3 Connect to use guest links.`}
119 control={
120 <Button size="sm" variant="outline" onClick={openAuthPrompt}>
121 <T>Sign in</T>
122 </Button>
123 }
124 />
125 );
126}
127
128function GuestLinksRow() {
129 const searchableSetting = useSearchableSetting();
130 const settings = useScopedSettings();
131 const updateSettings = useUpdateScopedSettings();
132 const gt = useGT();
133 const messages = useMessages();
134 const scope = useOptionalSettingsScope();
135 const primaryPolicy = usePrimaryManagedPolicy();
136 // Guests arrive through T3 Connect, so a policy that turns Connect off turns this off too.
137 const connectDenial = firstManagedDenial(
138 scope
139 ? scope.connectedEnvironments.map((environment) => environment.serverConfig?.managedPolicy)
140 : [primaryPolicy],
141 (policy) => managedCapabilityDenial(policy, "connect", messages),
142 );
143 return (
144 <SettingsRow
145 serverScoped
146 {...searchableSetting("guest-links")}
147 settingKeys={["guestSharingEnabled"]}
148 // Turning guest links off still works without T3 Connect.
149 managed={settings.guestSharingEnabled ? undefined : connectDenial}
150 description={
151 <T>
152 Share a thread with a guest who watches it live in a browser and sends messages you
153 approve. Needs T3 Connect: sign in and link this machine in{" "}
154 <Link to="/settings/access" className="underline underline-offset-2">
155 Sharing & access
156 </Link>
157 . Turning it off stops every guest link.
158 </T>
159 }
160 control={
161 <ScopedSwitch
162 settingKeys={["guestSharingEnabled"]}
163 checked={settings.guestSharingEnabled}
164 onCheckedChange={(checked) => updateSettings({ guestSharingEnabled: Boolean(checked) })}
165 aria-label={gt`Guest links`}
166 />
167 }
168 />
169 );
170}
171
172function LinkedEnvironmentsRow() {
173 const searchableSetting = useSearchableSetting();
174 const settings = useScopedSettings();
175 const updateSettings = useUpdateScopedSettings();
176 const gt = useGT();
177 return (
178 <SettingsRow
179 serverScoped
180 {...searchableSetting("linked-environments-beta")}
181 settingKeys={["linkedEnvironmentsEnabled"]}
182 description={
183 <T>
184 Let agents here work on your other machines, and theirs here. Turn it on for each machine,
185 then link them in{" "}
186 <Link to="/settings/connections" className="underline underline-offset-2">
187 Connections
188 </Link>
189 . While off, nothing new starts over a link; running tasks finish.
190 </T>
191 }
192 control={
193 <ScopedSwitch
194 settingKeys={["linkedEnvironmentsEnabled"]}
195 checked={settings.linkedEnvironmentsEnabled}
196 onCheckedChange={(checked) =>
197 updateSettings({ linkedEnvironmentsEnabled: Boolean(checked) })
198 }
199 aria-label={gt`Linked environments`}
200 />
201 }
202 />
203 );
204}
205
206function WorkflowsRow() {
207 const searchableSetting = useSearchableSetting();
208 const settings = useScopedSettings();
209 const updateSettings = useUpdateScopedSettings();
210 const gt = useGT();
211 return (
212 <SettingsRow
213 serverScoped
214 {...searchableSetting("workflows-beta")}
215 settingKeys={["workflowsEnabled"]}
216 description={gt`Run multi-step workflows from files in the workflows folder of this server's T3 home. Open them from the command palette. While off, nothing in that folder runs; runs wait until it is on again.`}
217 control={
218 <ScopedSwitch
219 settingKeys={["workflowsEnabled"]}
220 checked={settings.workflowsEnabled}
221 onCheckedChange={(checked) => updateSettings({ workflowsEnabled: Boolean(checked) })}
222 aria-label={gt`Workflows`}
223 />
224 }
225 />
226 );
227}
228
229const NO_GROUPING: Intl.NumberFormatOptions = { useGrouping: false };
230
231export function WorkflowSkippedRunsRow() {
232 const searchableSetting = useSearchableSetting();
233 const settings = useScopedSettings();
234 const updateSettings = useUpdateScopedSettings();
235 const mixed = useScopedSettingsMixed(["workflowSkippedRunsKept"]);
236 const gt = useGT();
237 if (!settings.workflowsEnabled) return null;
238 const kept = settings.workflowSkippedRunsKept;
239 return (
240 <SettingsRow
241 serverScoped
242 {...searchableSetting("workflow-skipped-runs")}
243 settingKeys={["workflowSkippedRunsKept"]}
244 description={gt`How many skipped runs each workflow keeps in its history. Older skipped runs are deleted; runs that did something are always kept.`}
245 resetAction={
246 mixed || kept !== DEFAULT_WORKFLOW_SKIPPED_RUNS_KEPT ? (
247 <SettingResetButton
248 ariaLabel={gt`Reset skipped runs kept to default`}
249 onClick={() =>
250 updateSettings({ workflowSkippedRunsKept: DEFAULT_WORKFLOW_SKIPPED_RUNS_KEPT })
251 }
252 />
253 ) : null
254 }
255 control={
256 <div className="w-24">
257 <NumberField
258 value={mixed ? null : kept}
259 min={0}
260 max={MAX_WORKFLOW_SKIPPED_RUNS_KEPT}
261 format={NO_GROUPING}
262 size="sm"
263 onValueCommitted={(value) => {
264 if (value === null || !Number.isInteger(value) || (!mixed && value === kept)) return;
265 updateSettings({ workflowSkippedRunsKept: value });
266 }}
267 >
268 <NumberFieldGroup>
269 <NumberFieldInput
270 aria-label={gt`Skipped runs kept`}
271 placeholder={mixed ? gt`Mixed` : undefined}
272 onKeyDown={commitNumberFieldOnEnter}
273 />
274 </NumberFieldGroup>
275 </NumberField>
276 </div>
277 }
278 />
279 );
280}
281
282function PromptSuggestionsRow() {
283 const searchableSetting = useSearchableSetting();
284 const settings = useScopedSettings();
285 const updateSettings = useUpdateScopedSettings();
286 const gt = useGT();
287 return (
288 <SettingsRow
289 serverScoped
290 {...searchableSetting("prompt-suggestions-beta")}
291 settingKeys={["promptSuggestionsEnabled"]}
292 description={gt`Show a predicted next message in the empty composer after a Claude or Codex turn. Tab uses it. Each is an extra cached request on your plan. Needs Codex 0.165+. Claude threads update on restart.`}
293 control={
294 <ScopedSwitch
295 settingKeys={["promptSuggestionsEnabled"]}
296 checked={settings.promptSuggestionsEnabled}
297 onCheckedChange={(checked) =>
298 updateSettings({ promptSuggestionsEnabled: Boolean(checked) })
299 }
300 aria-label={gt`Suggest next prompt`}
301 />
302 }
303 />
304 );
305}
306
307function SimlockHostsRow() {
308 const searchableSetting = useSearchableSetting();
309 const settings = useScopedSettings();
310 const updateSettings = useUpdateScopedSettings();
311 const gt = useGT();
312 return (
313 <SettingsRow
314 serverScoped
315 {...searchableSetting("simlock-hosts")}
316 settingKeys={["simlockDeviceHostsEnabled"]}
317 description={
318 <T>
319 Let the Device panel lease simulators and emulators from your own{" "}
320 <a
321 href="https://incubator.callstack.com/simlock/"
322 target="_blank"
323 rel="noreferrer"
324 className="underline underline-offset-2"
325 >
326 Simlock
327 </a>{" "}
328 pool, added in{" "}
329 <Link to="/settings/devices" className="underline underline-offset-2">
330 Devices
331 </Link>
332 . An alpha that may change or break. T3 Code never installs Simlock.
333 </T>
334 }
335 control={
336 <ScopedSwitch
337 settingKeys={["simlockDeviceHostsEnabled"]}
338 checked={settings.simlockDeviceHostsEnabled}
339 onCheckedChange={(checked) =>
340 updateSettings({ simlockDeviceHostsEnabled: Boolean(checked) })
341 }
342 aria-label={gt`Simlock device hosts`}
343 />
344 }
345 />
346 );
347}
348
349/** Shows only when every machine in scope is a Mac, since only macOS servers honor it. */
350function FastWorktreeCheckoutRow() {
351 const searchableSetting = useSearchableSetting();
352 const { scope, connectedEnvironments } = useSettingsScope();
353 const settings = useScopedSettings();
354 const updateSettings = useUpdateScopedSettings();
355 const gt = useGT();
356 if (
357 scope.kind === "project" ||
358 scope.kind === "checkout" ||
359 connectedEnvironments.length === 0 ||
360 connectedEnvironments.some(
361 (environment) =>
362 environment.serverConfig?.environment.capabilities.fastWorktreeCheckout !== true,
363 )
364 )
365 return null;
366 return (
367 <SettingsRow
368 serverScoped
369 {...searchableSetting("worktree-fast-checkout")}
370 settingKeys={["fastWorktreeCheckout"]}
371 description={gt`On a Mac, clone new worktrees from a checkout cached in the T3 home folder instead of writing every file. Uses Git’s normal checkout when it can’t. Turning it off deletes the cache.`}
372 control={
373 <ScopedSwitch
374 settingKeys={["fastWorktreeCheckout"]}
375 checked={settings.fastWorktreeCheckout}
376 onCheckedChange={(checked) => updateSettings({ fastWorktreeCheckout: Boolean(checked) })}
377 aria-label={gt`Fast worktree checkout`}
378 />
379 }
380 />
381 );
382}
383
384/** Shows only when every machine in scope honors it; older servers drop the setting. */
385const AGENT_FEEDBACK_MODES = AgentFeedbackMode.literals;
386const AGENT_FEEDBACK_MODE_LABELS: Record<AgentFeedbackMode, string> = {
387 off: msg("Off"),
388 "on-request": msg("When I ask"),
389 auto: msg("Automatic"),
390};
391const AGENT_FEEDBACK_MODE_DESCRIPTIONS: Record<AgentFeedbackMode, string> = {
392 off: msg("Agents send no feedback to the T3 team."),
393 "on-request": msg(
394 "When you ask, agents show you a short report about T3 Code and send it to the T3 team if you approve.",
395 ),
396 auto: msg(
397 "Agents also report T3 Code problems they hit on their own, such as a T3 tool that failed.",
398 ),
399};
400
401function AgentFeedbackRow() {
402 const searchableSetting = useSearchableSetting();
403 const { scope, connectedEnvironments } = useSettingsScope();
404 const settings = useScopedSettings();
405 const updateSettings = useUpdateScopedSettings();
406 const gt = useGT();
407 const m = useMessages();
408 const mixed = useScopedSettingsMixed(["agentFeedback"]);
409 if (
410 scope.kind === "project" ||
411 scope.kind === "checkout" ||
412 connectedEnvironments.length === 0 ||
413 connectedEnvironments.some(
414 (environment) => environment.serverConfig?.environment.capabilities.agentFeedback !== true,
415 )
416 )
417 return null;
418 return (
419 <SettingsRow
420 serverScoped
421 {...searchableSetting("agent-feedback")}
422 settingKeys={["agentFeedback"]}
423 description={
424 mixed
425 ? gt`The selected machines use different agent feedback modes.`
426 : m(AGENT_FEEDBACK_MODE_DESCRIPTIONS[settings.agentFeedback.mode])
427 }
428 control={
429 <Select
430 value={mixed ? null : settings.agentFeedback.mode}
431 onValueChange={(mode) => {
432 if (mode !== null) updateSettings({ agentFeedback: { mode } });
433 }}
434 >
435 <SelectTrigger size="sm" className="w-full sm:w-40" aria-label={gt`Agent feedback`}>
436 <SelectValue>
437 {(mode: AgentFeedbackMode | null) =>
438 mode === null ? gt`Mixed` : m(AGENT_FEEDBACK_MODE_LABELS[mode])
439 }
440 </SelectValue>
441 </SelectTrigger>
442 <SelectPopup align="end" alignItemWithTrigger={false}>
443 {AGENT_FEEDBACK_MODES.map((mode) => (
444 <SelectItem key={mode} hideIndicator value={mode}>
445 {m(AGENT_FEEDBACK_MODE_LABELS[mode])}
446 </SelectItem>
447 ))}
448 </SelectPopup>
449 </Select>
450 }
451 />
452 );
453}