Files
buzz/desktop/src/features/agents/ui/RestartDiffBadge.tsx
Taylor Ho de8a2741c7 feat(desktop-messages): show compact Buzz link metadata (#6252)
**Category:** improvement
**User Impact:** Buzz links in messages now resolve into compact,
descriptive chips with predictable navigation, while tooltips use the
neutral secondary surface consistently across light and dark themes.

**Problem:** Raw Buzz-native links and opaque identifiers make message
context difficult to scan, while oversized previews disrupt the
conversation. Missing, delayed, or deleted metadata also needs a stable
presentation that does not mislead users or break navigation.

**Solution:** Keep message and issue chips metadata-independent: message
chips render only the channel name, while issue chips render only the
repository name—never fetched content/title or an event hash. Fetched
context remains available in each hover tooltip. Other native links
continue to resolve into concise inline labels, with muted secondary
fallbacks, distinct deleted states, and existing navigation paths
preserved. This also makes two explicit shared-tooltip behavior changes:

1. **Color:** shared and rich tooltips move from the primary color pair
to the neutral secondary semantic pair, including dedicated huddle-token
handling and matching rich-descendant foregrounds.
2. **Hover behavior:** tooltip roots set Radix
`disableHoverableContent`, and tooltip content is pointer-transparent,
so moving off the trigger dismisses the tooltip instead of letting the
pointer enter and keep the popover open.

Together these preserve readable contrast, authoritative project
context, and predictable hover dismissal.

<details>
<summary>File changes</summary>

**desktop/src/features/communities/useCommunityInit.ts**
Primes channel metadata needed to resolve native links promptly.

**desktop/src/features/messages/lib/messageLinkMetadata.test.mjs**
Covers message preview extraction, fallbacks, and deleted-message
semantics.

**desktop/src/features/messages/lib/messageLinkMetadata.ts**
Normalizes fetched message metadata into compact labels and status-aware
presentation.

**desktop/src/features/messages/ui/SentFromThreadLine.tsx**
Provides thread context to linked-message metadata resolution.

**desktop/src/shared/lib/useResolvedLinkPreviews.ts**
Exposes resolved preview state for native entity chips.

**desktop/src/shared/styles/globals/markdown.css**
Adds compact chip layout and semantic disabled-state styling.

**desktop/src/shared/styles/globals/theme.css**
Defines the semantic colors used by unavailable and deleted chips.

**desktop/src/shared/ui/markdown.test.mjs**
Exercises native-link rendering and provider-backed entity metadata
behavior.

**desktop/src/shared/ui/markdown.tsx**
Routes native markdown links through metadata-aware chip components
without changing navigation contracts.

**desktop/src/shared/ui/markdown/ChannelDeepLink.test.mjs**
Covers resolved, unresolved, private, archived, and forum channel
presentations.

**desktop/src/shared/ui/markdown/ChannelDeepLink.tsx**
Renders channel names and concise channel metadata inline with stable
fallbacks.

**desktop/src/shared/ui/markdown/MessageLinkPill.tsx**
Renders loading, ready, unavailable, DM, forum, and deleted message
states compactly.

**desktop/src/shared/ui/markdown/entityLinks.tsx**
Enriches repository, issue, and pull-request chips and uses
containing-project context in tooltips.

**desktop/src/shared/ui/markdown/types.ts**
Extends markdown runtime metadata required by native chip rendering.

**desktop/src/shared/ui/markdown/useMessageLinkMetadata.ts**
Fetches and classifies linked-message metadata while preserving
navigable fallbacks.

**desktop/src/testing/e2eBridge.ts**
Adds deterministic metadata controls for runtime visual and navigation
tests.

**desktop/tailwind.config.js**
Makes semantic disabled colors available to chip styles.

**desktop/tests/e2e/entity-link-recipient-cards.spec.ts**
Verifies entity labels, project-aware tooltips, delayed metadata, and
navigation behavior.

**desktop/tests/e2e/navigation.spec.ts**
Verifies channel and message chip states, metadata resolution, deletion
handling, and navigation.

**desktop/src/shared/ui/tooltip.tsx**
Migrates the shared tooltip surface from the primary color pair to the
semantic secondary pair. It also sets Radix `disableHoverableContent`
and makes tooltip content pointer-transparent so leaving the trigger
dismisses the tooltip predictably.

**desktop/src/features/agents/ui/RestartDiffBadge.tsx**
Aligns restart-diff tooltip values and supporting copy with the
secondary tooltip foreground.

**desktop/src/features/channels/ui/AddChannelBotTeamsSection.tsx**
Aligns rich team tooltip descriptions, persona chips, avatars, and names
with secondary tooltip semantics.

**desktop/src/features/projects/ui/ProjectAuthorIdentity.tsx**
Uses the matching secondary tooltip foreground for project author
metadata.

**desktop/src/features/projects/ui/ProjectCards.tsx**
Aligns repository-unavailable tooltip descriptions with the secondary
tooltip foreground.

**desktop/src/shared/styles/globals/utilities.css**
Makes huddle tooltips consume their dedicated palette directly without
misleading primary or secondary aliases.

**desktop/src/shared/styles/globals/tooltipSemantics.test.mjs**
Pins direct huddle-token consumption and rejects semantic alias drift.

**desktop/tests/e2e/tooltip-semantics.spec.ts**
Verifies simple and rich tooltip surfaces and descendant tokens in Buzz
light and Catppuccin Mocha dark themes.

**desktop/playwright.config.ts**
Registers tooltip semantic coverage in the desktop smoke suite.

</details>

## Reproduction steps

1. Run the desktop app and open a message containing Buzz links for a
channel, message, repository, issue, and pull request.
2. Confirm message links show only the channel name and issue links show
only the repository name inline, with no fetched content/title or event
hash; confirm other native links remain compact rather than rendering
raw identifiers or expanded previews.
3. Hover the chips and confirm the neutral secondary tooltip adds
concise context without duplicating the visible label.
4. Open each chip and confirm it follows the same channel, message,
repository, issue, or pull-request navigation as before.
5. Inspect links while metadata is loading, unavailable, or definitively
deleted and confirm the fallback remains compact, legible, and navigable
where appropriate.
6. In Buzz light and Catppuccin Mocha dark themes, compare a simple
channel-members tooltip and the rich Add agents team tooltip; both
should use secondary semantics with readable nested content.
7. Move the pointer from a trigger toward its tooltip; confirm the
tooltip dismisses rather than remaining open as hoverable content.

## Screenshots

The matrix below covers both the default light theme and Catppuccin
Mocha with an orange accent. Message/issue-chip rows affected by the
stable-label pivot are temporarily omitted until they can be recaptured
from the real built UI; the prior images showed the obsolete expanding
inline label.

| State | Default light | Dark · orange accent |
|---|---|---|
| Public stream channel tooltip | ![Public stream channel tooltip —
default
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/light-default/01-public-stream-channel-tooltip.png)
| ![Public stream channel tooltip — dark orange
accent](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/dark-orange/01-public-stream-channel-tooltip.png)
|
| Private forum channel tooltip | ![Private forum channel tooltip —
default
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/light-default/02-private-forum-channel-tooltip.png)
| ![Private forum channel tooltip — dark orange
accent](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/dark-orange/02-private-forum-channel-tooltip.png)
|
| Public forum channel tooltip | ![Public forum channel tooltip —
default
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/light-default/03-forum-channel-tooltip.png)
| ![Public forum channel tooltip — dark orange
accent](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/dark-orange/03-forum-channel-tooltip.png)
|
| Channel references, including unresolved | ![Channel references,
including unresolved — default
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/light-default/04-unresolved-channel-reference.png)
| ![Channel references, including unresolved — dark orange
accent](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/dark-orange/04-unresolved-channel-reference.png)
|
| Unknown channel permalink | ![Unknown channel permalink — default
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/light-default/05-unknown-channel-permalink.png)
| ![Unknown channel permalink — dark orange
accent](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/dark-orange/05-unknown-channel-permalink.png)
|
| Archived channel tooltip | ![Archived channel tooltip — default
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/light-default/06-archived-channel-tooltip.png)
| ![Archived channel tooltip — dark orange
accent](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/dark-orange/06-archived-channel-tooltip.png)
|
| Repository entity | ![Repository entity — default
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/light-default/13-repository-entity.png)
| ![Repository entity — dark orange
accent](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/dark-orange/13-repository-entity.png)
|
| Pull request entity | ![Pull request entity — default
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/light-default/14-pull-request-entity.png)
| ![Pull request entity — dark orange
accent](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/chip-metadata/dark-orange/14-pull-request-entity.png)
|
| Entity metadata fallback | ![Corrected entity metadata fallback
tooltip — default
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/17-entity-metadata-fallback-corrected-light.png)
| ![Corrected entity metadata fallback tooltip — dark orange
accent](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6252/17-entity-metadata-fallback-corrected-dark-orange.png)
|



### Tooltip semantic surface spot check

| Buzz light | Catppuccin Mocha dark |
|---|---|
| ![Rich team tooltip on the secondary surface in Buzz
light](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6290/buzz-team-tooltip.png)
| ![Rich team tooltip on the secondary surface in Catppuccin Mocha
dark](https://d24qwcpro867f5.cloudfront.net/repos/buzz/prs/6290/catppuccin-mocha-team-tooltip.png)
|

---------

Signed-off-by: Taylor Ho <taylorkmho@gmail.com>
Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@buzz.block.builderlab.xyz>
2026-08-20 19:01:18 -07:00

210 lines
6.9 KiB
TypeScript

import { RefreshCw } from "lucide-react";
import { Badge } from "@/shared/ui/badge";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui/tooltip";
import type { RestartDiffEntry, RestartChange } from "@/shared/api/types";
import { cn } from "@/shared/lib/cn";
// ── Auto-restart copy ─────────────────────────────────────────────────────────
/**
* Shared blurb strings for the auto-restart state. Exported so the Runtime-tab
* banner can import the same constants — the two surfaces must never drift.
*/
export const AUTO_RESTART_ON_BLURB =
"Configuration changed since this agent started. Buzz can restart it automatically after ~3 minutes idle, or stop and respawn it to apply now.";
export const AUTO_RESTART_OFF_BLURB =
"Configuration changed since this agent started. Automatic restart is off for this agent — stop and respawn it to apply the changes.";
// ── Label helpers ─────────────────────────────────────────────────────────────
/**
* Humanise a serde dotted-path field id into a display label.
* `snake_case` → `"Snake case"`, `env.FOO` → `"FOO (env)"`.
* Unknown paths render as-is — no per-field label map.
*/
function humaniseFieldId(field: string): string {
if (field.startsWith("env.")) {
const key = field.slice(4);
return `${key} (env)`;
}
// snake_case → words, sentence case
return field.replace(/_/g, " ").replace(/\b\w/, (c) => c.toUpperCase());
}
// ── Change description ────────────────────────────────────────────────────────
function formatJsonValue(v: unknown): string {
if (v === null) return "null";
if (v === undefined) return "—";
if (typeof v === "string") return v;
return JSON.stringify(v);
}
function ChangeDescription({ change }: { change: RestartChange }) {
switch (change.kind) {
case "value":
return (
<span>
<span className="line-through opacity-60">
{formatJsonValue(change.before)}
</span>
{" → "}
<span>{formatJsonValue(change.after)}</span>
</span>
);
case "text": {
const before = change.before_chars ?? 0;
const after = change.after_chars ?? 0;
return (
<span>
{before} chars → {after} chars
</span>
);
}
case "masked":
return (
<span>
<span className="line-through opacity-60">
{change.before ?? "••••"}
</span>
{" → "}
<span>{change.after ?? "••••"}</span>
</span>
);
case "added":
return <span>added</span>;
case "removed":
return <span>removed</span>;
default:
// Unknown kind — render nothing, remain type-safe at runtime
return null;
}
}
// ── Diff list ─────────────────────────────────────────────────────────────────
const TOOLTIP_CAP = 6;
/**
* `tooltip` — renders inside the semantic secondary tooltip surface; uses
* `text-secondary-foreground` variants for contrast there.
* `inline` — renders inside the amber Runtime banner or other light
* surfaces; inherits foreground from the container instead.
*/
function DiffList({
entries,
cap,
variant = "tooltip",
}: {
entries: RestartDiffEntry[];
cap?: number;
variant?: "tooltip" | "inline";
}) {
const visible = cap !== undefined ? entries.slice(0, cap) : entries;
const overflow =
cap !== undefined && entries.length > cap ? entries.length - cap : 0;
const valueClass =
variant === "tooltip" ? "text-secondary-foreground/80" : "text-foreground";
const overflowClass =
variant === "tooltip"
? "text-secondary-foreground/60"
: "text-muted-foreground";
return (
<ul className="space-y-1">
{visible.map((entry) => (
<li className="flex items-baseline gap-1.5" key={entry.field}>
<span className="shrink-0 font-medium">
{humaniseFieldId(entry.field)}:
</span>
<span className={valueClass}>
<ChangeDescription change={entry.change} />
</span>
</li>
))}
{overflow > 0 ? (
<li className={overflowClass}>and {overflow} more</li>
) : null}
</ul>
);
}
// ── Badge + tooltip ───────────────────────────────────────────────────────────
/**
* The restart-required badge. When `restartDiff` is non-empty, shows a hover
* tooltip with the itemised before→after diff (capped at {@link TOOLTIP_CAP}
* entries) plus the auto-restart blurb. Renders as a non-interactive `<span>`
* so it can safely be placed adjacent to (not inside) a `<button>` — it must
* never be a descendant of an interactive element.
*/
export function RestartDiffBadge({
autoRestartEnabled = false,
restartDiff,
className,
}: {
autoRestartEnabled?: boolean;
restartDiff: RestartDiffEntry[];
className?: string;
}) {
const badge = (
<Badge className={cn("cursor-default gap-1", className)} variant="warning">
<RefreshCw className="h-3 w-3" />
Restart required
</Badge>
);
if (restartDiff.length === 0) {
// No diff data — render plain badge without tooltip.
return badge;
}
return (
<Tooltip>
{/* asChild renders the trigger as the Badge's <span>, which is a valid
non-interactive element. No nested button. */}
<TooltipTrigger asChild>
<Badge
className={cn("cursor-default gap-1", className)}
variant="warning"
tabIndex={0}
data-testid="restart-diff-badge"
>
<RefreshCw className="h-3 w-3" />
Restart required
</Badge>
</TooltipTrigger>
<TooltipContent className="max-w-72 text-xs" side="bottom">
<p className="mb-1.5 font-semibold">Config changed since last start:</p>
<DiffList cap={TOOLTIP_CAP} entries={restartDiff} />
<p className="mt-1.5 text-secondary-foreground/70">
{autoRestartEnabled ? AUTO_RESTART_ON_BLURB : AUTO_RESTART_OFF_BLURB}
</p>
</TooltipContent>
</Tooltip>
);
}
/**
* Full uncapped diff list for the Runtime-tab banner. Renders inline; no
* tooltip wrapper.
*/
export function RestartDiffList({
restartDiff,
}: {
restartDiff: RestartDiffEntry[];
}) {
if (restartDiff.length === 0) return null;
return (
<div
className="mt-2 text-xs text-muted-foreground"
data-testid="restart-diff-list"
>
<DiffList entries={restartDiff} variant="inline" />
</div>
);
}