codex-devtools 0.1.11 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7055,6 +7055,14 @@ class HttpApiClient {
7055
7055
  async getSessionChunks(sessionId) {
7056
7056
  return this.get(`/sessions/${encodeURIComponent(sessionId)}/chunks`);
7057
7057
  }
7058
+ async getStats(scope = { type: "all" }) {
7059
+ if (scope.type === "project") {
7060
+ return this.get(
7061
+ `/stats?scope=project&cwd=${encodeURIComponent(scope.cwd)}`
7062
+ );
7063
+ }
7064
+ return this.get("/stats?scope=all");
7065
+ }
7058
7066
  async searchSessions(query) {
7059
7067
  return this.get(`/search?q=${encodeURIComponent(query)}`);
7060
7068
  }
@@ -7642,8 +7650,57 @@ const createSessionSlice = (client2) => (set, get) => ({
7642
7650
  });
7643
7651
  }
7644
7652
  });
7653
+ function normalizeScope$1(scope) {
7654
+ var _a;
7655
+ if (!scope || scope.type === "all") {
7656
+ return { type: "all" };
7657
+ }
7658
+ const cwd = (_a = scope.cwd) == null ? void 0 : _a.trim();
7659
+ if (!cwd) {
7660
+ return { type: "all" };
7661
+ }
7662
+ return {
7663
+ type: "project",
7664
+ cwd
7665
+ };
7666
+ }
7667
+ const createStatsSlice = (client2) => (set, get) => ({
7668
+ statsData: null,
7669
+ statsScope: { type: "all" },
7670
+ statsLoading: false,
7671
+ statsError: null,
7672
+ fetchStats: async (scope, options) => {
7673
+ var _a;
7674
+ const resolvedScope = normalizeScope$1(scope != null ? scope : get().statsScope);
7675
+ const background = (_a = options == null ? void 0 : options.background) != null ? _a : false;
7676
+ if (!background) {
7677
+ set({ statsLoading: true, statsError: null });
7678
+ }
7679
+ try {
7680
+ const statsData = await client2.getStats(resolvedScope);
7681
+ set((state) => ({
7682
+ statsData,
7683
+ statsScope: resolvedScope,
7684
+ statsLoading: background ? state.statsLoading : false,
7685
+ statsError: null
7686
+ }));
7687
+ } catch (error) {
7688
+ set((state) => ({
7689
+ statsScope: resolvedScope,
7690
+ statsLoading: background ? state.statsLoading : false,
7691
+ statsError: error instanceof Error ? error.message : "Failed to fetch stats"
7692
+ }));
7693
+ }
7694
+ },
7695
+ setStatsScope: async (scope) => {
7696
+ const resolvedScope = normalizeScope$1(scope);
7697
+ set({ statsScope: resolvedScope });
7698
+ await get().fetchStats(resolvedScope);
7699
+ }
7700
+ });
7645
7701
  const DASHBOARD_TAB_ID$2 = "dashboard";
7646
7702
  const SETTINGS_TAB_ID$2 = "settings";
7703
+ const STATS_TAB_ID$3 = "stats";
7647
7704
  function createSessionTabId(sessionId) {
7648
7705
  return `session:${sessionId}`;
7649
7706
  }
