Files
buzz/desktop/src/features/agents/ui/TeamIdentityCard.tsx
Will Pfleger cc00060ea3 feat(agent): Phase 2 — wire Rust and TS consumers to generated model-capabilities module (#3958)
## What

Phase 2 consumer cutover targeting the
`duncan/databricks-model-label-registry` umbrella branch. Wires
`crates/**` and `desktop/**` consumers to the generated capability
module introduced in Phase 1 (#3821), while keeping old and new paths
both live for differential testing. Phase 3 removes the old paths.

## Commits (boundary-separated)

### feat(agent): Phase 2a — wire Rust consumers to generated capability
module (`crates/**`, `scripts/**`)

- `catalog.rs`: `DATABRICKS_V2_KNOWN_MODELS` re-exported from the
generated module — single source of truth.
- `llm.rs`: `databricks_v2_route_for_model` delegates to
`resolve_model_capabilities("databricks_v2", model)`. Old segment-based
classifier preserved as `#[cfg(test)] _old_*` for the differential
harness. New `databricks_v2_route_differential_old_vs_new` test confirms
100% agreement on all 20 route vectors.
- `config.rs`: new `effort_table_fixture_differential_old_vs_new` test
runs `resolve_model_capabilities` over the 36-entry
`effortTable.fixture.json` and asserts old/new agree modulo a doc-cited
allowlist (4 F1 corrections).
- `scripts/run-differential.mjs`: JS differential harness over
effortTable fixture + normative corpus + catalog-sample fixture. 85
checks, 0 unexpected divergences (5 allowlisted: 4 F1 corrections +
goose-opus-5 anthropic route correction).
- `scripts/MODELS_DEV_RECONCILIATION.md`: deferred MINOR from Phase 1 —
8 trailing-double-space line breaks replaced with `<br>`.

### feat(desktop): Phase 2b — cut TS consumers to generated
model-capabilities module (`desktop/**`)

- `buzzAgentConfig.ts`: adds
`getProviderEffortConfigFromManifest(provider, model?)` — thin wrapper
over `resolveModelCapabilities()` from `modelCapabilities.ts`. Maps
`supportedEfforts → validValues` and `defaultEffort → defaultValue`
(null preserved for manual-budget/Inherit). Old
`getProviderEffortConfig()` and all hand-tables stay live for the
differential harness; Phase 3 retires them.
- `formatAgentModelLabel.ts`: registry-label lookup re-pointed from
hand-maintained `databricksModelNames.ts` import to generated
`DATABRICKS_MODEL_NAMES` exported from `modelCapabilities.ts`. Same Map
shape, identical contents, behavior unchanged.

### fix(scripts): add ts-esm-loader and fix allowlist coverage in
run-differential (`scripts/**`)

- `scripts/ts-esm-loader.mjs`: minimal ESM custom loader that resolves
extensionless relative TS imports. Required because Phase 2b's
`buzzAgentConfig.ts` imports `modelCapabilities` without `.ts` extension
— which Node's `--experimental-strip-types` runner cannot resolve
without a hook.
- `scripts/run-differential.mjs`: shebang updated to self-bootstrap with
the loader; fixes the `totalAllowlisted` counter (was declared but never
incremented — always printed `0 allowlisted`). Replaced with per-axis
hit tracking: reports exercised slot count (`N/total`) in summary; fails
with `STALE_ALLOWLIST` if any declared entry fires zero divergences,
preventing stale entries from silently masking future regressions.

## Verification

- `cargo test -p buzz-agent --lib`: 426/426
- Corpus: 45/45 · schema-negative: 24/24 · `--check` byte-clean
- Differential: 85 checks, 0 unexpected divergences, 6/6 allowlist slots
exercised
- Desktop: 3847/3847 · typecheck clean · biome clean
- Mobile: 1019 pass, 1 skipped — same 5 flaky tests in
`mobile/test/features/channels/` that reproduce at the umbrella base;
zero mobile files in this branch range
- `git diff --check`: clean

## What Remains (Phase 3)

Remove old hand-maintained paths: `_old_*` functions in
`llm.rs`/`config.rs`, old `getProviderEffortConfig` tables in
`buzzAgentConfig.ts`, old `databricksModelNames.ts` import in
`formatAgentModelLabel.ts`, old `databricks_model_names.rs` module.

---------

Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: npub1g8493u0xfsjrvflg4n08ezd7vec99mnwzlv0qgwpr9d7gvjwhuzqx59rhw <41ea58f1e64c243627e8acde7c89be667052ee6e17d8f021c1195be4324ebf04@buzz.block.builderlab.xyz>
Signed-off-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@buzz.block.builderlab.xyz>
Co-authored-by: npub1g8493u0xfsjrvflg4n08ezd7vec99mnwzlv0qgwpr9d7gvjwhuzqx59rhw <41ea58f1e64c243627e8acde7c89be667052ee6e17d8f021c1195be4324ebf04@buzz.block.builderlab.xyz>
2026-08-03 14:58:34 -04:00

219 lines
6.9 KiB
TypeScript

import type { ReactNode } from "react";
import { Info, Link, Users } from "lucide-react";
import { ProfileAvatar } from "@/features/profile/ui/ProfileAvatar";
import type { AgentPersona } from "@/shared/api/types";
import { Card } from "@/shared/ui/card";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui/tooltip";
import { formatAgentModelLabel } from "@/features/agents/lib/formatAgentModelLabel";
import { IdentityInitialsAvatar } from "./IdentityInitialsAvatar";
type TeamIdentityCardProps = {
actions: ReactNode;
children?: ReactNode;
dataTestId: string;
description?: string | null;
isSymlink?: boolean;
memberCount: number;
personas: AgentPersona[];
sourceDir?: string | null;
symlinkTarget?: string | null;
teamName: string;
version?: string | null;
};
const MAX_VISIBLE_MEMBER_AVATARS = 4;
export function TeamIdentityCard({
actions,
children,
dataTestId,
description,
isSymlink = false,
memberCount,
personas,
sourceDir,
symlinkTarget,
teamName,
version,
}: TeamIdentityCardProps) {
const footerModelLabel = getTeamFooterModelLabel(personas);
const trimmedDescription = description?.trim();
return (
<Card
className="min-w-0 overflow-hidden rounded-2xl p-0 transition-colors hover:border-border hover:bg-muted/65"
data-testid={dataTestId}
>
<div className="relative aspect-[4/5] min-w-0 overflow-hidden bg-muted/50">
<div className="absolute top-3 left-3 z-30 flex max-w-[calc(100%-4rem)] flex-wrap items-center gap-1.5">
{isSymlink ? (
<Tooltip>
<TooltipTrigger asChild>
<span className="flex h-6 w-6 items-center justify-center rounded-full border border-border/65 bg-background/90 text-muted-foreground shadow-xs">
<Link className="h-3.5 w-3.5" />
</span>
</TooltipTrigger>
<TooltipContent side="bottom" className="max-w-xs">
<p>Linked from {symlinkTarget ?? sourceDir}</p>
</TooltipContent>
</Tooltip>
) : null}
{version ? (
<span className="rounded-full border border-border/65 bg-background/90 px-2 py-1 text-2xs font-medium leading-none text-muted-foreground shadow-xs">
v{version}
</span>
) : null}
{trimmedDescription ? (
<Tooltip>
<TooltipTrigger asChild>
<button
aria-label={`${teamName} description`}
className="flex h-6 w-6 items-center justify-center rounded-full border border-border/65 bg-background/90 text-muted-foreground shadow-xs"
type="button"
>
<Info className="h-3.5 w-3.5" />
</button>
</TooltipTrigger>
<TooltipContent side="bottom" className="max-w-xs">
<p>{trimmedDescription}</p>
</TooltipContent>
</Tooltip>
) : null}
</div>
<div className="absolute top-3 right-3 z-40">{actions}</div>
<TeamAvatarRow
memberCount={memberCount}
personas={personas}
teamName={teamName}
/>
<div className="absolute right-3 bottom-3 left-3 z-30 flex min-w-0 flex-col gap-0.5 text-left text-sm leading-5">
<span className="min-w-0 truncate font-semibold tracking-normal text-foreground">
{teamName}
</span>
<span className="min-w-0 truncate font-normal text-secondary-foreground/75">
{footerModelLabel}
</span>
</div>
</div>
{children}
</Card>
);
}
function TeamAvatarRow({
memberCount,
personas,
teamName,
}: {
memberCount: number;
personas: AgentPersona[];
teamName: string;
}) {
const visiblePersonas = personas.slice(0, MAX_VISIBLE_MEMBER_AVATARS);
const overflowCount = Math.max(0, memberCount - visiblePersonas.length);
const stackItemCount = visiblePersonas.length + (overflowCount > 0 ? 1 : 0);
if (visiblePersonas.length === 0 && overflowCount === 0) {
return (
<div className="absolute inset-x-4 top-0 bottom-12 flex items-center justify-center">
<div className="flex h-24 w-24 items-center justify-center rounded-full border border-border/65 bg-background/80 text-muted-foreground shadow-xs">
<Users className="h-9 w-9" />
</div>
</div>
);
}
return (
<div className="absolute inset-x-0 top-0 bottom-12 flex items-center justify-center">
<div
aria-label={`${teamName} member avatars`}
className="flex max-w-full items-center justify-center px-4"
role="img"
>
{visiblePersonas.map((persona, index) => (
<TeamAvatarItem
index={index}
isFollowedByAnother={index < stackItemCount - 1}
key={persona.id}
persona={persona}
/>
))}
{overflowCount > 0 ? (
<div
className={visiblePersonas.length > 0 ? "-ml-5" : ""}
style={{ zIndex: stackItemCount }}
>
<span className="flex h-14 w-14 items-center justify-center rounded-full bg-card text-sm font-semibold text-muted-foreground">
+{overflowCount}
</span>
</div>
) : null}
</div>
</div>
);
}
function TeamAvatarItem({
index,
isFollowedByAnother,
persona,
}: {
index: number;
isFollowedByAnother: boolean;
persona: AgentPersona;
}) {
const avatarUrl = persona.avatarUrl?.trim() ?? null;
return (
<div
className={`h-14 w-14 ${index > 0 ? "-ml-5" : ""}`}
data-team-member-avatar="avatar"
style={{
zIndex: index + 1,
...(isFollowedByAnother && {
mask: "radial-gradient(circle 32px at calc(100% + 8px) 50%, transparent 99%, #fff 100%)",
WebkitMask:
"radial-gradient(circle 32px at calc(100% + 8px) 50%, transparent 99%, #fff 100%)",
}),
}}
>
{avatarUrl ? (
<ProfileAvatar
avatarUrl={avatarUrl}
className="h-full w-full bg-muted shadow-none"
iconClassName="h-6 w-6"
label={persona.displayName}
testId={`team-member-avatar-${persona.id}`}
/>
) : (
<IdentityInitialsAvatar
className="border-0 shadow-none"
colorIndex={index}
label={persona.displayName}
size={56}
/>
)}
</div>
);
}
function getTeamFooterModelLabel(personas: AgentPersona[]) {
const modelLabels = personas
.map((persona) => formatAgentModelLabel(persona.model, persona.provider))
.filter((model): model is string => Boolean(model));
if (modelLabels.length === 0) return "Auto";
const uniqueModels = new Map(
modelLabels.map((model) => [model.toLowerCase(), model]),
);
return uniqueModels.size === 1
? (uniqueModels.values().next().value ?? "Auto")
: "Mixed models";
}