From 25f7dfe138107fb9919378d38b4938f05724f701 Mon Sep 17 00:00:00 2001 From: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 Date: Wed, 29 Jul 2026 18:57:48 -0400 Subject: [PATCH] refactor(agent-usage): move usage-ingress wiring into the feature hook main's file-size ratchet (#3352) replaced the static per-file override map with a git-diff base comparison, dropping the 1025-line ceiling that UserProfilePanel.tsx had been living under. The 7-day ingress query was agent-usage logic sitting in a profile file; moving it home puts the panel back under the 1000-line limit with no behavior change. Co-authored-by: Will Pfleger Signed-off-by: Will Pfleger --- desktop/src/features/agent-usage/hooks.ts | 23 +++++++++++++++++++ .../features/profile/ui/UserProfilePanel.tsx | 15 ++---------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/desktop/src/features/agent-usage/hooks.ts b/desktop/src/features/agent-usage/hooks.ts index 8a6c09bc9..1861bd8bd 100644 --- a/desktop/src/features/agent-usage/hooks.ts +++ b/desktop/src/features/agent-usage/hooks.ts @@ -8,6 +8,7 @@ import { } from "@/shared/api/tauriArchive"; import { buildLocalDayBoundaries, + deriveUsageIngressTrailing, msUntilNextLocalMidnight, type UsageWindowDays, } from "./lib/agentUsage"; @@ -100,3 +101,25 @@ export function useAgentUsageSeries({ gcTime: 5 * 60_000, }); } + +/** + * Trailing text for the profile Info tab's usage ingress row (plan:328). + * + * Owns its own 7-day window deliberately: the row summarises recent usage + * independently of the focused view's 7d/30d selector, so the two must not + * share a query. Returns `undefined` while the query is disabled or still + * loading, which the row renders as no trailing text at all. + * + * `enabled` gates the query off entirely when the row won't render. + */ +export function useUsageIngress( + agentPubkey: string | null, + enabled: boolean, +): string | undefined { + const query = useAgentUsageSeries({ + agentPubkey: agentPubkey ?? undefined, + days: 7, + enabled, + }); + return query.data ? deriveUsageIngressTrailing(query.data) : undefined; +} diff --git a/desktop/src/features/profile/ui/UserProfilePanel.tsx b/desktop/src/features/profile/ui/UserProfilePanel.tsx index 1c5430c01..bece887e0 100644 --- a/desktop/src/features/profile/ui/UserProfilePanel.tsx +++ b/desktop/src/features/profile/ui/UserProfilePanel.tsx @@ -68,8 +68,7 @@ import { } from "@/features/profile/ui/UserProfilePanelSections"; import { AgentConfigurationFocusedView } from "@/features/profile/ui/UserProfilePanelAgentDetails"; import { AgentUsageFocusedView } from "@/features/agent-usage/ui/AgentUsageFocusedView"; -import { useAgentUsageSeries } from "@/features/agent-usage/hooks"; -import { deriveUsageIngressTrailing } from "@/features/agent-usage/lib/agentUsage"; +import { useUsageIngress } from "@/features/agent-usage/hooks"; import { UserProfileAgentSettingsMenuSlot } from "@/features/profile/ui/UserProfileAgentActions"; import { useProfileAgentDeletion } from "@/features/profile/ui/UserProfilePanelDeletion"; import { useProfileFieldBuckets } from "@/features/profile/ui/UserProfilePanelFields"; @@ -342,17 +341,7 @@ export function UserProfilePanel({ Boolean(effectivePubkey) && canOpenAgentActivity(effectivePubkey); const canViewUsage = viewerIsOwner && isBot && Boolean(effectivePubkey); - // Info-tab ingress row's trailing text (plan:328) needs its own 7-day - // query — independent of the focused view's own 7d/30d selector, and - // gated off entirely when the row won't render. - const usageIngressQuery = useAgentUsageSeries({ - agentPubkey: effectivePubkey ?? undefined, - days: 7, - enabled: canViewUsage, - }); - const usageIngressTrailing = usageIngressQuery.data - ? deriveUsageIngressTrailing(usageIngressQuery.data) - : undefined; + const usageIngressTrailing = useUsageIngress(effectivePubkey, canViewUsage); const canOpenAgentLogs = isOwner === true && managedAgent?.backend.type === "local"; const canInstantiateAgent =