feat(webui): port the shared primitives (Phase 2)

The Preact tree's ui/src/base/ was deleted with the dashboard. This rebuilds
what depended on it, on the shadcn layer rather than as new bespoke markup.

Badge and Card come from the shadcn-vue CLI, so they match the already-vendored
components, and the composed pieces sit on top of them:

- Badge gains the five status variants the pills used, over the palette's status
  tokens. The pill's dot did not come across: the Badge's own shape is the
  affordance, and the same variant now covers a trend indicator, where a dot
  reads as noise.
- base/StatTile.vue uses full Card composition instead of dumping everything
  into one content slot, with base/Sparkline.vue and the goodDirection logic
  that says whether "up" is good news.
- base/Gauge.vue and base/SegmentBar.vue, both of them: the original exported
  two components from one file and budget composition uses the second.
- base/LogRow.vue over lib/log.ts, which holds the LOG_LEVELS wire contract
  (the server matches that CSV server-side, so it is not a display choice).
- lib/status.ts, so status colour has one home: a task state, a gate result, a
  log level and a trend all draw from the same five kinds.

Two deliberate departures:

The icon module is not ported. Its name-to-glyph string lookup is the pattern
shadcn-vue's rules call out as wrong, and nothing consumes the five bespoke
glyphs anyway: the navigation is text with tooltips. Icons come from @lucide/vue
at the call site, and the five become components if a page draws them.

The gauge's aria-label announces the rounded percentage. It announced the raw
one, so a screen reader read 71.38461538461539% where the screen showed 71%
(bead 86au).

Also lands the four modules the checklist marks copy-verbatim, which encode
bugs fixed just before the delete: dashboard/activity-detail, chat/
command-scroll, workflows/workflow-rows and logs/logs-empty.
This commit is contained in:
sam committed 2026-09-20 19:38:17 +10:00
1 parent c578a4d6c3
commit 3d20dde9cb
23 files changed
+740 -16

No files matched your search

