@devries-cameron20 / t3code Mirror · read-only / commits / 433837752c
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 22, 15:45 UTC

feat(web): "failed to start" screen helps users recover and report the crash (#25345)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Theo Browne committed Oct 25, 2026 at 23:22 UTC 433837752cf0561e8bcab297d959380ba9f5a894
3 files changed +573 -81
apps/web/index.html
+148 -31
@@ -439,13 +439,23 @@
439 object-fit: contain;
440 }
441
442 + /* App CSS locks body and #root scrolling once main loads, so the error screen scrolls itself. */
443 + #boot-shell:has(> #boot-error) {
444 + height: 100%;
445 + overflow-x: hidden;
446 + overflow-y: auto;
447 + }
448 +
449 #boot-error {
450 --boot-error-fg: #262626;
451 --boot-error-bg: #ffffff;
452 + --boot-error-line: color-mix(in srgb, currentColor 12%, transparent);
453 display: flex;
454 flex-direction: column;
455 align-items: flex-start;
456 + align-self: flex-start;
457 width: min(400px, calc(100% - 48px));
458 + padding: clamp(24px, 22vh, 220px) 0 24px;
459 font-size: 13px;
460 line-height: 20px;
461 }
@@ -469,36 +479,134 @@
479
480 #boot-error p {
481 margin: 4px 0 0;
472 - opacity: 0.6;
482 + opacity: 0.7;
483 overflow-wrap: anywhere;
484 text-wrap: pretty;
485 }
486
477 - #boot-error code {
487 + #boot-error code,
488 + #boot-error pre {
489 font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
490 font-size: 12px;
491 overflow-wrap: anywhere;
492 }
493
494 + #boot-error a {
495 + color: inherit;
496 + text-decoration-line: underline;
497 + text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
498 + text-underline-offset: 3px;
499 + }
500 +
501 + #boot-error a:hover {
502 + text-decoration-color: currentColor;
503 + }
504 +
505 #boot-error button {
484 - border: 0;
506 + height: 32px;
507 + padding: 0 14px;
508 + border: 1px solid var(--boot-error-line);
509 + border-radius: 6px;
510 + background: transparent;
511 + color: inherit;
512 font: inherit;
513 + font-weight: 500;
514 cursor: pointer;
515 }
516
489 - #boot-error button:focus-visible {
517 + #boot-error button[aria-disabled="true"] {
518 + opacity: 0.6;
519 + cursor: default;
520 + }
521 +
522 + #boot-error :is(button, a, summary, pre):focus-visible {
523 outline: 2px solid var(--boot-error-fg);
524 outline-offset: 2px;
525 }
526
527 + #boot-error-actions {
528 + display: flex;
529 + flex-wrap: wrap;
530 + gap: 8px;
531 + margin-top: 16px;
532 + }
533 +
534 + #boot-error #boot-error-reload {
535 + border-color: var(--boot-error-fg);
536 + background: var(--boot-error-fg);
537 + color: var(--boot-error-bg);
538 + }
539 +
540 + #boot-error-reload:hover {
541 + opacity: 0.9;
542 + }
543 +
544 + #boot-error #boot-error-update-note {
545 + margin-top: 8px;
546 + font-size: 12px;
547 + line-height: 18px;
548 + }
549 +
550 + #boot-error details {
551 + width: 100%;
552 + margin-top: 32px;
553 + }
554 +
555 + #boot-error summary {
556 + display: inline-flex;
557 + align-items: center;
558 + gap: 8px;
559 + border-radius: 4px;
560 + list-style: none;
561 + opacity: 0.7;
562 + cursor: pointer;
563 + }
564 +
565 + #boot-error summary::-webkit-details-marker {
566 + display: none;
567 + }
568 +
569 + #boot-error summary::before {
570 + content: "";
571 + width: 5px;
572 + height: 5px;
573 + border-right: 1.5px solid currentColor;
574 + border-bottom: 1.5px solid currentColor;
575 + transform: rotate(-45deg);
576 + }
577 +
578 + #boot-error details[open] summary::before {
579 + transform: rotate(45deg);
580 + }
581 +
582 + #boot-error summary:hover,
583 + #boot-error details[open] summary {
584 + opacity: 1;
585 + }
586 +
587 + #boot-error details > :not(summary) {
588 + display: grid;
589 + gap: 8px;
590 + margin-top: 20px;
591 + }
592 +
593 + #boot-error details > a {
594 + display: block;
595 + width: fit-content;
596 + }
597 +
598 + #boot-error details p {
599 + margin: 0;
600 + font-size: 12px;
601 + line-height: 18px;
602 + }
603 +
604 #boot-error-command {
605 display: flex;
606 align-items: center;
607 gap: 8px;
498 - box-sizing: border-box;
499 - width: 100%;
608 padding: 4px 4px 4px 10px;
501 - border: 1px solid color-mix(in srgb, currentColor 10%, transparent);
609 + border: 1px solid var(--boot-error-line);
610 border-radius: 6px;
611 }
612
@@ -506,49 +614,58 @@
614 flex: 1;
615 min-width: 0;
616 opacity: 0.8;
509 - user-select: all;
617 }
618
512 - #boot-error-copy {
619 + #boot-error .boot-error-icon {
620 display: grid;
621 flex: none;
622 place-items: center;
516 - width: 24px;
623 + min-width: 24px;
624 height: 24px;
625 + padding: 0 4px;
626 + border: 0;
627 border-radius: 4px;
519 - background: transparent;
520 - color: inherit;
521 - opacity: 0.6;
628 + font-size: 12px;
629 + font-weight: 400;
630 + opacity: 0.7;
631 }
632
524 - #boot-error-copy:hover {
633 + #boot-error .boot-error-icon:hover {
634 opacity: 1;
635 background: color-mix(in srgb, currentColor 8%, transparent);
636 }
637
529 - #boot-error-triage {
530 - width: 100%;
531 - margin-top: 40px;
638 + #boot-error-details {
639 + max-height: 200px;
640 + margin: 0;
641 + padding: 10px 12px;
642 + overflow: auto;
643 + border: 1px solid var(--boot-error-line);
644 + border-radius: 6px;
645 + font-size: 11px;
646 + line-height: 16px;
647 + white-space: pre-wrap;
648 + opacity: 0.8;
649 }
650
534 - #boot-error-triage p {
535 - margin: 0 0 8px;
536 - font-size: 12px;
537 - line-height: 18px;
651 + #boot-error-report {
652 + display: flex;
653 + align-items: center;
654 + gap: 16px;
655 }
656
540 - #boot-error-reload {
541 - height: 32px;
542 - margin-top: 16px;
543 - padding: 0 14px;
544 - border-radius: 6px;
545 - background: var(--boot-error-fg);
546 - color: var(--boot-error-bg);
547 - font-weight: 500;
657 + #boot-error-report button {
658 + height: 28px;
659 + padding: 0 10px;
660 }
661
550 - #boot-error-reload:hover {
551 - opacity: 0.9;
662 + .boot-error-sr {
663 + position: absolute;
664 + width: 1px;
665 + height: 1px;
666 + overflow: hidden;
667 + clip-path: inset(50%);
668 + white-space: nowrap;
669 }
670 </style>
671 <title>T3 Code (Beta)</title>
apps/web/src/lib/bootError.test.ts
+81 -2
@@ -1,7 +1,12 @@
1 -import type { DesktopBridge, DesktopCliCommandState } from "@t3tools/contracts";
1 +import type { DesktopBridge, DesktopCliCommandState, DesktopUpdateState } from "@t3tools/contracts";
2 import { describe, expect, it, vi } from "vite-plus/test";
3
4 -import { resolveTriageCommand } from "./bootError";
4 +import {
5 + type BootErrorEnvironment,
6 + buildErrorReport,
7 + resolveTriageCommand,
8 + updateActionFor,
9 +} from "./bootError";
10
11 const desktopWith = (getState: () => Promise<DesktopCliCommandState>) =>
12 ({ cliCommand: { getState } }) as unknown as DesktopBridge;
@@ -52,3 +57,77 @@ describe("resolveTriageCommand", () => {
57 ).resolves.toBe("npx t3 triage");
58 });
59 });
60 +
61 +const environment: BootErrorEnvironment = {
62 + version: "0.1.3-nightly.20261026.3707",
63 + channel: "nightly",
64 + surface: "web",
65 + platform: "MacIntel",
66 + userAgent: "Test",
67 + time: "2026-10-26T00:00:00.000Z",
68 +};
69 +
70 +describe("buildErrorReport", () => {
71 + it("drops hosts and tokens from URLs in the error", () => {
72 + const error = new TypeError(
73 + "Failed to fetch dynamically imported module: http://studio.tail1234.ts.net:3773/assets/a.js?pair=SECRET#token=SECRET",
74 + {
75 + cause: new Error(
76 + "ws://studio.tail1234.ts.net:3773/ws?token=SECRET closed, main-a.js?sig=SECRET",
77 + ),
78 + },
79 + );
80 + error.stack = `TypeError: ${error.message}\n at http://studio.tail1234.ts.net:3773/src/main.tsx?t=1:10:5`;
81 + const report = buildErrorReport(error, environment);
82 + expect(report).not.toContain("SECRET");
83 + expect(report).not.toContain("tail1234");
84 + expect(report).toContain("module: /assets/a.js\n at /src/main.tsx:10:5");
85 + expect(report).toContain("Caused by: Error: /ws closed, main-a.js");
86 + expect(report).toContain("Version: 0.1.3-nightly.20261026.3707");
87 + });
88 +
89 + it("keeps the header when a Firefox stack frame starts with the error name", () => {
90 + const error = new Error("boot failed");
91 + error.stack = "ErrorBoundary@/assets/main.js:1:2";
92 + expect(buildErrorReport(error, environment)).toMatch(
93 + /^Error: boot failed\nErrorBoundary@\/assets\/main.js:1:2\n/,
94 + );
95 + const unnamed = new Error();
96 + unnamed.stack = "ErrorBoundary@/assets/main.js:1:2";
97 + expect(buildErrorReport(unnamed, environment)).toMatch(/^Error\nErrorBoundary@/);
98 + });
99 +
100 + it("stops at cause cycles and survives values that are not errors", () => {
101 + const loop = new Error("outer");
102 + loop.cause = loop;
103 + expect(buildErrorReport(loop, environment).match(/outer/g)).toHaveLength(1);
104 + expect(buildErrorReport("plain text", environment)).toMatch(/^plain text\n/);
105 + expect(buildErrorReport({ code: 42 }, environment)).toMatch(/^\{"code":42\}\n/);
106 + expect(buildErrorReport(Object.create(null), environment)).toMatch(/^\{\}\n/);
107 + expect(buildErrorReport(undefined, environment)).toMatch(/^\(no error message\)\n/);
108 + });
109 +
110 + it("cuts long errors but keeps the environment", () => {
111 + const report = buildErrorReport("x".repeat(20_000), environment);
112 + expect(report).toContain("[truncated]");
113 + expect(report.length).toBeLessThan(7_000);
114 + expect(report).toContain("Time: 2026-10-26T00:00:00.000Z");
115 + });
116 +});
117 +
118 +describe("updateActionFor", () => {
119 + it("offers an action only when a newer build exists", () => {
120 + const state = (status: DesktopUpdateState["status"], downloadPercent: number | null = null) =>
121 + ({ status, downloadPercent }) as DesktopUpdateState;
122 + expect(updateActionFor(state("available"))).toEqual({ kind: "download" });
123 + expect(updateActionFor(state("downloading", 41.6))).toEqual({
124 + kind: "downloading",
125 + percent: 42,
126 + });
127 + expect(updateActionFor(state("downloaded"))).toEqual({ kind: "install" });
128 + for (const status of ["disabled", "idle", "checking", "up-to-date", "error"] as const) {
129 + expect(updateActionFor(state(status))).toBeNull();
130 + }
131 + expect(updateActionFor(undefined)).toBeNull();
132 + });
133 +});
apps/web/src/lib/bootError.ts
+344 -48
@@ -1,6 +1,15 @@
1 -import type { DesktopBridge } from "@t3tools/contracts";
1 +import type { DesktopBridge, DesktopUpdateState } from "@t3tools/contracts";
2
3 const FALLBACK_TRIAGE_COMMAND = "npx t3 triage";
4 +const DOWNLOAD_URL = "https://t3.codes/download";
5 +const ISSUE_URL = "https://github.com/pingdotgg/t3code/issues/new";
6 +const LAST_FAILURE_KEY = "t3code:boot-failed-at";
7 +const REPEAT_FAILURE_MS = 5 * 60_000;
8 +const MAX_CAUSES = 3;
9 +const MAX_ERROR_CHARS = 6_000;
10 +const COPY_BLOCKED = "Copy was blocked. The text is selected so you can copy it manually.";
11 +const UPDATE_DOWNLOAD_FAILED = "The update download failed. Try Download update again.";
12 +const UPDATE_INSTALL_FAILED = "The update install failed. Try Restart to update again.";
13
14 /** The Windows launcher is a `.cmd` run from PowerShell, which needs `&` to run a quoted path. */
15 function launcherCommand(launcherPath: string) {
@@ -28,6 +37,120 @@ export async function resolveTriageCommand(bridge: DesktopBridge | undefined) {
37 return FALLBACK_TRIAGE_COMMAND;
38 }
39
40 +/** The update button only appears when the desktop updater has a newer build to offer. */
41 +export function updateActionFor(state: DesktopUpdateState | null | undefined) {
42 + switch (state?.status) {
43 + case "available":
44 + return { kind: "download" } as const;
45 + case "downloading":
46 + return { kind: "downloading", percent: Math.round(state.downloadPercent ?? 0) } as const;
47 + case "downloaded":
48 + return { kind: "install" } as const;
49 + default:
50 + return null;
51 + }
52 +}
53 +
54 +function safeString(value: unknown) {
55 + try {
56 + return String(value);
57 + } catch {
58 + return "";
59 + }
60 +}
61 +
62 +function describeOne(value: unknown) {
63 + if (value instanceof Error) {
64 + const header = value.message ? `${value.name}: ${value.message}` : value.name;
65 + // V8 stacks start with the header; Safari and Firefox stacks do not.
66 + const stack = typeof value.stack === "string" ? value.stack : "";
67 + return stack === header || stack.startsWith(`${header}\n`)
68 + ? stack
69 + : [header, stack].filter(Boolean).join("\n");
70 + }
71 + if (typeof value === "string") return value;
72 + try {
73 + return JSON.stringify(value) ?? safeString(value);
74 + } catch {
75 + return safeString(value);
76 + }
77 +}
78 +
79 +/** Hosts can name private machines, and pairing tokens live in query strings and hashes. */
80 +function redact(text: string) {
81 + return text
82 + .replace(/\b[a-z][\w+.-]*:\/\/[^\s/?#'"()]+/gi, "")
83 + .replace(/[?#][^\s'"()]*=[^\s'"()]*?((?::\d+){1,2})?(?=[\s'"()]|$)/g, "$1");
84 +}
85 +
86 +export interface BootErrorEnvironment {
87 + readonly version: string;
88 + readonly channel: string;
89 + readonly surface: "desktop" | "web";
90 + readonly platform: string;
91 + readonly userAgent: string;
92 + readonly time: string;
93 +}
94 +
95 +/** Plain text that is shown and copied as-is, so users see exactly what they share. */
96 +export function buildErrorReport(error: unknown, environment: BootErrorEnvironment) {
97 + const parts: Array<string> = [];
98 + const seen = new Set<unknown>();
99 + let current = error;
100 + while (current != null && !seen.has(current) && parts.length <= MAX_CAUSES) {
101 + seen.add(current);
102 + const text = describeOne(current);
103 + parts.push(parts.length === 0 ? text : `Caused by: ${text}`);
104 + current = current instanceof Error ? current.cause : undefined;
105 + }
106 + let details = redact(parts.join("\n") || "(no error message)");
107 + if (details.length > MAX_ERROR_CHARS) {
108 + details = `${details.slice(0, MAX_ERROR_CHARS)}\n[truncated]`;
109 + }
110 + return [
111 + details,
112 + "",
113 + `Version: ${environment.version}`,
114 + `Channel: ${environment.channel}`,
115 + `Surface: ${environment.surface}`,
116 + `Platform: ${environment.platform}`,
117 + `User agent: ${environment.userAgent}`,
118 + `Time: ${environment.time}`,
119 + ].join("\n");
120 +}
121 +
122 +function clientPlatform(bridge: DesktopBridge | undefined) {
123 + try {
124 + return bridge?.getClientPlatform?.() ?? navigator.platform;
125 + } catch {
126 + return navigator.platform;
127 + }
128 +}
129 +
130 +function readEnvironment(bridge: DesktopBridge | undefined): BootErrorEnvironment {
131 + const version = import.meta.env.APP_VERSION;
132 + return {
133 + version,
134 + channel:
135 + import.meta.env.VITE_RELEASE_CHANNEL || /-(nightly|preview)\./.exec(version)?.[1] || "stable",
136 + surface: bridge ? "desktop" : "web",
137 + platform: clientPlatform(bridge),
138 + userAgent: navigator.userAgent,
139 + time: new Date().toISOString(),
140 + };
141 +}
142 +
143 +/** Opens More options by default when startup already failed in this tab a moment ago. */
144 +function isRepeatFailure(now: number) {
145 + try {
146 + const previous = Number(sessionStorage.getItem(LAST_FAILURE_KEY));
147 + sessionStorage.setItem(LAST_FAILURE_KEY, String(now));
148 + return now - previous < REPEAT_FAILURE_MS;
149 + } catch {
150 + return false;
151 + }
152 +}
153 +
154 const icon = (paths: string) =>
155 `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${paths}</svg>`;
156 const COPY_ICON = icon(
@@ -35,65 +158,238 @@ const COPY_ICON = icon(
158 );
159 const CHECK_ICON = icon('<path d="M20 6 9 17l-5-5"/>');
160
161 +function element<K extends keyof HTMLElementTagNameMap>(
162 + tag: K,
163 + props: Partial<HTMLElementTagNameMap[K]> = {},
164 + children: ReadonlyArray<Node | string> = [],
165 +) {
166 + const node = Object.assign(document.createElement(tag), props);
167 + node.append(...children);
168 + return node;
169 +}
170 +
171 +function selectContents(target: HTMLElement) {
172 + const range = document.createRange();
173 + range.selectNodeContents(target);
174 + const selection = window.getSelection();
175 + selection?.removeAllRanges();
176 + selection?.addRange(range);
177 +}
178 +
179 +function copySelection() {
180 + try {
181 + return document.execCommand("copy");
182 + } catch {
183 + return false;
184 + }
185 +}
186 +
187 +/** Plain http has no Clipboard API, but the legacy copy command still works on a selection. */
188 +function copyText(target: HTMLElement, onCopied: () => void, onBlocked: (hint: string) => void) {
189 + const fallback = () => {
190 + selectContents(target);
191 + if (copySelection()) return onCopied();
192 + onBlocked(
193 + /Mac|iPhone|iPad/.test(navigator.platform) ? "Press ⌘C to copy" : "Press Ctrl+C to copy",
194 + );
195 + };
196 + const clipboard = window.isSecureContext ? navigator.clipboard : undefined;
197 + if (typeof clipboard?.writeText !== "function") return fallback();
198 + clipboard.writeText(target.textContent ?? "").then(onCopied, fallback);
199 +}
200 +
201 +function mountUpdateButton(
202 + bridge: DesktopBridge,
203 + button: HTMLButtonElement,
204 + note: HTMLParagraphElement,
205 + announce: (text: string) => void,
206 +) {
207 + let action: ReturnType<typeof updateActionFor> = null;
208 + const render = (state: DesktopUpdateState) => {
209 + action = updateActionFor(state);
210 + button.hidden = action === null;
211 + // aria-disabled keeps keyboard focus on the button while the download runs.
212 + button.setAttribute("aria-disabled", String(action?.kind === "downloading"));
213 + if (action?.kind === "download") button.textContent = "Download update";
214 + if (action?.kind === "downloading")
215 + button.textContent = `Downloading update (${action.percent}%)`;
216 + if (action?.kind === "install") button.textContent = "Restart to update";
217 + const failure = !action
218 + ? ""
219 + : state.errorContext === "download"
220 + ? UPDATE_DOWNLOAD_FAILED
221 + : state.errorContext === "install"
222 + ? UPDATE_INSTALL_FAILED
223 + : "";
224 + if (failure === note.textContent) return;
225 + note.textContent = failure;
226 + note.hidden = !failure;
227 + if (failure) announce(failure);
228 + };
229 + button.addEventListener("click", () => {
230 + const run =
231 + action?.kind === "install"
232 + ? bridge.installUpdate()
233 + : action?.kind === "download"
234 + ? bridge.downloadUpdate()
235 + : undefined;
236 + run?.then(
237 + (result) => render(result.state),
238 + (error: unknown) => console.warn("Could not update T3 Code.", error),
239 + );
240 + });
241 + // A pushed state is newer than the initial read, so the read must not overwrite it.
242 + let pushed = false;
243 + try {
244 + bridge.onUpdateState((state) => {
245 + pushed = true;
246 + render(state);
247 + });
248 + bridge.getUpdateState().then(
249 + (state) => pushed || render(state),
250 + (error: unknown) => console.warn("Could not read the desktop update state.", error),
251 + );
252 + } catch (error) {
253 + console.warn("Could not read the desktop update state.", error);
254 + }
255 +}
256 +
257 export function showBootError(error: unknown) {
258 console.error("T3 Code failed to start.", error);
259 const bootShell = document.getElementById("boot-shell");
260 if (!bootShell) return;
261
43 - const content = document.createElement("div");
44 - content.id = "boot-error";
45 - content.setAttribute("role", "alert");
262 + const bridge = window.desktopBridge;
263 + const environment = readEnvironment(bridge);
264 + const offline = !bridge && navigator.onLine === false;
265
47 - const title = document.createElement("h1");
48 - title.textContent = "T3 Code could not load";
49 - content.append(title);
266 + const status = element("span", { className: "boot-error-sr" });
267 + status.setAttribute("aria-live", "polite");
268 + // Clearing first makes screen readers announce a repeated message.
269 + let announcement: ReturnType<typeof setTimeout> | undefined;
270 + const announce = (text: string) => {
271 + clearTimeout(announcement);
272 + status.textContent = "";
273 + announcement = setTimeout(() => (status.textContent = text), 100);
274 + };
275
51 - if (import.meta.env.DEV && error instanceof Error) {
52 - const detail = document.createElement("p");
53 - detail.append(Object.assign(document.createElement("code"), { textContent: error.message }));
54 - content.append(detail);
55 - }
276 + const message = element("div", {}, [
277 + element("h1", { textContent: "T3 Code failed to start" }),
278 + element("p", {
279 + textContent: offline
280 + ? "This browser appears to be offline. Check the connection, then reload."
281 + : "We are not sure why. Try a reload first.",
282 + }),
283 + ]);
284 + message.setAttribute("role", "alert");
285
57 - const reload = document.createElement("button");
58 - reload.id = "boot-error-reload";
59 - reload.type = "button";
60 - reload.textContent = "Reload";
286 + const reload = element("button", {
287 + id: "boot-error-reload",
288 + type: "button",
289 + textContent: "Reload",
290 + });
291 reload.addEventListener("click", () => window.location.reload());
292 + const update = element("button", { id: "boot-error-update", type: "button", hidden: true });
293 + const updateNote = element("p", { id: "boot-error-update-note", hidden: true });
294 + if (bridge) mountUpdateButton(bridge, update, updateNote, announce);
295
63 - const hint = document.createElement("p");
64 - hint.textContent = "If reloading does not help, run this in a terminal to find the cause:";
65 -
66 - const command = document.createElement("code");
67 - command.textContent = FALLBACK_TRIAGE_COMMAND;
68 - const commandRow = document.createElement("div");
69 - commandRow.id = "boot-error-command";
70 - commandRow.append(command);
71 - // The clipboard API exists only in secure contexts, such as HTTPS and the desktop app.
72 - if (window.isSecureContext) {
73 - const copy = document.createElement("button");
74 - copy.id = "boot-error-copy";
75 - copy.type = "button";
76 - copy.title = "Copy command";
77 - copy.setAttribute("aria-label", "Copy command");
78 - copy.innerHTML = COPY_ICON;
79 - copy.addEventListener("click", () => {
80 - navigator.clipboard.writeText(command.textContent ?? "").then(
81 - () => {
82 - copy.innerHTML = CHECK_ICON;
83 - copy.setAttribute("aria-label", "Copied");
84 - },
85 - (copyError) => console.warn("Could not copy the triage command.", copyError),
86 - );
87 - });
88 - commandRow.append(copy);
296 + const command = element("code", { textContent: FALLBACK_TRIAGE_COMMAND });
297 + const copyCommand = element("button", {
298 + className: "boot-error-icon",
299 + type: "button",
300 + title: "Copy command",
301 + innerHTML: COPY_ICON,
302 + });
303 + copyCommand.setAttribute("aria-label", "Copy command");
304 + copyCommand.addEventListener("click", () =>
305 + copyText(
306 + command,
307 + () => {
308 + copyCommand.innerHTML = CHECK_ICON;
309 + copyCommand.title = "Copied";
310 + copyCommand.setAttribute("aria-label", "Copied");
311 + announce("Copied to clipboard.");
312 + },
313 + (hint) => {
314 + copyCommand.textContent = hint;
315 + copyCommand.title = hint;
316 + copyCommand.setAttribute("aria-label", hint);
317 + announce(COPY_BLOCKED);
318 + },
319 + ),
320 + );
321 + void resolveTriageCommand(bridge).then((value) => (command.textContent = value));
322 +
323 + let report = "(no error message)";
324 + try {
325 + report = buildErrorReport(error, environment);
326 + } catch (reportError) {
327 + console.warn("Could not describe the startup error.", reportError);
328 }
329 + const details = element("pre", { id: "boot-error-details", tabIndex: 0, textContent: report });
330 + const copyDetails = element("button", { type: "button", textContent: "Copy error details" });
331 + copyDetails.addEventListener("click", () =>
332 + copyText(
333 + details,
334 + () => {
335 + copyDetails.textContent = "Copied";
336 + announce("Copied to clipboard.");
337 + },
338 + (hint) => {
339 + copyDetails.textContent = hint;
340 + announce(COPY_BLOCKED);
341 + },
342 + ),
343 + );
344
91 - const triage = document.createElement("div");
92 - triage.id = "boot-error-triage";
93 - triage.append(hint, commandRow);
345 + const issue = new URL(ISSUE_URL);
346 + issue.searchParams.set("template", "bug_report.yml");
347 + issue.searchParams.set("title", "T3 Code failed to start");
348 + issue.searchParams.set("area", "apps/web");
349 + issue.searchParams.set("version", `${environment.version} (${environment.channel})`);
350 + issue.searchParams.set("environment", `${environment.surface}, ${environment.platform}`);
351 + const link = (href: string, textContent: string) =>
352 + element("a", { href, textContent, target: "_blank", rel: "noreferrer" });
353 + const nightly = environment.channel === "nightly";
354
95 - content.append(reload, triage);
96 - bootShell.replaceChildren(content);
355 + const more = element("details", { open: isRepeatFailure(Date.now()) }, [
356 + element("summary", { textContent: "More options if it keeps failing" }),
357 + ...(bridge
358 + ? [
359 + link(
360 + nightly ? `${DOWNLOAD_URL}?channel=nightly` : DOWNLOAD_URL,
361 + nightly
362 + ? "Download and reinstall the latest nightly build"
363 + : "Download and reinstall T3 Code",
364 + ),
365 + ]
366 + : []),
367 + element("div", {}, [
368 + element("p", {
369 + textContent:
370 + "Run this on the computer that runs T3 Code. Your agent can check the local logs and help you file a bug report.",
371 + }),
372 + element("div", { id: "boot-error-command" }, [command, copyCommand]),
373 + ]),
374 + element("div", {}, [
375 + details,
376 + element("p", {
377 + textContent: "Details may include local file paths and names. Check before sharing.",
378 + }),
379 + element("div", { id: "boot-error-report" }, [
380 + copyDetails,
381 + link(issue.href, "File a bug report on GitHub"),
382 + ]),
383 + ]),
384 + ]);
385
98 - void resolveTriageCommand(window.desktopBridge).then((value) => (command.textContent = value));
386 + bootShell.replaceChildren(
387 + element("div", { id: "boot-error" }, [
388 + message,
389 + element("div", { id: "boot-error-actions" }, [reload, update]),
390 + updateNote,
391 + more,
392 + status,
393 + ]),
394 + );
395 }