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

contractLabels.ts

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