Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

perf(ui): take 212 KB of never-used code off the startup path

Harald4bdf3de896fa
diff --git a/jarvis/ui/web/frontend/src/components/deck/DeckActivityCards.tsx b/jarvis/ui/web/frontend/src/components/deck/DeckActivityCards.tsx
index 3c9be59d89..680c64b7ad 100644
--- a/jarvis/ui/web/frontend/src/components/deck/DeckActivityCards.tsx
+++ b/jarvis/ui/web/frontend/src/components/deck/DeckActivityCards.tsx
@@ -10,7 +10,18 @@ import { useEventStore } from "@/store/events";
import { useDeckStore } from "@/store/deck";
import { useRuns } from "@/hooks/useRuns";
import { useOutputsList, type OutputSummary } from "@/hooks/useOutputs";
-import { fetchIdeState, fetchTerminalActivity, type IdeState, type ActivityResponse } from "@/lib/agenticIdeApi";
+// Type-only, plus two loaders that pull the module in when the card first
+// asks. The agentic-IDE API module is the workspace's whole client surface;
+// importing two functions from it statically linked all of it into the STARTUP
+// chunk for a card that fetches over the network anyway. The dynamic import
+// costs one microtask before a request that takes milliseconds.
+import type { IdeState, ActivityResponse } from "@/lib/agenticIdeApi";
+
+const fetchIdeState = async (): Promise<IdeState> =>
+ (await import("@/lib/agenticIdeApi")).fetchIdeState();
+
+const fetchTerminalActivity = async (id: string | undefined): Promise<ActivityResponse> =>
+ (await import("@/lib/agenticIdeApi")).fetchTerminalActivity(id);
import { useCommandActivityStore } from "@/store/commandActivity";
import type { RunListItem } from "@/components/runs/types";
import { DeckCard } from "@/components/deck/DeckCard";
diff --git a/jarvis/ui/web/frontend/src/components/deck/DeckWiki.tsx b/jarvis/ui/web/frontend/src/components/deck/DeckWiki.tsx
index f8c32b261e..fd8285590e 100644
--- a/jarvis/ui/web/frontend/src/components/deck/DeckWiki.tsx
+++ b/jarvis/ui/web/frontend/src/components/deck/DeckWiki.tsx
@@ -6,10 +6,17 @@ import type { NodeObject } from "react-force-graph-3d";
import { useEventStore } from "@/store/events";
import { useDeckStore } from "@/store/deck";
import { fetchWikiTree } from "@/lib/wikiApi";
-import { toGraphData, type RenderEdge, type RenderNode, type WikiGraphPayload } from "@/lib/wikiGraph";
+import {
+ edgeDetails,
+ escapeTooltipText,
+ nodeDetails,
+ toGraphData,
+ type RenderEdge,
+ type RenderNode,
+ type WikiGraphPayload,
+} from "@/lib/wikiGraph";
import { detectWebgl } from "@/lib/graphDimension";
import { useDeckSlotPowered } from "@/components/deck/DeckReveal";
-import { edgeDetails, escapeTooltipText, nodeDetails } from "@/components/wiki/WikiGraph";
import { DeckCard, DeckIconButton } from "@/components/deck/DeckCard";
import { HudLamp, useElementSize } from "@/components/deck/HudFrame";
import { cn } from "@/lib/utils";
diff --git a/jarvis/ui/web/frontend/src/components/wiki/WikiGraph.tsx b/jarvis/ui/web/frontend/src/components/wiki/WikiGraph.tsx
index 6c9af8a662..0652c2269a 100644
--- a/jarvis/ui/web/frontend/src/components/wiki/WikiGraph.tsx
+++ b/jarvis/ui/web/frontend/src/components/wiki/WikiGraph.tsx
@@ -31,7 +31,10 @@ import {
BROKEN_EDGE_COLOUR,
clampCenterToView,
NODE_COLOUR,
+ edgeDetails,
endpointId,
+ escapeTooltipText,
+ nodeDetails,
nodeSizeScore,
sizeChanged,
toGraphData,
@@ -67,38 +70,11 @@ async function fetchGraph(): Promise<WikiGraphPayload> {
return res.json();
}
-export function escapeTooltipText(value: string): string {
- return value
- .replace(/&/g, "&amp;")
- .replace(/</g, "&lt;")
- .replace(/>/g, "&gt;")
- .replace(/"/g, "&quot;")
- .replace(/'/g, "&#39;");
-}
-
-export function nodeDetails(node: RenderNode, t: (key: string) => string): string {
- const backlinks = node.backlinkCount ?? 0;
- const suffix = t(
- backlinks === 1 ? "wiki_graph.backlink_one" : "wiki_graph.backlink_many",
- );
- return t("wiki_graph.node_details")
- .replace("{0}", node.title)
- .replace("{1}", node.kind)
- .replace("{2}", String(backlinks))
- .replace("{3}", suffix);
-}
-
-export function edgeDetails(
- edge: RenderEdge,
- titles: ReadonlyMap<string, string>,
-): string {
- const sourceId = endpointId(edge.source);
- const targetId = endpointId(edge.target);
- const source = titles.get(sourceId) ?? sourceId;
- const target = titles.get(targetId) ?? targetId;
- const relationship = edge.context.trim();
- return `${source} → ${target}${relationship ? ` · ${relationship}` : ""}`;
-}
+// The tooltip helpers moved to `lib/wikiGraph` — a module that imports
+// nothing — so the deck can use them without dragging this component's graph
+// library into the startup chunk. Re-exported here because this is where every
+// existing caller looks for them.
+export { edgeDetails, escapeTooltipText, nodeDetails } from "@/lib/wikiGraph";
/**
* Node radius in graph units — shared by the hit area and the label offset.
diff --git a/jarvis/ui/web/frontend/src/hooks/useCodingMode.ts b/jarvis/ui/web/frontend/src/hooks/useCodingMode.ts
index b658ca25aa..0fab283505 100644
--- a/jarvis/ui/web/frontend/src/hooks/useCodingMode.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useCodingMode.ts
@@ -1,7 +1,17 @@
import { useEffect } from "react";
import { useEventStore } from "@/store/events";
-import { fetchWorkspaces } from "@/lib/agenticIdeApi";
+
+/**
+ * Loaded on demand rather than imported.
+ *
+ * This hook runs in the app shell, so a static import would link the agentic
+ * IDE's entire API client into the STARTUP chunk to call one light endpoint.
+ * Every call site here already awaits a network round trip; the module arrives
+ * in the same tick the request would have started.
+ */
+const fetchWorkspaces = async () =>
+ (await import("@/lib/agenticIdeApi")).fetchWorkspaces();
/**
* Keeps the app-wide "coding mode" indicator in sync with the backend.
diff --git a/jarvis/ui/web/frontend/src/lib/wikiGraph.ts b/jarvis/ui/web/frontend/src/lib/wikiGraph.ts
index 8963613b1a..06d5701f09 100644
--- a/jarvis/ui/web/frontend/src/lib/wikiGraph.ts
+++ b/jarvis/ui/web/frontend/src/lib/wikiGraph.ts
@@ -325,3 +325,48 @@ export function toGraphData(payload: WikiGraphPayload): {
return { nodes, links };
}
+
+
+/**
+ * Tooltip text for one node, one edge, and the HTML escape both need.
+ *
+ * These live here, beside the data they describe, rather than in
+ * `components/wiki/WikiGraph` where they were written. The deck's wiki card
+ * needs exactly these three strings and nothing else from that component — and
+ * importing them from there pulled `react-force-graph-2d` with its whole d3
+ * stack into the STARTUP chunk, roughly 150 KB parsed before the first paint,
+ * for three pure string functions. This module imports nothing, so the graph
+ * library now travels only in the chunk that actually draws a graph.
+ */
+export function escapeTooltipText(value: string): string {
+ return value
+ .replace(/&/g, "&amp;")
+ .replace(/</g, "&lt;")
+ .replace(/>/g, "&gt;")
+ .replace(/"/g, "&quot;")
+ .replace(/'/g, "&#39;");
+}
+
+export function nodeDetails(node: RenderNode, t: (key: string) => string): string {
+ const backlinks = node.backlinkCount ?? 0;
+ const suffix = t(
+ backlinks === 1 ? "wiki_graph.backlink_one" : "wiki_graph.backlink_many",
+ );
+ return t("wiki_graph.node_details")
+ .replace("{0}", node.title)
+ .replace("{1}", node.kind)
+ .replace("{2}", String(backlinks))
+ .replace("{3}", suffix);
+}
+
+export function edgeDetails(
+ edge: RenderEdge,
+ titles: ReadonlyMap<string, string>,
+): string {
+ const sourceId = endpointId(edge.source);
+ const targetId = endpointId(edge.target);
+ const source = titles.get(sourceId) ?? sourceId;
+ const target = titles.get(targetId) ?? targetId;
+ const relationship = edge.context.trim();
+ return `${source} → ${target}${relationship ? ` · ${relationship}` : ""}`;
+}
diff --git a/jarvis/ui/web/frontend/src/schema/ws.ts b/jarvis/ui/web/frontend/src/schema/ws.ts
index cc8c23cf62..7175540955 100644
--- a/jarvis/ui/web/frontend/src/schema/ws.ts
+++ b/jarvis/ui/web/frontend/src/schema/ws.ts
@@ -1,4 +1,8 @@
-import { z } from "zod";
+// zod v4's core, which the installed zod 3.25 ships alongside v3 under this
+// subpath. Same API for everything below, a fraction of the bytes — and these
+// schemas sit in the STARTUP chunk because the socket opens as the app mounts,
+// so what zod costs here is paid before the first paint.
+import { z } from "zod/v4";
/** Envelope emitted by server over /ws for every bus-event.
*
@@ -11,7 +15,7 @@ export const WSEventEnvelope = z.object({
source_layer: z.string().default(""),
timestamp_ns: z.number(),
trace_id: z.string(),
- payload: z.record(z.unknown()).default({}),
+ payload: z.record(z.string(), z.unknown()).default({}),
});
export type WSEventEnvelopeT = z.infer<typeof WSEventEnvelope>;
@@ -35,7 +39,7 @@ export const WSMessageIn = z.object({
type: z.literal("message"),
kind: z.enum(["text", "voice", "system", "action"]),
content: z.string(),
- metadata: z.record(z.unknown()).optional(),
+ metadata: z.record(z.string(), z.unknown()).optional(),
});
export type WSMessageInT = z.infer<typeof WSMessageIn>;
@@ -57,7 +61,7 @@ export const WSCommand = z.object({
// task into the live conversation context.
"mission.inject",
]),
- payload: z.record(z.unknown()).default({}),
+ payload: z.record(z.string(), z.unknown()).default({}),
});
export type WSCommandT = z.infer<typeof WSCommand>;