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

contractLabels.ts

263 lines11.3 KB

1/**
2 * Translatable copies of the English labels in `@t3tools/contracts` helpers. Same ids, same
3 * English; apps call these instead of the contracts helpers so the text follows the UI language.
4 */
5import {
6 type BrowserImportFailureReason,
7 isRuntimeModeAbove,
8 managedCapabilityDenial as contractsManagedCapabilityDenial,
9 managedUpdatesDenial as contractsManagedUpdatesDenial,
10 type ManagedPolicySummary,
11 type ProjectCloneSnapshot,
12 type ProjectCloneStage,
13 type ProviderRuntimeModeLimit,
14 RUN_STOPPED_BY_PROVIDER_REASON,
15 RUN_STOPPED_BY_USER_REASON,
16 type RuntimeMode,
17 type WorktreeSetupStageId,
18 worktreeSetupStageLabel as contractsWorktreeSetupStageLabel,
19} from "@t3tools/contracts";
20import type { IdleCompactionMode } from "@t3tools/contracts/settings";
21import { mFallback, msg, type Msg } from "gt-i18n";
22import type { M } from "gt-i18n";
23​
24// Contracts decides each stage's English label; this table only makes that text translatable.
25const WORKTREE_SETUP_STAGE_LABELS: Readonly<Record<string, string>> = {
26 "Fetch base branch": msg("Fetch base branch"),
27 "Check out files": msg("Check out files"),
28 "Init submodules": msg("Init submodules"),
29 "Run setup script": msg("Run setup script"),
30 "Start agent": msg("Start agent"),
31};
32​
33/** @public */
34export function worktreeSetupStageLabel(id: WorktreeSetupStageId, resolve: M = mFallback): string {
35 const english = contractsWorktreeSetupStageLabel(id);
36 return resolve(WORKTREE_SETUP_STAGE_LABELS[english] ?? english);
38​
39// Other stop reasons are an agent's own words and show as written.
40const RUN_STOP_REASON_LABELS: Readonly<Record<string, string>> = {
41 [RUN_STOPPED_BY_USER_REASON]: msg("Stopped by user"),
42 [RUN_STOPPED_BY_PROVIDER_REASON]: msg("Stopped by the provider"),
43};
44​
45export function runStopReasonLabel(reason: string, resolve: M = mFallback): string {
46 const label = RUN_STOP_REASON_LABELS[reason];
47 return label === undefined ? reason : resolve(label);
49​
50const PROJECT_CLONE_STAGE_LABELS: Record<ProjectCloneStage, string | Msg> = {
51 connecting: msg({ context: "git clone stage" })`Connecting`,
52 counting: msg("Counting objects"),
53 receiving: msg("Receiving objects"),
54 resolving: msg("Resolving deltas"),
55 checkout: msg("Checking out files"),
56};
57​
58/** @public */
59export function projectCloneStageLabel(stage: ProjectCloneStage, resolve: M = mFallback): string {
60 return resolve(PROJECT_CLONE_STAGE_LABELS[stage]);
62​
63/** @public */
64export function projectCloneProgressSummary(
65 snapshot: Pick<ProjectCloneSnapshot, "stage" | "percent" | "detail" | "stalled">,
66 resolve: M = mFallback,
67): string {
68 const parts = [projectCloneStageLabel(snapshot.stage, resolve)];
69 if (snapshot.percent !== null) parts.push(`${snapshot.percent}%`);
70 // The detail carries git's last transfer speed, which a stall makes a lie.
71 if (snapshot.stalled) parts.push(resolve(msg({ context: "git clone progress" })`Stalled`));
72 else if (snapshot.detail) parts.push(snapshot.detail);
73 return parts.join(" · ");
75​
76/** @public */
77export function managedUpdatesMessage(organization: string, resolve: M = mFallback): string {
78 return resolve(msg`${{ organization }} manages T3 Code updates.`);
80​
81/** @public */
82export function managedNightlyDeniedMessage(organization: string, resolve: M = mFallback): string {
83 return resolve(
84 msg`${{ organization }} manages T3 Code updates. Only stable releases can be installed.`,
85 );
87​
88/** @public */
89export function managedUpdatesDenial(
90 summary: ManagedPolicySummary | undefined,
91 resolve: M = mFallback,
92): string | undefined {
93 return summary !== undefined && contractsManagedUpdatesDenial(summary) !== undefined
94 ? managedUpdatesMessage(summary.organization, resolve)
95 : undefined;
97​
98/** @public */
99export function managedRuntimeModeCeilingMessage(
100 organization: string,
101 ceiling: RuntimeMode,
102 resolve: M = mFallback,
103): string {
104 switch (ceiling) {
105 case "approval-required":
106 return resolve(msg`${{ organization }} limits threads to Supervised.`);
107 case "auto-accept-edits":
108 return resolve(msg`${{ organization }} limits threads to Auto-accept edits.`);
109 case "auto":
110 return resolve(msg`${{ organization }} limits threads to Auto.`);
111 case "full-access":
112 return resolve(msg`${{ organization }} limits threads to Full access.`);
113 }
115​
116/** @public */
117export function managedRuntimeModeDenial(
118 summary: ManagedPolicySummary | undefined,
119 mode: RuntimeMode,
120 resolve: M = mFallback,
121): string | undefined {
122 const ceiling = summary?.limits?.maxRuntimeMode;
123 return summary !== undefined && ceiling !== undefined && isRuntimeModeAbove(mode, ceiling)
124 ? managedRuntimeModeCeilingMessage(summary.organization, ceiling, resolve)
125 : undefined;
127​
128/** Why a provider cannot run `mode` in the current folder, or undefined when it can. */
129export function providerRuntimeModeLimitMessage(
130 limits: ReadonlyArray<ProviderRuntimeModeLimit> | undefined,
131 mode: RuntimeMode,
132 resolve: M = mFallback,
133): string | undefined {
134 const limit = limits?.find((candidate) => candidate.mode === mode);
135 if (limit === undefined) return undefined;
136 // Only Claude's auto mode reports limits today.
137 switch (limit.reason) {
138 case "managed-settings":
139 return resolve(msg("Your organization's Claude settings turn auto mode off."));
140 case "user-settings":
141 return resolve(msg("Your Claude settings turn auto mode off."));
142 case "project-settings":
143 return resolve(msg("This project's Claude settings turn auto mode off."));
144 case "settings":
145 return resolve(msg("Claude's settings turn auto mode off."));
146 }
148​
149export type ManagedCapability =
150 | "remoteClients"
151 | "connect"
152 | "webhookTasks"
153 | "browserCookieImport"
154 | "previewTunnel"
155 | "worktreeLayoutCommands";
156​
157function managedCapabilityDeniedMessage(
158 organization: string,
159 capability: ManagedCapability,
160 resolve: M,
161): string {
162 switch (capability) {
163 case "remoteClients":
164 return resolve(
165 msg`${{ organization }}'s policy does not allow connecting from other devices.`,
166 );
167 case "connect":
168 return resolve(msg`${{ organization }}'s policy does not allow T3 Connect.`);
169 case "webhookTasks":
170 return resolve(msg`${{ organization }}'s policy does not allow webhook tasks.`);
171 case "browserCookieImport":
172 return resolve(msg`${{ organization }}'s policy does not allow importing browser cookies.`);
173 case "previewTunnel":
174 return resolve(
175 msg`${{ organization }}'s policy does not allow opening this machine's local servers on other devices.`,
176 );
177 case "worktreeLayoutCommands":
178 return resolve(
179 msg`${{ organization }}'s policy does not allow project worktree layout commands.`,
180 );
181 }
183​
184/** @public */
185export function managedCapabilityDenial(
186 summary: ManagedPolicySummary | undefined,
187 capability: ManagedCapability,
188 resolve: M = mFallback,
189): string | undefined {
190 return summary !== undefined &&
191 contractsManagedCapabilityDenial(summary, capability) !== undefined
192 ? managedCapabilityDeniedMessage(summary.organization, capability, resolve)
193 : undefined;
195​
196const IDLE_COMPACTION_MODE_LABELS: Record<IdleCompactionMode | "default", string | Msg> = {
197 default: msg("Use default"),
198 onReturn: msg("When you return"),
199 beforeCacheExpires: msg("Before the cache expires (beta)"),
200 off: msg({ context: "idle compaction mode" })`Never`,
201};
202​
203/** @public Labels for `IDLE_COMPACTION_MODES` values, plus the per-instance "default". */
204export function idleCompactionModeLabel(
205 mode: IdleCompactionMode | "default",
206 resolve: M = mFallback,
207): string {
208 return resolve(IDLE_COMPACTION_MODE_LABELS[mode]);
210​
211const BROWSER_IMPORT_FAILURE_MESSAGES: Record<BrowserImportFailureReason, string> = {
212 notInstalled: msg("Not installed on this machine."),
213 needsKeychainApproval: msg("Needs Keychain access to read its cookies."),
214 keychainItemMissing: msg(
215 "No encryption key in your Keychain. Sign in to that browser once, then retry.",
216 ),
217 needsFullDiskAccess: msg(
218 "Give T3 Code Full Disk Access in System Settings → Privacy & Security, then retry.",
219 ),
220 browserRunning: msg("Quit the browser first so its cookie database can be read."),
221 unsupportedPlatform: msg("Importing from this browser isn't possible on this platform."),
222 keychainUnavailable: msg(
223 "The system keyring could not be accessed. Make sure your desktop keyring is running and unlocked, then retry.",
224 ),
225 unknownSource: msg("That browser is no longer available to import from."),
226 unknownSourceProfile: msg("That browser profile no longer exists."),
227 sessionUnavailable: msg("The target profile could not be opened."),
228 profileNotSaved: msg(
229 "The cookies were imported, but the new profile couldn't be saved. Try again.",
230 ),
231 profileLimitReached: msg(
232 "You've reached the profile limit. Delete a profile or import into an existing one.",
233 ),
234 readFailed: msg("The browser's cookie database could not be read."),
235};
236​
237/** @public `BROWSER_IMPORT_FAILURE_COPY[reason]`, translated. */
238export function browserImportFailureMessage(
239 reason: BrowserImportFailureReason,
240 resolve: M = mFallback,
241): string {
242 return resolve(BROWSER_IMPORT_FAILURE_MESSAGES[reason]);
244​
245// The server's source-control discovery hints, in the same English; commands and URLs stay as is.
246const INSTALL_HINTS = [
247 msg`Install Git from ${{ url: "https://git-scm.com/downloads" }} or with your package manager.`,
248 msg`Install Jujutsu with ${{ command: "`brew install jj`" }} or from ${{ url: "https://github.com/jj-vcs/jj" }}.`,
249 msg`Install the GitHub command-line tool (${{ cli: "`gh`" }}) via ${{ url: "https://cli.github.com/" }} or your package manager (for example ${{ command: "`brew install gh`" }}).`,
250 msg`Install the GitLab command-line tool (${{ cli: "`glab`" }}) from ${{ url: "https://gitlab.com/gitlab-org/cli" }} or your package manager (for example ${{ command: "`brew install glab`" }}).`,
251 msg`Install the Azure command-line tools (${{ cli: "`az`" }}), then enable Azure DevOps support with ${{ command: "`az extension add --name azure-devops`" }}.`,
252 msg("Add a Bitbucket token in Settings → Source control & issues."),
253 msg`Install the Origin CLI with ${{ install: "`curl -fsSL https://downloads.cursor.com/origin/install.sh | sh`" }}, then run ${{ login: "`origin auth login`" }}.`,
254 msg`Install ${{ fj: "`fj`" }} 0.6 or later from ${{ fjUrl: "https://codeberg.org/forgejo-contrib/forgejo-cli" }} and run ${{ fjLogin: "`fj --host <server-url> auth add-token`" }}, or install ${{ gt: "`gt`" }} 2.0 or later from ${{ gtUrl: "https://gitea.com/gitea/cli" }} and run ${{ gtLogin: "`gt auth login --host <server-url>`" }} for each Forgejo or Gitea server.`,
255 msg`Install the GitCafe CLI with ${{ install: "`bun install -g @gitcafe/cli`" }}, then run ${{ login: "`cafe auth login --host https://git.cafe/api`" }}, save a token in Settings, or set ${{ variable: "CAFE_TOKEN" }} on the server.`,
256 msg`Install the TanStack Source CLI with ${{ install: "`curl -fsSL https://source.tanstack.com/install | sh`" }}, then run ${{ login: "`src auth login --web --hostname source.tanstack.com`" }}, save a token in Settings, or set ${{ variable: "SRC_TOKEN" }} on the server.`,
257];
258​
259/** @public A source-control `installHint`, translated when it is one of the server's fixed hints. */
260export function sourceControlInstallHintText(hint: string, resolve: M = mFallback): string {
261 const known = INSTALL_HINTS.find((entry) => mFallback(entry) === hint);
262 return known === undefined ? hint : resolve(known);