From c7ce32df3e5150b4a5ff6505b9138eec0e94fb27 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 14 Nov 2026 22:49:15 +1100 Subject: [PATCH] feat(ui): split Workflows into a list page and a workflow page --- e2e/checks/execution-identities.cjs | 3 +- e2e/checks/loading-errors.cjs | 2 +- e2e/checks/org-schedule-trigger.cjs | 4 +- e2e/checks/workflow-loading.cjs | 2 +- e2e/checks/workflow-logic.cjs | 6 +- e2e/checks/workflow-phone-layout.cjs | 25 +- e2e/checks/workflow-validation.cjs | 3 +- ui/src/App.vue | 10 +- ui/src/chat/state.ts | 4 +- .../command-palette/CommandPalette.vue | 2 +- ui/src/router/index.ts | 13 + ui/src/workflows/TriggerSettings.vue | 2 +- ui/src/workflows/WorkflowEditor.vue | 7 +- ui/src/workflows/WorkflowPage.vue | 102 +++++++ ui/src/workflows/WorkflowsPage.vue | 251 ++++-------------- ui/src/workflows/use-workflow-stats.ts | 83 ++++++ 16 files changed, 294 insertions(+), 225 deletions(-) create mode 100644 ui/src/workflows/WorkflowPage.vue create mode 100644 ui/src/workflows/use-workflow-stats.ts diff --git a/e2e/checks/execution-identities.cjs b/e2e/checks/execution-identities.cjs index 8e87c627f..3cd990823 100644 --- a/e2e/checks/execution-identities.cjs +++ b/e2e/checks/execution-identities.cjs @@ -12,8 +12,7 @@ module.exports = async ({ page, go, shot }) => { agent = await response.json(); }; const openSettings = async () => { - await go('/workflows'); - await page.getByRole('button', { name: /^implement/ }).click(); + await go('/workflows/implement'); const runPicker = page.getByRole('combobox', { name: 'Run shown on the canvas' }); if (await runPicker.count()) { await runPicker.click(); await page.getByRole('option', { name: 'Definition', exact: true }).click(); } await page.locator('.vue-flow__node').filter({ hasText: 'Workflow' }).first().click(); diff --git a/e2e/checks/loading-errors.cjs b/e2e/checks/loading-errors.cjs index 61194f444..f49a09940 100644 --- a/e2e/checks/loading-errors.cjs +++ b/e2e/checks/loading-errors.cjs @@ -10,7 +10,7 @@ module.exports=async({page,go,shot,tolerate})=>{ if(new URL(route.request().url()).searchParams.has('workflow')) await route.fulfill({status:200,contentType:'application/json',body:'unreadable response'}); else await route.continue(); }); - await go('/workflows'); + await go('/workflows/implement'); await page.getByRole('alert').filter({hasText:'Could not load recent runs'}).waitFor(); await page.getByRole('tab',{name:/^Runs/}).click(); assert.equal(await page.getByText('No runs yet',{exact:true}).count(),0); diff --git a/e2e/checks/org-schedule-trigger.cjs b/e2e/checks/org-schedule-trigger.cjs index bc406f38d..42f28eadb 100644 --- a/e2e/checks/org-schedule-trigger.cjs +++ b/e2e/checks/org-schedule-trigger.cjs @@ -8,7 +8,7 @@ module.exports = async ({ page, go, shot, tolerate }) => { tolerate(ABSENT); await go('/'); assert.equal((await selectOrg(page, ORG.beta)).status(), 204); - await go('/workflows?workflow=feasibility'); + await go('/workflows/feasibility'); const origin = new URL(page.url()).origin; const headers = { 'X-Archie-CSRF': '1', Origin: origin }; const created = await page.request.post(`${origin}/api/bindings`, { @@ -22,7 +22,7 @@ module.exports = async ({ page, go, shot, tolerate }) => { assert.equal(created.status(), 201, `binding on the built-in schedule mapping refused: ${await created.text()}`); const binding = await created.json(); assert.equal(binding.org_id, ORG.beta); - await go('/workflows?workflow=feasibility'); + await go('/workflows/feasibility'); await page.getByText('Starts when').first().waitFor(); await shot('beta-trigger'); } finally { diff --git a/e2e/checks/workflow-loading.cjs b/e2e/checks/workflow-loading.cjs index 260a356dc..122bf9acc 100644 --- a/e2e/checks/workflow-loading.cjs +++ b/e2e/checks/workflow-loading.cjs @@ -7,7 +7,7 @@ module.exports = async ({ page, go, shot }) => { await go('/workflows'); assert.equal(await page.getByText('No workflows', { exact: true }).count(), 0, 'loading presented as empty'); await page.getByText('Loading workflows…', { exact: true }).waitFor({ state: 'hidden' }); - await page.getByRole('button', { name: /^implement/ }).click(); + await page.getByRole('link', { name: /^implement/ }).click(); assert.equal(await page.getByText(/workflow implement has no steps/).count(), 0, 'late definition left an empty canvas'); await page.locator('.vue-flow__node').filter({ hasText: 'Repository' }).first().waitFor(); await shot('loaded'); diff --git a/e2e/checks/workflow-logic.cjs b/e2e/checks/workflow-logic.cjs index 314812e81..ccc881076 100644 --- a/e2e/checks/workflow-logic.cjs +++ b/e2e/checks/workflow-logic.cjs @@ -29,7 +29,7 @@ module.exports = async ({ page, go, shot, settled }) => { const definition = resource.resource.value.definitions.find(entry => entry.id === 'feasibility'); definition.yaml = definition.yaml.replace(/\bid: assess\b/, 'id: Write a Product Requirement Document').replaceAll('steps.assess.', 'steps.Write a Product Requirement Document.'); await page.route('**/api/control-plane/resources/workflow-definitions', route => route.fulfill({ json: resource })); - await go('/workflows?workflow=feasibility'); + await go('/workflows/feasibility'); await page.getByRole('tab', { name: 'History', exact: true }).click(); const yaml = await page.getByLabel('Workflow YAML', { exact: true }).inputValue(); assert.ok(yaml.includes('id: write-a-product-requirement-document')); @@ -71,7 +71,7 @@ module.exports = async ({ page, go, shot, settled }) => { await page.route('**/api/tasks/999999/*?*', route => route.fulfill({ json: {} })); await page.route('**/api/tasks/999999/debug', route => route.fulfill({ json: {} })); await page.route('**/api/tasks/999999/attempts', route => route.fulfill({ json: { attempts: [{ attempt: 1, stages: [{ name: 'Write a Product Requirement Document', status: 'failed', error: 'Historical failure' }] }] } })); - await go('/workflows?workflow=feasibility'); + await go('/workflows/feasibility'); const picker = page.getByRole('combobox', { name: 'Run shown on the canvas' }); await picker.waitFor(); assert.match(await picker.innerText(), /Run #999999/); @@ -92,7 +92,7 @@ module.exports = async ({ page, go, shot, settled }) => { await page.getByRole('option', { name: 'Definition', exact: true }).click(); assert.equal(await picker.innerText(), 'Definition'); await shot('definition-picker'); - await go('/workflows?workflow=triage'); + await go('/workflows/triage'); const runPicker = page.getByRole('combobox', { name: 'Run shown on the canvas' }); if (await runPicker.count()) { await runPicker.click(); await page.getByRole('option', { name: 'Definition', exact: true }).click(); } await page.locator('.vue-flow').hover(); diff --git a/e2e/checks/workflow-phone-layout.cjs b/e2e/checks/workflow-phone-layout.cjs index c5a9ff152..551cc0396 100644 --- a/e2e/checks/workflow-phone-layout.cjs +++ b/e2e/checks/workflow-phone-layout.cjs @@ -6,8 +6,27 @@ const assert = require('node:assert/strict'); module.exports = async ({ page, go, shot, settled }) => { await page.setViewportSize({ width: 390, height: 844 }); + // The list is a page at phone width: rows open the workflow, and Enable or + // Disable is reachable from the row menu and from the workflow page. + await go('/workflows'); + const row = page.getByRole('link', { name: /^implement/ }); + await row.waitFor(); + const listWidth = await page.evaluate(() => ({ scrollWidth: document.documentElement.scrollWidth, width: innerWidth })); + assert.equal(listWidth.scrollWidth, listWidth.width, 'workflow list scrolls horizontally'); + await shot('list'); + await page.getByRole('button', { name: 'implement actions' }).click(); + await page.getByRole('menuitem', { name: /^(Enable|Disable)$/ }).waitFor(); + await page.keyboard.press('Escape'); + await row.click(); + await page.waitForURL(/\/workflows\/implement$/); + await page.locator('.workflow-canvas').waitFor(); + await page.getByRole('button', { name: 'More', exact: true }).click(); + await page.getByRole('menuitem', { name: /^(Enable|Disable)$/ }).waitFor(); + await page.keyboard.press('Escape'); + await go('/workflows?workflow=implement'); + assert.match(page.url(), /\/workflows\/implement$/, 'legacy ?workflow= link did not reach the workflow page'); for (const workflow of ['implement', 'feasibility']) { - await go(`/workflows?workflow=${workflow}`); + await go(`/workflows/${workflow}`); const canvas = page.locator('.workflow-canvas'); await canvas.waitFor(); const dimensions = await page.evaluate(() => ({ @@ -55,7 +74,7 @@ module.exports = async ({ page, go, shot, settled }) => { await page.keyboard.press('Escape'); } // YAML must not make the page scroll at phone width. - await go('/workflows?workflow=feasibility'); + await go('/workflows/feasibility'); await page.getByRole('tab', { name: 'History', exact: true }).click(); await settled(); const yamlPage = await page.evaluate(() => ({ @@ -76,7 +95,7 @@ module.exports = async ({ page, go, shot, settled }) => { await page.route('**/api/tasks/999999/*?*', route => route.fulfill({ json: {} })); await page.route('**/api/tasks/999999/debug', route => route.fulfill({ json: {} })); await page.route('**/api/tasks/999999/attempts', route => route.fulfill({ json: { attempts: [{ attempt: 1, stages: [] }] } })); - await go('/workflows?workflow=feasibility'); + await go('/workflows/feasibility'); const picker = page.getByRole('combobox', { name: 'Run shown on the canvas' }); await picker.waitFor(); assert.match(await picker.innerText(), /Run #999999/); diff --git a/e2e/checks/workflow-validation.cjs b/e2e/checks/workflow-validation.cjs index 7d30ddfeb..8188cd35f 100644 --- a/e2e/checks/workflow-validation.cjs +++ b/e2e/checks/workflow-validation.cjs @@ -1,7 +1,6 @@ const assert = require('node:assert/strict'); module.exports = async ({ page, go, shot }) => { - await go('/workflows'); - await page.getByRole('button', {name:/^implement(?! actions)/}).click(); + await go('/workflows/implement'); const runPicker = page.getByRole('combobox', { name: 'Run shown on the canvas' }); if (await runPicker.count()) { await runPicker.click(); await page.getByRole('option', { name: 'Definition', exact: true }).click(); } await page.locator('.vue-flow__node').filter({hasText:'Prepare worktree'}).first().click(); diff --git a/ui/src/App.vue b/ui/src/App.vue index b915147d2..d568722bc 100644 --- a/ui/src/App.vue +++ b/ui/src/App.vue @@ -16,7 +16,7 @@ import SectionCrumb from "@/components/topbar/SectionCrumb.vue"; import Brand from "@/components/topbar/Brand.vue"; import Logo from "@/components/topbar/Logo.vue"; import ConnectionPill from "@/components/topbar/ConnectionPill.vue"; -import { Breadcrumb, BreadcrumbItem, BreadcrumbList, BreadcrumbSeparator } from "@/components/ui/breadcrumb"; +import { Breadcrumb, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbSeparator } from "@/components/ui/breadcrumb"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Card } from "@/components/ui/card"; import { SidebarInset, SidebarProvider } from "@/components/ui/sidebar"; @@ -34,7 +34,7 @@ const accounts=useAccountsStore(); const session = useSessionStore(); const route = useRoute(); const router = useRouter(); -const workflowsPage = computed(() => route.path === "/workflows"); +const workflowsPage = computed(() => route.name === "workflow"); const hidden = computed(() => hiddenPaths(session.sections)); const main = ref(null); const newTaskOpen = ref(false); @@ -42,7 +42,7 @@ const newTaskOpen = ref(false); // it, so a bookmark or a chat link must not land on a form whose saves the // control plane refuses. watch([() => route.path, hidden], () => { - if (hidden.value.includes(route.path)) void router.replace("/"); + if (hidden.value.includes(typeof route.meta.navPath === "string" ? route.meta.navPath : route.path)) void router.replace("/"); }); watch(() => [route.path, accounts.instance], () => { const scope = route.meta.org ? "Organisation" : route.meta.settings ? "Instance" : ""; @@ -108,6 +108,10 @@ watch(() => accounts.status?.user, (user) => { +
diff --git a/ui/src/chat/state.ts b/ui/src/chat/state.ts index 7a19a584c..4c7c5860f 100644 --- a/ui/src/chat/state.ts +++ b/ui/src/chat/state.ts @@ -663,8 +663,8 @@ export const pageTag = computed(() => { const label = route.name === "task-detail" ? `Task #${route.params.id}` - : route.name === "workflows" && typeof route.query.workflow === "string" - ? `Workflow ${route.query.workflow}` + : route.name === "workflow" + ? `Workflow ${route.params.id}` : typeof route.meta.label === "string" ? route.meta.label : page; diff --git a/ui/src/components/command-palette/CommandPalette.vue b/ui/src/components/command-palette/CommandPalette.vue index 609208118..b1ca8b904 100644 --- a/ui/src/components/command-palette/CommandPalette.vue +++ b/ui/src/components/command-palette/CommandPalette.vue @@ -133,7 +133,7 @@ onUnmounted(() => document.removeEventListener("keydown", onGlobalKeydown)); v-for="id in workflows" :key="id" :value="`workflow:${id}`" - @select="go(`/workflows?workflow=${encodeURIComponent(id)}`)" + @select="go(`/workflows/${encodeURIComponent(id)}`)" > {{ id }} diff --git a/ui/src/router/index.ts b/ui/src/router/index.ts index e24acc603..5098879ee 100644 --- a/ui/src/router/index.ts +++ b/ui/src/router/index.ts @@ -32,6 +32,7 @@ const SkillsPage = () => import("@/skills/SkillsPage.vue"); const TaskDetailPage = () => import("@/tasks/TaskDetailPage.vue"); const TasksPage = () => import("@/tasks/TasksPage.vue"); const WorkflowsPage = () => import("@/workflows/WorkflowsPage.vue"); +const WorkflowPage = () => import("@/workflows/WorkflowPage.vue"); // internal/gateway/dashboard_tools.go mirrors this table. // @@ -73,12 +74,24 @@ const routes = [ path: "/workflows", name: "workflows", component: WorkflowsPage, + // Links written as /workflows?workflow= open that workflow's page. + beforeEnter: (to: RouteLocationGeneric) => { + const { workflow, ...query } = to.query; + if (typeof workflow === "string" && workflow) return { name: "workflow", params: { id: workflow }, query, replace: true }; + return true; + }, meta: { label: "Workflows", description: "Workflows and run history.", section: "workflows", }, }, + { + path: "/workflows/:id", + name: "workflow", + component: WorkflowPage, + meta: { label: "Workflow", nav: false, navPath: "/workflows" }, + }, { path: "/settings/skills", name: "skills", diff --git a/ui/src/workflows/TriggerSettings.vue b/ui/src/workflows/TriggerSettings.vue index 3af67b939..f7df18db8 100644 --- a/ui/src/workflows/TriggerSettings.vue +++ b/ui/src/workflows/TriggerSettings.vue @@ -43,7 +43,7 @@ function open(trigger: WorkflowTrigger): void { {{ statusLabel(trigger.binding.status) }} {{ trigger.detail }} - + {{ trigger.label }}{{ trigger.detail }}
diff --git a/ui/src/workflows/WorkflowEditor.vue b/ui/src/workflows/WorkflowEditor.vue index a2ef4491b..575be4050 100644 --- a/ui/src/workflows/WorkflowEditor.vue +++ b/ui/src/workflows/WorkflowEditor.vue @@ -10,7 +10,7 @@ import { AlertDialogTitle, } from "@/components/ui/alert-dialog"; import { computed, onBeforeUnmount, onMounted, ref, toRef, watch } from "vue"; -import { CircleAlert, Copy, RotateCcw, Trash2 } from "@lucide/vue"; +import { CircleAlert, Copy, Power, RotateCcw, Trash2 } from "@lucide/vue"; import { isSending, setTurnHooks } from "@/chat/state"; import { Button } from "@/components/ui/button"; @@ -66,9 +66,9 @@ const modelAliases = computed(() => const collection = computed(() => workflows.collection); // Which definition is open belongs to the page, which also lists them. const selected = defineModel("selected", { required: true }); -const emit = defineEmits<{ duplicate: [id: string] }>(); +const emit = defineEmits<{ duplicate: [id: string]; setEnabled: [value: boolean] }>(); // Stage statistics are read by the page with the rest of the workflow stats. -const props = defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string; startedBy: { workflow: string; via: string }[] }>(); +const props = defineProps<{ stageStats: StageStats[]; statsKnown: boolean; statsError: string; startedBy: { workflow: string; via: string }[]; enabled?: boolean }>(); const id = ref(""); const yaml = ref(""); const loadedYaml = ref(""); @@ -475,6 +475,7 @@ const runOptions = computed(() => [ Version {{ watchedRevision.version }} Draft changes {{ changes.length }} Discard changes + {{ props.enabled ? "Disable" : "Enable" }} Duplicate Delete workflow diff --git a/ui/src/workflows/WorkflowPage.vue b/ui/src/workflows/WorkflowPage.vue new file mode 100644 index 000000000..85dac9e7a --- /dev/null +++ b/ui/src/workflows/WorkflowPage.vue @@ -0,0 +1,102 @@ + + + diff --git a/ui/src/workflows/WorkflowsPage.vue b/ui/src/workflows/WorkflowsPage.vue index 3d21030ca..57dc876bf 100644 --- a/ui/src/workflows/WorkflowsPage.vue +++ b/ui/src/workflows/WorkflowsPage.vue @@ -1,76 +1,29 @@ diff --git a/ui/src/workflows/use-workflow-stats.ts b/ui/src/workflows/use-workflow-stats.ts new file mode 100644 index 000000000..a8f12a423 --- /dev/null +++ b/ui/src/workflows/use-workflow-stats.ts @@ -0,0 +1,83 @@ +import { onMounted, ref, shallowRef } from "vue"; +import { toast } from "vue-sonner"; + +import { api, describeError } from "@/lib/api"; +import { errors } from "@/copy/errors"; +import { keepValue } from "@/lib/keep-unchanged"; +import { upsertWorkflowDefinition, useWorkflowsStore } from "@/stores/workflows"; +import { useLiveResource } from "@/stores/session"; +import type { StageStats } from "./WorkflowRuns.vue"; +import { setWorkflowField } from "./workflow-edit"; +import type { WorkflowDefinition, WorkflowStats } from "./workflow-rows"; + +interface WorkflowsResponse { + definitions?: WorkflowDefinition[]; + workflows?: WorkflowStats[]; + stages?: StageStats[]; +} + +/** + * The workflow list and the workflow page read the same statistics and offer + * the same Enable/Disable and Duplicate, so both take them from here. + */ +export function useWorkflowStats() { + const store = useWorkflowsStore(); + const data = shallowRef({}); + const error = ref(null); + 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); + + // Live reloads and actions overlap; only the newest read may land. + let generation = 0; + async function load() { + const current = ++generation; + try { + // Running count and last status come from the per-workflow statistics: a + // page of the newest tasks would show nothing for a workflow whose runs + // are older than that page. + const response = (await api.workflows()) ?? {}; + if (current !== generation) return; + data.value = keepValue(data.value, response); + error.value = null; + statsKnown.value = true; + } catch (err) { + if (current === generation) error.value = describeError(err, errors.common.unknown); + } finally { + if (current === generation) loading.value = false; + } + } + useLiveResource("tasks", () => void load(), 5000); + onMounted(() => Promise.all([load(), store.load()])); + + const enabledOf = (id: string) => data.value.definitions?.find((d) => d.id === id)?.enabled; + + async function setEnabled(id: string, value: boolean) { + try { + await api.workflowEnabled(id, value); + toast.success(`${id} ${value ? "enabled" : "disabled"}`); + await load(); + } catch (err) { + const reason = describeError(err, errors.common.unknown); + toast.error(value ? errors.workflows.page.notEnabled(id, reason) : errors.workflows.page.notDisabled(id, reason)); + } + } + + /** Saves a copy of a workflow and returns its id, or "" when it was not saved. */ + async function duplicate(id: string): Promise { + const stored = store.collection.definitions; + const source = stored.find((d) => d.id === id); + if (!source) return ""; + let copy = `${id}-copy`; + for (let n = 2; stored.some((d) => d.id === copy); n++) copy = `${id}-copy-${n}`; + if (await store.save(upsertWorkflowDefinition(store.collection, { id: copy, yaml: setWorkflowField(source.yaml, "id", copy) }))) { + toast.success(`${copy} created`); + return copy; + } + toast.error(errors.workflows.page.notDuplicated(id, store.error || errors.workflows.page.saveFailed)); + return ""; + } + + return { store, data, error, loading, statsKnown, load, enabledOf, setEnabled, duplicate }; +}