diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a73cc5..dfd53a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Added +- **Topology detail panel.** Clicking a session or subagent opens a live side + panel instead of leaving the page: state, branch, title, last active, model, + tokens and cost (own sessions only), its subagents, the last 15 events, and a + link to the full session. The graph stays usable behind it; Esc or a click on + the background closes it. + - **Tell topology sessions and subagents apart.** Session cards show the git branch (new `sessions.git_branch`, migration 057, from `session.start`; never stored for `private` sessions) in place of the developer name the parent node diff --git a/packages/dashboard/src/components/flow/AgentNode.tsx b/packages/dashboard/src/components/flow/AgentNode.tsx index c5552f2..dc95cd2 100644 --- a/packages/dashboard/src/components/flow/AgentNode.tsx +++ b/packages/dashboard/src/components/flow/AgentNode.tsx @@ -41,7 +41,7 @@ const EVENT_COLORS: Record = { "teammate.idle": "text-gray-400 bg-gray-500/15", }; -export function AgentNode({ data }: NodeProps & { data: AgentNodeData }) { +export function AgentNode({ data, selected }: NodeProps & { data: AgentNodeData }) { const { agentId, agentType, description, model, startedAt, latestEvent, isToolRunning, currentToolName } = data; const debounced = useDebouncedToolState(isToolRunning, currentToolName, latestEvent); @@ -70,7 +70,7 @@ export function AgentNode({ data }: NodeProps & { data: AgentNodeData }) { initial={{ opacity: 0, scale: 0.85 }} animate={{ opacity: 1, scale: 1, borderColor }} transition={{ type: "spring", stiffness: 500, damping: 35 }} - className="rounded-xl border bg-gray-900 px-3 py-2 shadow-lg" + className={`rounded-xl border bg-gray-900 px-3 py-2 shadow-lg cursor-pointer hover:brightness-110 ${selected ? "ring-2 ring-blue-400/60" : ""}`} style={{ width: 240, borderWidth: 1 }} > diff --git a/packages/dashboard/src/components/flow/AgentSummaryNode.tsx b/packages/dashboard/src/components/flow/AgentSummaryNode.tsx index d451cdc..5ec5d69 100644 --- a/packages/dashboard/src/components/flow/AgentSummaryNode.tsx +++ b/packages/dashboard/src/components/flow/AgentSummaryNode.tsx @@ -11,7 +11,7 @@ export function AgentSummaryNode({ data }: NodeProps & { data: AgentSummaryNodeD initial={{ opacity: 0, scale: 0.85 }} animate={{ opacity: 1, scale: 1 }} transition={{ type: "spring", stiffness: 500, damping: 35 }} - className="rounded-xl border border-gray-700 bg-gray-900 px-3 py-2 shadow-lg" + className="cursor-pointer rounded-xl border border-gray-700 bg-gray-900 px-3 py-2 shadow-lg hover:brightness-110" style={{ width: 240 }} > diff --git a/packages/dashboard/src/components/flow/DetailPanel.tsx b/packages/dashboard/src/components/flow/DetailPanel.tsx new file mode 100644 index 0000000..c85165f --- /dev/null +++ b/packages/dashboard/src/components/flow/DetailPanel.tsx @@ -0,0 +1,191 @@ +import type { ReactNode } from "react"; +import type { Node } from "@xyflow/react"; +import { Link } from "wouter"; +import { GitBranch, X, ExternalLink, Check } from "lucide-react"; +import type { FeedEvent } from "@devscope/shared"; +import type { SessionNodeData, AgentNodeData, AgentSummaryNodeData } from "./flowTypes"; +import { STATE_CONFIG } from "./sessionStates"; +import { EVENT_LABELS, getEventSummary } from "@/lib/eventDisplay"; +import { formatCost, formatTokenCount, timeAgo } from "@/lib/utils"; +import { ProjectLabel } from "@/components/ProjectLabel"; + +interface DetailPanelProps { + node: Node; + /** All topology nodes, to list a session's subagents. */ + nodes: Node[]; + onClose: () => void; +} + +/** Side panel for the selected topology node; follows its live data. */ +export function DetailPanel({ node, nodes, onClose }: DetailPanelProps) { + return ( + + ); +} + +function SessionDetails({ data, nodes }: { data: SessionNodeData; nodes: Node[] }) { + const { session, activityState, lastActivityAt, recentEvents } = data; + const state = STATE_CONFIG[activityState]; + const agents = nodes.filter( + (n) => n.type === "agent" && (n.data as AgentNodeData).sessionId === session.id, + ); + const done = nodes.find( + (n) => n.type === "agentSummary" && (n.data as AgentSummaryNodeData).sessionId === session.id, + )?.data as AgentSummaryNodeData | undefined; + // Usage is only returned for the viewer's own sessions. + const hasUsage = session.tokenSource != null; + const totalTokens = + (session.totalInputTokens ?? 0) + + (session.totalOutputTokens ?? 0) + + (session.totalCacheCreationTokens ?? 0) + + (session.totalCacheReadTokens ?? 0); + + return ( +
+
+
+ + + {state.label} + +
+ {session.gitBranch ? ( +
+ + {session.gitBranch} +
+ ) : null} + {session.currentTitle ? ( +

{session.currentTitle}

+ ) : null} +
+ +
+ {timeAgo(lastActivityAt)} + {timeAgo(session.startedAt)} + {session.model ? {session.model} : null} + {hasUsage ? ( + + {formatTokenCount(totalTokens)} · {formatCost(session.estimatedCostUsd ?? 0)} + + ) : null} +
+ + {agents.length > 0 || done ? ( +
+
    + {agents.map((n) => { + const agent = n.data as AgentNodeData; + return ( +
  • + {agent.agentType} + {agent.model ? {agent.model} : null} + {agent.description ?
    {agent.description}
    : null} +
  • + ); + })} + {done ? ( +
  • + + {done.total} done: {done.types.map((t) => `${t.agentType} ×${t.count}`).join(", ")} +
  • + ) : null} +
+
+ ) : null} + + + + +
+ ); +} + +function AgentDetails({ data }: { data: AgentNodeData }) { + return ( +
+
+
+ {data.agentType} + Running +
+ {data.description ?

{data.description}

: null} +
+ +
+ {timeAgo(data.startedAt)} + {data.model ? {data.model} : null} +
+ + + + +
+ ); +} + +function RecentActivity({ events }: { events: FeedEvent[] }) { + return ( +
+ {events.length === 0 ? ( +

No recent events.

+ ) : ( +
    + {events.map((event) => ( +
  • + {EVENT_LABELS[event.eventType] ?? event.eventType} + {getEventSummary(event)} + {timeAgo(event.timestamp)} +
  • + ))} +
+ )} +
+ ); +} + +function FullSessionLink({ sessionId }: { sessionId: string }) { + return ( + + Open full session + + ); +} + +function Section({ title, children }: { title: string; children: ReactNode }) { + return ( +
+

{title}

+ {children} +
+ ); +} + +function Fact({ label, children }: { label: string; children: ReactNode }) { + return ( +
+
{label}
+
{children}
+
+ ); +} diff --git a/packages/dashboard/src/components/flow/FlowView.tsx b/packages/dashboard/src/components/flow/FlowView.tsx index 15c3ba5..6afab5c 100644 --- a/packages/dashboard/src/components/flow/FlowView.tsx +++ b/packages/dashboard/src/components/flow/FlowView.tsx @@ -1,11 +1,14 @@ -import { Component, useEffect, type ReactNode } from "react"; +import { Component, useEffect, useMemo, useState, type ReactNode } from "react"; import { ReactFlow, Background, Controls, MiniMap, + type Node, } from "@xyflow/react"; import "@xyflow/react/dist/style.css"; +import type { AgentSummaryNodeData } from "./flowTypes"; +import { DetailPanel } from "./DetailPanel"; import { nodeTypes } from "./nodeTypes"; import { useFlowLayout } from "./useFlowLayout"; import { useActivityStore } from "@/stores/activityStore"; @@ -42,10 +45,18 @@ class FlowErrorBoundary extends Component< const CLEANUP_INTERVAL_MS = 10_000; +/** The node whose details a click opens: sessions and agents; the done card opens its session. */ +function selectionFor(node: Node): string | null { + if (node.type === "session" || node.type === "agent") return node.id; + if (node.type === "agentSummary") return `session-${(node.data as AgentSummaryNodeData).sessionId}`; + return null; +} + export function FlowView() { const { nodes: layoutNodes, edges: layoutEdges } = useFlowLayout(); const connected = useActivityStore((s) => s.connected); const cleanupStale = useActivityStore((s) => s.cleanupStale); + const [selectedId, setSelectedId] = useState(null); // Periodically remove ended sessions after a grace period, with their finished agents useEffect(() => { @@ -53,6 +64,22 @@ export function FlowView() { return () => clearInterval(id); }, [cleanupStale]); + useEffect(() => { + if (!selectedId) return; + const onKey = (e: KeyboardEvent) => { + if (e.key === "Escape") setSelectedId(null); + }; + window.addEventListener("keydown", onKey); + return () => window.removeEventListener("keydown", onKey); + }, [selectedId]); + + // The panel follows the node's live data and closes when the node goes away. + const selectedNode = selectedId ? layoutNodes.find((n) => n.id === selectedId) : undefined; + const nodes = useMemo( + () => layoutNodes.map((n) => (n.id === selectedNode?.id ? { ...n, selected: true } : n)), + [layoutNodes, selectedNode?.id], + ); + if (layoutNodes.length === 0 && connected) { return (
@@ -71,12 +98,15 @@ export function FlowView() { } return ( -
+
setSelectedId(selectionFor(node))} + onPaneClick={() => setSelectedId(null)} + elementsSelectable={false} fitView proOptions={{ hideAttribution: true }} > @@ -95,6 +125,9 @@ export function FlowView() { maskColor="rgba(0, 0, 0, 0.7)" /> + {selectedNode ? ( + setSelectedId(null)} /> + ) : null}
); diff --git a/packages/dashboard/src/components/flow/SessionNode.tsx b/packages/dashboard/src/components/flow/SessionNode.tsx index df60753..896cc87 100644 --- a/packages/dashboard/src/components/flow/SessionNode.tsx +++ b/packages/dashboard/src/components/flow/SessionNode.tsx @@ -1,8 +1,8 @@ import { Handle, Position, type NodeProps } from "@xyflow/react"; import { motion } from "motion/react"; -import { navigate } from "wouter/use-browser-location"; import type { SessionNodeData } from "./flowTypes"; import type { SessionActivityState } from "./flowTypes"; +import { STATE_CONFIG, STATE_PULSE_COLORS } from "./sessionStates"; import type { PromptEventPayload, AgentEventPayload } from "@devscope/shared"; import { ShieldOff, Lock, GitBranch } from "lucide-react"; import { ActivityBadge } from "./ActivityBadge"; @@ -58,64 +58,7 @@ const EVENT_COLORS: Record = { "teammate.idle": "text-gray-400 bg-gray-500/15", }; -const STATE_CONFIG: Record = { - running: { - label: "Running", - badgeClass: "bg-amber-500/15 text-amber-400", - borderColor: "rgba(245, 158, 11, 0.4)", - pulse: true, - }, - thinking: { - label: "Thinking", - badgeClass: "bg-blue-500/15 text-blue-400", - borderColor: "rgba(59, 130, 246, 0.4)", - pulse: true, - }, - waiting: { - label: "Waiting", - badgeClass: "bg-orange-500/15 text-orange-400", - borderColor: "rgba(249, 115, 22, 0.4)", - pulse: true, - }, - compacting: { - label: "Compacting", - badgeClass: "bg-purple-500/15 text-purple-400", - borderColor: "rgba(168, 85, 247, 0.4)", - pulse: true, - }, - idle: { - label: "Your turn", - badgeClass: "bg-emerald-500/15 text-emerald-400", - borderColor: "rgba(16, 185, 129, 0.4)", - pulse: false, - }, - inactive: { - label: "Inactive", - badgeClass: "bg-gray-700 text-gray-400", - borderColor: "rgba(55, 65, 81, 1)", - pulse: false, - }, - ended: { - label: "Ended", - badgeClass: "bg-gray-700 text-gray-400", - borderColor: "rgba(55, 65, 81, 1)", - pulse: false, - }, -}; - -const STATE_PULSE_COLORS: Record = { - running: "bg-amber-400", - thinking: "bg-blue-400", - waiting: "bg-orange-400", - compacting: "bg-purple-400", -}; - -export function SessionNode({ data }: NodeProps & { data: SessionNodeData }) { +export function SessionNode({ data, selected }: NodeProps & { data: SessionNodeData }) { const { session, latestEvent, isToolRunning, currentToolName, activityState, lastActivityAt } = data; const isDangerousMode = session.permissionMode === "dangerously-skip-permissions"; const isRedactedMode = session.privacyMode === "private"; @@ -151,11 +94,10 @@ export function SessionNode({ data }: NodeProps & { data: SessionNodeData }) { return ( { navigate(`/dashboard/sessions/${session.id}`); }} initial={{ opacity: 0, y: 12 }} animate={{ opacity: displayState === "inactive" ? 0.55 : 1, y: 0, borderColor: stateConfig.borderColor }} transition={{ type: "spring", stiffness: 500, damping: 35 }} - className="rounded-xl border bg-gray-900 px-4 py-3 shadow-lg cursor-pointer hover:brightness-110" + className={`rounded-xl border bg-gray-900 px-4 py-3 shadow-lg cursor-pointer hover:brightness-110 ${selected ? "ring-2 ring-blue-400/60" : ""}`} style={{ width: 280, borderWidth: 1 }} > diff --git a/packages/dashboard/src/components/flow/flowTypes.ts b/packages/dashboard/src/components/flow/flowTypes.ts index be5303a..bde2ff6 100644 --- a/packages/dashboard/src/components/flow/flowTypes.ts +++ b/packages/dashboard/src/components/flow/flowTypes.ts @@ -41,6 +41,8 @@ export interface AgentNodeData { latestEvent: FeedEvent | null; isToolRunning: boolean; currentToolName: string | null; + /** Newest first, for the detail panel. */ + recentEvents: FeedEvent[]; } /** All finished subagents of one session, collapsed into a single node. */ diff --git a/packages/dashboard/src/components/flow/sessionStates.ts b/packages/dashboard/src/components/flow/sessionStates.ts new file mode 100644 index 0000000..2a72e81 --- /dev/null +++ b/packages/dashboard/src/components/flow/sessionStates.ts @@ -0,0 +1,59 @@ +import type { SessionActivityState } from "./flowTypes"; + +/** Badge, border and pulse per session state, shared by the node and the detail panel. */ +export const STATE_CONFIG: Record = { + running: { + label: "Running", + badgeClass: "bg-amber-500/15 text-amber-400", + borderColor: "rgba(245, 158, 11, 0.4)", + pulse: true, + }, + thinking: { + label: "Thinking", + badgeClass: "bg-blue-500/15 text-blue-400", + borderColor: "rgba(59, 130, 246, 0.4)", + pulse: true, + }, + waiting: { + label: "Waiting", + badgeClass: "bg-orange-500/15 text-orange-400", + borderColor: "rgba(249, 115, 22, 0.4)", + pulse: true, + }, + compacting: { + label: "Compacting", + badgeClass: "bg-purple-500/15 text-purple-400", + borderColor: "rgba(168, 85, 247, 0.4)", + pulse: true, + }, + idle: { + label: "Your turn", + badgeClass: "bg-emerald-500/15 text-emerald-400", + borderColor: "rgba(16, 185, 129, 0.4)", + pulse: false, + }, + inactive: { + label: "Inactive", + badgeClass: "bg-gray-700 text-gray-400", + borderColor: "rgba(55, 65, 81, 1)", + pulse: false, + }, + ended: { + label: "Ended", + badgeClass: "bg-gray-700 text-gray-400", + borderColor: "rgba(55, 65, 81, 1)", + pulse: false, + }, +}; + +export const STATE_PULSE_COLORS: Record = { + running: "bg-amber-400", + thinking: "bg-blue-400", + waiting: "bg-orange-400", + compacting: "bg-purple-400", +}; diff --git a/packages/dashboard/src/components/flow/useFlowLayout.ts b/packages/dashboard/src/components/flow/useFlowLayout.ts index f706451..0cd17df 100644 --- a/packages/dashboard/src/components/flow/useFlowLayout.ts +++ b/packages/dashboard/src/components/flow/useFlowLayout.ts @@ -21,6 +21,9 @@ const NOW_REFRESH_MS = 10_000; /** States in which the session is doing work, so its edge animates. */ const WORKING_STATES = new Set(["running", "thinking", "compacting"]); +/** Events kept per node for the detail panel. */ +const RECENT_EVENT_LIMIT = 15; + const TOOL_EVENT_TYPES = new Set(["tool.start", "tool.complete", "tool.fail"]); /** @@ -249,6 +252,7 @@ export function useFlowLayout(): { nodes: Node[]; edges: Edge[] } { latestEvent: null, isToolRunning: false, currentToolName: null, + recentEvents: [], }; nodes.push({ @@ -324,7 +328,7 @@ export function useFlowLayout(): { nodes: Node[]; edges: Edge[] } { const { sessionEvents: ownEvents } = attributeEventsToAgents(allSessionEvents, sessionAgents, events); - const recentEvents = ownEvents.slice(0, 3); + const recentEvents = ownEvents.slice(0, RECENT_EVENT_LIMIT); const latestEvent = ownEvents[0] ?? latestSessionEvents[sessionId] ?? null; let isToolRunning = false; @@ -388,6 +392,7 @@ export function useFlowLayout(): { nodes: Node[]; edges: Edge[] } { data: { ...data, latestEvent: agentLatest, + recentEvents: agentEvts.slice(0, RECENT_EVENT_LIMIT), isToolRunning: agentToolRunning, currentToolName: agentToolName, }, diff --git a/packages/dashboard/src/components/landing/demoTopologyData.ts b/packages/dashboard/src/components/landing/demoTopologyData.ts index 29ebf68..6592869 100644 --- a/packages/dashboard/src/components/landing/demoTopologyData.ts +++ b/packages/dashboard/src/components/landing/demoTopologyData.ts @@ -159,6 +159,7 @@ export function buildDemoLayout(): { nodes: Node[]; edges: Edge[] } { latestEvent: null, isToolRunning: false, currentToolName: null, + recentEvents: [], }; nodes.push({ id: `agent-${a.agentId}`, type: "agent", position: { x: 0, y: 0 }, data }); edges.push({ diff --git a/packages/shared/src/models.ts b/packages/shared/src/models.ts index a06a148..1d12745 100644 --- a/packages/shared/src/models.ts +++ b/packages/shared/src/models.ts @@ -27,6 +27,8 @@ export interface Session { status: "active" | "ended"; permissionMode: string | null; privacyMode: PrivacyMode; + /** Claude Code model id at session start (migration 037). */ + model?: string | null; /** Branch at session start; null for private sessions and older plugins. */ gitBranch?: string | null; currentTitle?: string | null;