@@ -7674,6 +7731,10 @@ const createTabSlice = (_client) => (set, get) => ({
7674
7731
  openDashboardTab: () => {
7675
7732
  set({ activeTabId: DASHBOARD_TAB_ID$2, activeSessionId: null });
7676
7733
  },
7734
+ openStatsTab: () => {
7735
+ set({ activeTabId: STATS_TAB_ID$3, activeSessionId: null });
7736
+ void get().fetchStats(get().statsScope);
7737
+ },
7677
7738
  openSettingsTab: () => {
7678
7739
  set({ activeTabId: SETTINGS_TAB_ID$2, activeSessionId: null });
7679
7740
  },
@@ -7690,6 +7751,9 @@ const createTabSlice = (_client) => (set, get) => ({
7690
7751
  if (tab.type === "session" && tab.sessionId) {
7691
7752
  void get().fetchChunks(tab.sessionId);
7692
7753
  }
7754
+ if (tab.type === "stats") {
7755
+ void get().fetchStats(get().statsScope);
7756
+ }
7693
7757
  },
7694
7758
  closeTab: (tabId) => {
7695
7759
  set((state) => {
@@ -7728,6 +7792,7 @@ const createUISlice = (_client) => (set) => ({
7728
7792
  const createAppStore = (client2 = api) => create()((...args) => ({
7729
7793
  ...createProjectSlice(client2)(...args),
7730
7794
  ...createSessionSlice(client2)(...args),
7795
+ ...createStatsSlice(client2)(...args),
7731
7796
  ...createConversationSlice(client2)(...args),
7732
7797
  ...createConfigSlice(client2)(...args),
7733
7798
  ...createTabSlice()(...args),
@@ -7737,6 +7802,7 @@ const createAppStore = (client2 = api) => create()((...args) => ({
7737
7802
  const useAppStore = createAppStore();
7738
7803
  const REFRESH_DEBOUNCE_MS = 120;
7739
7804
  const FALLBACK_POLL_INTERVAL_MS = 5e3;
7805
+ const STATS_TAB_ID$2 = "stats";
7740
7806
  function initializeEventListeners(store = useAppStore, client2 = api) {
7741
7807
  let refreshTimer = null;
7742
7808
  let pollTimer = null;
@@ -7760,6 +7826,9 @@ function initializeEventListeners(store = useAppStore, client2 = api) {
7760
7826
  if (state.activeSessionId) {
7761
7827
  void state.fetchChunks(state.activeSessionId);
7762
7828
  }
7829
+ if (state.activeTabId === STATS_TAB_ID$2) {
7830
+ void state.fetchStats(state.statsScope, { background: true });
7831
+ }
7763
7832
  }, REFRESH_DEBOUNCE_MS);
7764
7833
  });
7765
7834
  const runFallbackRefresh = () => {
@@ -7782,7 +7851,8 @@ function initializeEventListeners(store = useAppStore, client2 = api) {
7782
7851
  prefetchPreviews: false,
7783
7852
  background: true
7784
7853
  }) : Promise.resolve(),
7785
- state.activeSessionId ? state.fetchChunks(state.activeSessionId) : Promise.resolve()
7854
+ state.activeSessionId ? state.fetchChunks(state.activeSessionId) : Promise.resolve(),
7855
+ state.activeTabId === STATS_TAB_ID$2 ? state.fetchStats(state.statsScope, { background: true }) : Promise.resolve()
7786
7856
  ]).finally(() => {
7787
7857
  polling = false;
7788
7858
  });
@@ -9353,6 +9423,256 @@ const DashboardView = () => {
9353
9423
  ] })
9354
9424
  ] });
9355
9425
  };
9426
+ function formatDuration$1(durationMs) {
9427
+ if (!Number.isFinite(durationMs) || durationMs <= 0) {
9428
+ return "0m";
9429
+ }
9430
+ const totalMinutes = Math.round(durationMs / 6e4);
9431
+ const hours = Math.floor(totalMinutes / 60);
9432
+ const minutes = totalMinutes % 60;
9433
+ if (hours <= 0) {
9434
+ return `${minutes}m`;
9435
+ }
9436
+ if (minutes === 0) {
9437
+ return `${hours}h`;
9438
+ }
9439
+ return `${hours}h ${minutes}m`;
9440
+ }
9441
+ function normalizeScope(scope) {
9442
+ if (scope.type === "project" && scope.cwd.trim().length > 0) {
9443
+ return { type: "project", cwd: scope.cwd.trim() };
9444
+ }
9445
+ return { type: "all" };
9446
+ }
9447
+ const StatsView = () => {
9448
+ const {
9449
+ projects,
9450
+ statsData,
9451
+ statsScope,
9452
+ statsLoading,
9453
+ statsError,
9454
+ fetchStats,
9455
+ setStatsScope
9456
+ } = useAppStore((state) => ({
9457
+ projects: state.projects,
9458
+ statsData: state.statsData,
9459
+ statsScope: state.statsScope,
9460
+ statsLoading: state.statsLoading,
9461
+ statsError: state.statsError,
9462
+ fetchStats: state.fetchStats,
9463
+ setStatsScope: state.setStatsScope
9464
+ }));
9465
+ reactExports.useEffect(() => {
9466
+ if (!statsData && !statsLoading) {
9467
+ void fetchStats(statsScope);
9468
+ }
9469
+ }, [statsData, statsLoading, fetchStats, statsScope]);
9470
+ const dailyMaxOutput = reactExports.useMemo(
9471
+ () => {
9472
+ var _a;
9473
+ return Math.max(...(_a = statsData == null ? void 0 : statsData.daily.map((point) => point.outputTokens)) != null ? _a : [1]);
9474
+ },
9475
+ [statsData]
9476
+ );
9477
+ const hourlyMaxEvents = reactExports.useMemo(
9478
+ () => {
9479
+ var _a;
9480
+ return Math.max(...(_a = statsData == null ? void 0 : statsData.hourly.map((point) => point.eventCount)) != null ? _a : [1]);
9481
+ },
9482
+ [statsData]
9483
+ );
9484
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "stats-shell", children: [
9485
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("header", { className: "stats-header", children: [
9486
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h2", { children: "Stats" }),
9487
+ /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: "Token volume, activity patterns, model usage, and reasoning effort." })
9488
+ ] }),
9489
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "stats-controls", children: [
9490
+ /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "sidebar-label", htmlFor: "stats-scope", children: "Scope" }),
9491
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(
9492
+ "select",
9493
+ {
9494
+ id: "stats-scope",
9495
+ className: "app-select",
9496
+ value: statsScope.type,
9497
+ onChange: (event) => {
9498
+ var _a, _b;
9499
+ if (event.target.value === "project") {
9500
+ const defaultProject = (_b = (_a = projects[0]) == null ? void 0 : _a.cwd) != null ? _b : "";
9501
+ void setStatsScope({ type: "project", cwd: defaultProject });
9502
+ return;
9503
+ }
9504
+ void setStatsScope({ type: "all" });
9505
+ },
9506
+ children: [
9507
+ /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "all", children: "All projects" }),
9508
+ /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "project", children: "Single project" })
9509
+ ]
9510
+ }
9511
+ ),
9512
+ statsScope.type === "project" ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
9513
+ /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: "sidebar-label", htmlFor: "stats-project", children: "Project" }),
9514
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(
9515
+ "select",
9516
+ {
9517
+ id: "stats-project",
9518
+ className: "app-select",
9519
+ value: statsScope.cwd,
9520
+ onChange: (event) => {
9521
+ void setStatsScope({ type: "project", cwd: event.target.value });
9522
+ },
9523
+ children: [
9524
+ projects.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("option", { value: "", children: "No projects available" }) : null,
9525
+ projects.map((project) => /* @__PURE__ */ jsxRuntimeExports.jsxs("option", { value: project.cwd, children: [
9526
+ project.name,
9527
+ " - ",
9528
+ project.cwd
9529
+ ] }, project.cwd))
9530
+ ]
9531
+ }
9532
+ )
9533
+ ] }) : null,
9534
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
9535
+ "button",
9536
+ {
9537
+ type: "button",
9538
+ className: "tabbar-action",
9539
+ onClick: () => {
9540
+ void fetchStats(normalizeScope(statsScope));
9541
+ },
9542
+ children: "Refresh"
9543
+ }
9544
+ )
9545
+ ] }),
9546
+ statsError ? /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "stats-error", children: statsError }) : null,
9547
+ !statsData ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "empty-view", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "empty-title", children: statsLoading ? "Loading stats..." : "No stats available yet" }) }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
9548
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "stats-kpi-grid", children: [
9549
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("article", { className: "stat-card", children: [
9550
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stat-label", children: "Total tokens" }),
9551
+ /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "stat-value", children: statsData.totals.totalTokens.toLocaleString() })
9552
+ ] }),
9553
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("article", { className: "stat-card", children: [
9554
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stat-label", children: "Generated tokens" }),
9555
+ /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "stat-value", children: statsData.totals.outputTokens.toLocaleString() })
9556
+ ] }),
9557
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("article", { className: "stat-card", children: [
9558
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stat-label", children: "Active time" }),
9559
+ /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "stat-value", children: formatDuration$1(statsData.totals.durationMs) })
9560
+ ] }),
9561
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("article", { className: "stat-card", children: [
9562
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stat-label", children: "Sessions" }),
9563
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("strong", { className: "stat-value", children: [
9564
+ statsData.totals.sessions.toLocaleString(),
9565
+ statsData.totals.archivedSessions > 0 ? ` (${statsData.totals.archivedSessions.toLocaleString()} archived)` : ""
9566
+ ] })
9567
+ ] })
9568
+ ] }),
9569
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "stats-section", children: [
9570
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "stats-section-header", children: [
9571
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { children: "Generated tokens by day" }),
9572
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stats-section-subtle", children: "Output tokens" })
9573
+ ] }),
9574
+ statsData.daily.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "empty-copy", children: "No daily token data yet." }) : /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "stats-day-list", children: statsData.daily.map((point) => {
9575
+ const widthPercent = dailyMaxOutput > 0 ? Math.max(6, point.outputTokens / dailyMaxOutput * 100) : 6;
9576
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { className: "stats-day-row", children: [
9577
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stats-day-label", children: point.date }),
9578
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "stats-day-bar-wrap", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "stats-day-bar", style: { width: `${widthPercent}%` } }) }),
9579
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stats-day-value", children: point.outputTokens.toLocaleString() })
9580
+ ] }, point.date);
9581
+ }) })
9582
+ ] }),
9583
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "stats-grid-2", children: [
9584
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("article", { className: "stats-section", children: [
9585
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "stats-section-header", children: [
9586
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { children: "Most active days" }),
9587
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stats-section-subtle", children: "By event count" })
9588
+ ] }),
9589
+ statsData.topDays.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "empty-copy", children: "No activity data yet." }) : /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "stats-top-list", children: statsData.topDays.map((day) => /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { className: "stats-top-item", children: [
9590
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: day.date }),
9591
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
9592
+ day.eventCount.toLocaleString(),
9593
+ " events"
9594
+ ] })
9595
+ ] }, day.date)) })
9596
+ ] }),
9597
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("article", { className: "stats-section", children: [
9598
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "stats-section-header", children: [
9599
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { children: "Most active hours" }),
9600
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stats-section-subtle", children: "By event count" })
9601
+ ] }),
9602
+ statsData.topHours.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "empty-copy", children: "No activity data yet." }) : /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "stats-top-list", children: statsData.topHours.map((hour) => /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { className: "stats-top-item", children: [
9603
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
9604
+ String(hour.hour).padStart(2, "0"),
9605
+ ":00"
9606
+ ] }),
9607
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
9608
+ hour.eventCount.toLocaleString(),
9609
+ " events"
9610
+ ] })
9611
+ ] }, hour.hour)) })
9612
+ ] })
9613
+ ] }),
9614
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "stats-section", children: [
9615
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "stats-section-header", children: [
9616
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { children: "Hourly activity heatmap" }),
9617
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stats-section-subtle", children: "Event count + token volume + session presence" })
9618
+ ] }),
9619
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "stats-heatmap-grid", children: statsData.hourly.map((point) => {
9620
+ const intensity = point.eventCount <= 0 ? 0 : point.eventCount / hourlyMaxEvents;
9621
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(
9622
+ "div",
9623
+ {
9624
+ className: "stats-heat-cell",
9625
+ style: {
9626
+ backgroundColor: intensity === 0 ? "rgba(59, 130, 246, 0.08)" : `rgba(59, 130, 246, ${0.16 + intensity * 0.66})`
9627
+ },
9628
+ title: `${String(point.hour).padStart(2, "0")}:00 • ${point.eventCount.toLocaleString()} events • ${point.totalTokens.toLocaleString()} tokens • ${point.sessionCount.toLocaleString()} sessions`,
9629
+ children: [
9630
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: String(point.hour).padStart(2, "0") }),
9631
+ /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { children: point.eventCount.toLocaleString() })
9632
+ ]
9633
+ },
9634
+ point.hour
9635
+ );
9636
+ }) })
9637
+ ] }),
9638
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "stats-grid-2", children: [
9639
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("article", { className: "stats-section", children: [
9640
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "stats-section-header", children: [
9641
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { children: "Models and reasoning effort" }),
9642
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stats-section-subtle", children: "Token distribution" })
9643
+ ] }),
9644
+ statsData.models.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "empty-copy", children: "No model usage data yet." }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "stats-table-wrap", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("table", { className: "stats-table", children: [
9645
+ /* @__PURE__ */ jsxRuntimeExports.jsx("thead", { children: /* @__PURE__ */ jsxRuntimeExports.jsxs("tr", { children: [
9646
+ /* @__PURE__ */ jsxRuntimeExports.jsx("th", { children: "Model" }),
9647
+ /* @__PURE__ */ jsxRuntimeExports.jsx("th", { children: "Effort" }),
9648
+ /* @__PURE__ */ jsxRuntimeExports.jsx("th", { children: "Tokens" }),
9649
+ /* @__PURE__ */ jsxRuntimeExports.jsx("th", { children: "Sessions" })
9650
+ ] }) }),
9651
+ /* @__PURE__ */ jsxRuntimeExports.jsx("tbody", { children: statsData.models.map((model) => /* @__PURE__ */ jsxRuntimeExports.jsxs("tr", { children: [
9652
+ /* @__PURE__ */ jsxRuntimeExports.jsx("td", { children: model.model }),
9653
+ /* @__PURE__ */ jsxRuntimeExports.jsx("td", { children: model.reasoningEffort }),
9654
+ /* @__PURE__ */ jsxRuntimeExports.jsx("td", { children: model.totalTokens.toLocaleString() }),
9655
+ /* @__PURE__ */ jsxRuntimeExports.jsx("td", { children: model.sessionCount.toLocaleString() })
9656
+ ] }, `${model.model}::${model.reasoningEffort}`)) })
9657
+ ] }) })
9658
+ ] }),
9659
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("article", { className: "stats-section", children: [
9660
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "stats-section-header", children: [
9661
+ /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { children: "Reasoning effort mix" }),
9662
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "stats-section-subtle", children: "Across all models" })
9663
+ ] }),
9664
+ statsData.reasoningEfforts.length === 0 ? /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "empty-copy", children: "No reasoning effort data yet." }) : /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "stats-top-list", children: statsData.reasoningEfforts.map((effort) => /* @__PURE__ */ jsxRuntimeExports.jsxs("li", { className: "stats-top-item", children: [
9665
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: effort.reasoningEffort }),
9666
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { children: [
9667
+ effort.totalTokens.toLocaleString(),
9668
+ " tokens"
9669
+ ] })
9670
+ ] }, effort.reasoningEffort)) })
9671
+ ] })
9672
+ ] })
9673
+ ] })
9674
+ ] });
9675
+ };
9356
9676
  const SettingsView = () => {
9357
9677
  const { appConfig, configLoading, fetchConfig, updateConfig } = useAppStore((state) => ({
9358
9678
  appConfig: state.appConfig,
@@ -11320,6 +11640,16 @@ function getPreludeHint(kind) {
11320
11640
  return "System prelude";
11321
11641
  }
11322
11642
  }
11643
+ function buildSessionTokenStats() {
11644
+ return {
11645
+ totalTokens: 0,
11646
+ inputTokens: 0,
11647
+ outputTokens: 0
11648
+ };
11649
+ }
11650
+ function buildSystemPreludeKey(timestamp, rowIndex) {
11651
+ return `${timestamp}-${rowIndex}`;
11652
+ }
11323
11653
  const ChatHistory = ({ sessionId }) => {
11324
11654
  const { chunks, chunksLoading, chunksSessionId, sessions } = useAppStore((state) => ({
11325
11655
  chunks: state.chunks,
@@ -11334,7 +11664,40 @@ const ChatHistory = ({ sessionId }) => {
11334
11664
  estimateSize: () => 168,
11335
11665
  overscan: 6
11336
11666
  });
11667
+ const [expandedPreludeKeys, setExpandedPreludeKeys] = reactExports.useState(
11668
+ () => /* @__PURE__ */ new Set()
11669
+ );
11337
11670
  const virtualRows = rowVirtualizer.getVirtualItems();
11671
+ const remeasureVisibleRows = reactExports.useCallback(() => {
11672
+ rowVirtualizer.measure();
11673
+ const parent = parentRef.current;
11674
+ if (!parent) {
11675
+ return;
11676
+ }
11677
+ for (const row of rowVirtualizer.getVirtualItems()) {
11678
+ const element = parent.querySelector(`[data-index="${row.index}"]`);
11679
+ if (!element) {
11680
+ continue;
11681
+ }
11682
+ rowVirtualizer.measureElement(element);
11683
+ }
11684
+ }, [rowVirtualizer]);
11685
+ const toggleSystemPrelude = reactExports.useCallback((preludeKey) => {
11686
+ setExpandedPreludeKeys((current) => {
11687
+ const next = new Set(current);
11688
+ if (next.has(preludeKey)) {
11689
+ next.delete(preludeKey);
11690
+ } else {
11691
+ next.add(preludeKey);
11692
+ }
11693
+ return next;
11694
+ });
11695
+ remeasureVisibleRows();
11696
+ notifyChatLayoutInvalidated();
11697
+ }, [remeasureVisibleRows]);
11698
+ reactExports.useEffect(() => {
11699
+ setExpandedPreludeKeys(/* @__PURE__ */ new Set());
11700
+ }, [sessionId]);
11338
11701
  reactExports.useEffect(() => {
11339
11702
  const container = parentRef.current;
11340
11703
  if (!container) {
@@ -11350,15 +11713,37 @@ const ChatHistory = ({ sessionId }) => {
11350
11713
  return;
11351
11714
  }
11352
11715
  const handleLayoutInvalidation = () => {
11353
- rowVirtualizer.measure();
11716
+ remeasureVisibleRows();
11717
+ requestAnimationFrame(() => {
11718
+ remeasureVisibleRows();
11719
+ });
11354
11720
  };
11355
11721
  window.addEventListener(CHAT_LAYOUT_INVALIDATED_EVENT, handleLayoutInvalidation);
11356
11722
  return () => {
11357
11723
  window.removeEventListener(CHAT_LAYOUT_INVALIDATED_EVENT, handleLayoutInvalidation);
11358
11724
  };
11359
- }, [rowVirtualizer]);
11725
+ }, [remeasureVisibleRows]);
11726
+ reactExports.useEffect(() => {
11727
+ remeasureVisibleRows();
11728
+ const raf = requestAnimationFrame(() => {
11729
+ remeasureVisibleRows();
11730
+ });
11731
+ return () => cancelAnimationFrame(raf);
11732
+ }, [chunks, expandedPreludeKeys, remeasureVisibleRows]);
11360
11733
  const hasChunks = chunks.length > 0;
11361
11734
  const isLoading = chunksLoading && chunksSessionId === sessionId;
11735
+ const sessionTokenStats = reactExports.useMemo(() => {
11736
+ return chunks.reduce((totals, chunk) => {
11737
+ var _a, _b, _c;
11738
+ if (chunk.type !== "ai") {
11739
+ return totals;
11740
+ }
11741
+ totals.totalTokens += (_a = chunk.metrics.totalTokens) != null ? _a : 0;
11742
+ totals.inputTokens += (_b = chunk.metrics.inputTokens) != null ? _b : 0;
11743
+ totals.outputTokens += (_c = chunk.metrics.outputTokens) != null ? _c : 0;
11744
+ return totals;
11745
+ }, buildSessionTokenStats());
11746
+ }, [chunks]);
11362
11747
  const initialModelUsage = reactExports.useMemo(() => {
11363
11748
  if (!sessionId) {
11364
11749
  return null;
@@ -11386,14 +11771,27 @@ const ChatHistory = ({ sessionId }) => {
11386
11771
  ] });
11387
11772
  }
11388
11773
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
11389
- initialModelUsage ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "chat-model-summary", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "chat-model-summary-label", children: [
11390
- "Initial model: ",
11391
- /* @__PURE__ */ jsxRuntimeExports.jsx("code", { children: initialModelUsage.model }),
11392
- initialModelUsage.reasoningEffort !== "unknown" ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
11393
- " ",
11394
- /* @__PURE__ */ jsxRuntimeExports.jsx("code", { children: initialModelUsage.reasoningEffort })
11395
- ] }) : null
11396
- ] }) }) : null,
11774
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "chat-session-token-sticky", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "chat-session-token-strip", "aria-label": "Session token totals and initial model", children: [
11775
+ initialModelUsage ? /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "chat-session-token-pair", children: [
11776
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "chat-session-token-key", children: "Model:" }),
11777
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "chat-session-token-value", children: [
11778
+ initialModelUsage.model,
11779
+ initialModelUsage.reasoningEffort !== "unknown" ? ` (${initialModelUsage.reasoningEffort})` : ""
11780
+ ] })
11781
+ ] }) : null,
11782
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "chat-session-token-pair", children: [
11783
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "chat-session-token-key", children: "In:" }),
11784
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "chat-session-token-value", children: sessionTokenStats.inputTokens.toLocaleString() })
11785
+ ] }),
11786
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "chat-session-token-pair", children: [
11787
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "chat-session-token-key", children: "Out:" }),
11788
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "chat-session-token-value", children: sessionTokenStats.outputTokens.toLocaleString() })
11789
+ ] }),
11790
+ /* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "chat-session-token-pair", children: [
11791
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "chat-session-token-key", children: "Total:" }),
11792
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "chat-session-token-value", children: sessionTokenStats.totalTokens.toLocaleString() })
11793
+ ] })
11794
+ ] }) }),
11397
11795
  /* @__PURE__ */ jsxRuntimeExports.jsx(
11398
11796
  "div",
11399
11797
  {
@@ -11408,6 +11806,8 @@ const ChatHistory = ({ sessionId }) => {
11408
11806
  return null;
11409
11807
  }
11410
11808
  const systemPreludeKind = chunk.type === "system" ? classifyCodexBootstrapMessage(chunk.content) : null;
11809
+ const systemPreludeKey = chunk.type === "system" && systemPreludeKind && systemPreludeKind !== "collaboration_mode" ? buildSystemPreludeKey(chunk.timestamp, virtualRow.index) : null;
11810
+ const isSystemPreludeExpanded = systemPreludeKey !== null && expandedPreludeKeys.has(systemPreludeKey);
11411
11811
  const key = `${chunk.type}-${chunk.timestamp}-${virtualRow.index}`;
11412
11812
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
11413
11813
  "div",
@@ -11429,16 +11829,28 @@ const ChatHistory = ({ sessionId }) => {
11429
11829
  "Collaboration mode: ",
11430
11830
  /* @__PURE__ */ jsxRuntimeExports.jsx("code", { children: extractCollaborationModeLabel(chunk.content) })
11431
11831
  ] }) }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(
11432
- "details",
11832
+ "section",
11433
11833
  {
11434
- className: `chat-system-prelude ${systemPreludeKind}`,
11435
- onToggle: notifyChatLayoutInvalidated,
11834
+ className: `chat-system-prelude ${systemPreludeKind}${isSystemPreludeExpanded ? " open" : ""}`,
11436
11835
  children: [
11437
- /* @__PURE__ */ jsxRuntimeExports.jsxs("summary", { className: "chat-system-prelude-summary", children: [
11438
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: getPreludeLabel(systemPreludeKind) }),
11439
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "chat-system-prelude-summary-hint", children: getPreludeHint(systemPreludeKind) })
11440
- ] }),
11441
- /* @__PURE__ */ jsxRuntimeExports.jsx("pre", { className: "chat-system-prelude-content", children: chunk.content })
11836
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(
11837
+ "button",
11838
+ {
11839
+ type: "button",
11840
+ className: "chat-system-prelude-summary",
11841
+ "aria-expanded": isSystemPreludeExpanded,
11842
+ onClick: () => {
11843
+ if (systemPreludeKey) {
11844
+ toggleSystemPrelude(systemPreludeKey);
11845
+ }
11846
+ },
11847
+ children: [
11848
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: getPreludeLabel(systemPreludeKind) }),
11849
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "chat-system-prelude-summary-hint", children: getPreludeHint(systemPreludeKind) })
11850
+ ]
11851
+ }
11852
+ ),
11853
+ isSystemPreludeExpanded ? /* @__PURE__ */ jsxRuntimeExports.jsx("pre", { className: "chat-system-prelude-content", children: chunk.content }) : null
11442
11854
  ]
