The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | import { managedCapabilityDenial } from "@t3tools/client-runtime/contract-labels"; |
| 2 | import { useAuth } from "@clerk/react"; |
| 3 | import { Link } from "@tanstack/react-router"; |
| 4 | import { T, useGT, useMessages } from "gt-react"; |
| 5 | |
| 6 | import { hasCloudPublicConfig } from "~/cloud/publicConfig"; |
| 7 | import { useT3ConnectAuthPrompt } from "../clerk/useT3ConnectAuthPrompt"; |
| 8 | import { Button } from "../ui/button"; |
| 9 | import { Switch } from "../ui/switch"; |
| 10 | import { ScopedSwitch } from "./ScopedSwitch"; |
| 11 | import { SettingsPageContainer, SettingsRow, SettingsSection } from "./settingsLayout"; |
| 12 | import { useSearchableSetting } from "./settingsSearch"; |
| 13 | import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings"; |
| 14 | import { useOptionalSettingsScope, useSettingsScope } from "./SettingsScopeContext"; |
| 15 | import { firstManagedDenial, usePrimaryManagedPolicy } from "~/state/managedPolicy"; |
| 16 | |
| 17 | /** Features still settling in. */ |
| 18 | export function LabsSettingsPanel() { |
| 19 | const gt = useGT(); |
| 20 | return ( |
| 21 | <SettingsPageContainer> |
| 22 | <SettingsSection id="beta" title={gt("Beta")}> |
| 23 | <BoringSidebarRow /> |
| 24 | {/* Clerk is only mounted when this build has T3 Connect. */} |
| 25 | {hasCloudPublicConfig() ? <GuestLinksRowWithSignIn /> : <GuestLinksRow />} |
| 26 | <LinkedEnvironmentsRow /> |
| 27 | <PromptSuggestionsRow /> |
| 28 | <SimlockHostsRow /> |
| 29 | <FastWorktreeCheckoutRow /> |
| 30 | </SettingsSection> |
| 31 | </SettingsPageContainer> |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | function BoringSidebarRow() { |
| 36 | const searchableSetting = useSearchableSetting(); |
| 37 | const settings = useScopedSettings(); |
| 38 | const updateSettings = useUpdateScopedSettings(); |
| 39 | const gt = useGT(); |
| 40 | return ( |
| 41 | <SettingsRow |
| 42 | {...searchableSetting("boring-sidebar")} |
| 43 | description={gt( |
| 44 | "Group sidebar threads into project folders. Pinned threads stay on top, and Snoozed and Settled stay below the folders.", |
| 45 | )} |
| 46 | control={ |
| 47 | <Switch |
| 48 | checked={settings.boringSidebarEnabled} |
| 49 | onCheckedChange={(checked) => updateSettings({ boringSidebarEnabled: Boolean(checked) })} |
| 50 | aria-label={gt("Boring sidebar (group by project)")} |
| 51 | /> |
| 52 | } |
| 53 | > |
| 54 | {settings.boringSidebarEnabled ? ( |
| 55 | <div className="mt-2 mb-2 border-l-2 border-border/60 ps-3"> |
| 56 | <BoringSidebarMultilineRow /> |
| 57 | </div> |
| 58 | ) : null} |
| 59 | </SettingsRow> |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | function BoringSidebarMultilineRow() { |
| 64 | const searchableSetting = useSearchableSetting(); |
| 65 | const settings = useScopedSettings(); |
| 66 | const updateSettings = useUpdateScopedSettings(); |
| 67 | const gt = useGT(); |
| 68 | return ( |
| 69 | <SettingsRow |
| 70 | {...searchableSetting("boring-sidebar-multiline")} |
| 71 | className="px-0 py-2 sm:px-0" |
| 72 | description={gt( |
| 73 | "Show folder threads on two lines: the title, then the branch, pull request, and agent.", |
| 74 | )} |
| 75 | control={ |
| 76 | <Switch |
| 77 | checked={settings.boringSidebarMultilineRows} |
| 78 | onCheckedChange={(checked) => |
| 79 | updateSettings({ boringSidebarMultilineRows: Boolean(checked) }) |
| 80 | } |
| 81 | aria-label={gt("Two-line folder rows")} |
| 82 | /> |
| 83 | } |
| 84 | /> |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | /** Signed out of T3 Connect, the row offers to sign in instead of its switch. */ |
| 89 | function GuestLinksRowWithSignIn() { |
| 90 | const searchableSetting = useSearchableSetting(); |
| 91 | const gt = useGT(); |
| 92 | const { isSignedIn } = useAuth(); |
| 93 | const { openAuthPrompt } = useT3ConnectAuthPrompt(); |
| 94 | // `isSignedIn` is undefined until Clerk loads. |
| 95 | if (isSignedIn !== false) return <GuestLinksRow />; |
| 96 | return ( |
| 97 | <SettingsRow |
| 98 | {...searchableSetting("guest-links")} |
| 99 | description={gt( |
| 100 | "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.", |
| 101 | )} |
| 102 | control={ |
| 103 | <Button size="sm" variant="outline" onClick={openAuthPrompt}> |
| 104 | <T>Sign in</T> |
| 105 | </Button> |
| 106 | } |
| 107 | /> |
| 108 | ); |
| 109 | } |
| 110 | |
| 111 | function GuestLinksRow() { |
| 112 | const searchableSetting = useSearchableSetting(); |
| 113 | const settings = useScopedSettings(); |
| 114 | const updateSettings = useUpdateScopedSettings(); |
| 115 | const gt = useGT(); |
| 116 | const messages = useMessages(); |
| 117 | const scope = useOptionalSettingsScope(); |
| 118 | const primaryPolicy = usePrimaryManagedPolicy(); |
| 119 | // Guests arrive through T3 Connect, so a policy that turns Connect off turns this off too. |
| 120 | const connectDenial = firstManagedDenial( |
| 121 | scope |
| 122 | ? scope.connectedEnvironments.map((environment) => environment.serverConfig?.managedPolicy) |
| 123 | : [primaryPolicy], |
| 124 | (policy) => managedCapabilityDenial(policy, "connect", messages), |
| 125 | ); |
| 126 | return ( |
| 127 | <SettingsRow |
| 128 | serverScoped |
| 129 | {...searchableSetting("guest-links")} |
| 130 | settingKeys={["guestSharingEnabled"]} |
| 131 | // Turning guest links off still works without T3 Connect. |
| 132 | managed={settings.guestSharingEnabled ? undefined : connectDenial} |
| 133 | description={ |
| 134 | <T> |
| 135 | Share a thread with a guest who watches it live in a browser and sends messages you |
| 136 | approve. Needs T3 Connect: sign in and link this machine in{" "} |
| 137 | <Link to="/settings/access" className="underline underline-offset-2"> |
| 138 | Sharing & access |
| 139 | </Link> |
| 140 | . Turning it off stops every guest link. |
| 141 | </T> |
| 142 | } |
| 143 | control={ |
| 144 | <ScopedSwitch |
| 145 | settingKeys={["guestSharingEnabled"]} |
| 146 | checked={settings.guestSharingEnabled} |
| 147 | onCheckedChange={(checked) => updateSettings({ guestSharingEnabled: Boolean(checked) })} |
| 148 | aria-label={gt("Guest links")} |
| 149 | /> |
| 150 | } |
| 151 | /> |
| 152 | ); |
| 153 | } |
| 154 | |
| 155 | function LinkedEnvironmentsRow() { |
| 156 | const searchableSetting = useSearchableSetting(); |
| 157 | const settings = useScopedSettings(); |
| 158 | const updateSettings = useUpdateScopedSettings(); |
| 159 | const gt = useGT(); |
| 160 | return ( |
| 161 | <SettingsRow |
| 162 | serverScoped |
| 163 | {...searchableSetting("linked-environments-beta")} |
| 164 | settingKeys={["linkedEnvironmentsEnabled"]} |
| 165 | description={ |
| 166 | <T> |
| 167 | Let agents here work on your other machines, and theirs here. Turn it on for each machine, |
| 168 | then link them in{" "} |
| 169 | <Link to="/settings/connections" className="underline underline-offset-2"> |
| 170 | Connections |
| 171 | </Link> |
| 172 | . While off, nothing new starts over a link; running tasks finish. |
| 173 | </T> |
| 174 | } |
| 175 | control={ |
| 176 | <ScopedSwitch |
| 177 | settingKeys={["linkedEnvironmentsEnabled"]} |
| 178 | checked={settings.linkedEnvironmentsEnabled} |
| 179 | onCheckedChange={(checked) => |
| 180 | updateSettings({ linkedEnvironmentsEnabled: Boolean(checked) }) |
| 181 | } |
| 182 | aria-label={gt("Linked environments")} |
| 183 | /> |
| 184 | } |
| 185 | /> |
| 186 | ); |
| 187 | } |
| 188 | |
| 189 | function PromptSuggestionsRow() { |
| 190 | const searchableSetting = useSearchableSetting(); |
| 191 | const settings = useScopedSettings(); |
| 192 | const updateSettings = useUpdateScopedSettings(); |
| 193 | const gt = useGT(); |
| 194 | return ( |
| 195 | <SettingsRow |
| 196 | serverScoped |
| 197 | {...searchableSetting("prompt-suggestions-beta")} |
| 198 | settingKeys={["promptSuggestionsEnabled"]} |
| 199 | description={gt( |
| 200 | "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.", |
| 201 | )} |
| 202 | control={ |
| 203 | <ScopedSwitch |
| 204 | settingKeys={["promptSuggestionsEnabled"]} |
| 205 | checked={settings.promptSuggestionsEnabled} |
| 206 | onCheckedChange={(checked) => |
| 207 | updateSettings({ promptSuggestionsEnabled: Boolean(checked) }) |
| 208 | } |
| 209 | aria-label={gt("Suggest next prompt")} |
| 210 | /> |
| 211 | } |
| 212 | /> |
| 213 | ); |
| 214 | } |
| 215 | |
| 216 | function SimlockHostsRow() { |
| 217 | const searchableSetting = useSearchableSetting(); |
| 218 | const settings = useScopedSettings(); |
| 219 | const updateSettings = useUpdateScopedSettings(); |
| 220 | const gt = useGT(); |
| 221 | return ( |
| 222 | <SettingsRow |
| 223 | serverScoped |
| 224 | {...searchableSetting("simlock-hosts")} |
| 225 | settingKeys={["simlockDeviceHostsEnabled"]} |
| 226 | description={ |
| 227 | <T> |
| 228 | Let the Device panel lease simulators and emulators from your own{" "} |
| 229 | <a |
| 230 | href="https://incubator.callstack.com/simlock/" |
| 231 | target="_blank" |
| 232 | rel="noreferrer" |
| 233 | className="underline underline-offset-2" |
| 234 | > |
| 235 | Simlock |
| 236 | </a>{" "} |
| 237 | pool, added in{" "} |
| 238 | <Link to="/settings/devices" className="underline underline-offset-2"> |
| 239 | Devices |
| 240 | </Link> |
| 241 | . An alpha that may change or break. T3 Code never installs Simlock. |
| 242 | </T> |
| 243 | } |
| 244 | control={ |
| 245 | <ScopedSwitch |
| 246 | settingKeys={["simlockDeviceHostsEnabled"]} |
| 247 | checked={settings.simlockDeviceHostsEnabled} |
| 248 | onCheckedChange={(checked) => |
| 249 | updateSettings({ simlockDeviceHostsEnabled: Boolean(checked) }) |
| 250 | } |
| 251 | aria-label={gt("Simlock device hosts")} |
| 252 | /> |
| 253 | } |
| 254 | /> |
| 255 | ); |
| 256 | } |
| 257 | |
| 258 | /** Shows only when every machine in scope is a Mac, since only macOS servers honor it. */ |
| 259 | function FastWorktreeCheckoutRow() { |
| 260 | const searchableSetting = useSearchableSetting(); |
| 261 | const { scope, connectedEnvironments } = useSettingsScope(); |
| 262 | const settings = useScopedSettings(); |
| 263 | const updateSettings = useUpdateScopedSettings(); |
| 264 | const gt = useGT(); |
| 265 | if ( |
| 266 | scope.kind === "project" || |
| 267 | scope.kind === "checkout" || |
| 268 | connectedEnvironments.length === 0 || |
| 269 | connectedEnvironments.some( |
| 270 | (environment) => |
| 271 | environment.serverConfig?.environment.capabilities.fastWorktreeCheckout !== true, |
| 272 | ) |
| 273 | ) |
| 274 | return null; |
| 275 | return ( |
| 276 | <SettingsRow |
| 277 | serverScoped |
| 278 | {...searchableSetting("worktree-fast-checkout")} |
| 279 | settingKeys={["fastWorktreeCheckout"]} |
| 280 | description={gt( |
| 281 | "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.", |
| 282 | )} |
| 283 | control={ |
| 284 | <ScopedSwitch |
| 285 | settingKeys={["fastWorktreeCheckout"]} |
| 286 | checked={settings.fastWorktreeCheckout} |
| 287 | onCheckedChange={(checked) => updateSettings({ fastWorktreeCheckout: Boolean(checked) })} |
| 288 | aria-label={gt("Fast worktree checkout")} |
| 289 | /> |
| 290 | } |
| 291 | /> |
| 292 | ); |
| 293 | } |