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

contractLabels.ts

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