Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

LabsSettingsPanel.tsx

467 lines15.8 KB

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