+75
View File
@@ -0,0 +1,75 @@
<script setup lang="ts">
import { computed } from "vue";
/**
* Arc gauge for a single headline percentage.
*
* A percentage that decides whether you need to act deserves more than a line
* of text: the arc is readable at a glance from across a room, which a number
* is not. Colour follows the value, so "is this bad" is answered before the
* digits are read.
*/
const props = withDefaults(defineProps<{ value: number | string; label: string; size?: number }>(), {
size: 168,
});
const pct = computed(() => Math.max(0, Math.min(100, Number(props.value) || 0)));
const rounded = computed(() => Math.round(pct.value));
const stroke = computed(() => (pct.value >= 90 ? "var(--ok)" : pct.value >= 70 ? "var(--warn)" : "var(--danger)"));
// 240-degree arc, opening downward, so the value reads left-to-right.
const R = 62;
const SWEEP = 240;
const START = 150;
const circumference = 2 * Math.PI * R * (SWEEP / 360);
function arc(from: number, deg: number): string {
const cx = props.size / 2;
const cy = props.size / 2;
const a0 = (from * Math.PI) / 180;
const a1 = ((from + deg) * Math.PI) / 180;
const large = deg > 180 ? 1 : 0;
return [
`M ${cx + R * Math.cos(a0)} ${cy + R * Math.sin(a0)}`,
`A ${R} ${R} 0 ${large} 1 ${cx + R * Math.cos(a1)} ${cy + R * Math.sin(a1)}`,
].join(" ");
}
</script>
<template>
<div class="relative grid place-items-center">
<!--
The label announces the rounded value. It used to announce the raw one, so
a screen reader read "71.38461538461539%" before the same figure was
shown rounded.
-->
<svg
class="block w-full max-w-[200px]"
:viewBox="`0 0 ${props.size} ${props.size * 0.78}`"
role="img"
:aria-label="`${props.label}: ${rounded}%`"
>
<path
:d="arc(START, SWEEP)"
fill="none"
stroke="var(--border)"
stroke-width="12"
stroke-linecap="round"
/>
<path
:d="arc(START, SWEEP)"
fill="none"
:stroke="stroke"
stroke-width="12"
stroke-linecap="round"
:stroke-dasharray="circumference"
:stroke-dashoffset="circumference * (1 - pct / 100)"
class="transition-[stroke-dashoffset] duration-[600ms] ease-[cubic-bezier(0.4,0,0.2,1)]"
/>
</svg>
<div class="absolute top-[52%] -translate-y-1/2 text-center">
<div class="text-2xl font-semibold tracking-[-0.03em]">{{ rounded }}%</div>
<div class="text-xs text-fg-muted">{{ props.label }}</div>
</div>
</div>
</template>
+33
View File
@@ -0,0 +1,33 @@
<script setup lang="ts">
import { fmtValue, LEVEL_COLOR, levelKind, shortTime, type LogEntry } from "@/lib/log";
/**
* Shared log-entry rendering. Both the daemon-wide log page and a task's own
* attempt log render the same entry shape, so the row lives here rather than
* being duplicated a second time.
*/
const props = defineProps<{ entry: LogEntry }>();
const fields = () => Object.entries(props.entry.fields ?? {});
</script>
<template>
<div
class="grid grid-cols-[62px_52px_1fr] items-baseline gap-3 border-b border-border px-1 py-2 hover:bg-accent"
>
<span class="font-mono text-fg-subtle">{{ shortTime(props.entry.time) }}</span>
<span class="text-[10px] font-semibold tracking-[0.04em]" :class="LEVEL_COLOR[levelKind(props.entry.level)]">
{{ (props.entry.level || "info").toUpperCase() }}
</span>
<span class="flex min-w-0 flex-wrap items-baseline gap-2">
<span class="break-words text-foreground">{{ props.entry.message || props.entry.msg || "" }}</span>
<span
v-for="[k, v] in fields()"
:key="k"
class="max-w-full truncate rounded-sm bg-muted px-2 text-fg-muted"
>
<span class="text-fg-subtle after:opacity-60 after:content-['=']">{{ k }}</span>{{ fmtValue(v) }}
</span>
</span>
</div>
</template>
+46
View File
@@ -0,0 +1,46 @@
<script setup lang="ts">
import { computed } from "vue";
import { STATUS_FILL, type StatusKind } from "@/lib/status";
/**
* Segmented proportional bar with a legend.
*
* Used for budget composition -- what is spent, committed and still free --
* because three related quantities are easier to compare in one bar than in
* three separate numbers.
*/
const props = defineProps<{
segments: Array<{ label: string; value: number; kind?: StatusKind }>;
}>();
const total = computed(() => props.segments.reduce((a, s) => a + (s.value || 0), 0) || 1);
const partWidth = (value: number) => `${((value / total.value) * 100).toFixed(1)}%`;
const fill = (kind?: StatusKind) => STATUS_FILL[kind ?? "idle"];
</script>
<template>
<div>
<div class="flex h-[10px] gap-[2px] overflow-hidden rounded-full bg-border">
<span
v-for="s in props.segments.filter((s) => s.value > 0)"
:key="s.label"
class="block h-full"
:class="fill(s.kind)"
:style="`width:${partWidth(s.value)}`"
:title="`${s.label}: ${s.value}`"
/>
</div>
<div class="mt-3 flex flex-wrap gap-4">
<span
v-for="s in props.segments"
:key="s.label"
class="inline-flex items-center gap-2 text-xs text-fg-muted"
>
<span class="size-2 rounded-full" :class="fill(s.kind)" />
{{ s.label }}
</span>
</div>
</div>
</template>
+45
View File
@@ -0,0 +1,45 @@
<script setup lang="ts">
import { computed } from "vue";
/**
* Inline SVG sparkline. Shows shape, not exact values: the tile's headline
* number carries the precision.
*/
const props = withDefaults(
defineProps<{ series: number[]; stroke?: string; width?: number; height?: number }>(),
{ stroke: "var(--ok)", width: 220, height: 34 },
);
const points = computed(() => {
const max = Math.max(...props.series, 1);
const min = Math.min(...props.series, 0);
const span = max - min || 1;
const step = props.series.length > 1 ? props.width / (props.series.length - 1) : props.width;
return props.series
.map(
(v, i) =>
`${(i * step).toFixed(1)},${(props.height - ((v - min) / span) * props.height).toFixed(1)}`,
)
.join(" ");
});
</script>
<template>
<svg
class="mt-3 block h-[34px] w-full"
:viewBox="`0 0 ${props.width} ${props.height}`"
preserveAspectRatio="none"
aria-hidden="true"
>
<polyline
:points="points"
fill="none"
:stroke="props.stroke"
stroke-width="1.5"
stroke-linecap="round"
stroke-linejoin="round"
vector-effect="non-scaling-stroke"
/>
</svg>
</template>
+63
View File
@@ -0,0 +1,63 @@
<script setup lang="ts">
import { TrendingDown, TrendingUp } from "@lucide/vue";
import { computed } from "vue";
import { Badge } from "@/components/ui/badge";
import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import Sparkline from "./Sparkline.vue";
/**
* A KPI tile: label, big value, trend against a stated comparison window, and
* a sparkline. The comparison line is not decoration -- a number without a
* baseline cannot be acted on, so `compare` is required.
*
* trend > 0 renders as an increase. `goodDirection` says whether that is good,
* because rising latency and rising success rate are not the same news.
*
* The headline value is rendered whatever its type, including 0 and "": a tile
* that showed a label and a comparison line with no number above them read as
* a broken dashboard on every fresh install.
*/
const props = withDefaults(
defineProps<{
label: string;
value: string | number;
unit?: string;
trend?: number | null;
compare: string;
series?: number[];
goodDirection?: "up" | "down";
}>(),
{ series: () => [], goodDirection: "up" },
);
const dir = computed(() => (props.trend == null ? null : props.trend >= 0 ? "up" : "down"));
const good = computed(() => (dir.value == null ? null : dir.value === props.goodDirection));
const trendIcon = computed(() => (dir.value === "up" ? TrendingUp : TrendingDown));
const trendLabel = computed(() => `${Math.abs(props.trend ?? 0).toFixed(1)}%`);
</script>
<template>
<Card>
<CardHeader>
<CardTitle>{{ props.label }}</CardTitle>
<CardDescription v-if="props.compare">{{ props.compare }}</CardDescription>
<CardAction v-if="dir">
<Badge :variant="good ? 'ok' : 'danger'">
<component :is="trendIcon" />
{{ trendLabel }}
</Badge>
</CardAction>
</CardHeader>
<CardContent>
<div class="text-3xl font-semibold tracking-[-0.03em]">
{{ props.value }}<span v-if="props.unit" class="ml-1 text-lg text-fg-muted">{{ props.unit }}</span>
</div>
<Sparkline
v-if="props.series.length > 1"
:series="props.series"
:stroke="good === false ? 'var(--danger)' : 'var(--ok)'"
/>
</CardContent>
</Card>
</template>