diff --git a/desktop/src/features/agents/observerRelayStore.ts b/desktop/src/features/agents/observerRelayStore.ts index 6aa397edb..213cefa19 100644 --- a/desktop/src/features/agents/observerRelayStore.ts +++ b/desktop/src/features/agents/observerRelayStore.ts @@ -128,6 +128,16 @@ function observerTag(event: RelayEvent, tagName: string) { return event.tags.find((tag) => tag[0] === tagName)?.[1] ?? null; } +function pillDiagBridgeAgents( + agents: readonly Pick[], +) { + return agents.map((agent) => ({ + pubkey: normalizePubkey(agent.pubkey), + status: agent.status, + startsObserver: agent.status === "running" || agent.status === "deployed", + })); +} + function appendAgentEvent(agentPubkey: string, event: ObserverEvent) { const key = normalizePubkey(agentPubkey); const current = eventsByAgent.get(key) ?? []; @@ -390,6 +400,13 @@ export function useManagedAgentObserverBridge( [agents], ); + console.log("[pill-diag] observer bridge render", { + subscriptionId, + hasActiveAgent, + agents: pillDiagBridgeAgents(agents), + at: new Date().toISOString(), + }); + const agentPubkeys = React.useMemo( () => agents.map((agent) => agent.pubkey), [agents], diff --git a/desktop/src/features/sidebar/lib/useActiveWorkingChannelsById.ts b/desktop/src/features/sidebar/lib/useActiveWorkingChannelsById.ts index dc0de7f4d..81aa5b323 100644 --- a/desktop/src/features/sidebar/lib/useActiveWorkingChannelsById.ts +++ b/desktop/src/features/sidebar/lib/useActiveWorkingChannelsById.ts @@ -22,6 +22,9 @@ import { normalizePubkey } from "@/shared/lib/pubkey"; type WorkingAgentName = Pick; type WorkingAgent = Pick; +type PillDiagProfile = UserProfileSummary & { + pubkey?: string; +}; type OwnedRelayWorkingAgent = Pick & { status: "deployed"; }; @@ -85,6 +88,86 @@ export function mergeWorkingAgents( return [...mergedByPubkey.values()]; } +function summarizeAgent(agent: WorkingAgentName & { status?: string }) { + return { + pubkey: normalizePubkey(agent.pubkey), + name: agent.name, + status: agent.status ?? null, + }; +} + +function summarizeRelayProfile( + pubkey: string, + profile: PillDiagProfile | undefined, + currentPubkey: string | undefined, +) { + return { + pubkey: normalizePubkey(pubkey), + profileKeyPubkey: profile?.pubkey ? normalizePubkey(profile.pubkey) : null, + displayName: profile?.displayName ?? null, + isAgent: profile?.isAgent ?? null, + ownerPubkey: profile?.ownerPubkey + ? normalizePubkey(profile.ownerPubkey) + : null, + ownsAuthorAgent: ownsAuthorAgent(profile, currentPubkey), + }; +} + +function logPillDiagnostics({ + currentPubkey, + managedAgents, + relayAgents, + profiles, + ownedRelayAgents, + workingAgents, + activeWorkingChannels, +}: { + currentPubkey: string | undefined; + managedAgents: readonly WorkingAgent[]; + relayAgents: readonly Pick[]; + profiles: Record | undefined; + ownedRelayAgents: readonly WorkingAgent[]; + workingAgents: readonly WorkingAgent[]; + activeWorkingChannels: readonly ActiveChannelTurnSummary[]; +}) { + const normalizedProfiles = Object.fromEntries( + relayAgents.map((agent) => { + const pubkey = normalizePubkey(agent.pubkey); + const profile = profiles?.[pubkey] as PillDiagProfile | undefined; + return [ + pubkey, + summarizeRelayProfile(agent.pubkey, profile, currentPubkey), + ]; + }), + ); + + console.groupCollapsed("[pill-diag] active working channels inputs", { + currentPubkey: currentPubkey ? normalizePubkey(currentPubkey) : null, + managedAgentCount: managedAgents.length, + relayAgentCount: relayAgents.length, + ownedRelayAgentCount: ownedRelayAgents.length, + workingAgentCount: workingAgents.length, + activeChannelCount: activeWorkingChannels.length, + }); + console.log("[pill-diag] currentPubkey", { + currentPubkey: currentPubkey ? normalizePubkey(currentPubkey) : null, + }); + console.table(managedAgents.map(summarizeAgent)); + console.log("[pill-diag] managedAgents", managedAgents.map(summarizeAgent)); + console.table(relayAgents.map(summarizeAgent)); + console.log("[pill-diag] relayAgents", relayAgents.map(summarizeAgent)); + console.log("[pill-diag] profilesByRelayAgent", normalizedProfiles); + console.table(ownedRelayAgents.map(summarizeAgent)); + console.log( + "[pill-diag] ownedRelayAgents", + ownedRelayAgents.map(summarizeAgent), + ); + console.table(workingAgents.map(summarizeAgent)); + console.log("[pill-diag] workingAgents", workingAgents.map(summarizeAgent)); + console.log("[pill-diag] activeWorkingChannels", activeWorkingChannels); + console.groupEnd(); +} + export function useActiveWorkingChannelsById(): ReadonlyMap< string, ActiveChannelTurnSummary @@ -127,6 +210,26 @@ export function useActiveWorkingChannelsById(): ReadonlyMap< const activeWorkingChannels = useActiveAgentTurnsByChannel(); + React.useEffect(() => { + logPillDiagnostics({ + currentPubkey, + managedAgents, + relayAgents, + profiles: relayAgentProfilesQuery.data?.profiles, + ownedRelayAgents, + workingAgents, + activeWorkingChannels, + }); + }, [ + activeWorkingChannels, + currentPubkey, + managedAgents, + ownedRelayAgents, + relayAgentProfilesQuery.data?.profiles, + relayAgents, + workingAgents, + ]); + return React.useMemo( () => new Map(