11443
11855
  }
11444
11856
  ) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "chat-system-message", children: /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: chunk.content }) }) : null,
@@ -11471,7 +11883,20 @@ const ChatHistory = ({ sessionId }) => {
11471
11883
  }
11472
11884
  )
11473
11885
  ] });
11474
- }, [chunks, hasChunks, initialModelUsage, isLoading, rowVirtualizer, virtualRows]);
11886
+ }, [
11887
+ chunks,
11888
+ hasChunks,
11889
+ initialModelUsage,
11890
+ isLoading,
11891
+ rowVirtualizer,
11892
+ sessionTokenStats.inputTokens,
11893
+ sessionTokenStats.outputTokens,
11894
+ sessionTokenStats.totalTokens,
11895
+ expandedPreludeKeys,
11896
+ remeasureVisibleRows,
11897
+ toggleSystemPrelude,
11898
+ virtualRows
11899
+ ]);
11475
11900
  return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "chat-shell", ref: parentRef, children: content });
11476
11901
  };
11477
11902
  const SessionTabContent = ({ tab }) => {
@@ -11695,6 +12120,7 @@ const Sidebar = () => {
11695
12120
  ] });
11696
12121
  };
11697
12122
  const DASHBOARD_TAB_ID$1 = "dashboard";
12123
+ const STATS_TAB_ID$1 = "stats";
11698
12124
  const SETTINGS_TAB_ID$1 = "settings";
