feat(ui): inspect workflow step runs from canvas

This commit is contained in:
sam committed 2026-10-05 12:53:34 +11:00
1 parent 895a04047d
commit 1510c41254
10 files changed
+351 -89

No files matched your search

+141
View File
@@ -0,0 +1,141 @@
<script setup lang="ts">
import { computed, onUnmounted, ref, watch } from "vue";
import { api } from "@/lib/api";
import { useLiveResource } from "@/stores/live-updates";
import { Badge } from "@/components/ui/badge";
import ChangeCapture from "@/tasks/ChangeCapture.vue";
import TaskLogs from "@/tasks/TaskLogs.vue";
import { stageStatusMeta } from "@/tasks/stage-rail";
import { describeTimelineEvent, duration } from "@/tasks/timeline-event";
import type { ChangesState, LogState, TaskEvent, TaskRecord } from "@/tasks/task-run";
import type { StageRun } from "./workflow-graph";
const props = defineProps<{ task: TaskRecord; attempt: number; stage: StageRun; stages: StageRun[] }>();
const events = ref<TaskEvent[]>([]);
const changes = ref<ChangesState>();
const logs = ref<LogState | null>();
const activityError = ref("");
const changesError = ref("");
const expanded = ref(false);
const key = computed(() => `${props.task.id}/${props.attempt}/${props.stage.id ?? props.stage.name}`);
let generation = 0;
let timer: ReturnType<typeof setInterval> | undefined;
let loading = false;
let queued = false;
async function refresh(): Promise<void> {
if (!props.attempt) return;
if (loading) { queued = true; return; }
loading = true;
const current = generation;
const id = String(props.task.id);
const params = { attempt: props.attempt };
const results = await Promise.allSettled([
api.taskDebug<{ events?: TaskEvent[] }>(id, params),
api.taskChanges<ChangesState>(id, params),
api.taskLogs<LogState>(id, { ...params, stage: props.stage.name }),
]);
if (current !== generation) return;
const [activity, capture, log] = results;
activityError.value = activity.status === "rejected" ? "Could not load step activity" : "";
if (activity.status === "fulfilled") events.value = activity.value.events ?? [];
changesError.value = capture.status === "rejected" ? "Could not load captured changes" : "";
if (capture.status === "fulfilled") changes.value = capture.value;
logs.value = log.status === "fulfilled" ? log.value : null;
loading = false;
if (queued) { queued = false; void refresh(); }
}
watch(key, () => {
generation++;
loading = false;
queued = false;
events.value = [];
changes.value = undefined;
logs.value = undefined;
activityError.value = "";
changesError.value = "";
expanded.value = false;
void refresh();
}, { immediate: true });
watch(() => props.stage.status, (status) => {
clearInterval(timer);
void refresh();
// Logs can arrive between task events; read them while the stage is active.
if (status === "running") timer = setInterval(() => void refresh(), 2000);
}, { immediate: true });
useLiveResource("tasks", () => void refresh(), 300);
onUnmounted(() => { generation++; clearInterval(timer); });
const meta = computed(() => stageStatusMeta(props.stage.status));
const names = computed(() => new Set([props.stage.name, ...(props.stage.agents ?? []).map((agent) => agent.name.split("/").at(-1) ?? agent.name)]));
const nextStart = computed(() => props.stages.find((stage) => stage.name === props.stage.name && stage.started_at && props.stage.started_at && stage.started_at > props.stage.started_at)?.started_at);
function inWindow(at: string | number | Date | undefined): boolean {
if (!props.stage.started_at || !at) return props.stages.filter((stage) => stage.name === props.stage.name).length === 1;
const time = new Date(at).getTime();
return time >= Date.parse(props.stage.started_at) && (!props.stage.finished_at || time <= Date.parse(props.stage.finished_at)) && (!nextStart.value || time < Date.parse(nextStart.value));
}
const activity = computed(() => events.value.filter((event) => {
if (Number(event.attempt) !== props.attempt) return false;
if (event.data?.step_id != null) return Number(event.data.step_id) === props.stage.id;
return names.value.has(event.stage ?? "") && inWindow(event.at);
}).sort((a, b) => String(a.at ?? "").localeCompare(String(b.at ?? ""))));
const groups = computed(() => {
const agents = props.stage.agents ?? [];
const branches = new Set(["", ...agents.map((agent) => agent.name.includes("/") ? agent.name.split("/")[0]! : ""), ...activity.value.map((event) => String(event.data?.branch ?? ""))]);
return [...branches].map((branch) => ({
branch,
agents: agents.filter((agent) => (agent.name.includes("/") ? agent.name.split("/")[0] : "") === branch),
reports: activity.value.filter((event) => event.kind === "agent_finish" && String(event.data?.branch ?? "") === branch),
tools: activity.value.filter((event) => event.kind === "tool_call" && String(event.data?.branch ?? "") === branch),
})).filter((group) => group.agents.length || group.reports.length || group.tools.length);
});
const captures = computed(() => (changes.value?.captures ?? []).filter((capture) => capture.stage === props.stage.name && inWindow(capture.captured_at)));
const scopedLogs = computed(() => logs.value ? { ...logs.value, entries: (logs.value.entries ?? []).filter((entry) => inWindow(entry.time)) } : logs.value);
</script>
<template>
<div class="space-y-5 p-4 text-sm">
<div class="flex items-center gap-2">
<Badge :variant="meta.kind">{{ meta.label }}</Badge>
<span class="text-xs text-muted-foreground">{{ stage.duration_ms == null ? "Duration not recorded" : duration(stage.duration_ms) }}</span>
<span class="ml-auto text-xs text-muted-foreground">Attempt {{ attempt }}</span>
</div>
<p v-if="stage.error" class="rounded-md bg-danger-soft p-3 break-words whitespace-pre-wrap text-danger">{{ stage.error }}</p>
<p v-if="activityError" role="alert" class="text-danger">{{ activityError }}</p>
<section v-for="group in groups" :key="group.branch" class="space-y-3">
<h3 v-if="group.branch" class="font-medium">{{ group.branch }}</h3>
<p v-else-if="groups.length > 1" class="text-xs text-muted-foreground">Activity without branch attribution</p>
<div v-for="agent in group.agents" :key="agent.id" class="space-y-1">
<div class="flex items-center gap-2 text-xs"><span class="font-mono">{{ agent.name.split('/').at(-1) }}</span><Badge :variant="stageStatusMeta(agent.status).kind">{{ agent.status }}</Badge></div>
<p v-if="agent.detail" class="break-words whitespace-pre-wrap">{{ agent.detail }}</p>
</div>
<div v-for="(report, i) in group.reports" :key="i" class="space-y-1">
<p v-if="report.detail && !group.agents.some((agent) => agent.detail === report.detail)" class="break-words whitespace-pre-wrap">{{ report.detail }}</p>
<p class="text-xs text-muted-foreground">Agent's own report · {{ describeTimelineEvent(report).title }}</p>
</div>
<div v-if="group.tools.length" class="space-y-1">
<h4 class="text-xs font-medium text-muted-foreground">Tool calls · {{ group.tools.length }}</h4>
<ol class="divide-y divide-border rounded-md border border-border">
<li v-for="(tool, i) in expanded ? group.tools : group.tools.slice(0, 12)" :key="i" class="px-3 py-2">
<div class="flex justify-between gap-2 text-xs"><span class="font-mono">{{ tool.data?.tool }}</span><span :class="tool.data?.failed ? 'text-danger' : 'text-muted-foreground'">{{ tool.data?.failed ? 'Failed' : 'Returned' }}</span></div>
<p v-if="tool.detail" class="mt-1 break-words whitespace-pre-wrap text-xs text-muted-foreground">{{ tool.detail }}</p>
</li>
</ol>
<button v-if="group.tools.length > 12" type="button" class="text-xs text-primary hover:underline" @click="expanded = !expanded">{{ expanded ? 'Show first 12' : `Show all ${group.tools.length}` }}</button>
</div>
<p v-if="group.reports.length" class="text-xs text-muted-foreground">{{ group.reports.map((report) => describeTimelineEvent(report).detail).filter(Boolean).join(' · ') }}</p>
<p v-else-if="group.agents.length" class="text-xs text-muted-foreground">{{ group.agents.reduce((sum, agent) => sum + agent.tokens_used, 0).toLocaleString() }} tokens recorded</p>
</section>
<section class="space-y-3">
<h3 class="text-xs font-medium text-muted-foreground">Captured changes</h3>
<p v-if="changesError" role="alert" class="text-danger">{{ changesError }}</p>
<ChangeCapture v-for="(capture, i) in captures" :key="i" :capture="capture" :task="task" />
<p v-if="changes && !captures.length" class="text-xs text-muted-foreground">No changes captured for this step</p>
</section>
<section class="space-y-2">
<h3 class="text-xs font-medium text-muted-foreground">Log <span title="Only lines tagged with this stage are shown">· stage-tagged lines</span></h3>
<TaskLogs :state="scopedLogs" :attempt="attempt" :filterable="false" />
</section>
</div>
</template>
+27 -4
View File
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { computed, ref, watch } from "vue";
import { Ellipsis, RotateCcw, Trash2 } from "@lucide/vue";
import { Ellipsis, RotateCcw, Trash2, X } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import {
@@ -13,6 +13,8 @@ import {
import { Spinner } from "@/components/ui/spinner";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Textarea } from "@/components/ui/textarea";
import StepRun from "./StepRun.vue";
import { withRuns, workflowGraph } from "./workflow-graph";
import StepEditor from "./StepEditor.vue";
import WorkflowSettings from "./WorkflowSettings.vue";
import RunWorkflowButton from "./RunWorkflowButton.vue";
@@ -58,17 +60,26 @@ watch(selectedStep, (path) => {
});
const localError = ref("");
const { runs, watched, watchedRun, stages, pick, follow, refresh } = useWorkflowRuns(selected);
const { runs, watched, watchedRun, stages, attempt, pick, follow, refresh } = useWorkflowRuns(selected);
const stepTab = ref("definition");
const selectedNode = computed(() => withRuns(workflowGraph(yaml.value), stages.value).nodes.find((node) => JSON.stringify(node.data.path) === JSON.stringify(selectedStep.value))?.data);
function openStep(path: StepPath): void {
selectedStep.value = path;
stepTab.value = selectedNode.value?.run && watchedRun.value ? "run" : "definition";
}
watch(watched, () => { selectedStep.value = null; });
const triggers = useWorkflowTriggers(selected);
// Canvas edits are edits to the YAML; a newly placed step opens for editing.
const stepTypeNames = computed(() => vocabulary.value.map((info) => info.name));
function insertAt(after: number, type: string): void {
stepTab.value = "definition";
const inserted = insertStep(yaml.value, after, type);
yaml.value = inserted.source;
selectedStep.value = inserted.path;
}
function duplicateAt(path: StepPath): void {
stepTab.value = "definition";
const copied = duplicateStep(yaml.value, path);
yaml.value = copied.source;
selectedStep.value = copied.path;
@@ -224,7 +235,7 @@ function syncScroll(event: Event): void {
:selected="selectedStep"
:triggers="triggers"
:types="stepTypeNames"
@edit="selectedStep = $event"
@edit="openStep"
@settings="selectedStep = null; settingsOpen = true"
@insert="insertAt"
@duplicate="duplicateAt"
@@ -247,8 +258,20 @@ function syncScroll(event: Event): void {
enter-active-class="transition duration-200"
leave-active-class="transition duration-150"
>
<div v-if="selectedStep" class="absolute inset-y-0 right-0 overflow-hidden rounded-r-lg">
<div v-if="selectedStep" class="absolute inset-y-0 right-0 flex flex-col overflow-hidden rounded-r-lg border-l border-border bg-card shadow-xl">
<template v-if="selectedNode?.run && watchedRun">
<div class="flex items-center gap-2 border-b border-border px-3 py-2">
<Tabs v-model="stepTab"><TabsList><TabsTrigger value="run">Run</TabsTrigger><TabsTrigger value="definition">Definition</TabsTrigger></TabsList></Tabs>
<span class="min-w-0 flex-1 truncate text-xs" :title="selectedNode.run.name">{{ selectedNode.run.name }}</span>
<Button type="button" variant="ghost" size="icon-sm" aria-label="Close step details" @click="selectedStep = null"><X /></Button>
</div>
<div v-if="stepTab === 'run'" class="min-h-0 w-[32rem] max-w-[calc(100vw-3rem)] flex-1 overflow-y-auto">
<StepRun :task="watchedRun" :attempt="attempt" :stage="selectedNode.run" :stages="stages" />
</div>
</template>
<StepEditor
class="min-h-0 flex-1"
v-if="stepTab === 'definition' || !selectedNode?.run || !watchedRun"
:key="JSON.stringify(selectedStep)"
v-model:yaml="yaml"
:path="selectedStep"
+14
View File
@@ -33,7 +33,21 @@ export interface StepNodeData {
}
/** One recorded run of a step, from the task's attempts view. */
export interface AgentRun {
id: number;
name: string;
status: string;
detail: string;
tokens_used: number;
started_at: string;
finished_at?: string;
}
export interface StageRun {
id?: number;
started_at?: string;
finished_at?: string;
agents?: AgentRun[];
name: string;
status: "ok" | "failed" | "interrupted" | "running" | "unknown" | string;
duration_ms?: number;
+12 -3
View File
@@ -23,6 +23,7 @@ export function useWorkflowRuns(workflow: Ref<string>) {
const runs = ref<WorkflowRun[]>([]);
const watched = ref("");
const stages = ref<StageRun[]>([]);
const attempt = ref(0);
let picked = false;
async function loadRuns(): Promise<void> {
@@ -38,11 +39,15 @@ export function useWorkflowRuns(workflow: Ref<string>) {
async function loadStages(): Promise<void> {
if (!watched.value) {
stages.value = [];
attempt.value = 0;
return;
}
const view = await api.taskAttempts<AttemptsView>(watched.value).catch(() => null);
const requested = watched.value;
const view = await api.taskAttempts<AttemptsView>(requested).catch(() => null);
if (watched.value !== requested) return;
const latest = [...(view?.attempts ?? [])].sort((a, b) => b.attempt - a.attempt)[0];
stages.value = latest?.stages ?? [];
attempt.value = latest?.attempt ?? 0;
}
// "Definition only" is a choice too, and a refresh must not undo it.
@@ -60,7 +65,11 @@ export function useWorkflowRuns(workflow: Ref<string>) {
picked = false;
void refresh();
}, { immediate: true });
watch(watched, () => void loadStages());
watch(watched, () => {
stages.value = [];
attempt.value = 0;
void loadStages();
});
useLiveResource("tasks", () => void refresh(), 300);
const watchedRun = computed(() => runs.value.find((run) => String(run.id) === watched.value));
@@ -72,5 +81,5 @@ export function useWorkflowRuns(workflow: Ref<string>) {
await refresh();
}
return { runs, watched, watchedRun, stages, pick, follow, refresh };
return { runs, watched, watchedRun, stages, attempt, pick, follow, refresh };
}