{
+ if (loadedVscodeIcons !== null) {
+ return Promise.resolve(loadedVscodeIcons);
+ }
+ if (pendingVscodeIcons === null) {
+ pendingVscodeIcons = import("../vscode-icons")
+ .then((mod) => {
+ loadedVscodeIcons = mod;
+ pendingVscodeIcons = null;
+ for (const listener of listeners) {
+ listener();
+ }
+ return mod;
+ })
+ .catch((error: unknown) => {
+ pendingVscodeIcons = null;
+ scheduleOnlineRetry();
+ throw error;
+ });
+ }
+ return pendingVscodeIcons;
+}
+
+/**
+ * Resolves a VS Code file/folder icon URL on demand so the 329 KB manifest
+ * stays out of the initial chat bundle. Returns null while the manifest chunk
+ * loads; callers render the generic file/folder icon until it resolves.
+ */
+export function useVscodeIconUrl(
+ pathValue: string,
+ kind: "file" | "directory",
+ theme: "light" | "dark",
+): string | null {
+ const mod = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
+
+ useEffect(() => {
+ if (mod !== null) {
+ return;
+ }
+ void loadVscodeIcons().catch(() => {
+ // Keep generic file/folder fallback if the icon manifest chunk fails to load.
+ });
+ }, [mod]);
+
+ return mod ? mod.getVscodeIconUrlForEntry(pathValue, kind, theme) : null;
+}
diff --git a/apps/web/src/lib/vscodeIconPath.ts b/apps/web/src/lib/vscodeIconPath.ts
new file mode 100644
index 000000000..037aea074
--- /dev/null
+++ b/apps/web/src/lib/vscodeIconPath.ts
@@ -0,0 +1,16 @@
+export function basenameOfPath(pathValue: string): string {
+ const slashIndex = pathValue.lastIndexOf("/");
+ if (slashIndex === -1) return pathValue;
+ return pathValue.slice(slashIndex + 1);
+}
+
+export function inferEntryKindFromPath(pathValue: string): "file" | "directory" {
+ const base = basenameOfPath(pathValue);
+ if (base.startsWith(".") && !base.slice(1).includes(".")) {
+ return "directory";
+ }
+ if (base.includes(".")) {
+ return "file";
+ }
+ return "directory";
+}
diff --git a/apps/web/src/routes/_chat.$environmentId.$threadId.tsx b/apps/web/src/routes/_chat.$environmentId.$threadId.tsx
index 164041eb2..dece3d03f 100644
--- a/apps/web/src/routes/_chat.$environmentId.$threadId.tsx
+++ b/apps/web/src/routes/_chat.$environmentId.$threadId.tsx
@@ -25,8 +25,6 @@ import {
} from "../environments/runtime";
import { deriveHostedStaticThreadRouteState } from "./-chatIndexState";
import { type DiffRouteSearch, parseDiffRouteSearch } from "../diffRouteSearch";
-import { AgentsPanel } from "../components/chat/AgentsPanel";
-import { ProjectBoardPanel } from "../components/chat/ProjectBoardPanel";
import {
ThreadPullRequestLinkContext,
type ThreadPullRequestLinks,
@@ -128,10 +126,7 @@ import {
type MediaChatTarget,
turnSummariesRevision,
} from "../components/media/mediaPanel.logic";
-import {
- SourceControlPanel,
- type SourceControlProjectTarget,
-} from "../components/source-control/SourceControlPanel";
+import type { SourceControlProjectTarget } from "../components/source-control/SourceControlPanel";
import { useCommandHandlers } from "../commands/commandHandlers";
import { usePanelTabCommands } from "../commands/panelTabCommands";
@@ -178,6 +173,21 @@ const DeviceFloatingWindow = lazy(() =>
default: module.DeviceFloatingWindow,
})),
);
+const AgentsPanel = lazy(() =>
+ import("../components/chat/AgentsPanel").then((module) => ({
+ default: module.AgentsPanel,
+ })),
+);
+const ProjectBoardPanel = lazy(() =>
+ import("../components/chat/ProjectBoardPanel").then((module) => ({
+ default: module.ProjectBoardPanel,
+ })),
+);
+const SourceControlPanel = lazy(() =>
+ import("../components/source-control/SourceControlPanel").then((module) => ({
+ default: module.SourceControlPanel,
+ })),
+);
const FileViewerOverlay = lazy(() => import("../components/file-viewer/FileViewerOverlay"));
/** Mount the heavy viewer chunk only after the first open request. */
@@ -1131,22 +1141,26 @@ function ChatThreadRouteView() {
<>
{openTabs.includes("agents") ? (
-
+
Loading agents…}
+ >
+
+
) : null}
{openTabs.includes("media") && serverThread ? (
@@ -1167,12 +1181,16 @@ function ChatThreadRouteView() {
) : null}
{openTabs.includes("threads") && serverThread ? (
-
+
Loading threads…}
+ >
+
+
) : null}
{openTabs.includes("device") && serverThread && currentThreadKey !== null ? (
@@ -1194,24 +1212,28 @@ function ChatThreadRouteView() {
- {
- activateDiffTab({
- diffMode: "workingTree",
- ...(filePath ? { diffFilePath: filePath } : {}),
- });
- }}
- {...(availableTabs.includes("pullRequest")
- ? { onOpenPullRequest: () => selectTab("pullRequest") }
- : {})}
- {...(!serverThread && draftThread
- ? { onActiveBranchChange: handleDraftSourceControlBranchChange }
- : {})}
- />
+ Loading source…}
+ >
+ {
+ activateDiffTab({
+ diffMode: "workingTree",
+ ...(filePath ? { diffFilePath: filePath } : {}),
+ });
+ }}
+ {...(availableTabs.includes("pullRequest")
+ ? { onOpenPullRequest: () => selectTab("pullRequest") }
+ : {})}
+ {...(!serverThread && draftThread
+ ? { onActiveBranchChange: handleDraftSourceControlBranchChange }
+ : {})}
+ />
+
) : null}
{openTabs.includes("pullRequest") ? (
diff --git a/apps/web/src/routes/_chat.draft.$draftId.tsx b/apps/web/src/routes/_chat.draft.$draftId.tsx
index 765c8e7ef..3fea2effb 100644
--- a/apps/web/src/routes/_chat.draft.$draftId.tsx
+++ b/apps/web/src/routes/_chat.draft.$draftId.tsx
@@ -41,10 +41,7 @@ import {
} from "../rightPanelLayout";
import { SidebarInset } from "../components/ui/sidebar";
import { RightPanelSheet } from "../components/RightPanelSheet";
-import {
- SourceControlPanel,
- type SourceControlProjectTarget,
-} from "../components/source-control/SourceControlPanel";
+import type { SourceControlProjectTarget } from "../components/source-control/SourceControlPanel";
import {
createProjectSelectorByRef,
createThreadSelectorAcrossEnvironments,
@@ -59,6 +56,11 @@ import {
import { usePanelTabCommands } from "../commands/panelTabCommands";
const FileViewerOverlay = lazy(() => import("../components/file-viewer/FileViewerOverlay"));
+const SourceControlPanel = lazy(() =>
+ import("../components/source-control/SourceControlPanel").then((module) => ({
+ default: module.SourceControlPanel,
+ })),
+);
/** A draft has no turns at all, which is a real "none" rather than an unknown. */
const EMPTY_TURN_DIFF_SUMMARIES = [] as const;
@@ -353,19 +355,23 @@ function DraftChatThreadRouteView() {
- {
- openDiffOnThreadRoute({
- diffMode: "workingTree",
- ...(filePath ? { diffFilePath: filePath } : {}),
- });
- }}
- onPrefetchDiff={prefetchWorkingTreeDiff}
- />
+ Loading source…}
+ >
+ {
+ openDiffOnThreadRoute({
+ diffMode: "workingTree",
+ ...(filePath ? { diffFilePath: filePath } : {}),
+ });
+ }}
+ onPrefetchDiff={prefetchWorkingTreeDiff}
+ />
+
) : null}
diff --git a/apps/web/src/theme/attachPierreCodeThemes.ts b/apps/web/src/theme/attachPierreCodeThemes.ts
new file mode 100644
index 000000000..64b6a3891
--- /dev/null
+++ b/apps/web/src/theme/attachPierreCodeThemes.ts
@@ -0,0 +1,5 @@
+import { registerCustomTheme, resolveThemes } from "@pierre/diffs";
+
+import { attachPierreCodeThemeRegistry } from "./codeTheme";
+
+attachPierreCodeThemeRegistry(registerCustomTheme, resolveThemes);
diff --git a/apps/web/src/theme/codeTheme.ts b/apps/web/src/theme/codeTheme.ts
index ca545a3b5..384804999 100644
--- a/apps/web/src/theme/codeTheme.ts
+++ b/apps/web/src/theme/codeTheme.ts
@@ -11,13 +11,13 @@
* The editor's selected text and cursor line take their backgrounds from
* the theme too (withEditorColors), so those are set to match the fit.
*/
-import { type DiffsTheme, registerCustomTheme, resolveThemes } from "@pierre/diffs";
+import type { DiffsTheme, registerCustomTheme, resolveThemes } from "@pierre/diffs";
import type { ThemeBase, ThemeCodePalette } from "@threadlines/contracts";
import type { Rgba } from "@threadlines/shared/themeColor";
import type { ThemeTokens } from "@threadlines/shared/themeTokens";
import { useMemo } from "react";
-import { type DiffThemeName, resolveDiffThemeName } from "../lib/diffRendering";
+import { type DiffThemeName, resolveDiffThemeName } from "../lib/diffThemeName";
import { useActiveTheme } from "./themeStore";
import type { ActiveTheme } from "./themeTypes";
@@ -125,36 +125,42 @@ export function customCodeThemeName(hash: string): DiffThemeName {
const builtinCodeThemeName = (base: ThemeBase): DiffThemeName => `tl-code-${base}`;
-const registered = new Set();
+interface PendingCodeThemeSpec {
+ readonly name: DiffThemeName;
+ readonly themeBase: ThemeBase;
+ readonly palette: ThemeCodePalette | null;
+ readonly tokens: ThemeTokens | null;
+}
-/**
- * Registers a code theme under its name, once (Pierre refuses a second
- * registration): the base's Pierre theme, with `palette` over it when the
- * theme has one, fitted to the backgrounds of `tokens` (a built-in's when
- * null).
- */
-function ensureRegistered(
- name: DiffThemeName,
- themeBase: ThemeBase,
- palette: ThemeCodePalette | null,
- tokens: ThemeTokens | null,
+interface PierreCodeThemeRegistry {
+ readonly registerCustomTheme: typeof registerCustomTheme;
+ readonly resolveThemes: typeof resolveThemes;
+}
+
+const pendingSpecs = new Map();
+const registeredWithPierre = new Set();
+let pierreRegistry: PierreCodeThemeRegistry | null = null;
+
+function registerSpecWithPierre(
+ registry: PierreCodeThemeRegistry,
+ spec: PendingCodeThemeSpec,
): void {
- if (registered.has(name)) return;
- registered.add(name);
- registerCustomTheme(
- name,
+ if (registeredWithPierre.has(spec.name)) return;
+ registeredWithPierre.add(spec.name);
+ registry.registerCustomTheme(
+ spec.name,
async () => {
const [[baseTheme], codeColors, builtinTokens] = await Promise.all([
- resolveThemes([resolveDiffThemeName(themeBase)], "shiki-js"),
+ registry.resolveThemes([resolveDiffThemeName(spec.themeBase)], "shiki-js"),
import("@threadlines/shared/themeCodeColors"),
- tokens ? null : import("@threadlines/shared/themeBuiltinTokens"),
+ spec.tokens ? null : import("@threadlines/shared/themeBuiltinTokens"),
]);
- if (!baseTheme?.textmate) throw new Error(`No base theme for ${name}`);
- const withPalette = palette
- ? buildCodeTheme(name, palette, baseTheme.textmate)
- : { ...baseTheme.textmate, name };
- const surfaceTokens = tokens ?? builtinTokens?.BUILTIN_THEME_TOKENS[themeBase];
- if (!surfaceTokens) throw new Error(`No tokens for ${name}`);
+ if (!baseTheme?.textmate) throw new Error(`No base theme for ${spec.name}`);
+ const withPalette = spec.palette
+ ? buildCodeTheme(spec.name, spec.palette, baseTheme.textmate)
+ : { ...baseTheme.textmate, name: spec.name };
+ const surfaceTokens = spec.tokens ?? builtinTokens?.BUILTIN_THEME_TOKENS[spec.themeBase];
+ if (!surfaceTokens) throw new Error(`No tokens for ${spec.name}`);
const surfaces = codeColors.codeSurfaces(surfaceTokens);
const fitted = fitCodeTheme(withPalette, surfaces, {
color: codeColors.fitCodeColor,
@@ -167,6 +173,43 @@ function ensureRegistered(
);
}
+/**
+ * Connects Pierre's theme registry once `@pierre/diffs` actually loads,
+ * registering any code themes requested before that point synchronously so
+ * chat routes do not pull `@pierre/diffs` into their initial chunk.
+ */
+export function attachPierreCodeThemeRegistry(
+ registerFn: typeof registerCustomTheme,
+ resolveFn: typeof resolveThemes,
+): void {
+ if (pierreRegistry === null) {
+ pierreRegistry = { registerCustomTheme: registerFn, resolveThemes: resolveFn };
+ }
+ for (const spec of pendingSpecs.values()) {
+ registerSpecWithPierre(pierreRegistry, spec);
+ }
+}
+
+/**
+ * Registers a code theme under its name, once (Pierre refuses a second
+ * registration): the base's Pierre theme, with `palette` over it when the
+ * theme has one, fitted to the backgrounds of `tokens` (a built-in's when
+ * null).
+ */
+function ensureRegistered(
+ name: DiffThemeName,
+ themeBase: ThemeBase,
+ palette: ThemeCodePalette | null,
+ tokens: ThemeTokens | null,
+): void {
+ if (!pendingSpecs.has(name)) {
+ pendingSpecs.set(name, { name, themeBase, palette, tokens });
+ }
+ if (pierreRegistry !== null) {
+ registerSpecWithPierre(pierreRegistry, pendingSpecs.get(name)!);
+ }
+}
+
/** The code theme a theme highlights with, registered and ready to resolve. */
export function codeThemeNameFor(theme: ActiveTheme): DiffThemeName {
// A custom theme once its content is here (its palette and tokens settle the name's colors).
diff --git a/apps/web/src/vscode-icons.ts b/apps/web/src/vscode-icons.ts
index 849f81124..2c921b5cd 100644
--- a/apps/web/src/vscode-icons.ts
+++ b/apps/web/src/vscode-icons.ts
@@ -1,6 +1,9 @@
+import { basenameOfPath, inferEntryKindFromPath } from "./lib/vscodeIconPath";
import vscodeIconsManifest from "./vscode-icons-manifest.json";
import languageAssociationsData from "./vscode-icons-language-associations.json";
+export { basenameOfPath, inferEntryKindFromPath };
+
const VSCODE_ICONS_VERSION = "v12.17.0";
const VSCODE_ICONS_BASE_URL = `https://cdn.jsdelivr.net/gh/vscode-icons/vscode-icons@${VSCODE_ICONS_VERSION}/icons`;
@@ -69,23 +72,6 @@ function toLowercaseLookup(source: Record): Record();
if (fileName.includes(".")) {