Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Added

- **Topology shows what each session is actually doing.** A session whose turn
finished reads "Your turn" instead of "Idle", turns a dimmed "Inactive" after
2 minutes without events, and shows "active 3m ago" instead of its start time.
The developer node counts active and inactive sessions separately, and an
edge animates only while its session is working. Finished subagents collapse
into one "✓ N subagents done" card per session instead of vanishing after 30 s.
`/api/sessions/active` returns each session's `lastEventAt` for this (timing
only, so it is also visible in the `activity` view).

- **Louder server voice.** `/api/ai/voice-audio` takes an optional `volume`
(Kokoro `volume_multiplier`, 0.5-3); the default `TTS_VOLUME=2` doubles the
loudness without clipping (Kokoro keeps peaks limited).
Expand Down
6 changes: 4 additions & 2 deletions packages/backend/src/db/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,16 @@ export async function getActiveAgents(sql: SQL) {
export async function getActiveSessions(sql: SQL, developerIds?: string[]) {
if (developerIds !== undefined) {
return await sql`
SELECT s.*, d.name as developer_name, d.email as developer_email, d.share_details as owner_share_details
SELECT s.*, d.name as developer_name, d.email as developer_email, d.share_details as owner_share_details,
LEAST((SELECT MAX(e.created_at) FROM events e WHERE e.session_id = s.id), NOW()) as last_event_at
FROM sessions s
JOIN developers d ON s.developer_id = d.id
WHERE s.status = 'active' AND s.developer_id IN (${inList(developerIds)})
ORDER BY s.started_at DESC`;
}
return await sql`
SELECT s.*, d.name as developer_name, d.email as developer_email, d.share_details as owner_share_details
SELECT s.*, d.name as developer_name, d.email as developer_email, d.share_details as owner_share_details,
LEAST((SELECT MAX(e.created_at) FROM events e WHERE e.session_id = s.id), NOW()) as last_event_at
FROM sessions s
JOIN developers d ON s.developer_id = d.id
WHERE s.status = 'active'
Expand Down
22 changes: 22 additions & 0 deletions packages/backend/src/routes/__tests__/sessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ describe("GET /sessions", () => {
projectName: "my-project",
startedAt: "2026-03-01T10:00:00Z",
endedAt: null,
lastEventAt: null,
status: "active",
permissionMode: "default",
privacyMode: "standard",
Expand Down Expand Up @@ -282,6 +283,27 @@ describe("GET /sessions/active", () => {
expect(s2.activeAgents[0].agentId).toBe("agent-3");
});

test("returns lastEventAt, also for a teammate's activity-only session", async () => {
const own = makeSessionRow({ id: "sess-1", last_event_at: "2026-03-01T10:09:00Z" });
const teammate = makeSessionRow({
id: "sess-2",
developer_id: "dev-bbb",
owner_share_details: false,
last_event_at: "2026-03-01T10:08:00Z",
});
mockGetActiveSessions.mockImplementation(() => Promise.resolve([own, teammate]));
mockGetActiveAgents.mockImplementation(() => Promise.resolve([]));
mockGetAllDeveloperIdsForUser.mockImplementation(() => Promise.resolve(["dev-aaa"]));

const app = buildApp({ orgDeveloperIds: ["dev-aaa", "dev-bbb"], user: { id: "user-1" } });
const body = await (await app.request("/sessions/active")).json();

expect(body.find((s: any) => s.id === "sess-1").lastEventAt).toBe("2026-03-01T10:09:00Z");
const s2 = body.find((s: any) => s.id === "sess-2");
expect(s2.lastEventAt).toBe("2026-03-01T10:08:00Z");
expect(s2.projectName).toBeNull();
});

test("passes orgDeveloperIds to getActiveSessions", async () => {
const devIds = ["dev-aaa"];
const app = buildApp({ orgDeveloperIds: devIds });
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/routes/sessions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function mapSession(row: any) {
projectName: row.project_name ?? null,
startedAt: row.started_at,
endedAt: row.ended_at,
lastEventAt: row.last_event_at ?? null,
status: row.status,
permissionMode: row.permission_mode ?? null,
privacyMode: row.privacy_mode ?? null,
Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/services/visibility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function visibilityForRow(row: any, viewerDevIds: string[]): Visibility {
// column added later stays hidden until someone decides it is safe to show.
const ACTIVITY_SESSION_KEYS = [
"id", "developer_id", "developer_name", "developer_email",
"started_at", "ended_at", "status", "event_count", "context_clear_count",
"started_at", "ended_at", "last_event_at", "status", "event_count", "context_clear_count",
] as const;

const ACTIVITY_EVENT_KEYS = [
Expand Down
29 changes: 11 additions & 18 deletions packages/dashboard/src/components/flow/AgentNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const EVENT_COLORS: Record<string, string> = {
};

export function AgentNode({ data }: NodeProps & { data: AgentNodeData }) {
const { agentId, agentType, startedAt, latestEvent, isToolRunning, currentToolName, isStopped } = data;
const { agentId, agentType, startedAt, latestEvent, isToolRunning, currentToolName } = data;

const debounced = useDebouncedToolState(isToolRunning, currentToolName, latestEvent);

Expand All @@ -61,11 +61,9 @@ export function AgentNode({ data }: NodeProps & { data: AgentNodeData }) {
}
}

const borderColor = isStopped
? "rgba(34, 197, 94, 0.4)" // green-500/40
: debounced.isToolRunning
? "rgba(245, 158, 11, 0.4)" // amber-500/40
: "rgba(168, 85, 247, 0.4)"; // purple-500/40
const borderColor = debounced.isToolRunning
? "rgba(245, 158, 11, 0.4)" // amber-500/40
: "rgba(168, 85, 247, 0.4)"; // purple-500/40

return (
<motion.div
Expand All @@ -75,19 +73,15 @@ export function AgentNode({ data }: NodeProps & { data: AgentNodeData }) {
className="rounded-xl border bg-gray-900 px-3 py-2 shadow-lg"
style={{ width: 240, borderWidth: 1 }}
>
<Handle type="target" position={Position.Top} className={isStopped ? "!bg-green-500" : "!bg-purple-500"} />
<Handle type="target" position={Position.Top} className="!bg-purple-500" />

<div className="flex items-center gap-2">
{isStopped ? (
<span className="h-2 w-2 shrink-0 rounded-full bg-green-400" />
) : (
<motion.span
className="h-2 w-2 shrink-0 rounded-full bg-purple-400"
animate={{ opacity: [1, 0.4, 1] }}
transition={{ duration: 1.4, repeat: Infinity, ease: "easeInOut" }}
/>
)}
<span className={`truncate text-sm font-medium ${isStopped ? "text-green-200" : "text-purple-200"}`}>
<motion.span
className="h-2 w-2 shrink-0 rounded-full bg-purple-400"
animate={{ opacity: [1, 0.4, 1] }}
transition={{ duration: 1.4, repeat: Infinity, ease: "easeInOut" }}
/>
<span className="truncate text-sm font-medium text-purple-200">
{agentType}
</span>
</div>
Expand All @@ -104,7 +98,6 @@ export function AgentNode({ data }: NodeProps & { data: AgentNodeData }) {
displayEvent={debounced.displayEvent}
/>

<Handle type="source" position={Position.Bottom} className={isStopped ? "!bg-green-500" : "!bg-purple-500"} />
</motion.div>
);
}
28 changes: 28 additions & 0 deletions packages/dashboard/src/components/flow/AgentSummaryNode.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Handle, Position, type NodeProps } from "@xyflow/react";
import { motion } from "motion/react";
import { Check } from "lucide-react";
import type { AgentSummaryNodeData } from "./flowTypes";

export function AgentSummaryNode({ data }: NodeProps & { data: AgentSummaryNodeData }) {
const { total, types } = data;

return (
<motion.div
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"
style={{ width: 240 }}
>
<Handle type="target" position={Position.Top} className="!bg-gray-600" />

<div className="flex items-center gap-2 text-sm font-medium text-gray-300">
<Check className="h-3.5 w-3.5 shrink-0 text-emerald-400" />
{total} subagent{total !== 1 ? "s" : ""} done
</div>
<div className="mt-1 truncate text-xs text-gray-500">
{types.map((t) => (t.count > 1 ? `${t.agentType} ×${t.count}` : t.agentType)).join(" · ")}
</div>
</motion.div>
);
}
21 changes: 14 additions & 7 deletions packages/dashboard/src/components/flow/DeveloperNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ function getInitials(name: string): string {
}

export function DeveloperNode({ data }: NodeProps & { data: DeveloperNodeData }) {
const { developer, sessionCount } = data;
const isActive = sessionCount > 0;
const { developer, activeCount, inactiveCount } = data;
const isActive = activeCount > 0;

const borderColor = isActive
? "rgba(16, 185, 129, 0.6)" // emerald-500/60
Expand Down Expand Up @@ -43,11 +43,18 @@ export function DeveloperNode({ data }: NodeProps & { data: DeveloperNodeData })
</div>
</div>
</div>
{sessionCount > 0 && (
<div className="mt-2 text-center">
<span className="rounded-full bg-emerald-500/15 px-2 py-0.5 text-xs font-medium text-emerald-400">
{sessionCount} active session{sessionCount !== 1 ? "s" : ""}
</span>
{(activeCount > 0 || inactiveCount > 0) && (
<div className="mt-2 flex justify-center gap-1.5">
{activeCount > 0 && (
<span className="rounded-full bg-emerald-500/15 px-2 py-0.5 text-xs font-medium text-emerald-400">
{activeCount} active
</span>
)}
{inactiveCount > 0 && (
<span className="rounded-full bg-gray-700 px-2 py-0.5 text-xs font-medium text-gray-400">
{inactiveCount} inactive
</span>
)}
</div>
)}
<Handle type="source" position={Position.Bottom} className="!bg-gray-600" />
Expand Down
13 changes: 3 additions & 10 deletions packages/dashboard/src/components/flow/FlowView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@ import {
MiniMap,
} from "@xyflow/react";
import "@xyflow/react/dist/style.css";
import { DeveloperNode } from "./DeveloperNode";
import { SessionNode } from "./SessionNode";
import { AgentNode } from "./AgentNode";
import { nodeTypes } from "./nodeTypes";
import { useFlowLayout } from "./useFlowLayout";
import { useActivityStore } from "@/stores/activityStore";

const nodeTypes = {
developer: DeveloperNode,
session: SessionNode,
agent: AgentNode,
};

class FlowErrorBoundary extends Component<
{ children: ReactNode },
{ hasError: boolean }
Expand Down Expand Up @@ -55,7 +47,7 @@ export function FlowView() {
const connected = useActivityStore((s) => s.connected);
const cleanupStale = useActivityStore((s) => s.cleanupStale);

// Periodically remove ended sessions and stopped agents after grace period
// Periodically remove ended sessions after a grace period, with their finished agents
useEffect(() => {
const id = setInterval(cleanupStale, CLEANUP_INTERVAL_MS);
return () => clearInterval(id);
Expand Down Expand Up @@ -97,6 +89,7 @@ export function FlowView() {
nodeColor={(node) => {
if (node.type === "developer") return "#10b981";
if (node.type === "agent") return "#a855f7";
if (node.type === "agentSummary") return "#374151";
return "#6b7280";
}}
maskColor="rgba(0, 0, 0, 0.7)"
Expand Down
15 changes: 10 additions & 5 deletions packages/dashboard/src/components/flow/SessionNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,17 @@ const STATE_CONFIG: Record<SessionActivityState, {
pulse: true,
},
idle: {
label: "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",
Expand All @@ -110,8 +116,7 @@ const STATE_PULSE_COLORS: Record<string, string> = {
};

export function SessionNode({ data }: NodeProps & { data: SessionNodeData }) {
const { session, developerName, latestEvent, isToolRunning, currentToolName, activityState } = data;
const startedAt = session.startedAt ?? "";
const { session, developerName, latestEvent, isToolRunning, currentToolName, activityState, lastActivityAt } = data;
const isDangerousMode = session.permissionMode === "dangerously-skip-permissions";
const isRedactedMode = session.privacyMode === "private";

Expand Down Expand Up @@ -148,7 +153,7 @@ export function SessionNode({ data }: NodeProps & { data: SessionNodeData }) {
<motion.div
onClick={() => { navigate(`/dashboard/sessions/${session.id}`); }}
initial={{ opacity: 0, y: 12 }}
animate={{ opacity: 1, y: 0, borderColor: stateConfig.borderColor }}
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"
style={{ width: 280, borderWidth: 1 }}
Expand Down Expand Up @@ -194,7 +199,7 @@ export function SessionNode({ data }: NodeProps & { data: SessionNodeData }) {
</div>

<div className="mt-1 text-xs text-gray-600">
{startedAt ? timeAgo(startedAt) : ""}
active {timeAgo(lastActivityAt)}
</div>

<ActivityBadge
Expand Down
17 changes: 15 additions & 2 deletions packages/dashboard/src/components/flow/flowTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ export type SessionActivityState =
| "waiting"
| "compacting"
| "idle"
| "inactive"
| "ended";

export interface DeveloperNodeData {
[key: string]: unknown;
developer: Developer;
sessionCount: number;
/** Sessions neither inactive nor ended. */
activeCount: number;
inactiveCount: number;
}

export interface SessionNodeData {
Expand All @@ -24,6 +27,8 @@ export interface SessionNodeData {
isToolRunning: boolean;
currentToolName: string | null;
activityState: SessionActivityState;
/** Latest event of the session or its subagents, else its start. */
lastActivityAt: string;
}

export interface AgentNodeData {
Expand All @@ -35,5 +40,13 @@ export interface AgentNodeData {
latestEvent: FeedEvent | null;
isToolRunning: boolean;
currentToolName: string | null;
isStopped: boolean;
}

/** All finished subagents of one session, collapsed into a single node. */
export interface AgentSummaryNodeData {
[key: string]: unknown;
sessionId: string;
total: number;
/** Count per agent type, most frequent first. */
types: { agentType: string; count: number }[];
}
54 changes: 54 additions & 0 deletions packages/dashboard/src/components/flow/layout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import dagre from "@dagrejs/dagre";
import type { Node, Edge } from "@xyflow/react";

const NODE_WIDTH_DEVELOPER = 200;
const NODE_HEIGHT_DEVELOPER = 90;
const NODE_WIDTH_SESSION = 280;
const NODE_HEIGHT_SESSION = 160;
const NODE_WIDTH_AGENT = 240;
const NODE_HEIGHT_AGENT = 110;
const NODE_HEIGHT_AGENT_SUMMARY = 64;

function getNodeDimensions(type: string): { width: number; height: number } {
switch (type) {
case "developer":
return { width: NODE_WIDTH_DEVELOPER, height: NODE_HEIGHT_DEVELOPER };
case "agent":
return { width: NODE_WIDTH_AGENT, height: NODE_HEIGHT_AGENT };
case "agentSummary":
return { width: NODE_WIDTH_AGENT, height: NODE_HEIGHT_AGENT_SUMMARY };
default:
return { width: NODE_WIDTH_SESSION, height: NODE_HEIGHT_SESSION };
}
}

export function getLayoutedElements(
nodes: Node[],
edges: Edge[],
): { nodes: Node[]; edges: Edge[] } {
const g = new dagre.graphlib.Graph();
g.setDefaultEdgeLabel(() => ({}));
g.setGraph({ rankdir: "TB", nodesep: 40, ranksep: 80 });

for (const node of nodes) {
const { width, height } = getNodeDimensions(node.type ?? "session");
g.setNode(node.id, { width, height });
}

for (const edge of edges) {
g.setEdge(edge.source, edge.target);
}

dagre.layout(g);

const layoutedNodes = nodes.map((node) => {
const pos = g.node(node.id);
const { width, height } = getNodeDimensions(node.type ?? "session");
return {
...node,
position: { x: pos.x - width / 2, y: pos.y - height / 2 },
};
});

return { nodes: layoutedNodes, edges };
}
Loading
Loading