11699
12125
  const TabBar = () => {
11700
12126
  const {
@@ -11703,6 +12129,7 @@ const TabBar = () => {
11703
12129
  setActiveTab,
11704
12130
  closeTab,
11705
12131
  openDashboardTab,
12132
+ openStatsTab,
11706
12133
  openSettingsTab,
11707
12134
  toggleSidebarCollapsed,
11708
12135
  sidebarCollapsed
@@ -11712,6 +12139,7 @@ const TabBar = () => {
11712
12139
  setActiveTab: state.setActiveTab,
11713
12140
  closeTab: state.closeTab,
11714
12141
  openDashboardTab: state.openDashboardTab,
12142
+ openStatsTab: state.openStatsTab,
11715
12143
  openSettingsTab: state.openSettingsTab,
11716
12144
  toggleSidebarCollapsed: state.toggleSidebarCollapsed,
11717
12145
  sidebarCollapsed: state.sidebarCollapsed
@@ -11743,6 +12171,17 @@ const TabBar = () => {
11743
12171
  children: "Dashboard"
11744
12172
  }
11745
12173
  ),
12174
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
12175
+ "button",
12176
+ {
12177
+ className: `tabbar-action ${activeTabId === STATS_TAB_ID$1 ? "active" : ""}`,
12178
+ onClick: openStatsTab,
12179
+ type: "button",
12180
+ role: "tab",
12181
+ "aria-selected": activeTabId === STATS_TAB_ID$1,
12182
+ children: "Stats"
12183
+ }
12184
+ ),
11746
12185
  /* @__PURE__ */ jsxRuntimeExports.jsx(
11747
12186
  "button",
11748
12187
  {
@@ -11786,6 +12225,7 @@ const TabBar = () => {
11786
12225
  };
11787
12226
  const DASHBOARD_TAB_ID = "dashboard";
11788
12227
  const SETTINGS_TAB_ID = "settings";
12228
+ const STATS_TAB_ID = "stats";
11789
12229
  const TabbedLayout = () => {
11790
12230
  const { openTabs, activeTabId, sidebarCollapsed } = useAppStore((state) => ({
11791
12231
  openTabs: state.openTabs,
@@ -11797,13 +12237,15 @@ const TabbedLayout = () => {
11797
12237
  return (activeTab == null ? void 0 : activeTab.type) === "session" ? activeTab : null;
11798
12238
  }, [openTabs, activeTabId]);
11799
12239
  const settingsActive = activeTabId === SETTINGS_TAB_ID;
11800
- const dashboardActive = activeTabId === DASHBOARD_TAB_ID || !settingsActive && !activeSessionTab;
12240
+ const statsActive = activeTabId === STATS_TAB_ID;
12241
+ const dashboardActive = activeTabId === DASHBOARD_TAB_ID || !settingsActive && !statsActive && !activeSessionTab;
11801
12242
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "layout-shell", children: [
11802
12243
  !sidebarCollapsed ? /* @__PURE__ */ jsxRuntimeExports.jsx(Sidebar, {}) : null,
11803
12244
  /* @__PURE__ */ jsxRuntimeExports.jsxs("section", { className: "content-shell", children: [
11804
12245
  /* @__PURE__ */ jsxRuntimeExports.jsx(TabBar, {}),
11805
12246
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "content-body", children: [
11806
12247
  activeSessionTab ? /* @__PURE__ */ jsxRuntimeExports.jsx(SessionTabContent, { tab: activeSessionTab }) : null,
12248
+ statsActive ? /* @__PURE__ */ jsxRuntimeExports.jsx(StatsView, {}) : null,
11807
12249
  dashboardActive ? /* @__PURE__ */ jsxRuntimeExports.jsx(DashboardView, {}) : null,
11808
12250
  settingsActive ? /* @__PURE__ */ jsxRuntimeExports.jsx(SettingsView, {}) : null
11809
12251
  ] })