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
4 changes: 2 additions & 2 deletions scripts/generate-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ const MVP_COMPONENTS: Record<string, ComponentManifest> = {
'delegation-metrics': {
name: 'delegation-metrics',
displayName: 'Delegation Metrics',
description: 'Task delegation events, cost savings, and quality gate pass rates; dimension config switches between flat 2D donut and tilted 3D doughnut',
description: 'Task delegation events, model breakdown, cost savings, and quality gate pass rates; dimension config switches between flat 2D donut and tilted 3D doughnut',
category: 'quality',
version: '2.0.0',
version: '2.1.0',
implementationKey: 'delegation/DelegationMetrics',
configSchema: {
type: 'object',
Expand Down
20 changes: 20 additions & 0 deletions src/components/dashboard/delegation/DelegationMetrics2D.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ describe('DelegationMetrics2D', () => {
mockFetchWithItems([{
totalDelegations: 150,
qualityGatePassRate: 0.85,
qualityGatePassed: 128,
qualityGateTotal: 150,
totalSavingsUsd: 42.5,
byTaskType: [{ taskType: 'code-review', count: 80 }, { taskType: 'refactor', count: 70 }],
byModel: [{ model: 'Qwen3-Coder-30B', count: 80 }, { model: 'glm-4-plus', count: 70 }],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand All @@ -35,15 +38,20 @@ describe('DelegationMetrics2D', () => {
);
expect(await screen.findByText('150')).toBeInTheDocument();
expect(screen.getByText('85%')).toBeInTheDocument();
expect(screen.getByText('128 / 150 passed')).toBeInTheDocument();
expect(screen.getByText('Qwen3-Coder-30B (80)')).toBeInTheDocument();
expect(screen.getByTestId('delegation-2d-donut')).toBeInTheDocument();
});

it('shows empty state when no delegations', async () => {
mockFetchWithItems([{
totalDelegations: 0,
qualityGatePassRate: 0,
qualityGatePassed: 0,
qualityGateTotal: 0,
totalSavingsUsd: 0,
byTaskType: [],
byModel: [],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand All @@ -57,8 +65,11 @@ describe('DelegationMetrics2D', () => {
mockFetchWithItems([{
totalDelegations: 10,
qualityGatePassRate: 0.9,
qualityGatePassed: 9,
qualityGateTotal: 10,
totalSavingsUsd: 12.34,
byTaskType: [{ taskType: 'a', count: 10 }],
byModel: [{ model: 'Qwen3-Coder-30B', count: 10 }],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand All @@ -74,8 +85,11 @@ describe('DelegationMetrics2D', () => {
mockFetchWithItems([{
totalDelegations: 10,
qualityGatePassRate: 0.9,
qualityGatePassed: 9,
qualityGateTotal: 10,
totalSavingsUsd: 5,
byTaskType: [{ taskType: 'a', count: 10 }],
byModel: [],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand All @@ -91,8 +105,11 @@ describe('DelegationMetrics2D', () => {
mockFetchWithItems([{
totalDelegations: 100,
qualityGatePassRate: 0.75,
qualityGatePassed: 75,
qualityGateTotal: 100,
totalSavingsUsd: 0,
byTaskType: [{ taskType: 'a', count: 100 }],
byModel: [],
}]);
const { unmount } = render(
<DataSourceTestProvider client={qc}>
Expand All @@ -106,8 +123,11 @@ describe('DelegationMetrics2D', () => {
mockFetchWithItems([{
totalDelegations: 100,
qualityGatePassRate: 0.75,
qualityGatePassed: 75,
qualityGateTotal: 100,
totalSavingsUsd: 0,
byTaskType: [{ taskType: 'a', count: 100 }],
byModel: [],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand Down
14 changes: 14 additions & 0 deletions src/components/dashboard/delegation/DelegationMetrics2D.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ export default function DelegationMetrics2D({ config }: { config: Record<string,
{Math.round(data.qualityGatePassRate * 100)}%
</Text>
<Text as="div" size="md" color="primary">Quality Gate Pass Rate</Text>
<Text as="div" size="sm" color="secondary">
{data.qualityGatePassed} / {data.qualityGateTotal} passed
</Text>
</div>
)}
{showSavings && (
Expand Down Expand Up @@ -237,6 +240,17 @@ export default function DelegationMetrics2D({ config }: { config: Record<string,
</Text>
</div>
))}
{data.byModel.length > 0 && (
<>
<span aria-hidden style={{ display: 'inline-block', width: 10, height: 1, background: 'var(--line-2)', flex: '0 0 auto' }} />
<Text as="span" size="sm" color="secondary" weight="semibold">Models:</Text>
{data.byModel.map((m) => (
<Text key={m.model} as="span" size="sm" family="mono" color="secondary">
{m.model} ({m.count})
</Text>
))}
</>
)}
</div>
{hoverIdx !== null && sliceArcs[hoverIdx] && (
<div
Expand Down
20 changes: 20 additions & 0 deletions src/components/dashboard/delegation/DelegationMetrics3D.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ describe('DelegationMetrics', () => {
mockFetchWithItems([{
totalDelegations: 150,
qualityGatePassRate: 0.85,
qualityGatePassed: 128,
qualityGateTotal: 150,
totalSavingsUsd: 42.5,
byTaskType: [{ taskType: 'code-review', count: 80 }, { taskType: 'refactor', count: 70 }],
byModel: [{ model: 'Qwen3-Coder-30B', count: 80 }, { model: 'glm-4-plus', count: 70 }],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand All @@ -58,14 +61,19 @@ describe('DelegationMetrics', () => {
);
expect(await screen.findByText('150')).toBeInTheDocument();
expect(screen.getByText('85%')).toBeInTheDocument();
expect(screen.getByText('128 / 150 passed')).toBeInTheDocument();
expect(screen.getByText('Qwen3-Coder-30B (80)')).toBeInTheDocument();
});

it('shows empty state when no delegations', async () => {
mockFetchWithItems([{
totalDelegations: 0,
qualityGatePassRate: 0,
qualityGatePassed: 0,
qualityGateTotal: 0,
totalSavingsUsd: 0,
byTaskType: [],
byModel: [],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand All @@ -83,8 +91,11 @@ describe('DelegationMetrics', () => {
mockFetchWithItems([{
totalDelegations: 10,
qualityGatePassRate: 0.9,
qualityGatePassed: 9,
qualityGateTotal: 10,
totalSavingsUsd: 12.34,
byTaskType: [{ taskType: 'a', count: 10 }],
byModel: [{ model: 'Qwen3-Coder-30B', count: 10 }],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand All @@ -100,8 +111,11 @@ describe('DelegationMetrics', () => {
mockFetchWithItems([{
totalDelegations: 10,
qualityGatePassRate: 0.9,
qualityGatePassed: 9,
qualityGateTotal: 10,
totalSavingsUsd: 5,
byTaskType: [{ taskType: 'a', count: 10 }],
byModel: [],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand All @@ -123,8 +137,11 @@ describe('DelegationMetrics', () => {
mockFetchWithItems([{
totalDelegations: 100,
qualityGatePassRate: 0.75,
qualityGatePassed: 75,
qualityGateTotal: 100,
totalSavingsUsd: 0,
byTaskType: [{ taskType: 'a', count: 100 }],
byModel: [],
}]);
const { unmount } = render(
<DataSourceTestProvider client={qc}>
Expand All @@ -138,8 +155,11 @@ describe('DelegationMetrics', () => {
mockFetchWithItems([{
totalDelegations: 100,
qualityGatePassRate: 0.75,
qualityGatePassed: 75,
qualityGateTotal: 100,
totalSavingsUsd: 0,
byTaskType: [{ taskType: 'a', count: 100 }],
byModel: [],
}]);
render(
<DataSourceTestProvider client={qc}>
Expand Down
17 changes: 16 additions & 1 deletion src/components/dashboard/delegation/DelegationMetrics3D.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { DoughnutChart, type DoughnutSlice } from './DoughnutChart';
export interface DelegationSummary {
totalDelegations: number;
qualityGatePassRate: number;
qualityGatePassed: number;
qualityGateTotal: number;
totalSavingsUsd: number;
byTaskType: Array<{ taskType: string; count: number }>;
byModel: Array<{ model: string; count: number }>;
}

export default function DelegationMetrics({ config }: { config: Record<string, unknown> }) {
Expand Down Expand Up @@ -70,6 +73,9 @@ export default function DelegationMetrics({ config }: { config: Record<string, u
{Math.round(data.qualityGatePassRate * 100)}%
</Text>
<Text as="div" size="md" color="primary">Quality Gate Pass Rate</Text>
<Text as="div" size="sm" color="secondary">
{data.qualityGatePassed} / {data.qualityGateTotal} passed
</Text>
</div>
)}
{showSavings && (
Expand All @@ -79,8 +85,17 @@ export default function DelegationMetrics({ config }: { config: Record<string, u
</div>
)}
</div>
<div style={{ flex: 1, minHeight: '150px' }}>
<div style={{ flex: 1, minHeight: '150px', display: 'flex', flexDirection: 'column', gap: '0.5rem' }}>
<DoughnutChart slices={slices} height={260} />
{data.byModel.length > 0 && (
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '4px 12px', justifyContent: 'center', paddingTop: 4, borderTop: '1px solid var(--line-2)' }}>
{data.byModel.map((m) => (
<Text key={m.model} as="span" size="sm" color="secondary">
{m.model} ({m.count})
</Text>
))}
</div>
)}
</div>
</div>
)}
Expand Down
15 changes: 15 additions & 0 deletions src/storybook/fixtures/delegation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export interface BuildDelegationMetricsOptions {
totalDelegations?: number;
/** Quality-gate pass rate, 0..1. Default 0.84. */
qualityGatePassRate?: number;
/** Quality-gate passed count. Derived from passRate * total if omitted. */
qualityGatePassed?: number;
/** Quality-gate total checks. Defaults to totalDelegations if omitted. */
qualityGateTotal?: number;
/** Total cost savings in USD. Default 158.42. */
totalSavingsUsd?: number;
/**
Expand All @@ -17,6 +21,7 @@ export interface BuildDelegationMetricsOptions {
}

const TASK_TYPES = ['code-review', 'pattern-match', 'document-summarize', 'classification'];
const MODELS = ['Qwen3-Coder-30B', 'glm-4-plus', 'codex-cli', 'gemini-cli'];

/**
* Build a single `DelegationSummary` record. Story callers should
Expand All @@ -28,6 +33,8 @@ export function buildDelegationMetrics(
): DelegationSummary {
const totalDelegations = opts.totalDelegations ?? 247;
const qualityGatePassRate = opts.qualityGatePassRate ?? 0.84;
const qualityGateTotal = opts.qualityGateTotal ?? totalDelegations;
const qualityGatePassed = opts.qualityGatePassed ?? Math.round(qualityGatePassRate * qualityGateTotal);
const totalSavingsUsd = opts.totalSavingsUsd ?? 158.42;
const profile = opts.profile ?? 'balanced';

Expand All @@ -43,10 +50,18 @@ export function buildDelegationMetrics(
count: Math.round(weights[i] * totalDelegations),
}));

const byModel = MODELS.map((model, i) => ({
model,
count: Math.round(weights[i] * totalDelegations),
}));

return {
totalDelegations,
qualityGatePassRate,
qualityGatePassed,
qualityGateTotal,
totalSavingsUsd,
byTaskType,
byModel,
};
}
Loading