/** * @file SessionCard.tsx * @description Compact session card for the Kanban board's "Sessions" view. * Mirrors AgentCard's information hierarchy (icon · title · meta line) but * surfaces session-relevant fields: model, agent count, cost, last activity. * Clicking the card navigates to the session detail page. * @author Nguyễn Ngọc Trí Vĩ */ /* ============================================================================= * MODULE_GUIDE — extended in-file reference (comments only; safe to read, never executed) * ============================================================================= * **Purpose:** Dashboard module consumed by the React client, MCP tools, or desktop shell depending on deployment mode. * * ## Design constraints * - Local-first: no telemetry leaves the machine unless the user configures webhooks. * - Fail-safe hooks path on the server must never block Claude Code; UI mirrors that * philosophy by degrading gracefully (empty states, stale badges, reconnect loops). * - Destructive flows stay behind explicit confirmation modals and server-side gates. * - Internationalization: user-visible strings belong in i18n JSON, not literals here. * * ## Remote data & SSH * Remote Data Sources let operators aggregate multiple machines. SSH entries describe * how to reach a peer dashboard; the global data scope (`dataScope.ts`) narrows every * scoped GET via `?sources=`. Health checks and import history surface in Settings. * * ## Internal dependencies * - `./StatusBadge` * - `../lib/types` * - `../lib/format` * * ## Public surface * - `SessionCard` — exported API; see TSDoc on the symbol for behavior. * * ## Testing pointers * - Prefer colocated `__tests__` with Vitest + Testing Library for UI. * - Server contract changes require `npm run test:server` and OpenAPI sync. * - MCP edits: `npm run mcp:typecheck` and `npm run mcp:build`. * * ## Related docs * - `ARCHITECTURE.md` — hooks → API → SQLite → WebSocket → UI pipeline. * - `docs/API.md` — REST reference. * - `.claude/skills/file-headers/` — mandatory `@author` header policy. * ============================================================================= */ /* ----------------------------------------------------------------------------- * EXPORT CATALOG — quick index of symbols defined below (documentation only). * ----------------------------------------------------------------------------- * **SessionCard** * Part of this module's public contract. Downstream imports should treat * the signature and return type as stable unless release notes say otherwise. * When behavior changes, update the `@file` overview and relevant tests. * * ----------------------------------------------------------------------------- */ import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; import { FolderOpen, Bot, Clock, Coins, Cpu } from "lucide-react"; import { SessionStatusBadge } from "./StatusBadge"; import { effectiveSessionStatus, isSessionAwaitingInput, sessionAwaitingReason, } from "../lib/types"; import type { Session } from "../lib/types"; import { formatDuration, timeAgo, formatModelName } from "../lib/format"; interface SessionCardProps { session: Session; onClick?: () => void; } function formatCost(cost: number): string { if (!Number.isFinite(cost) || cost <= 0) return "$0"; if (cost >= 1) return `$${cost.toFixed(2)}`; if (cost >= 0.01) return `$${cost.toFixed(3)}`; return `$${cost.toFixed(4)}`; } export function SessionCard({ session, onClick }: SessionCardProps) { const navigate = useNavigate(); const { t } = useTranslation("kanban"); const isActive = session.status === "active"; const isWaiting = isSessionAwaitingInput(session); const status = effectiveSessionStatus(session); const title = session.name?.trim() || t("session.anonymous"); const agentCount = session.agent_count ?? 0; const model = formatModelName(session.model); const lastActivity = session.last_activity || session.ended_at || session.started_at; function handleClick() { if (onClick) onClick(); else navigate(`/sessions/${session.id}`); } return (

{title}

{session.id.slice(0, 12)}

{/* compact: cards are narrow — inline reason chip would squeeze the title, so the reason stays hover-tooltip-only here. */}
{session.cwd && (

{session.cwd}

)}
{t("session.agentSummary", { count: agentCount })} {model && ( {model} )} {typeof session.cost === "number" && session.cost > 0 && ( {formatCost(session.cost)} )} {session.ended_at ? `${t("ran")}${formatDuration(session.started_at, session.ended_at)}` : `${t("running")}${formatDuration(session.started_at, new Date().toISOString())}`} {timeAgo(session.ended_at || lastActivity)}
); }