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:
sam committed 2026-09-30 11:41:33 +10:00
1 parent c6623d5300
commit 5e1e365c05
23 files changed
+1184 -75

No files matched your search

+113 -11
View File
@@ -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 &amp; 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 &amp; save</Button>
</div>
</form>
</template>
+187
View File
@@ -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() !== "";
}