Skip to content

Your team of AI agents, on your Mac, Windows or Linux. Agents that talk in channels, write code, review each other and use your tools, on the Claude Code, Codex, OpenCode or Pi you already have. Anything that touches the real world waits for your yes.

Open an agent's profile card from its face or name (#134)

Diasc8be362c3a77
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ae8ec55..4fd8e38 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@ What changed in each version of Tucano. The format follows [Keep a Changelog](ht
## [Unreleased]
+### Added
+
+- **An agent's profile card, from its face or name.** A click on an agent's face or name (on its message, in a thread, an `@mention`, the faces at the top of a channel, the top of its DM) opens a small card next to it, as Slack does; resting the mouse there for half a second opens it too, and it goes when the mouse leaves. The card shows its picture, name, `@handle` and role; what it's doing now (working, and on which step, with a link to the conversation; waiting for an answer or an approval, and whose, when there's a team; at its monthly limit; archived; or when it last spoke); its model and harness; its computer; the channels it's in; and buttons to message it or open its full page. The faces at the top of a channel and the name at the top of a DM open the card instead of the agent's page, and the DM's **See profile** button is now a gear for the conversation's settings. People's faces stay as they were. Esc gives the focus back to what opened it. Thanks [@rjgdias](https://github.com/rjgdias)! ([#134](https://github.com/eduwxyz/tucano/pull/134))
+
## [0.2.17] - 2026-11-07
> **Em português:**
diff --git a/scripts/screens-agent-card.mjs b/scripts/screens-agent-card.mjs
new file mode 100644
index 0000000..4b3c6ab
--- /dev/null
+++ b/scripts/screens-agent-card.mjs
@@ -0,0 +1,132 @@
+// Screenshots of an agent's profile card: from a message's face and name, in a thread,
+// at the top of a DM, in the dark and on a narrow window. Fresh data, fake engines.
+// Run after `npm run build`: node scripts/screens-agent-card.mjs [out-dir]
+import { _electron as electron } from 'playwright'
+import { mkdirSync, mkdtempSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { join } from 'node:path'
+
+const out = process.argv[2] ?? 'screens/agent-card'
+mkdirSync(out, { recursive: true })
+const data = mkdtempSync(join(tmpdir(), 'tucano-'))
+const app = await electron.launch({ args: ['.'], env: { ...process.env, TUCANO_DATA: data, TUCANO_SEED: '1', TUCANO_FAKE_ENGINES: '1', TUCANO_LOCALE: process.env.TUCANO_LOCALE ?? 'pt-BR' } })
+const win = await app.firstWindow()
+const errors = []
+win.on('pageerror', (e) => errors.push(String(e)))
+win.on('console', (m) => m.type() === 'error' && errors.push(m.text()))
+await win.setViewportSize({ width: 1280, height: 820 })
+await win.waitForSelector('.sidebar')
+const shot = (name) => win.screenshot({ path: `${out}/${name}.png` })
+const busy = '.msg .shimmer, .msg .typing, .system-line.is-pending'
+async function settle() {
+ const deadline = Date.now() + 20_000
+ let quiet = 0
+ while (Date.now() < deadline && quiet < 3) {
+ await win.waitForTimeout(500)
+ quiet = (await win.locator(busy).count()) === 0 ? quiet + 1 : 0
+ }
+}
+async function send(text) {
+ await win.fill('.composer textarea', text)
+ await win.keyboard.press('Enter')
+ await win.waitForTimeout(400)
+}
+
+// A channel with a reply from an agent.
+await win.locator('.nav-item', { hasText: /^#?\s*geral|general/i }).first().click().catch(() => {})
+await send('@lia o que você acha de revisar o checkout hoje?')
+await settle()
+
+// The face on the reply opens the card next to it.
+await win.locator('.msg--agent .msg__face').last().click()
+await win.waitForSelector('.agent-card')
+await win.waitForTimeout(250)
+await shot('01-card-from-face')
+
+// Esc closes it; the name opens it with the keyboard.
+await win.keyboard.press('Escape')
+await win.locator('.msg--agent .msg__author').last().focus()
+await win.keyboard.press('Enter')
+await win.waitForSelector('.agent-card')
+await win.waitForTimeout(250)
+await shot('02-card-from-name-keyboard')
+console.log('focus moved into the card:', await win.evaluate(() => !!document.activeElement?.closest('.agent-card')))
+await win.keyboard.press('Escape')
+console.log('focus back on the name after Esc:', await win.evaluate(() => !!document.activeElement?.classList.contains('msg__author')))
+
+// Hover: the mouse resting on the @mention opens the card after a moment, without taking focus;
+// it stays while the mouse moves onto the card, and goes once the mouse leaves both.
+await win.mouse.move(700, 600)
+await win.focus('.composer textarea')
+const chip = await win.locator('.msg--me .mention').first().boundingBox()
+await win.mouse.move(chip.x + chip.width / 2, chip.y + chip.height / 2, { steps: 4 })
+await win.waitForTimeout(250)
+const early = await win.locator('.agent-card').count()
+await win.waitForTimeout(450)
+const late = await win.locator('.agent-card').count()
+await shot('08-card-on-hover')
+const typing = await win.evaluate(() => document.activeElement?.tagName === 'TEXTAREA')
+const box = await win.locator('.agent-card').boundingBox()
+await win.mouse.move(box.x + box.width / 2, box.y + 40, { steps: 6 })
+await win.waitForTimeout(800)
+const kept = await win.locator('.agent-card').count()
+await win.mouse.move(700, 650, { steps: 4 })
+await win.waitForTimeout(600)
+const gone = (await win.locator('.agent-card').count()) === 0
+console.log('hover:', { openAt250ms: early > 0, openAt700ms: late > 0, focusStaysInComposer: typing, keptOnCard: kept > 0, goneAfterLeaving: gone })
+
+// While the agent works, the card says on what.
+await send('@theo demore 6 s e calcule a mediana de 3, 9 e 4')
+await win.waitForSelector('.msg .shimmer', { timeout: 10_000 }).catch(() => {})
+await win.locator('.msg--agent .msg__face').last().click()
+await win.waitForSelector('.agent-card')
+await win.waitForTimeout(250)
+await shot('03-card-working')
+await win.keyboard.press('Escape')
+await settle()
+
+// In a thread on the side.
+await win.locator('.msg--agent').last().hover()
+await win.locator('.msg--agent .msg__reply').last().click({ force: true })
+await win.waitForSelector('.thread .msg__face, .thread__lead .msg__face', { timeout: 5000 }).catch(() => {})
+const inThread = win.locator('.thread .msg--agent .msg__face, .thread__lead .msg--agent .msg__face').first()
+if (await inThread.count()) {
+ await inThread.click()
+ await win.waitForSelector('.agent-card')
+ await win.waitForTimeout(250)
+ await shot('04-card-in-thread')
+ await win.keyboard.press('Escape')
+ const threadStillOpen = await win.locator('.side-panel--thread').count()
+ console.log('thread stays open after Esc on the card:', threadStillOpen > 0)
+}
+
+// "Mensagem" on the card opens the DM; its top opens the card again, with the conversation's settings.
+await win.locator('.msg--agent .msg__face').first().click()
+await win.click('.agent-card button:has-text("Mensagem")')
+await win.waitForSelector('.topbar__name[aria-haspopup]')
+await win.click('.topbar__name')
+await win.waitForSelector('.agent-card')
+await win.waitForTimeout(250)
+await shot('05-card-dm-top')
+await win.keyboard.press('Escape')
+
+// Dark.
+await win.evaluate(() => (document.documentElement.dataset.theme = 'dark'))
+await win.click('.topbar__name')
+await win.waitForSelector('.agent-card')
+await win.waitForTimeout(250)
+await shot('06-card-dark')
+await win.keyboard.press('Escape')
+await win.evaluate(() => delete document.documentElement.dataset.theme)
+
+// Narrow, on a reply in the DM.
+await win.setViewportSize({ width: 420, height: 800 })
+await send('oi, tudo certo?')
+await settle()
+await win.locator('.msg--agent .msg__face').last().click()
+await win.waitForSelector('.agent-card')
+await win.waitForTimeout(250)
+await shot('07-card-narrow')
+
+console.log(errors.length ? `errors:\n${errors.join('\n')}` : 'no errors')
+await app.close()
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx
index 33c0da3..00d61e9 100644
--- a/src/renderer/src/App.tsx
+++ b/src/renderer/src/App.tsx
@@ -13,6 +13,7 @@ import { SkillsPage } from './components/Skills'
import { ReportPage } from './components/Report'
import { Onboarding } from './components/Onboarding'
import { Dialogs } from './components/Dialogs'
+import { AgentCardLayer } from './components/AgentCard'
import { WhatsNew } from './components/Update'
import { CoreDown, Toasts } from './components/Toast'
import { Icon } from './components/ui'
@@ -106,6 +107,7 @@ export function App(): ReactNode {
{view.kind === 'report' && <ReportPage />}
{view.kind === 'settings' && <SettingsPage />}
</main>
+ <AgentCardLayer />
<Dialogs />
<NameModal />
<WhatsNew />
diff --git a/src/renderer/src/agent-card.ts b/src/renderer/src/agent-card.ts
new file mode 100644
index 0000000..931c8f1
--- /dev/null
+++ b/src/renderer/src/agent-card.ts
@@ -0,0 +1,148 @@
+// What an agent's profile card says about it right now, and where the card goes on the
+// screen. Kept apart from React so both can be tested without a browser.
+import type { Agent, Conversation, Message } from '../../shared/types'
+
+export type AgentNow =
+ | { kind: 'working'; conversationId: string; doing?: string; since: number }
+ | { kind: 'waiting'; conversationId: string; on: 'input' | 'approval'; askedTo?: string } // askedTo: the person a question is for (team mode)
+ | { kind: 'archived' }
+ | { kind: 'limit' }
+ | { kind: 'idle'; lastAt?: number }
+
+// Archived first (it does nothing), then what it's doing (the latest reply at work, with the
+// step running), then what waits on me, then the monthly limit, else when it last spoke.
+export function agentNow(agent: Pick<Agent, 'id' | 'archived' | 'used' | 'limit'>, messages: readonly Message[]): AgentNow {
+ if (agent.archived) return { kind: 'archived' }
+ // In time order: the messages come per conversation, one list after another.
+ const own = messages.filter((m) => m.author.kind === 'agent' && m.author.id === agent.id).sort((a, b) => a.at - b.at)
+ const working = own.findLast((m) => m.run?.status === 'working')
+ if (working) {
+ const step = working.run!.steps.findLast((st) => st.status === 'running')
+ return { kind: 'working', conversationId: working.conversationId, doing: step?.label, since: working.at }
+ }
+ const waiting = own.findLast((m) => m.run?.status === 'waiting_input' || m.run?.status === 'waiting_approval')
+ if (waiting) {
+ const on = waiting.run!.status === 'waiting_input' ? 'input' : 'approval'
+ return { kind: 'waiting', conversationId: waiting.conversationId, on, ...(on === 'input' && waiting.run!.askedTo ? { askedTo: waiting.run!.askedTo } : {}) }
+ }
+ if (agent.limit > 0 && agent.used >= agent.limit) return { kind: 'limit' }
+ return { kind: 'idle', lastAt: own.at(-1)?.at }
+}
+
+// The channels it's in, by name, in the sidebar's order.
+export const agentChannels = (agentId: string, conversations: readonly Conversation[]): Conversation[] => conversations.filter((c) => c.kind === 'channel' && c.members.includes(agentId))
+
+export interface Box {
+ left: number
+ top: number
+ width: number
+ height: number
+}
+
+const GAP = 8 // between the card and what was clicked
+const EDGE = 12 // the least room kept to the window's edges
+
+// Next to what was clicked, like Slack: to its right, top-aligned with it; else to its left;
+// else below it, else above. `below`: what's in a top bar opens it under itself, the way a menu
+// does. Always whole on screen. A narrow window (a phone) gets the card across its width, under the click.
+export function placeCard(anchor: Box, card: { width: number; height: number }, view: { width: number; height: number }, prefer: 'side' | 'below' = 'side'): { left: number; top: number; width: number } {
+ const clampTop = (t: number): number => Math.max(EDGE, Math.min(t, view.height - card.height - EDGE))
+ if (view.width < card.width + 2 * EDGE + 40) {
+ const width = view.width - 2 * EDGE
+ const below = anchor.top + anchor.height + GAP
+ const top = below + card.height <= view.height - EDGE ? below : anchor.top - GAP - card.height
+ return { left: EDGE, top: clampTop(top), width }
+ }
+ const right = anchor.left + anchor.width + GAP
+ if (prefer === 'side' && right + card.width <= view.width - EDGE) return { left: right, top: clampTop(anchor.top), width: card.width }
+ const left = anchor.left - GAP - card.width
+ if (prefer === 'side' && left >= EDGE) return { left, top: clampTop(anchor.top), width: card.width }
+ const x = Math.max(EDGE, Math.min(anchor.left, view.width - card.width - EDGE))
+ const below = anchor.top + anchor.height + GAP
+ return { left: x, top: clampTop(below + card.height <= view.height - EDGE ? below : anchor.top - GAP - card.height), width: card.width }
+}
+
+// ---------- which card is open, and how ----------
+
+export const HOVER_OPEN_MS = 500 // the pointer rests on a face this long before its card opens
+export const HOVER_CLOSE_MS = 300 // and the card waits this long after it leaves, to reach the card
+const SCROLL_QUIET_MS = 250 // right after a scroll, a face passing under the pointer isn't a hover
+
+export interface CardOpen<A> {
+ agentId: string
+ anchor: A // what opened it: the card goes next to it and gives it focus back
+ via: 'click' | 'hover' // a clicked card stays until clicked away; a hovered one goes with the pointer
+ settingsOf?: string // opened from the top of a DM: the card also leads to that conversation's settings
+ below?: boolean // opened from a top bar: under it, like a menu
+}
+export type CardOptions = Pick<CardOpen<unknown>, 'settingsOf' | 'below'>
+
+// One card at a time. A click (or Enter) opens it at once and the same click again closes it;
+// a pointer resting on a face opens it after a moment and, leaving the face and the card, closes it.
+// A click on a face whose card the hover opened keeps that card, as a clicked one.
+export function cardState<A>(ms = { open: HOVER_OPEN_MS, close: HOVER_CLOSE_MS }) {
+ let current: CardOpen<A> | null = null
+ let openTimer: ReturnType<typeof setTimeout> | undefined
+ let closeTimer: ReturnType<typeof setTimeout> | undefined
+ let scrolledAt = -Infinity
+ const listeners = new Set<() => void>()
+ const set = (next: CardOpen<A> | null): void => {
+ current = next
+ listeners.forEach((l) => l())
+ }
+ const stopOpening = (): void => {
+ clearTimeout(openTimer)
+ openTimer = undefined
+ }
+ const stopClosing = (): void => {
+ clearTimeout(closeTimer)
+ closeTimer = undefined
+ }
+ const leave = (): void => {
+ stopOpening()
+ if (current?.via !== 'hover') return
+ stopClosing()
+ closeTimer = setTimeout(() => {
+ closeTimer = undefined
+ if (current?.via === 'hover') set(null)
+ }, ms.close)
+ }
+ return {
+ get: (): CardOpen<A> | null => current,
+ subscribe(l: () => void): () => void {
+ listeners.add(l)
+ return () => void listeners.delete(l)
+ },
+ click(agentId: string, anchor: A, opts: CardOptions = {}): void {
+ stopOpening()
+ stopClosing()
+ if (current?.anchor === anchor) return set(current.via === 'hover' ? { ...current, via: 'click' } : null)
+ set({ agentId, anchor, via: 'click', ...opts })
+ },
+ hoverEnter(agentId: string, anchor: A, opts: CardOptions = {}): void {
+ if (current?.via === 'click') return // a clicked card stays the one open
+ if (current?.anchor === anchor) return stopClosing() // back on its face in time
+ if (Date.now() - scrolledAt < SCROLL_QUIET_MS) return
+ stopOpening()
+ openTimer = setTimeout(() => {
+ openTimer = undefined
+ stopClosing()
+ set({ agentId, anchor, via: 'hover', ...opts })
+ }, ms.open)
+ },
+ hoverLeave: leave,
+ cardEnter: stopClosing,
+ cardLeave: leave,
+ scrolled(): void {
+ scrolledAt = Date.now()
+ stopOpening()
+ },
+ close(): CardOpen<A> | null {
+ stopOpening()
+ stopClosing()
+ const was = current
+ if (was) set(null)
+ return was
+ }
+ }
+}
diff --git a/src/renderer/src/components/AgentCard.tsx b/src/renderer/src/components/AgentCard.tsx
new file mode 100644
index 0000000..f1efbaf
--- /dev/null
+++ b/src/renderer/src/components/AgentCard.tsx
@@ -0,0 +1,278 @@
+// An agent's profile card, like Slack's: a click on its face or name (on a message, a mention,
+// the faces of a channel, the top of its DM) opens a small card next to the click with who it
+// is, what it's doing now and where it works, and the way to talk to it or see its whole page.
+// The mouse resting on a face opens it too, after a moment, and it goes when the mouse leaves the
+// face and the card. One card at a time; Esc, a click outside or leaving it with Tab closes it.
+import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore, type CSSProperties, type ReactNode } from 'react'
+import { L } from '../../../shared/lang'
+import { ENGINES } from '../../../shared/types'
+import { agentById, canDecide, modelById, navigate, openDialog, openDm, personName, useStore } from '../store'
+import { agentChannels, agentNow, cardState, placeCard, type AgentNow, type CardOpen, type CardOptions } from '../agent-card'
+import { AgentAvatar, Icon, ago, ownColor } from './ui'
+
+type Open = CardOpen<HTMLElement>
+
+const cards = cardState<HTMLElement>()
+
+export const openAgentCard = (agentId: string, anchor: HTMLElement, opts: CardOptions = {}): void => cards.click(agentId, anchor, opts)
+
+export function closeAgentCard(restoreFocus = false): void {
+ const was = cards.close()
+ if (restoreFocus && was?.anchor.isConnected) was.anchor.focus()
+}
+
+// A real button that opens the card on a click (or Enter), and on a mouse resting on it.
+// `tabIndex={-1}` for a face next to a name that opens the same card: one stop for the
+// keyboard, a bigger target for the mouse. Touch has no hover: a tap is a click.
+export function AgentCardButton({ agentId, settingsOf, below, className, style, title, label, tabIndex, children }: { agentId: string; settingsOf?: string; below?: boolean; className?: string; style?: CSSProperties; title?: string; label?: string; tabIndex?: number; children: ReactNode }): ReactNode {
+ const ref = useRef<HTMLButtonElement>(null)
+ const expanded = useSyncExternalStore(cards.subscribe, () => !!ref.current && cards.get()?.anchor === ref.current)
+ return (
+ <button
+ ref={ref}
+ type="button"
+ className={className}
+ style={style}
+ title={title}
+ aria-label={label}
+ aria-haspopup="dialog"
+ aria-expanded={expanded}
+ tabIndex={tabIndex}
+ onClick={(e) => cards.click(agentId, e.currentTarget, { settingsOf, below })}
+ onPointerEnter={(e) => e.pointerType === 'mouse' && cards.hoverEnter(agentId, e.currentTarget, { settingsOf, below })}
+ onPointerLeave={(e) => e.pointerType === 'mouse' && cards.hoverLeave()}
+ >
+ {children}
+ </button>
+ )
+}
+
+// Mounted once, over the app.
+export function AgentCardLayer(): ReactNode {
+ const open = useSyncExternalStore(cards.subscribe, cards.get)
+ // Going somewhere else closes it.
+ const view = useStore((s) => s.view)
+ useEffect(() => closeAgentCard(), [view])
+ // A face passing under a still pointer while the page scrolls isn't a hover.
+ useEffect(() => {
+ window.addEventListener('scroll', cards.scrolled, true)
+ return () => window.removeEventListener('scroll', cards.scrolled, true)
+ }, [])
+ if (!open) return null
+ return <AgentCard key={`${open.agentId}-${open.settingsOf ?? ''}`} open={open} />
+}
+
+const CHANNELS_SHOWN = 4
+
+function AgentCard({ open }: { open: Open }): ReactNode {
+ const agent = useStore((s) => agentById(s, open.agentId))
+ const messages = useStore((s) => s.messages)
+ const conversations = useStore((s) => s.conversations)
+ const model = useStore((s) => (agent ? modelById(s, agent.modelId) : undefined))
+ // Already in its DM: "Message" would lead right here.
+ const inItsDm = useStore((s) => {
+ if (s.view?.kind !== 'conversation') return false
+ const id = s.view.id
+ const c = s.conversations.find((x) => x.id === id)
+ return c?.kind === 'dm' && c.members[0] === open.agentId
+ })
+ const now = useMemo(() => (agent ? agentNow(agent, Object.values(messages).flat()) : undefined), [agent, messages])
+ // With a team, what an agent waits on may be someone else's: a question to another person,
+ // an approval only the admins or the agent's person decide.
+ const waitsOn = useStore((s): string | undefined => {
+ if (now?.kind !== 'waiting') return undefined
+ if (now.on === 'approval') return canDecide(s, { agentId: open.agentId }) ? undefined : ''
+ return now.askedTo && s.you && now.askedTo !== s.you ? personName(s, now.askedTo) : undefined
+ })
+ const channels = useMemo(() => agentChannels(open.agentId, conversations), [open.agentId, conversations])
+ const titleOf = (id: string): string => {
+ const c = conversations.find((x) => x.id === id)
+ return !c ? '' : c.kind === 'channel' ? L(`em #${c.name}`, `in #${c.name}`) : L('na DM', 'in the DM')
+ }
+
+ const card = useRef<HTMLDivElement>(null)
+ const [place, setPlace] = useState<{ left: number; top: number; width?: number } | null>(null)
+ const nameId = useId()
+
+ // Next to what was clicked, measured once the card is laid out (hidden until then).
+ useLayoutEffect(() => {
+ const el = card.current
+ if (!el) return
+ const measure = (): void => {
+ if (!open.anchor.isConnected) return closeAgentCard()
+ const r = open.anchor.getBoundingClientRect()
+ setPlace(placeCard({ left: r.left, top: r.top, width: r.width, height: r.height }, { width: 320, height: el.offsetHeight }, { width: window.innerWidth, height: window.innerHeight }, open.below ? 'below' : 'side'))
+ }
+ measure()
+ const resize = new ResizeObserver(measure)
+ resize.observe(el)
+ window.addEventListener('resize', measure)
+ return () => {
+ resize.disconnect()
+ window.removeEventListener('resize', measure)
+ }
+ }, [open.anchor])
+
+ // A clicked card takes focus once it's placed (hidden, it can't), so a screen reader reads it
+ // and Tab walks its buttons. A hovered one doesn't take focus from where you're typing.
+ const placed = !!place
+ const clicked = open.via === 'click'
+ useEffect(() => {
+ if (placed && clicked) card.current?.focus({ preventScroll: true })
+ }, [placed, clicked])
+
+ // Esc closes it before anything under it (a thread panel) takes the key; a click outside,
+ // or a scroll under it, closes it too.
+ useEffect(() => {
+ const inside = (t: EventTarget | null): boolean => t instanceof Node && (!!card.current?.contains(t) || open.anchor.contains(t))
+ const onKey = (e: KeyboardEvent): void => {
+ if (e.key !== 'Escape') return
+ e.preventDefault()
+ e.stopPropagation()
+ closeAgentCard(open.via === 'click') // a hovered card never had the focus to give back
+ }
+ const onDown = (e: PointerEvent): void => void (!inside(e.target) && closeAgentCard())
+ const onScroll = (e: Event): void => void (!(e.target instanceof Node && card.current?.contains(e.target)) && closeAgentCard())
+ window.addEventListener('keydown', onKey, true)
+ window.addEventListener('pointerdown', onDown, true)
+ window.addEventListener('scroll', onScroll, true)
+ return () => {
+ window.removeEventListener('keydown', onKey, true)
+ window.removeEventListener('pointerdown', onDown, true)
+ window.removeEventListener('scroll', onScroll, true)
+ }
+ }, [open.anchor])
+
+ if (!agent || !now) return null
+ const tuca = agent.kind === 'tuca'
+ const go = (fn: () => void): void => {
+ closeAgentCard()
+ fn()
+ }
+
+ return (
+ <div
+ ref={card}
+ className={`agent-card c-${agent.color}`}
+ style={{ ...ownColor(agent), ...(place ? { left: place.left, top: place.top, width: place.width } : { visibility: 'hidden' }) }}
+ role="dialog"
+ aria-labelledby={nameId}
+ tabIndex={-1}
+ onPointerEnter={(e) => e.pointerType === 'mouse' && cards.cardEnter()}
+ onPointerLeave={(e) => e.pointerType === 'mouse' && cards.cardLeave()}
+ onBlur={(e) => {
+ // Tab out of the card closes it; a click elsewhere is the pointer's job.
+ if (e.relatedTarget instanceof Node && !e.currentTarget.contains(e.relatedTarget) && !open.anchor.contains(e.relatedTarget)) closeAgentCard()
+ }}
+ >
+ <div className="agent-card__band" aria-hidden />
+ <div className="agent-card__head">
+ <span className="agent-card__face">
+ <AgentAvatar agent={agent} size={64} busy={now.kind === 'working'} />
+ </span>
+ <div className="agent-card__who">
+ <h2 id={nameId} className="agent-card__name">
+ {agent.name}
+ </h2>
+ <div className="agent-card__handle">@{agent.handle}</div>
+ {(agent.role || tuca) && <div className="agent-card__role">{agent.role || L('Monta os agentes do time', 'Builds the team’s agents')}</div>}
+ </div>
+ </div>
+
+ <NowLine now={now} titleOf={titleOf} waitsOn={waitsOn} />
+
+ <dl className="agent-card__facts">
+ <div>
+ <dt>{L('Modelo', 'Model')}</dt>
+ <dd>
+ {model?.label ?? agent.modelId}
+ {model && <span className="muted"> · {ENGINES[model.engine].label}</span>}
+ </dd>
+ </div>
+ {agent.computer && (
+ <div>
+ <dt>{L('Computador', 'Computer')}</dt>
+ <dd>{agent.computerKind === 'mac' ? L('Roda no seu computador', 'Runs on your computer') : L('Um computador só dele, isolado', 'One of its own, isolated')}</dd>
+ </div>
+ )}
+ {!tuca && (
+ <div>
+ <dt>{L('Canais', 'Channels')}</dt>
+ <dd className="agent-card__channels">
+ {channels.length === 0 && <span className="muted">{L('Só na DM', 'Only in its DM')}</span>}
+ {channels.slice(0, CHANNELS_SHOWN).map((c) => (
+ <button key={c.id} type="button" className="agent-card__channel" onClick={() => go(() => navigate({ kind: 'conversation', id: c.id }))}>
+ #{c.name}
+ </button>
+ ))}
+ {channels.length > CHANNELS_SHOWN && <span className="muted">+{channels.length - CHANNELS_SHOWN}</span>}
+ </dd>
+ </div>
+ )}
+ </dl>
+
+ <div className="agent-card__actions">
+ {!inItsDm && !agent.archived && (
+ <button type="button" className="btn btn--primary btn--sm" onClick={() => go(() => void openDm(agent.id))}>
+ <Icon name="send" size={13} /> {L('Mensagem', 'Message')}
+ </button>
+ )}
+ <button type="button" className={`btn btn--sm ${inItsDm || agent.archived ? 'btn--primary' : ''}`} onClick={() => go(() => navigate({ kind: 'agent', id: agent.id }))}>
+ <Icon name="user" size={13} /> {L('Ver perfil completo', 'View full profile')}
+ </button>
+ {open.settingsOf && (
+ <button type="button" className="icon-btn agent-card__settings" title={L('Configurações da conversa', 'Conversation settings')} aria-label={L('Configurações da conversa', 'Conversation settings')} onClick={() => go(() => openDialog({ kind: 'settings', id: open.settingsOf! }))}>
+ <Icon name="gear" size={15} />
+ </button>
+ )}
+ </div>
+ </div>
+ )
+}
+
+// `waitsOn`: unset, it waits on me; a name, on that person; empty, on someone who decides (not me).
+function NowLine({ now, titleOf, waitsOn }: { now: AgentNow; titleOf: (conversationId: string) => string; waitsOn?: string }): ReactNode {
+ const where = 'conversationId' in now ? titleOf(now.conversationId) : ''
+ const go = (): void => {
+ if (!('conversationId' in now)) return
+ closeAgentCard()
+ navigate({ kind: 'conversation', id: now.conversationId })
+ }
+ if (now.kind === 'working')
+ return (
+ <button type="button" className="agent-card__now is-working" onClick={go}>
+ <span className="agent-card__dot" aria-hidden />
+ <span>
+ <b>{L(`Trabalhando agora ${where}`, `Working now ${where}`)}</b>
+ {now.doing && <span className="agent-card__doing">{now.doing}…</span>}
+ </span>
+ </button>
+ )
+ if (now.kind === 'waiting')
+ return (
+ <button type="button" className="agent-card__now is-waiting" onClick={go}>
+ <span className="agent-card__dot" aria-hidden />
+ <b>
+ {now.on === 'input'
+ ? waitsOn
+ ? L(`Esperando ${waitsOn} responder ${where}`, `Waiting for ${waitsOn} to answer ${where}`)
+ : L(`Esperando sua resposta ${where}`, `Waiting for your answer ${where}`)
+ : waitsOn === undefined
+ ? L(`Esperando sua aprovação ${where}`, `Waiting for your approval ${where}`)
+ : L(`Esperando aprovação ${where}`, `Waiting for approval ${where}`)}
+ </b>
+ </button>
+ )
+ return (
+ <p className={`agent-card__now is-${now.kind}`}>
+ <span className="agent-card__dot" aria-hidden />
+ {now.kind === 'archived'
+ ? L('Arquivado: não responde', 'Archived: it doesn’t reply')
+ : now.kind === 'limit'
+ ? L('Bateu o limite do mês', 'Hit the monthly limit')
+ : now.lastAt
+ ? L(`Disponível · falou ${ago(now.lastAt)}`, `Available · last spoke ${ago(now.lastAt)}`)
+ : L('Disponível', 'Available')}
+ </p>
+ )
+}
diff --git a/src/renderer/src/components/Conversation.tsx b/src/renderer/src/components/Conversation.tsx
index 14115a0..b9c10bd 100644
--- a/src/renderer/src/components/Conversation.tsx
+++ b/src/renderer/src/components/Conversation.tsx
@@ -86,6 +86,7 @@ import { ArtifactCard, BrowserCard, ServiceCard, SidePanel } from './Panel'
import { when } from './Routines'
import { AgentProposal, ProposalCard } from './Tuca'
import { FoldToggle } from './Fold'
+import { AgentCardButton } from './AgentCard'
// Something exact a person may want to check (the raw error, a tool's arguments), folded until asked.
export function Details({ label, initiallyOpen = false, children }: { label: string; initiallyOpen?: boolean; children: ReactNode }): ReactNode {
@@ -179,10 +180,18 @@ export function ConversationView({ id }: { id: string }): ReactNode {
<section className="conversation">
<header className="topbar">
<div className="topbar__title">
- <button className="topbar__name" title={conv.kind === 'channel' ? L('Configurações do canal', 'Channel settings') : L('Configurações da conversa', 'Conversation settings')} onClick={() => openDialog({ kind: 'settings', id })}>
- {dmAgent ? <AgentAvatar agent={dmAgent} size={22} /> : <Icon name="hash" />}
- <h1>{title}</h1>
- </button>
+ {/* A channel's name opens its settings; a DM's, like Slack, the agent's card (its settings: the gear on the right, or the card). */}
+ {dmAgent ? (
+ <AgentCardButton agentId={dmAgent.id} settingsOf={id} below className="topbar__name" title={L(`Perfil de ${dmAgent.name}`, `${dmAgent.name}’s profile`)}>
+ <AgentAvatar agent={dmAgent} size={22} />
+ <h1>{title}</h1>
+ </AgentCardButton>
+ ) : (
+ <button className="topbar__name" title={L('Configurações do canal', 'Channel settings')} onClick={() => openDialog({ kind: 'settings', id })}>
+ <Icon name="hash" />
+ <h1>{title}</h1>
+ </button>
+ )}
{dmAgent?.role && (
<span className="tag topbar__role" title={dmAgent.role}>
{dmAgent.role}
@@ -194,9 +203,9 @@ export function ConversationView({ id }: { id: string }): ReactNode {
{conv.kind === 'channel' && (
<div className="stack" title={L('Agentes no canal', 'Agents in the channel')}>
{members.map((a) => (
- <button key={a.id} className="stack__item" onClick={() => navigate({ kind: 'agent', id: a.id })} title={a.name}>
+ <AgentCardButton key={a.id} agentId={a.id} below className="stack__item" title={a.name}>
<AgentAvatar agent={a} size={24} />
- </button>
+ </AgentCardButton>
))}
<span className="stack__count">{members.length} {L(`agente${members.length === 1 ? '' : 's'}`, `agent${members.length === 1 ? '' : 's'}`)}</span>
{editsChannel && (
@@ -210,8 +219,8 @@ export function ConversationView({ id }: { id: string }): ReactNode {
<Icon name="book" size={14} /> {L('Resumo', 'Summary')}
</button>
{dmAgent && (
- <button className="btn btn--ghost" onClick={() => navigate({ kind: 'agent', id: dmAgent.id })}>
- {L('Ver perfil', 'See profile')}
+ <button className="icon-btn" title={L('Configurações da conversa', 'Conversation settings')} aria-label={L('Configurações da conversa', 'Conversation settings')} onClick={() => openDialog({ kind: 'settings', id })}>
+ <Icon name="gear" size={16} />
</button>
)}
</div>
@@ -443,15 +452,22 @@ const MessageRow = memo(function MessageRow({ message, grouped, replies }: { mes
// Someone else's message reads like any other voice in the conversation: on the left, with their name.
<article className={`msg ${agent ? 'msg--agent' : other ? 'msg--agent msg--person' : 'msg--me'} ${grouped ? 'msg--grouped' : ''} ${threadOpen ? 'is-thread-open' : ''}`} data-id={message.id}>
<div className="msg__gutter">
- {!grouped && (agent ? <AgentAvatar agent={agent} size={34} busy={message.run?.status === 'working'} /> : <MeAvatar initials={other ? initials(other) : me.initials} size={34} />)}
+ {!grouped &&
+ (agent ? (
+ <AgentCardButton agentId={agent.id} className="msg__face" tabIndex={-1} label={L(`Perfil de ${agent.name}`, `${agent.name}’s profile`)}>
+ <AgentAvatar agent={agent} size={34} busy={message.run?.status === 'working'} />
+ </AgentCardButton>
+ ) : (
+ <MeAvatar initials={other ? initials(other) : me.initials} size={34} />
+ ))}
</div>
<div className="msg__body">
{!grouped && (
<div className="msg__head">
{agent ? (
- <button className="msg__author link" onClick={() => navigate({ kind: 'agent', id: agent.id })}>
+ <AgentCardButton agentId={agent.id} className="msg__author link">
{name}
- </button>
+ </AgentCardButton>
) : (
<span className="msg__author">{name}</span>
)}
@@ -1050,10 +1066,10 @@ function Mention({ handle }: { handle: string }): ReactNode {
const agent = useStore((s) => s.agents.find((a) => a.handle.toLowerCase() === handle.toLowerCase()))
if (!agent) return <strong>@{handle}</strong>
return (
- <button className={`mention c-${agent.color}`} style={ownColor(agent)} title={agent.role ? `${agent.name} · ${agent.role}` : agent.name} onClick={() => navigate({ kind: 'agent', id: agent.id })}>
+ <AgentCardButton agentId={agent.id} className={`mention c-${agent.color}`} style={ownColor(agent)} title={agent.role ? `${agent.name} · ${agent.role}` : agent.name}>
<AgentAvatar agent={agent} size={16} />
<span>@{agent.handle}</span>
- </button>
+ </AgentCardButton>
)
}
const plainMarkdown = { pre: CodeBlock, a: (p: { href?: string; children?: ReactNode }) => <WikiLink href={p.href}>{p.children}</WikiLink>, span: MentionSpan }
diff --git a/src/renderer/src/styles.css b/src/renderer/src/styles.css
index 2c358aa..d16cd24 100644
--- a/src/renderer/src/styles.css
+++ b/src/renderer/src/styles.css
@@ -8351,6 +8351,200 @@ button.wk-pill.is-on { box-shadow: 0 0 0 1.5px var(--k); background: color-mix(i
flex: none;
}
+/* ---------- an agent's profile card ---------- */
+/* A face on a message opens the card: a real button the size of the face. */
+.msg__face {
+ display: inline-flex;
+ border-radius: 30%;
+}
+.msg__face:hover .avatar {
+ filter: brightness(1.04);
+}
+.msg__face:active {
+ transform: scale(0.96);
+}
+/* Opened from the top of a DM (or the faces of a channel), the button shows it's open. */
+.topbar__name[aria-expanded='true'],
+.msg__author[aria-expanded='true'] {
+ background: var(--hover);
+}
+.msg__author.link {
+ border-radius: 4px;
+ margin: 0 -2px;
+ padding: 0 2px;
+}
+/* Next to the click, like Slack: who the agent is, what it's doing, where it works. */
+.agent-card {
+ position: fixed;
+ z-index: 65;
+ width: 320px;
+ max-height: calc(100vh - 24px);
+ overflow: auto;
+ border-radius: var(--radius-lg);
+ background: var(--panel);
+ box-shadow: var(--shadow-lg), 0 0 0 1px var(--border);
+ color: var(--text);
+ --pop-y: 2px;
+ animation: pop var(--dur-fast) var(--ease-out) both;
+}
+.agent-card:focus {
+ outline: none;
+}
+.agent-card:focus-visible {
+ box-shadow: var(--shadow-lg), 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-soft);
+}
+/* A band of the agent's own color, the face sitting on its edge. */
+.agent-card__band {
+ height: 52px;
+ background: linear-gradient(135deg, color-mix(in srgb, var(--agent, var(--accent)) 34%, var(--panel)), color-mix(in srgb, var(--agent, var(--accent)) 14%, var(--panel)));
+}
+.agent-card__head {
+ padding: 0 16px;
+ margin-top: -32px;
+}
+.agent-card__face {
+ flex: none;
+ display: inline-flex;
+ border-radius: 30%;
+ box-shadow: 0 0 0 3px var(--panel);
+ background: var(--panel);
+}
+.agent-card__who {
+ min-width: 0;
+ margin-top: 8px;
+ overflow-wrap: anywhere;
+}
+.agent-card__name {
+ margin: 0;
+ font-size: 16px;
+ font-weight: 650;
+ letter-spacing: -0.015em;
+ line-height: 1.25;
+ overflow-wrap: anywhere;
+}
+.agent-card__handle {
+ font-size: 12.5px;
+ color: var(--text-3);
+}
+.agent-card__name + .agent-card__handle {
+ margin-top: 1px;
+}
+.agent-card__role {
+ margin-top: 4px;
+ font-size: 13px;
+ color: var(--text-2);
+ line-height: 1.4;
+}
+.agent-card__now {
+ display: flex;
+ align-items: flex-start;
+ gap: 8px;
+ width: calc(100% - 24px);
+ margin: 12px 12px 0;
+ padding: 8px 10px;
+ border-radius: var(--radius);
+ background: var(--hover);
+ font-size: 13px;
+ line-height: 1.4;
+ color: var(--text-2);
+ text-align: left;
+}
+.agent-card__now b {
+ font-weight: 600;
+ color: var(--text);
+}
+button.agent-card__now:hover {
+ background: var(--active);
+}
+.agent-card__doing {
+ display: block;
+ color: var(--text-2);
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ max-width: 250px;
+}
+.agent-card__dot {
+ flex: none;
+ width: 8px;
+ height: 8px;
+ margin-top: 5px;
+ border-radius: 50%;
+ background: var(--ok);
+}
+.is-idle .agent-card__dot {
+ background: transparent;
+ box-shadow: inset 0 0 0 1.5px var(--ok);
+}
+.is-working .agent-card__dot {
+ background: var(--accent);
+ animation: fade-pulse var(--dur-loop) var(--ease-in-out) infinite;
+}
+.is-waiting .agent-card__dot {
+ background: var(--warn);
+}
+.is-limit .agent-card__dot {
+ background: var(--danger);
+}
+.is-archived .agent-card__dot {
+ background: var(--text-3);
+}
+.agent-card__facts {
+ display: grid;
+ gap: 6px;
+ margin: 12px 16px 0;
+ font-size: 13px;
+}
+.agent-card__facts > div {
+ display: grid;
+ grid-template-columns: 84px 1fr;
+ gap: 8px;
+ align-items: baseline;
+}
+.agent-card__facts dt {
+ color: var(--text-3);
+}
+.agent-card__facts dd {
+ margin: 0;
+ min-width: 0;
+ overflow-wrap: anywhere;
+}
+.agent-card__channels {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 4px;
+}
+.agent-card__channel {
+ padding: 0 6px;
+ border-radius: 6px;
+ background: var(--hover);
+ font-size: 12.5px;
+ color: var(--text-2);
+}
+.agent-card__channel:hover {
+ background: var(--active);
+ color: var(--text);
+}
+.agent-card__actions {
+ display: flex;
+ align-items: center;
+ gap: 8px;
+ padding: 14px 16px 16px;
+}
+.agent-card__actions .btn {
+ flex: 1;
+ justify-content: center;
+}
+.agent-card__settings {
+ flex: none;
+}
+@media (prefers-reduced-motion: reduce) {
+ .agent-card,
+ .is-working .agent-card__dot {
+ animation: none;
+ }
+}
+
/* Over a server's page (Servers.tsx): the window's top 40 px stay the app's. */
.server-bar { position: fixed; inset: 0 0 auto 0; height: 40px; z-index: 1000; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--border); -webkit-app-region: drag; font-size: 13px; }
.server-bar button { -webkit-app-region: no-drag; }
diff --git a/test/agent-card.test.ts b/test/agent-card.test.ts
new file mode 100644
index 0000000..0f11c7b
--- /dev/null
+++ b/test/agent-card.test.ts
@@ -0,0 +1,220 @@
+import { existsSync, readFileSync } from 'node:fs'
+import { chromium } from 'playwright'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { agentChannels, agentNow, cardState, HOVER_CLOSE_MS, HOVER_OPEN_MS, placeCard } from '../src/renderer/src/agent-card'
+import type { Conversation, Message, Run } from '../src/shared/types'
+
+const agent = { id: 'lia', archived: false, used: 0, limit: 1000 }
+const msg = (id: string, author: string, at: number, run?: Partial<Run>, conversationId = 'c1'): Message => ({
+ id,
+ conversationId,
+ author: author === 'me' ? { kind: 'person', id: 'p_me' } : { kind: 'agent', id: author },
+ text: '',
+ at,
+ run: run && { status: 'done', steps: [], ...run }
+})
+
+describe('what an agent’s card says it is doing', () => {
+ it('says where it works now and the step running', () => {
+ const messages = [
+ msg('1', 'lia', 1, { status: 'done' }),
+ msg('2', 'lia', 2, { status: 'working', steps: [{ id: 's1', label: 'Lendo o arquivo', status: 'done' }, { id: 's2', label: 'Rodando os testes', status: 'running' }] }, 'c2'),
+ msg('3', 'theo', 3, { status: 'working' })
+ ]
+ expect(agentNow(agent, messages)).toEqual({ kind: 'working', conversationId: 'c2', doing: 'Rodando os testes', since: 2 })
+ })
+ it('says it waits on me, for an answer or an approval', () => {
+ expect(agentNow(agent, [msg('1', 'lia', 1, { status: 'waiting_input' })])).toEqual({ kind: 'waiting', conversationId: 'c1', on: 'input' })
+ expect(agentNow(agent, [msg('1', 'lia', 1, { status: 'waiting_approval' })])).toEqual({ kind: 'waiting', conversationId: 'c1', on: 'approval' })
+ })
+ it('with a team, says whom a question is for', () => {
+ expect(agentNow(agent, [msg('1', 'lia', 1, { status: 'waiting_input', askedTo: 'p_ana' })])).toEqual({ kind: 'waiting', conversationId: 'c1', on: 'input', askedTo: 'p_ana' })
+ })
+ it('reads the messages in time order, whatever conversation they come from', () => {
+ expect(agentNow(agent, [msg('1', 'lia', 5, { status: 'done' }, 'c1'), msg('2', 'lia', 2, { status: 'done' }, 'c2')])).toEqual({ kind: 'idle', lastAt: 5 })
+ })
+ it('puts work before waiting, and both before the limit', () => {
+ const messages = [msg('1', 'lia', 1, { status: 'waiting_input' }), msg('2', 'lia', 2, { status: 'working' })]
+ expect(agentNow({ ...agent, used: 1000 }, messages).kind).toBe('working')
+ expect(agentNow({ ...agent, used: 1000 }, [msg('1', 'lia', 1)])).toEqual({ kind: 'limit' })
+ })
+ it('says an archived agent does nothing, whatever its messages say', () => {
+ expect(agentNow({ ...agent, archived: true }, [msg('1', 'lia', 1, { status: 'working' })])).toEqual({ kind: 'archived' })
+ })
+ it('otherwise says when it last spoke, or nothing if it never did', () => {
+ expect(agentNow(agent, [msg('1', 'lia', 5), msg('2', 'me', 9), msg('3', 'theo', 10)])).toEqual({ kind: 'idle', lastAt: 5 })
+ expect(agentNow(agent, [msg('1', 'me', 1)])).toEqual({ kind: 'idle', lastAt: undefined })
+ })
+})
+
+it('lists the channels an agent is in, not the DMs', () => {
+ const conv = (id: string, kind: Conversation['kind'], members: string[]): Conversation => ({ id, kind, name: id, members })
+ const all = [conv('eng', 'channel', ['lia', 'theo']), conv('dados', 'channel', ['theo']), conv('dm', 'dm', ['lia']), conv('geral', 'channel', ['lia'])]
+ expect(agentChannels('lia', all).map((c) => c.id)).toEqual(['eng', 'geral'])
+})
+
+describe('where the card goes', () => {
+ const view = { width: 1280, height: 820 }
+ const card = { width: 320, height: 300 }
+ const face = { left: 360, top: 150, width: 34, height: 34 }
+
+ it('opens to the right of what was clicked, top-aligned with it', () => {
+ expect(placeCard(face, card, view)).toEqual({ left: 402, top: 150, width: 320 })
+ })
+ it('goes left when there’s no room on the right (a face in a thread panel at the edge)', () => {
+ expect(placeCard({ left: 1100, top: 150, width: 34, height: 34 }, card, view)).toEqual({ left: 772, top: 150, width: 320 })
+ })
+ it('stays whole on screen near the bottom', () => {
+ const p = placeCard({ ...face, top: 700 }, card, view)
+ expect(p.top + card.height).toBeLessThanOrEqual(view.height - 12)
+ })
+ it('opens under a top bar’s button, kept inside the window', () => {
+ expect(placeCard({ left: 262, top: 20, width: 60, height: 28 }, card, view, 'below')).toEqual({ left: 262, top: 56, width: 320 })
+ expect(placeCard({ left: 1200, top: 20, width: 24, height: 24 }, card, view, 'below').left).toBe(1280 - 320 - 12)
+ })
+ it('spans a narrow window, under the click or above it', () => {
+ const phone = { width: 360, height: 700 }
+ expect(placeCard({ left: 20, top: 100, width: 34, height: 34 }, card, phone)).toEqual({ left: 12, top: 142, width: 336 })
+ expect(placeCard({ left: 20, top: 600, width: 34, height: 34 }, card, phone).top).toBe(600 - 8 - 300)
+ })
+})
+
+describe('opening the card on a click and on hover', () => {
+ beforeEach(() => void vi.useFakeTimers())
+ afterEach(() => void vi.useRealTimers())
+ const face = { name: 'Lia’s face' }
+ const other = { name: 'Theo’s face' }
+ const open = (s: ReturnType<typeof cardState<object>>) => s.get() && { agentId: s.get()!.agentId, anchor: s.get()!.anchor, via: s.get()!.via }
+
+ it('opens after the pointer rests on a face for the delay, not before', () => {
+ const s = cardState<object>()
+ s.hoverEnter('lia', face)
+ vi.advanceTimersByTime(HOVER_OPEN_MS - 1)
+ expect(s.get()).toBeNull()
+ vi.advanceTimersByTime(1)
+ expect(open(s)).toEqual({ agentId: 'lia', anchor: face, via: 'hover' })
+ })
+ it('doesn’t open when the pointer leaves before the delay', () => {
+ const s = cardState<object>()
+ s.hoverEnter('lia', face)
+ vi.advanceTimersByTime(HOVER_OPEN_MS - 100)
+ s.hoverLeave()
+ vi.advanceTimersByTime(HOVER_OPEN_MS * 4)
+ expect(s.get()).toBeNull()
+ })
+ it('stays while the pointer moves from the face onto the card, and goes a moment after it leaves both', () => {
+ const s = cardState<object>()
+ s.hoverEnter('lia', face)
+ vi.advanceTimersByTime(HOVER_OPEN_MS)
+ s.hoverLeave()
+ vi.advanceTimersByTime(HOVER_CLOSE_MS - 50)
+ s.cardEnter()
+ vi.advanceTimersByTime(HOVER_CLOSE_MS * 10)
+ expect(open(s)?.via).toBe('hover')
+ s.cardLeave()
+ vi.advanceTimersByTime(HOVER_CLOSE_MS - 1)
+ expect(s.get()).not.toBeNull()
+ vi.advanceTimersByTime(1)
+ expect(s.get()).toBeNull()
+ })
+ it('stays when the pointer comes back to its face in time', () => {
+ const s = cardState<object>()
+ s.hoverEnter('lia', face)
+ vi.advanceTimersByTime(HOVER_OPEN_MS)
+ s.hoverLeave()
+ vi.advanceTimersByTime(HOVER_CLOSE_MS - 50)
+ s.hoverEnter('lia', face)
+ vi.advanceTimersByTime(HOVER_CLOSE_MS * 10)
+ expect(open(s)?.anchor).toBe(face)
+ })
+ it('opens at once on a click, which the same click closes, and a clicked card ignores the pointer', () => {
+ const s = cardState<object>()
+ s.click('lia', face)
+ expect(open(s)).toEqual({ agentId: 'lia', anchor: face, via: 'click' })
+ s.hoverLeave()
+ s.hoverEnter('theo', other)
+ vi.advanceTimersByTime(HOVER_OPEN_MS * 4)
+ expect(open(s)).toEqual({ agentId: 'lia', anchor: face, via: 'click' })
+ s.click('lia', face)
+ expect(s.get()).toBeNull()
+ })
+ it('keeps a hovered card open as a clicked one when its face is clicked', () => {
+ const s = cardState<object>()
+ s.hoverEnter('lia', face)
+ vi.advanceTimersByTime(HOVER_OPEN_MS)
+ s.click('lia', face)
+ s.hoverLeave()
+ vi.advanceTimersByTime(HOVER_CLOSE_MS * 10)
+ expect(open(s)).toEqual({ agentId: 'lia', anchor: face, via: 'click' })
+ })
+ it('a click before the delay opens it right away, with no second card after', () => {
+ const s = cardState<object>()
+ s.hoverEnter('lia', face)
+ vi.advanceTimersByTime(100)
+ s.click('lia', face)
+ vi.advanceTimersByTime(HOVER_OPEN_MS * 4)
+ expect(open(s)?.via).toBe('click')
+ })
+ it('shows one card at a time: a hovered face replaces the hovered card once its delay passes', () => {
+ const s = cardState<object>()
+ s.hoverEnter('lia', face)
+ vi.advanceTimersByTime(HOVER_OPEN_MS)
+ s.hoverLeave()
+ s.hoverEnter('theo', other)
+ vi.advanceTimersByTime(HOVER_OPEN_MS)
+ expect(open(s)).toEqual({ agentId: 'theo', anchor: other, via: 'hover' })
+ })
+ it('doesn’t open while the page scrolls under a still pointer', () => {
+ const s = cardState<object>()
+ s.hoverEnter('lia', face)
+ s.scrolled()
+ vi.advanceTimersByTime(HOVER_OPEN_MS * 2)
+ expect(s.get()).toBeNull()
+ s.scrolled()
+ vi.advanceTimersByTime(50)
+ s.hoverEnter('theo', other) // a face passing under the pointer, right after the scroll
+ vi.advanceTimersByTime(HOVER_OPEN_MS * 2)
+ expect(s.get()).toBeNull()
+ s.hoverEnter('theo', other) // the pointer moves onto it once the page is still
+ vi.advanceTimersByTime(HOVER_OPEN_MS)
+ expect(open(s)?.agentId).toBe('theo')
+ })
+ it('tells who listens when the card opens and closes', () => {
+ const s = cardState<object>()
+ const seen = vi.fn()
+ const stop = s.subscribe(seen)
+ s.click('lia', face)
+ s.close()
+ stop()
+ s.click('lia', face)
+ expect(seen).toHaveBeenCalledTimes(2)
+ })
+})
+
+// Layout needs a browser: a long name or role must wrap inside the card, not widen it.
+it.skipIf(!existsSync(chromium.executablePath()))('keeps a long name, handle and role inside the card', async () => {
+ const browser = await chromium.launch({ headless: true })
+ try {
+ const page = await browser.newPage({ viewport: { width: 1280, height: 820 } })
+ const long = 'Pesquisa-e-desenvolvimento-de-projetos-complexos'.repeat(3)
+ await page.setContent(`
+ <style>${readFileSync(new URL('../src/renderer/src/styles.css', import.meta.url), 'utf8')}</style>
+ <div class="agent-card c-sky" style="left: 20px; top: 20px">
+ <div class="agent-card__band"></div>
+ <div class="agent-card__head">
+ <span class="agent-card__face"><span class="avatar" style="width:64px;height:64px"></span></span>
+ <div class="agent-card__who">
+ <h2 class="agent-card__name">${long}</h2>
+ <div class="agent-card__handle">@${long.toLowerCase()}</div>
+ <div class="agent-card__role">${long}</div>
+ </div>
+ </div>
+ <dl class="agent-card__facts"><div><dt>Modelo</dt><dd>${long}</dd></div></dl>
+ <div class="agent-card__actions"><button class="btn btn--primary btn--sm">Mensagem</button><button class="btn btn--sm">Ver perfil completo</button></div>
+ </div>`)
+ const fits = await page.locator('.agent-card').evaluate((card) => ({ width: (card as HTMLElement).offsetWidth, overflow: card.scrollWidth > card.clientWidth, position: getComputedStyle(card).position }))
+ expect(fits).toEqual({ width: 320, overflow: false, position: 'fixed' })
+ } finally {
+ await browser.close()
+ }
+})