YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix(workflows): make block type labels directly editable (#7439)
Louis Beaumonta49d8a4927c1
diff --git a/apps/screenpipe-app-tauri/components/workflows/workflow-block-types.test.tsx b/apps/screenpipe-app-tauri/components/workflows/workflow-block-types.test.tsxnew file mode 100644index 000000000..5bec26539--- /dev/null+++ b/apps/screenpipe-app-tauri/components/workflows/workflow-block-types.test.tsx@@ -0,0 +1,46 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com+import React, { useState } from "react";+import { fireEvent, render, screen, waitFor } from "@testing-library/react";+import { beforeEach, describe, expect, it, vi } from "vitest";+import { WorkflowEditor } from "../../../../packages/workflows-ui/src/workflow-editor";+import { createFixtureWorkflowsPlatform, fixtureWorkflowAnalysis } from "@screenpipe/workflows-ui/fixture";+import type { WorkflowEdit } from "../../../../packages/workflows-ui/src/workflow-edits";++const workflow = fixtureWorkflowAnalysis.analysis.workflows.find(w => w.title === "Research synthesis")!;+const type = () => screen.getByRole("combobox", { name: "Block 1 type in step 1", exact: true });+beforeEach(() => { sessionStorage.clear(); localStorage.clear(); });+function Harness({ save }: { save: (draft: WorkflowEdit) => Promise<typeof workflow> }) {+ const [value, setValue] = useState(workflow);+ return <WorkflowEditor workflow={value} save={async draft => { const saved = await save(draft); setValue(saved); return saved; }} />;+}++describe("direct workflow block type editing", () => {+ it("changes type without a menu and preserves the block's text and source", async () => {+ const save = vi.fn(createFixtureWorkflowsPlatform().saveWorkflowEdits!);+ render(<Harness save={save} />);+ expect(screen.queryByRole("dialog")).not.toBeInTheDocument();+ expect(Array.from((type() as HTMLSelectElement).options, option => option.value)).toEqual(["action", "input", "output", "decision", "check"]);+ fireEvent.change(type(), { target: { value: "decision" } });+ await waitFor(() => expect(save).toHaveBeenCalledTimes(1), { timeout: 2000 });+ expect(save.mock.calls[0][0].stages[0].procedure[0]).toEqual({+ sourceIndex: 0, kind: "decision", text: workflow.stages[0].procedure![0].text,+ });+ fireEvent.click(screen.getByRole("button", { name: "Undo last edit" }));+ expect(type()).toHaveValue(workflow.stages[0].procedure![0].kind);+ await waitFor(() => expect(save).toHaveBeenCalledTimes(2), { timeout: 2000 });+ });++ it("retains a failed type edit for retry instead of reverting the label", async () => {+ const save = vi.fn().mockRejectedValueOnce(new Error("Offline. Try again.")).mockResolvedValue({ ...workflow, revision: 1 });+ render(<WorkflowEditor workflow={workflow} save={save} />);+ fireEvent.change(type(), { target: { value: "check" } });+ await screen.findByText("Offline. Try again.", {}, { timeout: 2000 });+ expect(type()).toHaveValue("check");+ const recovered = JSON.parse(sessionStorage.getItem(`screenpipe:workflow-edit:${workflow.id ?? workflow.title}`)!);+ expect(recovered.stages[0].procedure[0].kind).toBe("check");+ fireEvent.click(screen.getByRole("button", { name: "Retry save", exact: true }));+ await waitFor(() => expect(save).toHaveBeenCalledTimes(2));+ expect(save.mock.calls[1][0].stages[0].procedure[0].kind).toBe("check");+ });+});diff --git a/apps/screenpipe-workflows-web/scripts/eval-workflow-block-types.cjs b/apps/screenpipe-workflows-web/scripts/eval-workflow-block-types.cjsnew file mode 100644index 000000000..925ce082e--- /dev/null+++ b/apps/screenpipe-workflows-web/scripts/eval-workflow-block-types.cjs@@ -0,0 +1,69 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com+const { chromium } = require("playwright");+const assert = require("node:assert/strict");+const fs = require("node:fs");+const path = require("node:path");+const out = process.env.WORKFLOW_EDITOR_ARTIFACTS || path.join(require("node:os").tmpdir(), "screenpipe-block-types");+fs.mkdirSync(out, { recursive: true });+(async () => {+ const browser = await chromium.launch({ headless: true, channel: "chrome" });+ const url = process.env.WORKFLOWS_PREVIEW_URL || "http://127.0.0.1:1431/preview";+ const key = "screenpipe:fictional-workflow-editor-preview";+ const errors = [];+ try {+ for (const touch of [false, true]) {+ const context = await browser.newContext({ viewport: { width: touch ? 390 : 1440, height: 1000 }, hasTouch: touch, isMobile: touch });+ const page = await context.newPage();+ page.setDefaultTimeout(10000);+ page.on("pageerror", e => errors.push(e.message));+ const open = async () => {+ await page.getByRole("button", { name: "Open map", exact: true }).first().click();+ await page.getByRole("textbox", { name: "Workflow title", exact: true }).waitFor();+ };+ const stored = () => page.evaluate(key => JSON.parse(localStorage.getItem(key)).analysis.workflows.find(w => w.id === "Research synthesis"), key);+ const saved = () => page.getByRole("status", { name: "Save status" }).filter({ hasText: /^Saved$/ }).waitFor();+ await page.goto(url); await open();+ const type = page.getByRole("combobox", { name: "Block 1 type in step 1", exact: true });+ const text = page.getByRole("textbox", { name: "Block 1 in step 1", exact: true });+ const originalText = await text.innerText();+ await type.focus();+ assert(await type.evaluate(el => document.activeElement === el));+ let baseline;+ for (const kind of ["input", "output", "decision", "check", "action"]) {+ await type.selectOption(kind); await saved();+ const workflow = await stored();+ assert.equal(workflow.stages[0].procedure[0].kind, kind);+ assert.equal(await text.innerText(), originalText);+ baseline ??= workflow;+ assert.deepEqual(workflow.stages[0].screenshot, baseline.stages[0].screenshot);+ assert.equal(await page.getByRole("dialog").count(), 0);+ }+ await type.selectOption("output"); await saved();+ await type.focus();+ await page.keyboard.press("i"); await page.keyboard.press("Enter"); await saved();+ assert.equal(await type.inputValue(), "input");+ await page.getByRole("button", { name: "Undo last edit", exact: true }).click(); await saved();+ assert.equal(await type.inputValue(), "output");+ await type.selectOption("decision"); await saved();+ await type.focus();+ await page.screenshot({ path: path.join(out, touch ? "after-touch.png" : "after-desktop.png") });+ const beforeReload = await stored();+ await page.reload(); await open();+ assert.equal(await type.inputValue(), "decision");+ assert.deepEqual(await stored(), beforeReload);+ if (touch) assert(await type.evaluate(el => el.getBoundingClientRect().right <= innerWidth));+ const grip = page.getByRole("button", { name: "Move block 1 in step 1", exact: true });+ await text.focus(); await grip.click();+ await page.getByRole("button", { name: "Delete block 1 in step 1", exact: true }).waitFor();+ await page.keyboard.press("Escape");+ assert(await grip.evaluate(el => document.activeElement === el));+ await grip.press("Alt+ArrowDown"); await saved();+ assert.equal((await stored()).stages[0].procedure[1].kind, "decision");+ console.log(`PASS ${touch ? "touch / narrow" : "desktop"}: all five types, keyboard, autosave, undo, reload, preserved text/screenshots, menu dismissal, reorder`);+ await context.close();+ }+ assert.deepEqual(errors, []);+ console.log("PASS no browser exceptions");+ } finally { await browser.close(); }+})().catch(e => { console.error(e); process.exitCode = 1; });diff --git a/apps/screenpipe-workflows-web/scripts/eval-workflow-editor.cjs b/apps/screenpipe-workflows-web/scripts/eval-workflow-editor.cjsindex b2005ecce..4dae8bc84 100644--- a/apps/screenpipe-workflows-web/scripts/eval-workflow-editor.cjs+++ b/apps/screenpipe-workflows-web/scripts/eval-workflow-editor.cjs@@ -133,7 +133,7 @@ require("node:fs").mkdirSync(out, { recursive: true });const text = field("Block 1 in step 1");const grip = button("Move block 1 in step 1");const before = await text.boundingBox();- assert.equal(await page.getByRole("combobox", { name: "Block 1 type in step 1" }).count(), 0);+ assert.equal(await page.getByRole("combobox", { name: "Block 1 type in step 1" }).count(), 1);assert.equal(await button("Delete block 1 in step 1").count(), 0);await text.hover();const handle = await grip.boundingBox();@@ -145,9 +145,6 @@ require("node:fs").mkdirSync(out, { recursive: true });await menu.waitFor();await page.mouse.move(0, 0);assert.equal(await menu.isVisible(), true);- await page.getByRole("combobox", { name: "Block 1 type in step 1" }).selectOption("decision");- await saved();- assert.equal((await stored()).stages[0].procedure[0].kind, "decision");await page.screenshot({ path: out + "/block-actions.png" });await page.keyboard.press("Escape");assert.equal(await menu.count(), 0);@@ -155,7 +152,6 @@ require("node:fs").mkdirSync(out, { recursive: true });await grip.click();await field("Workflow title").click();assert.equal(await menu.count(), 0);- await button("Undo last edit").click(); await saved();await grip.focus(); await page.keyboard.press("Enter");await button("Delete block 1 in step 1").click(); await saved();assert.equal((await stored()).stages[0].procedure.length, initialBlocks.length - 1);diff --git a/docs/pr-assets/workflow-block-types/after-desktop.png b/docs/pr-assets/workflow-block-types/after-desktop.pngnew file mode 100644index 000000000..06f20930cBinary files /dev/null and b/docs/pr-assets/workflow-block-types/after-desktop.png differdiff --git a/docs/pr-assets/workflow-block-types/after-touch.png b/docs/pr-assets/workflow-block-types/after-touch.pngnew file mode 100644index 000000000..780da9a9dBinary files /dev/null and b/docs/pr-assets/workflow-block-types/after-touch.png differdiff --git a/docs/pr-assets/workflow-block-types/before.png b/docs/pr-assets/workflow-block-types/before.pngnew file mode 100644index 000000000..9faaaff79Binary files /dev/null and b/docs/pr-assets/workflow-block-types/before.png differdiff --git a/packages/workflows-ui/src/workflow-editor.module.css b/packages/workflows-ui/src/workflow-editor.module.cssindex 51a009242..a1b08c26b 100644--- a/packages/workflows-ui/src/workflow-editor.module.css+++ b/packages/workflows-ui/src/workflow-editor.module.css@@ -70,10 +70,14 @@.blockControls { position: absolute; left: -30px; top: 1px; }.blockControls[data-open] { z-index: 5; }.block textarea, .block > div[data-testid="procedure-markdown"] { min-width: 0; grid-column: 1; grid-row: 1; }-.kindLabel { grid-column: 2; grid-row: 1; padding: 8px 4px; font-size: 11px; line-height: 1.4; color: var(--muted); pointer-events: none; }+.kindLabel { position: relative; grid-column: 2; grid-row: 1; width: 76px; }+.kindLabel select { appearance: none; -webkit-appearance: none; box-sizing: border-box; width: 100%; min-height: 30px; padding: 6px 18px 6px 4px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font: inherit; font-size: 11px; line-height: 1.4; cursor: pointer; }+.kindLabel select:hover, .kindLabel select:focus-visible { background: var(--soft); color: var(--ink); }+.kindLabel svg { position: absolute; right: 4px; top: 9px; color: var(--muted); pointer-events: none; opacity: 0; }+.kindLabel[data-kind="action"] { opacity: 0; }+.block:hover > .kindLabel, .block:focus-within > .kindLabel { opacity: 1; }+.block:hover > .kindLabel svg, .block:focus-within > .kindLabel svg { opacity: 1; }.blockMenu { position: absolute; left: 0; top: 29px; box-sizing: border-box; width: 200px; padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); box-shadow: 0 4px 12px #00000012; }-.blockMenu label { display: block; padding: 4px; font-size: 11px; color: var(--muted); }-.blockMenu select { display: block; box-sizing: border-box; width: 100%; margin-top: 6px; border: 1px solid var(--line); border-radius: 4px; padding: 6px 8px; font: inherit; font-size: 13px; color: var(--ink); background: var(--panel); }.blockMenu > button { justify-content: flex-start; width: 100%; padding: 7px 4px; }.source { margin: 2px 0 0 29px; }.source > details { margin: 0; border: 0; border-radius: 0; background: transparent; }@@ -88,6 +92,8 @@.error { padding: 12px; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; line-height: 1.6; }.srOnly { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; }@media (hover: none) {+ .kindLabel[data-kind="action"], .kindLabel svg { opacity: 1; }+ .kindLabel select { min-height: 32px; }.editor button { min-width: 32px; min-height: 32px; }}@media (prefers-reduced-motion: reduce) {@@ -102,7 +108,7 @@.source { margin-left: 25px; }.block { grid-template-columns: minmax(0, 1fr); }.block textarea, .block > div[data-testid="procedure-markdown"] { grid-column: 1; grid-row: 1; }- .kindLabel { grid-column: 1; grid-row: 2; padding: 0 5px 3px; }+ .kindLabel { grid-column: 1; grid-row: 2; }}@media (prefers-reduced-motion: no-preference) {diff --git a/packages/workflows-ui/src/workflow-editor.tsx b/packages/workflows-ui/src/workflow-editor.tsxindex 9e49daa0e..727e54a67 100644--- a/packages/workflows-ui/src/workflow-editor.tsx+++ b/packages/workflows-ui/src/workflow-editor.tsx@@ -6,6 +6,7 @@ import {ArrowDown,ArrowUp,GripVertical,+ ChevronDown,MoreHorizontal,Plus,Trash2,@@ -467,32 +468,10 @@ export function WorkflowEditor({ workflow, save, actions, renderSource }: {<GripVertical size={15} /></button>{blockMenu === detail.key && <div role="dialog" aria-label={`Actions for block ${detailIndex + 1} in step ${index + 1}`} className={styles.blockMenu}>- <label>Block type- <select- autoFocus- aria-label={`Block ${detailIndex + 1} type in step ${index + 1}`}- value={detail.kind}- onChange={(e) =>- stageChange(index, {- ...stage,- procedure: stage.procedure.map((p, i) =>- i === detailIndex- ? { ...p, kind: e.target.value as typeof p.kind }- : p,- ),- })- }- >- {["action", "input", "output", "decision", "check"].map(- (kind) => (- <option key={kind}>{kind}</option>- ),- )}- </select>- </label><buttontype="button"title="Delete block"+ autoFocusaria-label={`Delete block ${detailIndex + 1} in step ${index + 1}`}onClick={() => {setBlockMenu(null);@@ -508,7 +487,24 @@ export function WorkflowEditor({ workflow, save, actions, renderSource }: {</button></div>}</div>- {detail.kind !== "action" && <span className={styles.kindLabel}>{detail.kind}</span>}+ <div className={styles.kindLabel} data-kind={detail.kind}>+ <select+ aria-label={`Block ${detailIndex + 1} type in step ${index + 1}`}+ title="Change block type"+ value={detail.kind}+ onChange={(e) => stageChange(index, {+ ...stage,+ procedure: stage.procedure.map((p, i) =>+ i === detailIndex ? { ...p, kind: e.target.value as typeof p.kind } : p,+ ),+ })}+ >+ {["action", "input", "output", "decision", "check"].map(kind =>+ <option key={kind} value={kind}>{kind}</option>,+ )}+ </select>+ <ChevronDown size={12} aria-hidden="true" />+ </div><Textrichlabel={`Block ${detailIndex + 1} in step ${index + 1}`}