chore(sidebar): trace post-fix working pill state

Co-authored-by: Taylor Ho <taylorkmho@gmail.com>
Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
This commit is contained in:
npub1223z34hd7vtwc6qj4s7flsxkj644nlre2nthu7lrrmkumhu3xddsrx9r6w
2026-06-30 21:32:58 -07:00
co-authored by Taylor Ho
parent 96bd0adc8d
commit a8d6be013d
2 changed files with 120 additions and 0 deletions
@@ -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<ManagedAgent, "pubkey" | "status">[],
) {
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],
@@ -22,6 +22,9 @@ import { normalizePubkey } from "@/shared/lib/pubkey";
type WorkingAgentName = Pick<ManagedAgent, "pubkey" | "name">;
type WorkingAgent = Pick<ManagedAgent, "pubkey" | "name" | "status">;
type PillDiagProfile = UserProfileSummary & {
pubkey?: string;
};
type OwnedRelayWorkingAgent = Pick<RelayAgent, "pubkey" | "name"> & {
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<RelayAgent, "pubkey" | "name">[];
profiles: Record<string, UserProfileSummary> | 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(