From 285cf5947b14acb9a66d26a669ce632633fd0749 Mon Sep 17 00:00:00 2001 From: Robert Soriano Date: Sun, 9 Aug 2026 10:33:03 -0700 Subject: [PATCH 1/6] fix(web): preserve desktop route during Clerk auth (#5770) --- .../src/components/clerk/authRedirect.test.ts | 19 +++++++++++++++---- apps/web/src/components/clerk/authRedirect.ts | 17 ++++++++++++----- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/apps/web/src/components/clerk/authRedirect.test.ts b/apps/web/src/components/clerk/authRedirect.test.ts index 4c4cd72d93..140474120c 100644 --- a/apps/web/src/components/clerk/authRedirect.test.ts +++ b/apps/web/src/components/clerk/authRedirect.test.ts @@ -8,11 +8,22 @@ describe("resolveClerkSignInProps", () => { expect(resolveClerkSignInProps(href, false)).toEqual({ forceRedirectUrl: href }); }); - it("omits the redirect override on packaged desktop", () => { - expect(resolveClerkSignInProps("t3code://app/#/settings/general", true)).toEqual({}); + it("removes a Clerk virtual pathname and callback params while preserving the desktop route", () => { + expect( + resolveClerkSignInProps( + "t3code://app/CLERK-ROUTER/VIRTUAL/sign-up?__clerk_status=complete#/settings/connections", + true, + ), + ).toEqual({ + forceRedirectUrl: "t3code://app/#/settings/connections", + signUpForceRedirectUrl: "t3code://app/#/settings/connections", + }); }); - it("omits the redirect override on development desktop", () => { - expect(resolveClerkSignInProps("t3code-dev://app/#/settings/general", true)).toEqual({}); + it("preserves a clean development desktop route", () => { + expect(resolveClerkSignInProps("t3code-dev://app/#/settings/general", true)).toEqual({ + forceRedirectUrl: "t3code-dev://app/#/settings/general", + signUpForceRedirectUrl: "t3code-dev://app/#/settings/general", + }); }); }); diff --git a/apps/web/src/components/clerk/authRedirect.ts b/apps/web/src/components/clerk/authRedirect.ts index 13331a2779..251c5ee365 100644 --- a/apps/web/src/components/clerk/authRedirect.ts +++ b/apps/web/src/components/clerk/authRedirect.ts @@ -1,12 +1,19 @@ export interface ClerkSignInProps { forceRedirectUrl?: string; + signUpForceRedirectUrl?: string; } -// Clerk's native-app allowlist only authorizes the bare renderer root -// (t3code://app/), which @clerk/electron's OAuth transport already supplies, -// so any page-derived redirect override gets the whole sign-in request -// rejected. On Electron, omit the override and let Clerk use its defaults. export function resolveClerkSignInProps(href: string, isElectron: boolean): ClerkSignInProps { - if (isElectron) return {}; + if (isElectron) { + // Electron routes through the hash, so reset any Clerk virtual pathname without losing the T3 page. + const redirectUrl = new URL(href); + redirectUrl.pathname = "/"; + redirectUrl.search = ""; + + return { + forceRedirectUrl: redirectUrl.toString(), + signUpForceRedirectUrl: redirectUrl.toString(), + }; + } return { forceRedirectUrl: href }; } From 02f4ce566711e7989e10c2b937c2655ef19188ff Mon Sep 17 00:00:00 2001 From: Utkarsh Patil <73941998+UtkarshUsername@users.noreply.github.com> Date: Sun, 9 Aug 2026 23:34:34 +0530 Subject: [PATCH 2/6] fix(web): match create theme and import theme buttons to the standard outline style (#5860) --- apps/web/src/components/settings/ThemeSettings.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/apps/web/src/components/settings/ThemeSettings.tsx b/apps/web/src/components/settings/ThemeSettings.tsx index 4eb7904508..c289b1c160 100644 --- a/apps/web/src/components/settings/ThemeSettings.tsx +++ b/apps/web/src/components/settings/ThemeSettings.tsx @@ -555,9 +555,8 @@ export function ThemeLibrary({

Themes

- From deb901d6381e0c86ef326946c8fb45ee323db708 Mon Sep 17 00:00:00 2001 From: Matt Urenovich Date: Sun, 9 Aug 2026 17:10:49 -0400 Subject: [PATCH 3/6] fix(server): favicon resolution no longer pins the event loop (#5538) --- .../project/ProjectFaviconResolver.test.ts | 103 ++++++++++++++++++ .../src/project/ProjectFaviconResolver.ts | 16 ++- 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/apps/server/src/project/ProjectFaviconResolver.test.ts b/apps/server/src/project/ProjectFaviconResolver.test.ts index 34ad74da62..7448ced247 100644 --- a/apps/server/src/project/ProjectFaviconResolver.test.ts +++ b/apps/server/src/project/ProjectFaviconResolver.test.ts @@ -160,6 +160,109 @@ it.layer(TestLayer)("ProjectFaviconResolverLive", (it) => { }), ); + it.effect("resolves icon hrefs from object-literal route metadata", () => + Effect.gen(function* () { + const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver; + const cwd = yield* makeTempDir; + yield* writeTextFile( + cwd, + "src/routes/__root.tsx", + `export const Route = createRootRoute({ + head: () => ({ + links: [ + { rel: "stylesheet", href: "/app.css" }, + { rel: "icon", href: "/brand/logo.svg" }, + ], + }), +});`, + ); + yield* writeTextFile(cwd, "public/brand/logo.svg", "brand"); + + const resolved = yield* resolver.resolvePath(cwd); + + expect(resolved).not.toBeNull(); + expect(resolved).toContain("public/brand/logo.svg"); + }), + ); + + it.effect("resolves object-literal icon metadata when href precedes rel", () => + Effect.gen(function* () { + const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver; + const cwd = yield* makeTempDir; + yield* writeTextFile( + cwd, + "src/root.tsx", + `const links = [{ href: "/brand/logo.svg", rel: "shortcut icon" }];`, + ); + yield* writeTextFile(cwd, "public/brand/logo.svg", "brand"); + + const resolved = yield* resolver.resolvePath(cwd); + + expect(resolved).not.toBeNull(); + expect(resolved).toContain("public/brand/logo.svg"); + }), + ); + + it.effect("resolves object-literal icon metadata alongside nested objects", () => + Effect.gen(function* () { + const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver; + const cwd = yield* makeTempDir; + yield* writeTextFile( + cwd, + "src/root.tsx", + `const links = [{ attributes: {}, rel: "icon", href: "/brand/logo.svg" }];`, + ); + yield* writeTextFile(cwd, "public/brand/logo.svg", "brand"); + + const resolved = yield* resolver.resolvePath(cwd); + + expect(resolved).not.toBeNull(); + expect(resolved).toContain("public/brand/logo.svg"); + }), + ); + + it.effect("skips icon metadata without an href and keeps scanning", () => + Effect.gen(function* () { + const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver; + const cwd = yield* makeTempDir; + yield* writeTextFile( + cwd, + "src/root.tsx", + `const links = [{ rel: "icon" }, { rel: "icon", href: "/brand/logo.svg" }];`, + ); + yield* writeTextFile(cwd, "public/brand/logo.svg", "brand"); + + const resolved = yield* resolver.resolvePath(cwd); + + expect(resolved).not.toBeNull(); + expect(resolved).toContain("public/brand/logo.svg"); + }), + ); + + // A large icon source with no icon metadata used to pin the server's event loop for + // minutes: the object pattern was unanchored, so it restarted at every offset and + // rescanned forward from each one. Anchoring keeps this proportional to file size. + it.effect("scans large icon sources without an icon in reasonable time", () => + Effect.gen(function* () { + const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver; + const cwd = yield* makeTempDir; + // Mirrors a generated single-file build: large, brace-sparse, and no icon metadata. + const filler = `

${"pokopia companion guide ".repeat(24)}

\n`; + yield* writeTextFile( + cwd, + "index.html", + `guide\n${filler.repeat(1200)}`, + ); + + const startedAt = performance.now(); + const resolved = yield* resolver.resolvePath(cwd); + const elapsedMs = performance.now() - startedAt; + + expect(resolved).toBeNull(); + expect(elapsedMs).toBeLessThan(5_000); + }), + ); + it.effect("returns null when no icon is present", () => Effect.gen(function* () { const resolver = yield* ProjectFaviconResolver.ProjectFaviconResolver; diff --git a/apps/server/src/project/ProjectFaviconResolver.ts b/apps/server/src/project/ProjectFaviconResolver.ts index 0b447bd4f3..458954daed 100644 --- a/apps/server/src/project/ProjectFaviconResolver.ts +++ b/apps/server/src/project/ProjectFaviconResolver.ts @@ -55,10 +55,13 @@ const ICON_SOURCE_FILES = [ ] as const; // Matches tags or object-like icon metadata where rel/href can appear in any order. +// The tag pattern is anchored on `]*\brel=["'](?:icon|shortcut icon)["'])(?=[^>]*\bhref=["']([^"'?]+))[^>]*>/i; -const LINK_ICON_OBJ_RE = - /(?=[^}]*\brel\s*:\s*["'](?:icon|shortcut icon)["'])(?=[^}]*\bhref\s*:\s*["']([^"'?]+))[^}]*/i; +const ICON_REL_RE = /\brel\s*:\s*["'](?:icon|shortcut icon)["']/i; +const ICON_HREF_RE = /\bhref\s*:\s*["']([^"'?]+)/i; export class ProjectFaviconResolutionError extends Schema.TaggedErrorClass()( "ProjectFaviconResolutionError", @@ -99,8 +102,13 @@ export class ProjectFaviconResolver extends Context.Service< function extractIconHref(source: string): string | null { const htmlMatch = source.match(LINK_ICON_HTML_RE); if (htmlMatch?.[1]) return htmlMatch[1]; - const objMatch = source.match(LINK_ICON_OBJ_RE); - if (objMatch?.[1]) return objMatch[1]; + // Icon metadata counts when `rel` and `href` share a brace-free run, so a run holding `rel` + // but no href falls through to the next one rather than ending the search. + for (const run of source.split("}")) { + if (!ICON_REL_RE.test(run)) continue; + const hrefMatch = run.match(ICON_HREF_RE); + if (hrefMatch?.[1]) return hrefMatch[1]; + } return null; } From 062b4618c229f3e2f13e44efd8dab8c71ad33dae Mon Sep 17 00:00:00 2001 From: Tyler Date: Sun, 9 Aug 2026 16:16:12 -0500 Subject: [PATCH 4/6] fix(shared): bound the file-link label so bracket runs stop rescanning (#5782) Co-authored-by: tsouth89 Co-authored-by: Claude Opus 5 (1M context) --- .../shared/src/composerInlineTokens.test.ts | 21 +++++++++++++++++++ packages/shared/src/composerInlineTokens.ts | 16 +++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/shared/src/composerInlineTokens.test.ts b/packages/shared/src/composerInlineTokens.test.ts index 5a7c14f172..81fd6add20 100644 --- a/packages/shared/src/composerInlineTokens.test.ts +++ b/packages/shared/src/composerInlineTokens.test.ts @@ -129,4 +129,25 @@ describe("collectComposerInlineTokens", () => { }, ]); }); + + it("still collects a file link whose label is at the length cap", () => { + const label = `${"a".repeat(508)}.tsx`; + const tokens = collectComposerInlineTokens(`see [${label}](src/${label}) ok`); + + expect(tokens).toHaveLength(1); + expect(tokens[0]?.value).toBe(`src/${label}`); + }); + + it("leaves a file link past the label cap as plain text", () => { + const label = `${"a".repeat(509)}.tsx`; + expect(collectComposerInlineTokens(`see [${label}](src/${label}) ok`)).toEqual([]); + }); + + it("stays fast on unterminated bracket runs", () => { + // Unbounded, the label body rescanned the rest of the text from every + // whitespace: this input took seconds. + const started = performance.now(); + expect(collectComposerInlineTokens(" [[".repeat(40_000))).toEqual([]); + expect(performance.now() - started).toBeLessThan(1_000); + }); }); diff --git a/packages/shared/src/composerInlineTokens.ts b/packages/shared/src/composerInlineTokens.ts index dda548059d..11a5accf37 100644 --- a/packages/shared/src/composerInlineTokens.ts +++ b/packages/shared/src/composerInlineTokens.ts @@ -20,7 +20,21 @@ export interface CollectComposerInlineTokensOptions { const SKILL_TOKEN_REGEX = /(^|\s)\$([a-zA-Z][a-zA-Z0-9:_-]*)(?=\s)/g; const MENTION_TOKEN_REGEX = /(^|\s)@(?:"((?:\\.|[^"\\])*)"|([^\s@"]+))(?=\s)/g; -const FILE_LINK_TOKEN_REGEX = /(^|\s)\[((?:\\.|[^\]\\])*)\]\(([^)\s]+)\)(?=\s)/g; +/** + * The label body is bounded rather than `*`. Unbounded, every whitespace in + * the composer is a candidate start: the engine scans the rest of the text for + * a closing `]`, fails, and rescans from the next whitespace — quadratic on + * input like " [[[[[…". A cap makes each attempt constant-bounded. + * + * Only a basename ever survives the `label !== basename` check below, so this + * cannot reject a link a user could meaningfully write; the longest filename + * any common filesystem allows is 255. + */ +const MAX_FILE_LINK_LABEL_LENGTH = 512; +const FILE_LINK_TOKEN_REGEX = new RegExp( + `(^|\\s)\\[((?:\\\\.|[^\\]\\\\]){0,${MAX_FILE_LINK_LABEL_LENGTH}})\\]\\(([^)\\s]+)\\)(?=\\s)`, + "g", +); const URI_SCHEME_REGEX = /^[A-Za-z][A-Za-z0-9+.-]*:/; const WINDOWS_DRIVE_PATH_REGEX = /^[A-Za-z]:[\\/]/; // Autocomplete emits canonical file links, so ambiguous bare @scope/package text stays a package. From 659986ce384d29123269820ccb8340ab4d824cdd Mon Sep 17 00:00:00 2001 From: nathangerday <44236114+nathangerday@users.noreply.github.com> Date: Sun, 9 Aug 2026 23:22:52 +0200 Subject: [PATCH 5/6] fix(web): thread title button no longer eats the drag area (#5857) --- apps/web/src/components/chat/ChatHeader.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/components/chat/ChatHeader.tsx b/apps/web/src/components/chat/ChatHeader.tsx index 39fe6daceb..c5307ee748 100644 --- a/apps/web/src/components/chat/ChatHeader.tsx +++ b/apps/web/src/components/chat/ChatHeader.tsx @@ -266,7 +266,7 @@ export const ChatHeader = memo(function ChatHeader({ aria-label={`Thread actions for ${activeThreadTitle}`} aria-haspopup="menu" onClick={openMenuFromTitle} - className="group/thread-title inline-flex min-w-0 flex-1 cursor-pointer items-center gap-1 rounded-sm text-left focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring" + className="group/thread-title inline-flex min-w-0 cursor-pointer items-center gap-1 rounded-sm text-left focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring" /> } > From bd18d8d6d1feb23dd05dc357e34e353547a51d40 Mon Sep 17 00:00:00 2001 From: "t3-code[bot]" <269035359+t3-code[bot]@users.noreply.github.com> Date: Sun, 9 Aug 2026 23:26:26 +0200 Subject: [PATCH 6/6] fix(web): unify usage page chrome (#5823) --- apps/web/src/components/usage/UsagePage.tsx | 552 ++++++++++---------- 1 file changed, 279 insertions(+), 273 deletions(-) diff --git a/apps/web/src/components/usage/UsagePage.tsx b/apps/web/src/components/usage/UsagePage.tsx index b5b762aea7..2101ce0694 100644 --- a/apps/web/src/components/usage/UsagePage.tsx +++ b/apps/web/src/components/usage/UsagePage.tsx @@ -1,8 +1,8 @@ import type { UsageProviderKind } from "@t3tools/contracts"; -import { useCanGoBack, useNavigate, useRouter } from "@tanstack/react-router"; -import { ArrowLeftIcon, CheckIcon, RefreshCwIcon, XIcon } from "lucide-react"; +import { CheckIcon, RefreshCwIcon, XIcon } from "lucide-react"; import { useMemo, useState } from "react"; +import { isElectron } from "../../env"; import { cn } from "../../lib/utils"; import { useUsage, type EnvironmentUsageStatus } from "../../state/usage"; import { @@ -15,6 +15,8 @@ import { makeWindow, } from "@t3tools/shared/usageFormat"; import { ScrollArea } from "../ui/scroll-area"; +import { SidebarInset } from "../ui/sidebar"; +import { COLLAPSED_SIDEBAR_TITLEBAR_INSET_CLASS } from "../../workspaceTitlebar"; import { UsageChartLegend, UsageProviderChart, type UsageChartMetric } from "./UsageProviderChart"; import { PROVIDER_COLOR, PROVIDER_LABEL, PROVIDER_MARK, PROVIDER_ORDER } from "./usageProviders"; @@ -28,9 +30,6 @@ export function UsagePage() { const [windowDays, setWindowDays] = useState(30); const [metric, setMetric] = useState("cost"); const [breakdown, setBreakdown] = useState<"model" | "day">("model"); - const canGoBack = useCanGoBack(); - const navigate = useNavigate(); - const router = useRouter(); // Recomputed only when the window length changes, so a re-render does not // shift the range and refetch every environment. @@ -63,143 +62,207 @@ export function UsagePage() { const cachedShare = observedInput === 0 ? 0 : merged.cachedInputTokens / observedInput; return ( - -
-
-
- -
-

Usage

+ +
+ {!isElectron && ( +
+

Usage

+
+ )} + + {isElectron && ( +
+

Usage

+
+ )} + + +
+

{formatDayShort(window.sinceDay)} to {formatDayShort(window.untilDay)}

-
-
-
-
- {WINDOW_OPTIONS.map((option) => ( - - ))} -
- -
-
- - {settling ? ( - <> - {environments.length > 1 ? : null} - - - ) : ( - <> - - - {/* Cost first: the financial answer, then the provider split. */} -
- {/* The summary follows the chart toggle, so the headline and the - series are always reading the same units. */} -
-
- - {metric === "cost" ? "Raw token cost" : "Processed tokens"} - - - {metric === "cost" - ? `${formatUsd(merged.costUsd)}*` - : formatTokens(merged.totalTokens)} - - - {metric === "cost" - ? "* if billed at full API rate" - : `Input, cache reads and output across ${formatCount(merged.sessions)} sessions.`} - +
+
+ {WINDOW_OPTIONS.map((option) => ( + + ))}
+ +
+
- {orderedProviders.map((provider) => { - const share = metric === "cost" ? provider.costShare : provider.tokenShare; - return ( -
-
- - - {PROVIDER_LABEL[provider.provider]} - - - {metric === "cost" - ? formatUsd(provider.costUsd) - : formatTokens(provider.totalTokens)} - -
-
-
-
+ {settling ? ( + <> + {environments.length > 1 ? : null} + + + ) : ( + <> + + + {/* Cost first: the financial answer, then the provider split. */} +
+ {/* The summary follows the chart toggle, so the headline and the + series are always reading the same units. */} +
+
+ + {metric === "cost" ? "Raw token cost" : "Processed tokens"} + + + {metric === "cost" + ? `${formatUsd(merged.costUsd)}*` + : formatTokens(merged.totalTokens)} + {metric === "cost" - ? `${formatPercent(share)} of cost · ${formatTokens(provider.totalTokens)} tokens` - : `${formatPercent(share)} of tokens · ${formatUsd(provider.costUsd)}`} + ? "* if billed at full API rate" + : `Input, cache reads and output across ${formatCount(merged.sessions)} sessions.`}
- ); - })} -
-
-
-

- Daily {metric === "tokens" ? "processed tokens" : "cost"} -

-
+ {orderedProviders.map((provider) => { + const share = metric === "cost" ? provider.costShare : provider.tokenShare; + return ( +
+
+ + + {PROVIDER_LABEL[provider.provider]} + + + {metric === "cost" + ? formatUsd(provider.costUsd) + : formatTokens(provider.totalTokens)} + +
+
+
+
+ + {metric === "cost" + ? `${formatPercent(share)} of cost · ${formatTokens(provider.totalTokens)} tokens` + : `${formatPercent(share)} of tokens · ${formatUsd(provider.costUsd)}`} + +
+ ); + })} +
+ +
+
+

+ Daily {metric === "tokens" ? "processed tokens" : "cost"} +

+
+
+ {(["cost", "tokens"] as const).map((option) => ( + + ))} +
+ +
+
+ +
+
+ +
+ + + + + 0 + ? `${(merged.costQuality.cacheSavingsUsd / merged.costUsd).toFixed(1)}x the raw token cost` + : "vs full input rates" + } + /> +
+ +
+
+

Breakdown

- {(["cost", "tokens"] as const).map((option) => ( + {(["model", "day"] as const).map((option) => ( ))}
-
-
- -
-
-
- - - - - 0 - ? `${(merged.costQuality.cacheSavingsUsd / merged.costUsd).toFixed(1)}x the raw token cost` - : "vs full input rates" - } - /> -
- -
-
-

Breakdown

-
- {(["model", "day"] as const).map((option) => ( - - ))} -
-
- - {breakdown === "model" ? ( - - - - - - - - - - - {merged.models.length === 0 ? ( - - - - ) : ( - merged.models.map((model) => ( - - - - - + {breakdown === "model" ? ( +
ModelCostShareTokens
- No activity in this window. -
- - - {model.model} - - - {formatUsd(model.costUsd)} - - {formatPercent(model.costShare)} - - {formatTokens(model.totalTokens)} -
+ + + + + + - )) - )} - -
ModelCostShareTokens
- ) : ( - - - - - {PROVIDER_ORDER.map((provider) => ( - - ))} - - - - - - {recentDays.length === 0 ? ( - - - - ) : ( - recentDays.map((day) => ( - - - {PROVIDER_ORDER.map((provider) => ( - + {merged.models.length === 0 ? ( + + + + ) : ( + merged.models.map((model) => ( + + + + + + + )) + )} + +
Day - {PROVIDER_LABEL[provider]} - TotalTokens
- No activity in this window. -
{formatDayShort(day.day)} - {formatUsd(day.byProvider.get(provider)?.costUsd ?? 0)} + +
+ No activity in this window.
+ + + {model.model} + + + {formatUsd(model.costUsd)} + + {formatPercent(model.costShare)} + + {formatTokens(model.totalTokens)} +
+ ) : ( + + + + + {PROVIDER_ORDER.map((provider) => ( + ))} - - + + - )) - )} - -
Day + {PROVIDER_LABEL[provider]} + - {formatUsd(day.costUsd)} - - {formatTokens(day.totalTokens)} - TotalTokens
- )} -
- - )} + + + {recentDays.length === 0 ? ( + + + No activity in this window. + + + ) : ( + recentDays.map((day) => ( + + {formatDayShort(day.day)} + {PROVIDER_ORDER.map((provider) => ( + + {formatUsd(day.byProvider.get(provider)?.costUsd ?? 0)} + + ))} + + {formatUsd(day.costUsd)} + + + {formatTokens(day.totalTokens)} + + + )) + )} + + + )} + + + )} +
+
- + ); }