@devries-cameron20 / t3code Mirror · read-only
Fork 0

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, 03:37 UTC

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