feat(ui): one Runs view for a workflow, built on the run list the canvas uses (#1950, #1953)

This commit is contained in:
sam committed 2026-11-13 14:28:27 +11:00
1 parent 5e9e551fbb
commit a5ba2c994f
9 files changed
+132 -285

No files matched your search

-48
View File
@@ -1,48 +0,0 @@
<script setup lang="ts">
import { computed } from "vue";
import { Section } from "@/components/ui/section";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { formatMs, pct, workflowLabel } from "./labels";
import { maxStageMs, slowestStages, type StageStats } from "./stages";
import WorkflowBar from "./WorkflowBar.vue";
/** Which stage is eating the time. */
const props = defineProps<{ stages: StageStats[] }>();
const rows = computed(() => slowestStages(props.stages));
const maxMs = computed(() => maxStageMs(props.stages));
</script>
<template>
<Section title="Slowest stages" class="mb-0">
<Table>
<TableHeader>
<TableRow>
<TableHead>Workflow</TableHead>
<TableHead>Stage</TableHead>
<TableHead>Runs</TableHead>
<TableHead>Avg duration</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-for="(s, idx) in rows" :key="idx">
<TableCell>{{ workflowLabel(s.workflow) }}</TableCell>
<TableCell class="font-medium">{{ s.stage }}</TableCell>
<TableCell>{{ s.runs }}</TableCell>
<TableCell>
<div class="text-label">{{ formatMs(s.avg_ms) }}</div>
<WorkflowBar :fraction="pct(s.avg_ms || 0, maxMs)" kind="info" />
</TableCell>
</TableRow>
</TableBody>
</Table>
</Section>
</template>
-55
View File
@@ -1,55 +0,0 @@
<script setup lang="ts">
import { computed } from "vue";
import { Section } from "@/components/ui/section";
import {
Empty,
EmptyHeader,
EmptyTitle,
} from "@/components/ui/empty";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { pct, workflowLabel } from "./labels";
import { failingStages, type StageStats } from "./stages";
import WorkflowBar from "./WorkflowBar.vue";
/** Which stage is failing, over how many runs. */
const props = defineProps<{ stages: StageStats[] }>();
const rows = computed(() => failingStages(props.stages));
</script>
<template>
<Section title="Most failures" class="mb-0">
<Empty v-if="!rows.length">
<EmptyHeader>
<EmptyTitle>No failures recorded</EmptyTitle>
</EmptyHeader>
</Empty>
<Table v-else>
<TableHeader>
<TableRow>
<TableHead>Workflow</TableHead>
<TableHead>Stage</TableHead>
<TableHead>Failures</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-for="(s, idx) in rows" :key="idx">
<TableCell>{{ workflowLabel(s.workflow) }}</TableCell>
<TableCell class="font-medium">{{ s.stage }}</TableCell>
<TableCell>
<div class="text-label">{{ s.errors }} of {{ s.runs }}</div>
<WorkflowBar :fraction="pct(s.errors, s.runs)" kind="danger" />
</TableCell>
</TableRow>
</TableBody>
</Table>
</Section>
</template>
-26
View File
@@ -1,26 +0,0 @@
<script setup lang="ts">
import { computed } from "vue";
import { STATUS_FILL, type StatusKind } from "@/lib/status";
/**
* A small proportional bar under a rate. It carries the same shape in every
* workflow table so two rates can be compared by eye without reading either.
*/
const props = withDefaults(
defineProps<{ fraction: number; kind?: StatusKind }>(),
{ kind: "ok" },
);
const width = computed(() => `${Math.min(100, Math.max(0, props.fraction))}%`);
</script>
<template>
<div class="mt-2 h-[5px] w-[140px] overflow-hidden rounded-full bg-border">
<div
class="h-full rounded-full transition-[width]"
:class="STATUS_FILL[props.kind]"
:style="`width:${width}`"
/>
</div>
</template>
+8 -11
View File
@@ -40,6 +40,7 @@ import { deleteStep, duplicateStep, insertStep, moveStep, normalizeStepIDs, repl
import ChangeList from "@/components/ChangeList.vue";
import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { useWorkflowRuns } from "./workflow-runs";
import WorkflowRuns, { type StageStats } from "./WorkflowRuns.vue";
import { useWorkflowTriggers } from "./workflow-triggers";
import { useSettingsStore } from "@/stores/settings";
import {
@@ -69,7 +70,8 @@ const modelAliases = computed(() =>
const collection = computed(() => workflows.collection);
// Which definition is open belongs to the page, which also lists them.
const selected = defineModel<string>("selected", { required: true });
defineProps<{ runsCount?: number }>();
// Stage statistics are read by the page with the rest of the workflow stats.
defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string }>();
const id = ref("");
const yaml = ref("");
const loadedYaml = ref("");
@@ -413,7 +415,6 @@ const lines = computed(() => yamlLines(yaml.value));
// The sections that sit beside Canvas and YAML once the editor has the width
// for them (the workflow list takes 24rem of it), and otherwise the one menu,
// which names the section in view beside the tabs.
const SECTIONS: Record<string, string> = { history: "History", performance: "Performance", runs: "Runs" };
// The highlight layer sits behind the textarea and never scrolls by itself, so
// it follows the textarea's own scroll. Lines wrap at the editor's width, and
@@ -458,11 +459,9 @@ onBeforeUnmount(() => yamlObserver?.disconnect());
<TabsList class="shrink-0 justify-start">
<TabsTrigger value="canvas">Canvas</TabsTrigger>
<TabsTrigger value="yaml">YAML</TabsTrigger>
<TabsTrigger v-if="stored !== undefined" value="history" class="max-2xl:hidden">History</TabsTrigger>
<TabsTrigger v-if="$slots.performance" value="performance" class="max-2xl:hidden">Performance</TabsTrigger>
<TabsTrigger v-if="$slots.runs && stored !== undefined" value="runs" class="max-2xl:hidden">Runs <span class="ml-1 font-mono text-caption text-fg-subtle">{{ runsCount ?? 0 }}</span></TabsTrigger>
<TabsTrigger v-if="stored !== undefined" value="history">History</TabsTrigger>
<TabsTrigger v-if="stored !== undefined" value="runs">Runs <span v-if="runs.length" class="ml-1 font-mono text-caption text-fg-subtle">{{ runs.length }}</span></TabsTrigger>
</TabsList>
<span v-if="SECTIONS[view]" class="shrink-0 text-caption font-medium text-fg-muted 2xl:hidden">{{ SECTIONS[view] }}</span>
<div role="group" aria-label="Runs" class="workflow-run-actions ml-auto flex min-w-0 items-center gap-1 max-sm:col-span-2 max-sm:row-start-2 max-sm:ml-0">
<div v-if="stored !== undefined && (view === 'canvas' || view === 'yaml')" class="shrink-0">
<RunWorkflowButton
@@ -503,9 +502,6 @@ onBeforeUnmount(() => yamlObserver?.disconnect());
<Spinner v-if="state.saving" data-icon="inline-start" />Publish</Button>
</span>
<MoreMenu>
<DropdownMenuItem v-if="stored !== undefined" class="2xl:hidden" @select="view = 'history'">History</DropdownMenuItem>
<DropdownMenuItem v-if="$slots.performance" class="2xl:hidden" @select="view = 'performance'">Performance</DropdownMenuItem>
<DropdownMenuItem v-if="$slots.runs && stored !== undefined" class="2xl:hidden" @select="view = 'runs'">Runs <span class="ml-auto font-mono text-caption text-fg-subtle">{{ runsCount ?? 0 }}</span></DropdownMenuItem>
<!-- The run's page and the version it pinned are menu items, not
row controls: the row keeps the width for the picked run. -->
<DropdownMenuItem v-if="watchedRun" as-child><RouterLink :to="`/tasks/${watchedRun.id}`">Open run</RouterLink></DropdownMenuItem>
@@ -581,8 +577,9 @@ onBeforeUnmount(() => yamlObserver?.disconnect());
<TabsContent value="history" class="max-md:min-h-0 max-md:overflow-y-auto">
<WorkflowHistory v-model:selected="historyRevision" v-model:mode="historyMode" :revisions="revisions" :current="yaml" :error="historyError" :loaded="historyLoaded" :locked="archieWorking" @restore="restoreRevision" @retry="reloadHistory" />
</TabsContent>
<TabsContent value="performance" class="grid gap-4 max-md:min-h-0 max-md:overflow-y-auto"><slot name="performance" /></TabsContent>
<TabsContent value="runs" class="max-md:min-h-0 max-md:overflow-y-auto"><slot name="runs" /></TabsContent>
<TabsContent value="runs" class="max-md:min-h-0 max-md:overflow-y-auto">
<WorkflowRuns :runs="runs" :loading="runsLoading" :error="runsError" :stages="stageStats" :stats-known="statsKnown" :stats-error="statsError" @retry="refresh" />
</TabsContent>
<TabsContent value="yaml" class="max-md:min-h-0 max-md:overflow-y-auto">
<!--
A gutter and a highlighted layer behind the live textarea, so the YAML
+116
View File
@@ -0,0 +1,116 @@
<script setup lang="ts">
import { computed } from "vue";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { DataTable, type DataTableColumn } from "@/components/ui/data-table";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Progress } from "@/components/ui/progress";
import { Section } from "@/components/ui/section";
import { Spinner } from "@/components/ui/spinner";
import { Timestamp } from "@/components/ui/timestamp";
import { duration } from "@/lib/format";
import { statusKind, statusLabel } from "@/lib/task-meta";
import type { WorkflowRun } from "./workflow-runs";
/** One stage's timing and failures across the workflow's runs. */
export interface StageStats {
workflow: string;
stage: string;
runs: number;
errors: number;
avg_ms?: number;
}
/**
* How one workflow's runs went: its recent runs, then each stage's average
* time and failures across them. The run list is the one the canvas picks
* from, so the two never disagree.
*/
const props = defineProps<{
runs: WorkflowRun[];
loading: boolean;
error: string;
stages: StageStats[];
/** Stage statistics have been read at least once. */
statsKnown: boolean;
statsError: string;
}>();
const emit = defineEmits<{ retry: [] }>();
const runColumns: DataTableColumn<WorkflowRun>[] = [
{ id: "title", label: "Run", fixed: true, class: "w-full max-w-0" },
{ id: "source", label: "Source", class: "max-sm:hidden" },
{ id: "status", label: "Status", sort: (run) => run.status ?? "" },
{ id: "created", label: "Started", sort: (run) => run.created_at ?? "" },
];
// Slowest first: the stage worth looking at heads the table.
const stageRows = computed(() => [...props.stages].sort((a, b) => (b.avg_ms || 0) - (a.avg_ms || 0)));
const slowest = computed(() => Math.max(...props.stages.map((s) => s.avg_ms || 0), 1));
const stageColumns: DataTableColumn<StageStats>[] = [
{ id: "stage", label: "Stage", fixed: true },
{ id: "runs", label: "Runs", sort: (s) => s.runs },
{ id: "errors", label: "Failures", sort: (s) => s.errors },
{ id: "avg", label: "Average", sort: (s) => s.avg_ms || 0, class: "sm:w-48" },
];
function source(run: WorkflowRun): string {
if (!run.owner || !run.repo) return "";
return `${run.owner}/${run.repo}${run.issue_url && run.issue_number ? ` #${run.issue_number}` : ""}`;
}
</script>
<template>
<div class="space-y-4">
<Section title="Runs" class="mb-0">
<p v-if="loading && !runs.length" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading runs…</p>
<div v-else-if="error && !runs.length" role="alert" class="flex items-center gap-2 text-label text-danger">
{{ error }}
<Button variant="outline" size="sm" @click="emit('retry')">Retry</Button>
</div>
<Empty v-else-if="!runs.length"><EmptyHeader><EmptyTitle>No runs yet</EmptyTitle></EmptyHeader></Empty>
<template v-else>
<p v-if="error" role="alert" class="mb-2 text-label text-danger">{{ error }}</p>
<DataTable
:columns="runColumns"
:rows="runs"
:row-key="(run) => String(run.id)"
:row-link="(run) => `/tasks/${run.id}`"
:row-label="(run) => run.title || `Task ${run.id}`"
storage-key="workflow-runs"
>
<template #cell-title="{ row }"><span class="block truncate">{{ row.title || `Task ${row.id}` }}</span></template>
<template #cell-source="{ row }"><span class="font-mono text-caption text-fg-subtle">{{ source(row) }}</span></template>
<template #cell-status="{ row }"><Badge :variant="statusKind(row.status ?? '')">{{ statusLabel(row.status ?? "") }}</Badge></template>
<template #cell-created="{ row }"><Timestamp v-if="row.created_at" :at="row.created_at" /></template>
</DataTable>
</template>
</Section>
<Section title="Stages" class="mb-0">
<p v-if="!statsKnown && statsError" role="alert" class="text-label text-danger">{{ statsError }}</p>
<p v-else-if="!statsKnown" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading…</p>
<Empty v-else-if="!stages.length"><EmptyHeader><EmptyTitle>No stage timings yet</EmptyTitle></EmptyHeader></Empty>
<DataTable
v-else
:columns="stageColumns"
:rows="stageRows"
:row-key="(s) => s.stage"
storage-key="workflow-stages"
>
<template #cell-stage="{ row }"><span class="font-medium">{{ row.stage }}</span></template>
<template #cell-runs="{ row }"><span class="font-mono">{{ row.runs }}</span></template>
<template #cell-errors="{ row }">
<Badge v-if="row.errors" variant="danger">{{ row.errors }}</Badge>
</template>
<template #cell-avg="{ row }">
<div class="flex items-center gap-2">
<span class="w-14 shrink-0 font-mono text-caption">{{ row.avg_ms ? duration(row.avg_ms) : "" }}</span>
<Progress :model-value="Math.round(((row.avg_ms || 0) / slowest) * 100)" :aria-label="`${row.stage} average time`" class="h-1.5 max-sm:hidden" />
</div>
</template>
</DataTable>
</Section>
</div>
</template>
+4 -83
View File
@@ -21,21 +21,18 @@ import { MoreMenu } from "@/components/ui/more-menu";
import NewTaskForm from "@/tasks/NewTaskForm.vue";
import { Section } from "@/components/ui/section";
import { StatusDot } from "@/components/ui/status-dot";
import { Table, TableBody, TableCell, TableRow } from "@/components/ui/table";
import { Switch } from "@/components/ui/switch";
import { api, describeError } from "@/lib/api";
import { errors } from "@/copy/errors";
import { keepRows, keepValue } from "@/lib/keep-unchanged";
import { keepValue } from "@/lib/keep-unchanged";
import { delivered } from "@/lib/delivered";
import { compact } from "@/lib/format";
import { cn } from "@/lib/utils";
import { statusKind, statusLabel } from "@/lib/task-meta";
import { statusLabel } from "@/lib/task-meta";
import { upsertWorkflowDefinition, useWorkflowsStore } from "@/stores/workflows";
import { useLiveResource } from "@/stores/session";
import ApplyStatusRows from "@/settings/ApplyStatusRows.vue";
import SlowestStagesCard from "./SlowestStagesCard.vue";
import StageFailuresCard from "./StageFailuresCard.vue";
import type { StageStats } from "./stages";
import type { StageStats } from "./WorkflowRuns.vue";
import WorkflowEditor from "./WorkflowEditor.vue";
import WorkflowPicker from "./WorkflowPicker.vue";
import { setWorkflowField } from "./workflow-edit";
@@ -46,16 +43,6 @@ interface WorkflowsResponse {
workflows?: WorkflowStats[];
stages?: StageStats[];
}
interface RunTask {
id: number | string;
title?: string;
status?: string;
workflow?: string;
owner?: string;
repo?: string;
issue_number?: number;
issue_url?: string;
}
const store = useWorkflowsStore();
const data = shallowRef<WorkflowsResponse>({});
@@ -65,7 +52,6 @@ const loading = ref(true);
// Statistics are known once a read has returned them; until then, or after a
// failed read, a row says nothing about its runs rather than "Never run".
const statsKnown = ref(false);
const statsOf = (id: string) => JSON.stringify(data.value.workflows?.find((w) => w.workflow === id) ?? null);
// Live reloads and actions overlap; only the newest read may land.
let loadGeneration = 0;
@@ -75,14 +61,11 @@ async function load() {
// The sidebar's running count and last status come from the per-workflow
// statistics: a page of the newest tasks across every workflow would show
// nothing for a workflow whose runs are older than that page.
const before = statsOf(selected.value);
const response = (await api.workflows<WorkflowsResponse>()) ?? {};
if (current !== loadGeneration) return;
data.value = keepValue(data.value, response);
error.value = null;
statsKnown.value = true;
// The runs page only changes when the workflow's own statistics do.
if (runsFor !== selected.value || statsOf(selected.value) !== before) void loadWorkflowRuns();
} catch (err) {
if (current === loadGeneration) error.value = describeError(err, errors.common.unknown);
} finally {
@@ -203,35 +186,7 @@ function rowActions(id: string): RowAction[] {
return actions;
}
const stages = computed(() => (data.value.stages ?? []).filter((s) => s.workflow === selected.value));
// The selected workflow's runs come from a workflow-filtered page: the global
// list above holds only the newest tasks of every workflow.
const workflowRuns = shallowRef<RunTask[]>([]);
const runsLoading = ref(false);
const runsError = ref("");
let runsRequest = 0;
// A live reload keeps the rows on screen; only a new selection clears them.
let runsFor = "";
async function loadWorkflowRuns() {
const request = ++runsRequest;
const requested = selected.value;
if (requested !== runsFor) {
runsFor = requested;
workflowRuns.value = [];
runsLoading.value = true;
}
try {
const page = requested ? await api.taskPage<RunTask>({ workflow: requested }) : null;
if (request !== runsRequest) return;
workflowRuns.value = keepRows(workflowRuns.value, page?.tasks ?? []);
runsError.value = "";
} catch (err) {
if (request === runsRequest) runsError.value = describeError(err, errors.common.unknown);
} finally {
if (request === runsRequest) runsLoading.value = false;
}
}
watch(selected, () => void loadWorkflowRuns(), { immediate: true });
function create() {
let n = 1;
@@ -310,7 +265,7 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
<ApplyStatusRows kind="workflow-definitions" compact />
</header>
<WorkflowEditor v-model:selected="selected" v-model:view="view" :runs-count="workflowRuns.length">
<WorkflowEditor v-model:selected="selected" v-model:view="view" :stage-stats="stages" :stats-known="statsKnown" :stats-error="error ?? ''">
<template #title>
<h2 class="min-w-0 truncate text-title font-medium">{{ selected }}</h2>
<Badge v-if="provenance" variant="outline" class="shrink-0">{{ provenance }}</Badge>
@@ -319,40 +274,6 @@ const rate = (deliveredRuns = 0, total = 0) => (total ? deliveredRuns / total :
<template v-if="enabled !== undefined" #toolbar>
<Switch :model-value="enabled" :title="enabled ? 'Published version runs on events' : 'Published version ignores events'" aria-label="Published version enabled" @update:model-value="setEnabled(selected, $event)" />
</template>
<template #performance>
<p v-if="!statsKnown && error" class="text-label text-danger" role="alert">{{ error }}</p>
<p v-else-if="!statsKnown" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading…</p>
<Empty v-else-if="!stages.length">
<EmptyHeader>
<EmptyTitle>No stage timings yet</EmptyTitle>
</EmptyHeader>
</Empty>
<template v-else>
<SlowestStagesCard :stages="stages" />
<StageFailuresCard :stages="stages" />
</template>
</template>
<template #runs>
<p v-if="runsLoading" class="flex items-center gap-2 text-label text-fg-muted"><Spinner />Loading runs…</p>
<div v-else-if="runsError" role="alert" class="text-label text-danger">
<p>{{ runsError }}</p>
<Button variant="outline" size="sm" @click="loadWorkflowRuns">Retry</Button>
</div>
<Empty v-else-if="!workflowRuns.length">
<EmptyHeader>
<EmptyTitle>No runs yet</EmptyTitle>
</EmptyHeader>
</Empty>
<Table v-else aria-label="Runs">
<TableBody>
<TableRow v-for="t in workflowRuns" :key="t.id">
<TableCell class="w-full max-w-0 truncate"><RouterLink :to="`/tasks/${t.id}`" class="hover:underline">{{ t.title || `Task ${t.id}` }}</RouterLink></TableCell>
<TableCell class="hidden font-mono text-caption text-fg-subtle sm:table-cell">{{ t.owner && t.repo ? `${t.owner}/${t.repo}${t.issue_url && t.issue_number ? ` #${t.issue_number}` : ""}` : "" }}</TableCell>
<TableCell class="text-right"><Badge :variant="statusKind(t.status ?? '')">{{ statusLabel(t.status ?? "") }}</Badge></TableCell>
</TableRow>
</TableBody>
</Table>
</template>
</WorkflowEditor>
</Card>
</div>
-33
View File
@@ -1,33 +0,0 @@
/** Naming and numbers shared by the workflow tables. */
import { duration } from "../lib/format.ts";
const WORKFLOW_LABELS: Record<string, string> = {
implement: "Implement",
tdd: "TDD",
feasibility: "Feasibility check",
};
/** A workflow's display name. An unknown one is still shown, not hidden: a new
* workflow on the server should be visible before the UI knows its proper
* name. */
export function workflowLabel(name: string | undefined | null): string {
if (name && WORKFLOW_LABELS[name]) return WORKFLOW_LABELS[name];
if (!name) return "Unknown";
return name.charAt(0).toUpperCase() + name.slice(1).replace(/_/g, " ");
}
/** A percentage, or 0 when there is no whole to divide by. Accepts the absent
* case because the stats endpoint omits a field it has no data for. */
export function pct(
part: number | undefined | null,
whole: number | undefined | null,
): number {
if (!whole || !part) return 0;
return Math.round((part / whole) * 100);
}
export function formatMs(ms: number | undefined | null): string {
if (!ms) return "–";
return duration(ms);
}
-27
View File
@@ -1,27 +0,0 @@
/** Per-stage timing and failure data, and the two readings the page shows. */
export interface StageStats {
workflow: string;
stage: string;
runs: number;
errors: number;
avg_ms?: number;
}
/** Stages by average duration, slowest first. */
export function slowestStages(stages: StageStats[]): StageStats[] {
return [...stages].sort((a, b) => (b.avg_ms || 0) - (a.avg_ms || 0));
}
/** Only the stages that have failed, and by how much. A stage that has never
* errored is not a zero-length row here, it is absent. */
export function failingStages(stages: StageStats[]): StageStats[] {
return [...stages]
.filter((s) => s.errors > 0)
.sort((a, b) => b.errors - a.errors);
}
/** The largest duration in the set, used to scale the bars. */
export function maxStageMs(stages: StageStats[]): number {
return Math.max(...stages.map((s) => s.avg_ms || 0), 1);
}
+4 -2
View File
@@ -18,7 +18,8 @@ interface DebugView {
task?: { workflow_definition_yaml?: string };
}
const RECENT_RUNS = 20;
// The API caps a page at 50; the canvas picker and the Runs view share it.
const RECENT_RUNS = 50;
/**
* The recent runs of one workflow and the step states of the one being
@@ -120,8 +121,9 @@ export function useWorkflowRuns(workflow: Ref<string>) {
/** Watches a run that just started, once the task list has it. */
async function follow(id: number | string): Promise<void> {
picked = true;
// Changing the watched run loads its stages; only the list needs a read.
watched.value = String(id);
await refresh();
await loadRuns();
}
return { runs, error, loading, watched, watchedRun, stages, stagesError, attempt, pick, follow, refresh };