feat(webui): events counts, YAML reading, log rows and dashboard filters
Four findings from the ui-redesign verification pass, each with the module that owns the rule and the test that pins it. - events: the three-step strip's and the tab chips' counts move out of the SFC into events/counts.ts -- one read per step, an unreadable count stays blank rather than reading as zero (events-counts.test.ts). - workflows: workflows/workflow-yaml.ts reads the editor's YAML with a real parser (the yaml package, not a line scanner) to drive the read-only Steps preview and a live validity indicator; the editor gains a line-number gutter and light syntax colouring behind the textarea. Step types and their settings are not served to the dashboard, so those remain the server's to check on save, and a save it refuses still reports its own reason. - tasks: an ERROR log row is a block rather than only red text (lib/log.ts), the log pane ends with "End of attempt N - M lines", and the task head offers Archive when the server's own action list offers it (task-actions.ts, and TaskRowActions' new `only` narrows the list without inventing a control). - dashboard: the live activity feed gains the All/Tasks/System filter (activity-filter.ts) and every quality-gate row gains a pass bar (pass-bar.ts) that is red when the gate is failing. ui/dist regenerated; ui/package.json carries yaml ^2.9.1.
This commit is contained in:
1 parent
c6623d5300
commit
5e1e365c05
23 files changed
+1184
-75
No files matched your search
@@ -3,6 +3,7 @@ import {
|
||||
fmtValue,
|
||||
LEVEL_COLOR,
|
||||
levelKind,
|
||||
rowClass,
|
||||
shortTime,
|
||||
type LogEntry,
|
||||
} from "@/lib/log";
|
||||
@@ -19,7 +20,8 @@ const fields = () => Object.entries(props.entry.fields ?? {});
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="grid grid-cols-[62px_52px_1fr] items-baseline gap-3 border-b border-border px-1 py-2 hover:bg-accent"
|
||||
class="grid grid-cols-[62px_52px_1fr] items-baseline gap-3 border-b border-b-border border-l-2 px-1 py-2 hover:bg-accent"
|
||||
:class="rowClass(props.entry.level)"
|
||||
>
|
||||
<span class="font-mono text-fg-subtle">{{
|
||||
shortTime(props.entry.time)
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { delivered } from "@/lib/delivered";
|
||||
import { workflows } from "./state";
|
||||
import { STATUS_FILL } from "@/lib/status";
|
||||
import { passBar } from "./pass-bar";
|
||||
import { workflows, type WorkflowStat } from "./state";
|
||||
|
||||
/** Sharer of runs: how much of the work that finished passed its gates. */
|
||||
const stats = computed(() => workflows.value?.workflows ?? []);
|
||||
@@ -26,6 +27,11 @@ const pct = computed(() => {
|
||||
if (!totals.value.runs) return 0;
|
||||
return Math.round((totals.value.merged / totals.value.runs) * 100);
|
||||
});
|
||||
|
||||
/** One row's bar: the share of that gate's runs which got through, and whether
|
||||
* the gate is failing -- both decided in pass-bar.ts. */
|
||||
const rowBar = (stat: WorkflowStat) =>
|
||||
passBar(delivered(stat), stat.runs || 0);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -59,22 +65,29 @@ const pct = computed(() => {
|
||||
<li
|
||||
v-for="(w, i) in stats.slice(0, 3)"
|
||||
:key="i"
|
||||
class="flex items-center justify-between gap-3 border-b border-hairline py-1.5 text-sm last:border-b-0"
|
||||
class="flex flex-col gap-1.5 border-b border-hairline py-2 last:border-b-0"
|
||||
>
|
||||
<span class="truncate text-fg-muted">{{
|
||||
w.workflow || "workflow"
|
||||
}}</span>
|
||||
<Badge
|
||||
:variant="
|
||||
delivered(w) === (w.runs || 0)
|
||||
? 'ok'
|
||||
: (w.parked || 0) > 0
|
||||
? 'warn'
|
||||
: 'info'
|
||||
"
|
||||
<span class="flex items-baseline justify-between gap-3 text-sm">
|
||||
<span class="truncate text-fg-muted">{{
|
||||
w.workflow || "workflow"
|
||||
}}</span>
|
||||
<span class="shrink-0 font-mono text-xs text-fg-subtle">{{
|
||||
delivered(w)
|
||||
}}/{{ w.runs || 0 }}</span>
|
||||
</span>
|
||||
<!-- The bar restates the counts as a length: a gate drifting down
|
||||
is visible before the two numbers are read. Its track carries
|
||||
the failure when there is no width to show. -->
|
||||
<span
|
||||
class="block h-1.5 overflow-hidden rounded-full"
|
||||
:class="STATUS_FILL[rowBar(w).track]"
|
||||
>
|
||||
{{ delivered(w) }}/{{ w.runs || 0 }}
|
||||
</Badge>
|
||||
<span
|
||||
class="block h-full rounded-full"
|
||||
:class="STATUS_FILL[rowBar(w).kind]"
|
||||
:style="`width:${rowBar(w).pct}%`"
|
||||
/>
|
||||
</span>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, reactive } from "vue";
|
||||
import { computed, reactive, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
import { ChevronDown, ChevronRight } from "@lucide/vue";
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { SegmentedControl } from "@/components/ui/segmented-control";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
@@ -25,14 +26,19 @@ import { ago } from "@/lib/format";
|
||||
import { useLiveUpdatesStore } from "@/stores/live-updates";
|
||||
import ActivityRow from "./ActivityRow.vue";
|
||||
import { activityDetail } from "./activity-detail";
|
||||
import {
|
||||
ACTIVITY_FILTERS,
|
||||
activityEmptyTitle,
|
||||
filterActivity,
|
||||
type ActivityFilter,
|
||||
} from "./activity-filter";
|
||||
import { groupActivity, type ActivityGroup } from "./activity-group";
|
||||
|
||||
/**
|
||||
* The last 50 events, newest first, with the stream's own state on the card.
|
||||
* Runs of consecutive same-kind same-task events (the daemon's background
|
||||
* telemetry) collapse into one group row carrying an ×N badge; expanding one
|
||||
* reveals its events. The grouping lives in activity-group.ts and is tested
|
||||
* there; this card only renders it.
|
||||
* The last 50 events, newest first, with the stream's own state on the card and
|
||||
* the All / Tasks / System filter over it. The filter and the grouping rules
|
||||
* live in activity-filter.ts and activity-group.ts and are tested there; this
|
||||
* card only renders their result.
|
||||
*/
|
||||
|
||||
const router = useRouter();
|
||||
@@ -40,10 +46,18 @@ const { activity, streamKind, streamState } = storeToRefs(
|
||||
useLiveUpdatesStore(),
|
||||
);
|
||||
|
||||
/** Which view of the feed is showing: everything, task runs, or the daemon's
|
||||
* own background work. */
|
||||
const filter = ref<ActivityFilter>("all");
|
||||
const shown = computed(() => filterActivity(activity.value, filter.value));
|
||||
const emptyTitle = computed(() =>
|
||||
activityEmptyTitle(shown.value.length, filter.value),
|
||||
);
|
||||
|
||||
// Expansion is keyed on label:taskID, so a live run stays open as its events
|
||||
// arrive, and a collapsed group re-collapses only when the run breaks.
|
||||
const expanded = reactive(new Set<string>());
|
||||
const groups = computed(() => groupActivity(activity.value));
|
||||
const groups = computed(() => groupActivity(shown.value));
|
||||
|
||||
function toggle(key: string) {
|
||||
if (expanded.has(key)) expanded.delete(key);
|
||||
@@ -73,7 +87,12 @@ function openTask(taskID: number) {
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Live activity</CardTitle>
|
||||
<CardAction>
|
||||
<CardAction class="flex items-center gap-2">
|
||||
<SegmentedControl
|
||||
v-model="filter"
|
||||
label="Filter activity"
|
||||
:options="ACTIVITY_FILTERS"
|
||||
/>
|
||||
<Badge :variant="streamKind">{{ streamState }}</Badge>
|
||||
</CardAction>
|
||||
</CardHeader>
|
||||
@@ -105,16 +124,16 @@ function openTask(taskID: number) {
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-if="!activity.length">
|
||||
<TableRow v-if="!shown.length">
|
||||
<TableCell colspan="4">
|
||||
<Empty>
|
||||
<EmptyHeader>
|
||||
<EmptyTitle>Waiting for activity</EmptyTitle>
|
||||
<EmptyTitle>{{ emptyTitle }}</EmptyTitle>
|
||||
</EmptyHeader>
|
||||
</Empty>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<template v-if="activity.length">
|
||||
<template v-if="shown.length">
|
||||
<template v-for="group in groups" :key="group.key">
|
||||
<!-- A singleton is exactly the row the raw feed would show. -->
|
||||
<ActivityRow
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* The live activity feed's filter.
|
||||
*
|
||||
* Every event the dashboard receives belongs either to a task run or to the
|
||||
* daemon's own background work, and the two are read for different reasons:
|
||||
* "what is my work doing" against "what is the daemon doing". A task event is
|
||||
* one that resolves to a task -- the same test the table's rows already use to
|
||||
* link an event to a task -- so the filter can never disagree with the links
|
||||
* inside the rows it is filtering.
|
||||
*/
|
||||
|
||||
export type ActivityFilter = "all" | "tasks" | "system";
|
||||
|
||||
/** An event as far as the filter reads it: the task it belongs to, if any. */
|
||||
export interface ActivityFilterInput {
|
||||
task_id?: number | string | null;
|
||||
}
|
||||
|
||||
/** The three views, in the order the header renders them. */
|
||||
export const ACTIVITY_FILTERS: { value: ActivityFilter; label: string }[] = [
|
||||
{ value: "all", label: "All" },
|
||||
{ value: "tasks", label: "Tasks" },
|
||||
{ value: "system", label: "System" },
|
||||
];
|
||||
|
||||
/** belongsToTask is the same test the rows use to point an event at a task. */
|
||||
export function belongsToTask(
|
||||
event: ActivityFilterInput | null | undefined,
|
||||
): boolean {
|
||||
return (Number(event?.task_id) || 0) > 0;
|
||||
}
|
||||
|
||||
/** matchesActivityFilter decides one event, so a group row can be judged by the
|
||||
* events it stands for. */
|
||||
export function matchesActivityFilter(
|
||||
event: ActivityFilterInput | null | undefined,
|
||||
filter: ActivityFilter,
|
||||
): boolean {
|
||||
if (filter === "tasks") return belongsToTask(event);
|
||||
if (filter === "system") return !belongsToTask(event);
|
||||
return true;
|
||||
}
|
||||
|
||||
/** filterActivity keeps the events a view is about, in arrival order. The two
|
||||
* narrow views partition the feed: nothing shows in both, nothing in neither. */
|
||||
export function filterActivity<T extends ActivityFilterInput>(
|
||||
events: readonly T[],
|
||||
filter: ActivityFilter,
|
||||
): T[] {
|
||||
return events.filter((event) => matchesActivityFilter(event, filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* activityEmptyTitle words the empty state. A feed with nothing in it and a
|
||||
* feed this view emptied are different facts, and a blank title means there are
|
||||
* rows to show, so the caller renders no empty state at all.
|
||||
*/
|
||||
export function activityEmptyTitle(
|
||||
visible: number,
|
||||
filter: ActivityFilter,
|
||||
): string {
|
||||
if (visible > 0) return "";
|
||||
if (filter === "all") return "Waiting for activity";
|
||||
return filter === "tasks" ? "No task events yet" : "No system events yet";
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import type { StatusKind } from "@/lib/status";
|
||||
|
||||
/**
|
||||
* The bar under a quality-gate row.
|
||||
*
|
||||
* The rate above the rows says what the gates do overall; a row has to say
|
||||
* whether *this* gate is working. Two decisions live here, so the row and any
|
||||
* test read the same rule: the width is the share of that gate's runs which got
|
||||
* through, not a pass/fail flip, and a failing gate is red even when it
|
||||
* delivered nothing -- which is what carries the failure when the bar has no
|
||||
* width to show.
|
||||
*/
|
||||
|
||||
export interface PassBar {
|
||||
/** The share of the gate's runs that got through, 0-100. */
|
||||
pct: number;
|
||||
/** The fill's tone: passing, failing, or a gate that has run nothing. */
|
||||
kind: StatusKind;
|
||||
/** The track's tone: a failing gate with an empty fill draws the failure on
|
||||
* the track instead, rather than reading as a blank row. */
|
||||
track: StatusKind;
|
||||
}
|
||||
|
||||
export function passBar(delivered: number, runs: number): PassBar {
|
||||
const total = Math.max(0, Math.trunc(runs) || 0);
|
||||
if (!total) return { pct: 0, kind: "idle", track: "idle" };
|
||||
const through = Math.min(Math.max(Math.trunc(delivered) || 0, 0), total);
|
||||
if (through >= total) return { pct: 100, kind: "ok", track: "idle" };
|
||||
return {
|
||||
pct: Math.round((through / total) * 100),
|
||||
kind: "danger",
|
||||
track: "danger",
|
||||
};
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import { api } from "@/lib/api";
|
||||
import { useLiveResource } from "@/stores/live-updates";
|
||||
import MappingsPage from "@/mappings/MappingsPage.vue";
|
||||
import { activeTab, availableTabs } from "./tab-selection";
|
||||
import { loadEventCounts, type EventsCounts } from "./counts";
|
||||
|
||||
/**
|
||||
* The Events surfaces: what arrived, how its fields are read, and which workflow
|
||||
@@ -56,24 +57,14 @@ function show(id: unknown): void {
|
||||
// there.
|
||||
watch(active, (tab) => show(tab), { immediate: true });
|
||||
|
||||
// One count per step of the chain, for the strip and the tab chips. A count
|
||||
// that could not be read stays blank rather than reading as zero.
|
||||
const counts = ref<Record<string, number | undefined>>({});
|
||||
// One count per step of the chain, for the strip and the tab chips. The reads
|
||||
// and the counting live in counts.ts, so the strip, the chips and the test all
|
||||
// read one source rather than three.
|
||||
const counts = ref<EventsCounts>({});
|
||||
async function loadCounts() {
|
||||
const [captures, mappings, bindings] = await Promise.allSettled([
|
||||
api.captures<{ captures?: unknown[] | null }>(100),
|
||||
api.mappings<{ mappings?: unknown[] }>(),
|
||||
api.bindings<{ bindings?: unknown[] }>(),
|
||||
]);
|
||||
const size = (r: PromiseSettledResult<Record<string, unknown[] | null | undefined>>, key: string) =>
|
||||
r.status === "fulfilled" ? (r.value?.[key]?.length ?? 0) : undefined;
|
||||
counts.value = {
|
||||
inspector: size(captures as never, "captures"),
|
||||
mappings: size(mappings as never, "mappings"),
|
||||
bindings: size(bindings as never, "bindings"),
|
||||
};
|
||||
counts.value = await loadEventCounts(api);
|
||||
}
|
||||
onMounted(loadCounts);
|
||||
onMounted(() => void loadCounts());
|
||||
useLiveResource(null, () => void loadCounts(), 1000);
|
||||
|
||||
const steps = [
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* The Events chain's counts.
|
||||
*
|
||||
* The three-step strip and the tab chips both show one number per step, and
|
||||
* both read this. The three lists arrive from three separate loaded stores, so
|
||||
* counting them inside the page would put a second, quietly divergent answer
|
||||
* next to the first. A count that could not be read at all is `undefined` --
|
||||
* blank, never zero -- because "nothing arrived" and "the read failed" are
|
||||
* different facts about a deployment, and only the first one is about the
|
||||
* operator's events.
|
||||
*/
|
||||
|
||||
/** One count per tab id. A missing entry means that read did not answer. */
|
||||
export type EventsCounts = Record<string, number | undefined>;
|
||||
|
||||
/** The three reads, narrowed to what counting needs so the page's `api` object
|
||||
* fits and a test can stand in for it. */
|
||||
export interface EventsCountReaders {
|
||||
captures(limit?: number): Promise<unknown>;
|
||||
mappings(): Promise<unknown>;
|
||||
bindings(): Promise<unknown>;
|
||||
}
|
||||
|
||||
/** One step's count: the read that answers it, and the list it counts. */
|
||||
export interface EventsCountSource {
|
||||
/** The tab whose chip and strip step show this count. */
|
||||
tab: string;
|
||||
/** The list field of that read's response. */
|
||||
key: string;
|
||||
read(readers: EventsCountReaders): Promise<unknown>;
|
||||
}
|
||||
|
||||
// The Inspector tab shows a bounded page of captures, so its count counts that
|
||||
// same page: a chip reading 400 next to a tab showing 100 rows is a number the
|
||||
// operator cannot act on.
|
||||
const CAPTURE_PAGE = 100;
|
||||
|
||||
/** One source per step of the chain, in the order the strip reads them. */
|
||||
export const COUNT_SOURCES: EventsCountSource[] = [
|
||||
{
|
||||
tab: "inspector",
|
||||
key: "captures",
|
||||
read: (readers) => readers.captures(CAPTURE_PAGE),
|
||||
},
|
||||
{ tab: "mappings", key: "mappings", read: (readers) => readers.mappings() },
|
||||
{ tab: "bindings", key: "bindings", read: (readers) => readers.bindings() },
|
||||
];
|
||||
|
||||
/**
|
||||
* loadEventCounts reads the three lists and counts each. One read failing
|
||||
* leaves its own count blank and does not take the other two down with it: an
|
||||
* unreachable capture service must not blank the mappings count.
|
||||
*/
|
||||
export async function loadEventCounts(
|
||||
readers: EventsCountReaders,
|
||||
): Promise<EventsCounts> {
|
||||
const settled = await Promise.allSettled(
|
||||
COUNT_SOURCES.map((source) => source.read(readers)),
|
||||
);
|
||||
const counts: EventsCounts = {};
|
||||
COUNT_SOURCES.forEach((source, i) => {
|
||||
const result = settled[i];
|
||||
counts[source.tab] =
|
||||
result?.status === "fulfilled"
|
||||
? countList(result.value, source.key)
|
||||
: undefined;
|
||||
});
|
||||
return counts;
|
||||
}
|
||||
|
||||
/** countList counts the list a response carries. A response without it -- an
|
||||
* older server, a body nobody expected -- answered, and answered with nothing. */
|
||||
function countList(response: unknown, key: string): number {
|
||||
const list = (response as Record<string, unknown> | null | undefined)?.[key];
|
||||
return Array.isArray(list) ? list.length : 0;
|
||||
}
|
||||
@@ -51,6 +51,33 @@ export function levelKind(level: string | null | undefined): LevelKind {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The row's own treatment, by level. The level label carries the colour; the row
|
||||
* carries the weight: an ERROR line is a block the eye lands on, not red text
|
||||
* in a column of grey. Every row keeps a left edge of the same width, coloured
|
||||
* or not, so the three columns never shift between rows.
|
||||
*/
|
||||
export const LEVEL_ROW: Record<LevelKind, string> = {
|
||||
danger: "border-l-danger bg-danger-soft",
|
||||
warn: "border-l-transparent",
|
||||
info: "border-l-transparent",
|
||||
idle: "border-l-transparent",
|
||||
};
|
||||
|
||||
/** The classes one row wears for its level. */
|
||||
export function rowClass(level: string | null | undefined): string {
|
||||
return LEVEL_ROW[levelKind(level)];
|
||||
}
|
||||
|
||||
/**
|
||||
* The end of an attempt's log: which attempt, and how much it wrote. The count
|
||||
* is the lines on screen, so a filtered pane says how much the filter left.
|
||||
*/
|
||||
export function attemptFooter(attempt: number, lines: number): string {
|
||||
const count = Math.max(0, Math.trunc(lines) || 0);
|
||||
return `End of attempt ${attempt} \u00b7 ${count} line${count === 1 ? "" : "s"}`;
|
||||
}
|
||||
|
||||
export function fmtValue(v: unknown): string {
|
||||
if (v == null) return "";
|
||||
return typeof v === "object" ? JSON.stringify(v) : String(v);
|
||||
|
||||
@@ -13,7 +13,9 @@ import {
|
||||
import { StatusPill } from "@/components/ui/status-pill";
|
||||
import { statusKind, statusLabel } from "@/lib/task-meta";
|
||||
import StartNewRun from "./StartNewRun.vue";
|
||||
import TaskRowActions from "./TaskRowActions.vue";
|
||||
import { pillFor } from "./status-pill";
|
||||
import { shownActionIds } from "./task-actions";
|
||||
import { useTaskRun } from "./use-task-run";
|
||||
|
||||
/**
|
||||
@@ -28,6 +30,14 @@ const title = computed(() => run.task?.title || `Task #${props.id}`);
|
||||
const status = computed(() => run.task?.status ?? "");
|
||||
const pill = computed(() => pillFor(statusKind(status.value)));
|
||||
const parked = computed(() => status.value === "parked" && !!run.task?.park_reason);
|
||||
|
||||
// The head has room for one control: the reap an operator reaches for once a
|
||||
// task is finished with. Whether this task offers it at all is the server's
|
||||
// action list, never this page's opinion about the status.
|
||||
const HEAD_ACTIONS = ["archive"];
|
||||
const headerActions = computed(() =>
|
||||
shownActionIds(run.task?.actions, HEAD_ACTIONS),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -63,7 +73,15 @@ const parked = computed(() => status.value === "parked" && !!run.task?.park_reas
|
||||
/></a>
|
||||
</div>
|
||||
</div>
|
||||
<StartNewRun compact :id="id" />
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<TaskRowActions
|
||||
v-if="run.task && headerActions.length"
|
||||
:task="run.task"
|
||||
:only="HEAD_ACTIONS"
|
||||
@done="run.refreshAll()"
|
||||
/>
|
||||
<StartNewRun compact :id="id" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
|
||||
@@ -5,6 +5,7 @@ import LogRow from "@/base/LogRow.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { api } from "@/lib/api";
|
||||
import { attemptFooter } from "@/lib/log";
|
||||
|
||||
import PanelLoading from "./PanelLoading.vue";
|
||||
import TaskLogFilters from "./TaskLogFilters.vue";
|
||||
@@ -169,6 +170,11 @@ const download = computed(() =>
|
||||
>
|
||||
<LogRow v-for="(entry, i) in view.entries" :key="i" :entry="entry" />
|
||||
</div>
|
||||
<!-- Below the frame, not inside it: the log scrolls, and where an attempt
|
||||
ended is the one line that must stay put while it does. -->
|
||||
<p class="px-1 pt-2 text-xs text-fg-subtle">
|
||||
{{ attemptFooter(resolvedAttempt, view.entries.length) }}
|
||||
</p>
|
||||
<Button v-if="download" variant="outline" size="sm" class="mt-3" as-child>
|
||||
<a :href="download" download>Download log</a>
|
||||
</Button>
|
||||
|
||||
@@ -23,11 +23,14 @@ import {
|
||||
import { api, classifyActionError, type ActionErrorKind } from "@/lib/api";
|
||||
import { actionFor, type ActionMeta } from "@/lib/task-meta";
|
||||
import type { Task } from "./TaskRow.vue";
|
||||
import { shownActionIds } from "./task-actions";
|
||||
|
||||
/**
|
||||
* The lifecycle controls for one task. A task offers whatever the server says
|
||||
* it offers, so the decisions here are presentation only: which variant a
|
||||
* control wears, whether it needs confirming, and how a refusal reads.
|
||||
* control wears, whether it needs confirming, and how a refusal reads. A
|
||||
* caller may narrow the list to the controls it has room for (`only`), and
|
||||
* narrowing can only remove -- see task-actions.ts.
|
||||
*/
|
||||
|
||||
/** A control with its forge target already resolved. */
|
||||
@@ -41,7 +44,11 @@ interface Control {
|
||||
|
||||
type ControlVariant = "default" | "ghost" | "destructive";
|
||||
|
||||
const props = defineProps<{ task: Task }>();
|
||||
const props = defineProps<{
|
||||
task: Task;
|
||||
/** Render only these action ids, still only if the server offered them. */
|
||||
only?: string[];
|
||||
}>();
|
||||
const emit = defineEmits<{ done: [taskId: Task["id"]] }>();
|
||||
|
||||
const inFlight = ref(false);
|
||||
@@ -54,7 +61,7 @@ const confirming = ref<string | null>(null);
|
||||
const confirmingId = ref<string | null>(null);
|
||||
|
||||
const controls = computed<Control[]>(() =>
|
||||
(props.task.actions ?? [])
|
||||
shownActionIds(props.task.actions, props.only)
|
||||
.map((id) => actionFor(id))
|
||||
.filter((meta): meta is ActionMeta => meta !== null)
|
||||
.map((meta) => ({
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* Which lifecycle controls a surface renders.
|
||||
*
|
||||
* A task offers whatever the server says it offers -- the action list rides
|
||||
* with the task -- so a status the server will not archive is never offered an
|
||||
* Archive control here. A surface may narrow that list to the controls it has
|
||||
* room for (the task head has room for one), but narrowing can only ever
|
||||
* remove: a control the server did not send cannot be conjured by naming it.
|
||||
*/
|
||||
export function shownActionIds(
|
||||
actions: readonly string[] | null | undefined,
|
||||
only?: readonly string[],
|
||||
): string[] {
|
||||
if (!Array.isArray(actions)) return [];
|
||||
if (!only || only.length === 0) return [...actions];
|
||||
return actions.filter((id) => only.includes(id));
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { RotateCcw, Trash2 } from "@lucide/vue";
|
||||
import { ArrowRight, RotateCcw, Trash2 } from "@lucide/vue";
|
||||
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -14,6 +14,12 @@ import {
|
||||
useControlPlaneStore,
|
||||
type WorkflowDefinitionCollection,
|
||||
} from "@/stores/control-plane";
|
||||
import {
|
||||
parseWorkflowYaml,
|
||||
validationLabel,
|
||||
yamlLines,
|
||||
yamlTokenClass,
|
||||
} from "./workflow-yaml";
|
||||
|
||||
const store = useControlPlaneStore();
|
||||
const state = computed(() => store.stateFor("workflow-definitions"));
|
||||
@@ -93,6 +99,22 @@ async function restoreOne(): Promise<void> {
|
||||
);
|
||||
}
|
||||
|
||||
// What is typed, read by the rules this page can answer (workflow-yaml.ts). The
|
||||
// Steps preview, the gutter and the validity indicator are three readings of
|
||||
// one parse, so they cannot disagree about the same text. The server remains
|
||||
// the authority: step types and their settings are not served to the dashboard,
|
||||
// so a save it refuses still reports its own reason below.
|
||||
const parsed = computed(() => parseWorkflowYaml(yaml.value));
|
||||
const steps = computed(() => (parsed.value.ok ? parsed.value.steps : []));
|
||||
const lines = computed(() => yamlLines(yaml.value));
|
||||
|
||||
// The highlight layer sits behind the textarea and never scrolls by itself, so
|
||||
// it follows the textarea's own scroll.
|
||||
const scrolled = ref(0);
|
||||
function syncScroll(event: Event): void {
|
||||
scrolled.value = (event.target as HTMLTextAreaElement).scrollTop;
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -102,15 +124,93 @@ async function restoreOne(): Promise<void> {
|
||||
<Input id="workflow-id" v-model="id" name="workflow-id" required autocomplete="off" class="max-w-sm font-mono" />
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<Label for="workflow-yaml">YAML</Label>
|
||||
<Textarea
|
||||
id="workflow-yaml"
|
||||
v-model="yaml"
|
||||
name="workflow-yaml"
|
||||
required
|
||||
class="min-h-96 resize-y font-mono text-[13px]"
|
||||
spellcheck="false"
|
||||
/>
|
||||
<!-- The steps the YAML actually declares, as the server would read them:
|
||||
a parser's answer, never a scan for lines that look like steps. -->
|
||||
<span class="text-sm leading-none font-medium">Steps</span>
|
||||
<div
|
||||
class="flex h-9 flex-nowrap items-center gap-1.5 overflow-hidden"
|
||||
role="list"
|
||||
aria-label="Steps"
|
||||
>
|
||||
<template v-if="steps.length">
|
||||
<template v-for="(step, i) in steps" :key="step.index">
|
||||
<span
|
||||
role="listitem"
|
||||
class="shrink-0 rounded border border-border bg-secondary px-2 py-0.5 font-mono text-xs"
|
||||
:title="step.type"
|
||||
>{{ step.type }}</span
|
||||
>
|
||||
<ArrowRight
|
||||
v-if="i < steps.length - 1"
|
||||
class="size-3.5 shrink-0 text-fg-subtle"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</template>
|
||||
</template>
|
||||
<span v-else class="text-xs text-fg-subtle">No steps yet</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="space-y-1.5">
|
||||
<div class="flex items-baseline gap-2">
|
||||
<Label for="workflow-yaml">YAML</Label>
|
||||
<!-- What the page can check: the YAML parses, it carries an id, and it
|
||||
names at least one step with a type. Step types and settings are
|
||||
the server's to check, on save. -->
|
||||
<span
|
||||
class="ml-auto text-xs"
|
||||
:class="parsed.ok ? 'text-ok' : 'text-danger'"
|
||||
role="status"
|
||||
>{{ parsed.ok ? "✓" : "✕" }} {{ validationLabel(parsed) }}</span
|
||||
>
|
||||
</div>
|
||||
<!--
|
||||
A gutter and a highlighted layer behind the live textarea, so the YAML
|
||||
is numbered and coloured where it is edited rather than in a second,
|
||||
read-only pane beside it. The layer is aria-hidden and never focusable:
|
||||
the textarea in front of it stays the only thing the operator and a
|
||||
screen reader reach.
|
||||
-->
|
||||
<div
|
||||
class="relative overflow-hidden rounded-lg border border-input font-mono text-[13px] leading-6 focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/50"
|
||||
>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-y-0 left-0 w-11 select-none overflow-hidden border-r border-border bg-secondary/40 py-3 text-right"
|
||||
>
|
||||
<div :style="`transform:translateY(${-scrolled}px)`">
|
||||
<div
|
||||
v-for="line in lines"
|
||||
:key="line.number"
|
||||
class="min-h-6 pr-2 text-fg-subtle"
|
||||
>{{ line.number }}</div
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none absolute inset-0 overflow-hidden py-3 pr-3 pl-14 break-words whitespace-pre-wrap"
|
||||
>
|
||||
<div :style="`transform:translateY(${-scrolled}px)`">
|
||||
<div v-for="line in lines" :key="line.number" class="min-h-6">
|
||||
<span
|
||||
v-for="(token, i) in line.tokens"
|
||||
:key="i"
|
||||
:class="yamlTokenClass(token.kind)"
|
||||
>{{ token.text }}</span
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<Textarea
|
||||
id="workflow-yaml"
|
||||
v-model="yaml"
|
||||
name="workflow-yaml"
|
||||
required
|
||||
class="relative min-h-96 resize-y rounded-none border-0 bg-transparent py-3 pr-3 pl-14 text-[13px] leading-6 text-transparent caret-foreground shadow-none md:text-[13px] focus-visible:ring-0"
|
||||
spellcheck="false"
|
||||
@scroll="syncScroll"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="localError || state.error" class="text-sm text-danger" role="alert">
|
||||
{{ localError || state.error }}
|
||||
@@ -119,7 +219,9 @@ async function restoreOne(): Promise<void> {
|
||||
<span v-if="state.resource" class="mr-auto font-mono text-xs text-fg-subtle">Version {{ state.resource.version }}</span>
|
||||
<Button v-if="selected" type="button" variant="ghost" class="text-danger" @click="remove"><Trash2 /> Remove</Button>
|
||||
<Button v-if="shippedEntry" type="button" variant="outline" @click="restoreOne"><RotateCcw /> Restore this workflow</Button>
|
||||
<Button type="submit" :disabled="state.saving"><Spinner v-if="state.saving" data-icon="inline-start" /> Validate & save</Button>
|
||||
<!-- A definition the page can see is wrong is not submitted for the
|
||||
server to refuse: the indicator above the editor says what to fix. -->
|
||||
<Button type="submit" :disabled="state.saving || !parsed.ok"><Spinner v-if="state.saving" data-icon="inline-start" /> Validate & save</Button>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
@@ -0,0 +1,187 @@
|
||||
import { parseDocument } from "yaml";
|
||||
|
||||
/**
|
||||
* The workflow YAML editor's reading of what is typed.
|
||||
*
|
||||
* The server is the authority on a definition: `workflow.ParseDefinition`
|
||||
* parses with known fields, requires an id and at least one step, and checks
|
||||
* every step type against its registry and every step's settings against that
|
||||
* type's own rules. The registry is not served to the dashboard, so this module
|
||||
* answers the part the page can answer without inventing a second vocabulary:
|
||||
* does the YAML parse, does it carry an id, and does it name at least one step
|
||||
* that has a type. "Valid" here means exactly those three things -- a save the
|
||||
* server refuses still reports the server's own reason, and that path is
|
||||
* unchanged.
|
||||
*/
|
||||
|
||||
/** One chip in the read-only Steps preview. */
|
||||
export interface WorkflowStepChip {
|
||||
/** 1-based, the position the server's own errors use. */
|
||||
index: number;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export type WorkflowParse =
|
||||
| { ok: true; id: string; steps: WorkflowStepChip[] }
|
||||
| { ok: false; message: string; line?: number };
|
||||
|
||||
/** What the editor's indicator reads. */
|
||||
export function validationLabel(parsed: WorkflowParse): string {
|
||||
if (parsed.ok) return "Valid";
|
||||
return parsed.line ? `Line ${parsed.line}: ${parsed.message}` : parsed.message;
|
||||
}
|
||||
|
||||
export function parseWorkflowYaml(source: string): WorkflowParse {
|
||||
const document = parseDocument(source);
|
||||
const problem = document.errors[0];
|
||||
if (problem) {
|
||||
return {
|
||||
ok: false,
|
||||
message: firstLine(problem.message),
|
||||
line: problem.linePos?.[0]?.line,
|
||||
};
|
||||
}
|
||||
|
||||
const value: unknown = document.toJS();
|
||||
if (!isMapping(value)) {
|
||||
return { ok: false, message: "A workflow is a mapping with an id and steps." };
|
||||
}
|
||||
|
||||
const id = typeof value.id === "string" ? value.id.trim() : "";
|
||||
if (!id) return { ok: false, message: "workflow id is required" };
|
||||
|
||||
const steps = value.steps;
|
||||
if (steps === undefined || steps === null || steps === "")
|
||||
return { ok: false, message: `workflow ${id} has no steps` };
|
||||
if (!Array.isArray(steps))
|
||||
return { ok: false, message: `workflow ${id}: steps must be a list` };
|
||||
if (!steps.length)
|
||||
return { ok: false, message: `workflow ${id} has no steps` };
|
||||
|
||||
const chips: WorkflowStepChip[] = [];
|
||||
for (const [i, step] of steps.entries()) {
|
||||
if (!isMapping(step) || !isNonEmptyString(step.type)) {
|
||||
return {
|
||||
ok: false,
|
||||
message: `workflow ${id} step ${i + 1} needs a type`,
|
||||
};
|
||||
}
|
||||
chips.push({ index: i + 1, type: step.type.trim() });
|
||||
}
|
||||
return { ok: true, id, steps: chips };
|
||||
}
|
||||
|
||||
// --- the editor's own rendering ---------------------------------------------
|
||||
//
|
||||
// Light syntax colouring, not a parse: every character of the source comes back
|
||||
// exactly once, so the highlighted layer behind the textarea can never drift
|
||||
// out of step with the text in it.
|
||||
|
||||
export type YamlTokenKind = "key" | "string" | "comment" | "punct" | "plain";
|
||||
|
||||
export interface YamlToken {
|
||||
text: string;
|
||||
kind: YamlTokenKind;
|
||||
}
|
||||
|
||||
export interface YamlLine {
|
||||
/** 1-based, as the gutter prints it. */
|
||||
number: number;
|
||||
text: string;
|
||||
tokens: YamlToken[];
|
||||
}
|
||||
|
||||
/** The token's colour, from the design tokens only. */
|
||||
export function yamlTokenClass(kind: YamlTokenKind): string {
|
||||
switch (kind) {
|
||||
case "key":
|
||||
return "text-fg-muted";
|
||||
case "string":
|
||||
return "text-ok";
|
||||
case "comment":
|
||||
case "punct":
|
||||
return "text-fg-subtle";
|
||||
default:
|
||||
return "text-foreground";
|
||||
}
|
||||
}
|
||||
|
||||
export function yamlLines(source: string): YamlLine[] {
|
||||
return source
|
||||
.split("\n")
|
||||
.map((text, i) => ({ number: i + 1, text, tokens: lineTokens(text) }));
|
||||
}
|
||||
|
||||
// A list marker and any indentation that precedes it, then whatever follows.
|
||||
const LINE_PREFIX = /^(\s*)(-\s+)?/;
|
||||
// A mapping entry: a key, its colon, and the scalar after it. A key cannot
|
||||
// contain a colon, which is what keeps `https://…` a value and not a key.
|
||||
const MAPPING_ENTRY = /^([^:#\s][^:#]*?)(:)(\s*)(.*)$/;
|
||||
|
||||
function lineTokens(text: string): YamlToken[] {
|
||||
const { code, comment } = splitComment(text);
|
||||
const tokens = codeTokens(code);
|
||||
if (comment) tokens.push({ text: comment, kind: "comment" });
|
||||
return tokens;
|
||||
}
|
||||
|
||||
/** A `#` opens a comment at the start of a line or after a space, and only
|
||||
* outside a quoted scalar: `"a # b"` is a value, not a value and a comment. */
|
||||
function splitComment(text: string): { code: string; comment: string } {
|
||||
let quote = "";
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
const char = text[i];
|
||||
if (quote) {
|
||||
if (char === quote) quote = "";
|
||||
continue;
|
||||
}
|
||||
if (char === '"' || char === "'") {
|
||||
quote = char;
|
||||
continue;
|
||||
}
|
||||
if (char === "#" && (i === 0 || /\s/.test(text[i - 1] ?? ""))) {
|
||||
return { code: text.slice(0, i), comment: text.slice(i) };
|
||||
}
|
||||
}
|
||||
return { code: text, comment: "" };
|
||||
}
|
||||
|
||||
function codeTokens(code: string): YamlToken[] {
|
||||
if (!code) return [];
|
||||
const tokens: YamlToken[] = [];
|
||||
const prefix = LINE_PREFIX.exec(code);
|
||||
if (prefix?.[1]) tokens.push({ text: prefix[1], kind: "plain" });
|
||||
if (prefix?.[2]) tokens.push({ text: prefix[2], kind: "punct" });
|
||||
|
||||
const rest = code.slice(prefix?.[0].length ?? 0);
|
||||
if (!rest) return tokens;
|
||||
|
||||
const entry = MAPPING_ENTRY.exec(rest);
|
||||
if (!entry) return [...tokens, ...scalarTokens(rest)];
|
||||
|
||||
tokens.push({ text: entry[1] ?? "", kind: "key" });
|
||||
tokens.push({ text: entry[2] ?? ":", kind: "punct" });
|
||||
if (entry[3]) tokens.push({ text: entry[3], kind: "plain" });
|
||||
return [...tokens, ...scalarTokens(entry[4] ?? "")];
|
||||
}
|
||||
|
||||
function scalarTokens(value: string): YamlToken[] {
|
||||
if (!value) return [];
|
||||
const quoted = /^("[^"]*"?|'[^']*'?)([\s\S]*)$/.exec(value);
|
||||
if (!quoted) return [{ text: value, kind: "plain" }];
|
||||
const tokens: YamlToken[] = [{ text: quoted[1] ?? "", kind: "string" }];
|
||||
if (quoted[2]) tokens.push({ text: quoted[2], kind: "plain" });
|
||||
return tokens;
|
||||
}
|
||||
|
||||
function firstLine(message: string): string {
|
||||
return message.split("\n")[0]?.trim() || "invalid YAML";
|
||||
}
|
||||
|
||||
function isMapping(value: unknown): value is Record<string, unknown> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
|
||||
function isNonEmptyString(value: unknown): value is string {
|
||||
return typeof value === "string" && value.trim() !== "";
|
||||
}
|
||||
Reference in new issue
Block a user