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