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
feat(workflows): add Studio document exports and archive actions (#7716)
Louis Beaumontd75ccaedd27d
diff --git a/apps/screenpipe-app-tauri/lib/workflows/local-editor-parity.test.tsx b/apps/screenpipe-app-tauri/lib/workflows/local-editor-parity.test.tsxindex f974a854d..f62ef2336 100644--- a/apps/screenpipe-app-tauri/lib/workflows/local-editor-parity.test.tsx+++ b/apps/screenpipe-app-tauri/lib/workflows/local-editor-parity.test.tsx@@ -159,7 +159,7 @@ it("opens secondary tools by keyboard and restores focus without changing the drexpect(screen.getByRole("menuitem", { name: "Variables" })).toHaveFocus();fireEvent.keyDown(document.activeElement!, { key: "End" });// Disabled Undo is skipped until there is an edit to undo.- expect(screen.getByRole("menuitem", { name: "Workflow details" })).toHaveFocus();+ expect(screen.getByRole("menuitem", { name: "Archive workflow" })).toHaveFocus();fireEvent.keyDown(document.activeElement!, { key: "Escape" });expect(trigger).toHaveFocus();expect(screen.queryByRole("menu")).toBeNull();diff --git a/apps/screenpipe-app-tauri/lib/workflows/workflow-document-exports.test.tsx b/apps/screenpipe-app-tauri/lib/workflows/workflow-document-exports.test.tsxnew file mode 100644index 000000000..7e6da91cd--- /dev/null+++ b/apps/screenpipe-app-tauri/lib/workflows/workflow-document-exports.test.tsx@@ -0,0 +1,95 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com+import React from "react";+import { afterEach, expect, it, vi } from "vitest";+import { cleanup, fireEvent, render, screen, waitFor } from "@testing-library/react";+import { WorkflowEditor, WorkflowDocument } from "../../../../packages/workflows-ui/src/workflow-editor";+import { workflowEdit } from "../../../../packages/workflows-ui/src/workflow-edits";+import { workflowMarkdown } from "../../../../packages/workflows-ui/src/workflow-markdown";+import { printMarkdown } from "../../../../packages/workflows-ui/src/document-export";+import { fixtureWorkflowAnalysis } from "../../../../packages/workflows-ui/src/fixture-platform";++const source = () => structuredClone(fixtureWorkflowAnalysis.analysis.workflows[0]);+function choose(name: string) {+ fireEvent.click(screen.getByRole("button", { name: "More workflow actions" }));+ fireEvent.click(screen.getByRole("menuitem", { name, exact: true }));+}+afterEach(() => { cleanup(); vi.restoreAllMocks(); vi.unstubAllGlobals(); sessionStorage.clear(); });++it("exports authored context without captured sources or review history", () => {+ const workflow = source();+ workflow.reviewNote = "PRIVATE REVIEW NOTE";+ workflow.people = ["PRIVATE PERSON"];+ Object.assign(workflow.stages[0], { evidence: [{ detail: "PRIVATE CAPTURE" }], screenshot: "PRIVATE SCREENSHOT" });+ Object.assign(workflow.stages[0], { requiredAccess: "Reporting access", exceptions: "Stop without evidence", escalation: "Ask the owner", responseTemplate: "Hello **team**", linkedWorkflowId: "linked-review" });+ workflow.variables = [{ id: "customer", name: "Customer", kind: "input", description: "Account name", examples: [{ stepId: "step-0", field: "description", value: "Acme" }] }];+ const draft = workflowEdit(workflow);+ draft.stages[0].procedure = (["action", "input", "output", "decision", "check"] as const).map((kind, sourceIndex) => ({ kind, sourceIndex, text: `Keep ${kind} and \`code\`` }));+ const markdown = workflowMarkdown(draft);+ for (const text of [workflow.title, workflow.description, workflow.trigger, workflow.outcome, "Reporting access", "Stop without evidence", "Ask the owner", "Hello **team**", "linked-review", "Customer (input)", "Acme"]) expect(markdown).toContain(text);+ for (const block of draft.stages[0].procedure) expect(markdown).toContain(block.text);+ expect(markdown).not.toMatch(/PRIVATE REVIEW NOTE|PRIVATE PERSON|PRIVATE CAPTURE|PRIVATE SCREENSHOT|sourceIndex|expected_revision/);+});+it("copies the current unsaved draft without saving or adding toolbar buttons", async () => {+ const writeText = vi.fn().mockResolvedValue(undefined), save = vi.fn();+ vi.stubGlobal("navigator", { ...navigator, clipboard: { writeText } });+ render(<WorkflowEditor workflow={source()} save={save} sessionRecovery={false} saveDisabled />);+ fireEvent.change(screen.getByRole("textbox", { name: "Workflow title" }), { target: { value: "Unsaved title" } });+ expect(screen.queryByRole("button", { name: "Copy Markdown" })).toBeNull();+ choose("Copy Markdown");+ await waitFor(() => expect(writeText).toHaveBeenCalledWith(expect.stringContaining("# Unsaved title")));+ expect(save).not.toHaveBeenCalled();+ expect(await screen.findByText("Markdown copied")).toBeVisible();+});+it("keeps failed clipboard text selectable and supports read-only exports without archive", async () => {+ vi.stubGlobal("navigator", { ...navigator, clipboard: { writeText: vi.fn().mockRejectedValue(new Error("Denied")) } });+ HTMLDialogElement.prototype.showModal = function () { this.setAttribute("open", ""); };+ render(<WorkflowDocument workflow={source()} />);+ fireEvent.click(screen.getByRole("button", { name: "More workflow actions" }));+ expect(screen.queryByRole("menuitem", { name: "Archive workflow" })).toBeNull();+ fireEvent.click(screen.getByRole("menuitem", { name: "Copy Markdown" }));+ expect(await screen.findByRole("dialog")).toBeVisible();+ expect(screen.getByRole("textbox", { name: "Workflow Markdown" })).toHaveValue(workflowMarkdown(workflowEdit(source())));+ expect(screen.getAllByRole("dialog")).toHaveLength(1);+});+it("uses the download adapter, lets failures retry, and makes no cancelled-save claim", async () => {+ const download = vi.fn().mockRejectedValueOnce(new Error("No access")).mockResolvedValue(false);+ render(<WorkflowDocument workflow={source()} downloadDocument={download} />);+ choose("Download Markdown");+ expect(await screen.findByRole("alert")).toHaveTextContent("Could not download");+ choose("Download Markdown");+ await waitFor(() => expect(download).toHaveBeenCalledTimes(2));+ expect(download).toHaveBeenLastCalledWith(workflowMarkdown(workflowEdit(source())), expect.stringMatching(/\.md$/));+ expect(screen.queryByText(/downloaded/i)).toBeNull();+});+it("archives through normal revision-checked saving and retains review fields", async () => {+ const workflow = { ...source(), reviewNote: "Check access", reviewStatus: "needs-edits" as const, revision: 3 };+ const save = vi.fn(async (draft) => ({ ...workflow, archived: draft.archived, revision: 4 }));+ render(<WorkflowEditor workflow={workflow} save={save} sessionRecovery={false} />);+ choose("Archive workflow");+ await waitFor(() => expect(save).toHaveBeenCalledWith(expect.objectContaining({ archived: true, expected_revision: 3, reviewNote: "Check access", reviewStatus: "needs-edits" })), { timeout: 2000 });+});+it.each(["disabled", "dirty", "stale"])("disables archive for a %s editor", (reason) => {+ const workflow = source(), draft = workflowEdit(workflow);+ if (reason === "dirty") draft.title = "Unsaved";+ if (reason === "stale") draft.expected_revision += 1;+ render(<WorkflowEditor workflow={workflow} initialDraft={draft} save={vi.fn()} sessionRecovery={false} saveDisabled={reason === "disabled"} />);+ fireEvent.click(screen.getByRole("button", { name: "More workflow actions" }));+ expect(screen.getByRole("menuitem", { name: "Archive workflow" })).toBeDisabled();+});+it("prints safe document content and cleans up the temporary frame", () => {+ const append = document.body.appendChild.bind(document.body);+ let frame: HTMLIFrameElement | undefined;+ const print = vi.fn();+ vi.spyOn(document.body, "appendChild").mockImplementation((node) => {+ const result = append(node);+ if (node instanceof HTMLIFrameElement) { frame = node; frame.contentWindow!.print = print; }+ return result;+ });+ printMarkdown("Review", '# Review\n\n<script>bad()</script>\n\n');+ expect(print).toHaveBeenCalledOnce();+ expect(frame!.contentDocument!.body.textContent).toContain("Review");+ expect(frame!.contentDocument!.querySelector("script, img")).toBeNull();+ frame!.contentWindow!.dispatchEvent(new Event("afterprint"));+ expect(frame!.isConnected).toBe(false);+});diff --git a/docs/pr-assets/workflow-document-tools/compact-menu.png b/docs/pr-assets/workflow-document-tools/compact-menu.pngnew file mode 100644index 000000000..8b95ed584Binary files /dev/null and b/docs/pr-assets/workflow-document-tools/compact-menu.png differdiff --git a/docs/pr-assets/workflow-document-tools/copy-fallback.png b/docs/pr-assets/workflow-document-tools/copy-fallback.pngnew file mode 100644index 000000000..90720995dBinary files /dev/null and b/docs/pr-assets/workflow-document-tools/copy-fallback.png differdiff --git a/docs/pr-assets/workflow-document-tools/main-app-menu.png b/docs/pr-assets/workflow-document-tools/main-app-menu.pngnew file mode 100644index 000000000..93258bc0dBinary files /dev/null and b/docs/pr-assets/workflow-document-tools/main-app-menu.png differdiff --git a/docs/pr-assets/workflow-document-tools/menu.png b/docs/pr-assets/workflow-document-tools/menu.pngnew file mode 100644index 000000000..d9cd5df40Binary files /dev/null and b/docs/pr-assets/workflow-document-tools/menu.png differdiff --git a/packages/workflows-ui/src/document-actions.tsx b/packages/workflows-ui/src/document-actions.tsxindex a800cb336..a17c4094d 100644--- a/packages/workflows-ui/src/document-actions.tsx+++ b/packages/workflows-ui/src/document-actions.tsx@@ -4,8 +4,7 @@import { useRef, useState, type ReactNode } from "react";import { ArrowLeft, Check, Copy, Download, MoreHorizontal, Printer, Share2, X } from "lucide-react";import styles from "./document-actions.module.css";-import { DOMSerializer } from "prosemirror-model";-import { procedureMarkdownParser } from "./procedure-markdown";+import { downloadMarkdown, markdownFilename, printMarkdown } from "./document-export";/** Explicit text projection. Opening the picker never uploads a document. */export type LibraryShareDocument = { kind: "skill" | "sop"; title: string; markdown: string };@@ -37,37 +36,17 @@ export function DocumentActions({ document, onShare, download, children }: {}async function saveFile() {setError(""); setBusy(true);- const filename = document.kind === "skill" ? "SKILL.md" : `${document.title.replace(/[^a-z0-9_-]+/gi, "-").slice(0, 80) || "recipe"}.md`;+ const filename = document.kind === "skill" ? "SKILL.md" : markdownFilename(document.title, "recipe");try {- if (download) await download(document.markdown, filename);- else {- const url = URL.createObjectURL(new Blob([document.markdown], { type: "text/markdown;charset=utf-8" }));- const link = window.document.createElement("a"); link.href = url; link.download = filename; link.click();- setTimeout(() => URL.revokeObjectURL(url), 1000);- }+ await downloadMarkdown(document.markdown, filename, download);if (menu.current) menu.current.open = false;} catch { setError("Could not download. Your document is still open. Try again."); }finally { setBusy(false); }}function printDocument() {if (menu.current) menu.current.open = false;- // Print only this document. Build DOM from the allowlisted Markdown schema,- // never raw HTML or the app shell, and keep remote images as references.- const frame = window.document.createElement("iframe");- frame.title = "Document print preview";- frame.style.cssText = "position:fixed;width:0;height:0;border:0";- window.document.body.appendChild(frame);- const target = frame.contentDocument;- if (!target || !frame.contentWindow) { frame.remove(); setError("Could not open print preview."); return; }- target.title = document.title;- const style = target.createElement("style");- style.textContent = "body{font:15px/1.65 system-ui;margin:40px;color:#111}pre{white-space:pre-wrap}h1,h2,h3{line-height:1.3}a{color:inherit}blockquote{border-left:2px solid #aaa;padding-left:16px}";- target.head.appendChild(style);- const doc = procedureMarkdownParser.parse(document.markdown);- target.body.appendChild(DOMSerializer.fromSchema(doc.type.schema).serializeFragment(doc.content, { document: target }));- frame.contentWindow.addEventListener("afterprint", () => frame.remove(), { once: true });- frame.contentWindow.print();- setTimeout(() => frame.remove(), 60000);+ try { printMarkdown(document.title, document.markdown); }+ catch { setError("Could not open print preview. Try again."); }}return <><button className={styles.share} onClick={() => { setCopied(false); setError(""); onShare ? onShare(document) : dialog.current?.showModal(); }}><Share2 size={16} />Share</button>diff --git a/packages/workflows-ui/src/document-export.ts b/packages/workflows-ui/src/document-export.tsnew file mode 100644index 000000000..fb9deb0e3--- /dev/null+++ b/packages/workflows-ui/src/document-export.ts@@ -0,0 +1,38 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com+import { DOMSerializer } from "prosemirror-model";+import { procedureMarkdownParser } from "./procedure-markdown";++export type DownloadDocument = (content: string, filename: string) => Promise<boolean>;+export function markdownFilename(title: string, fallback = "workflow") {+ return `${title.replace(/[^a-z0-9_-]+/gi, "-").slice(0, 80) || fallback}.md`;+}+export async function downloadMarkdown(markdown: string, filename: string, download?: DownloadDocument) {+ if (download) return download(markdown, filename);+ const url = URL.createObjectURL(new Blob([markdown], { type: "text/markdown;charset=utf-8" }));+ try {+ const link = document.createElement("a"); link.href = url; link.download = filename; link.click();+ } finally { setTimeout(() => URL.revokeObjectURL(url), 1000); }+ return true;+}+export function printMarkdown(title: string, markdown: string) {+ // Print only this document. Build DOM from the allowlisted Markdown schema,+ // never raw HTML or the app shell, and keep remote images as references.+ const frame = window.document.createElement("iframe");+ frame.title = "Document print preview";+ frame.style.cssText = "position:fixed;width:0;height:0;border:0";+ window.document.body.appendChild(frame);+ const target = frame.contentDocument;+ if (!target || !frame.contentWindow) { frame.remove(); throw new Error("Could not open print preview."); }+ target.title = title;+ const style = target.createElement("style");+ style.textContent = "body{font:15px/1.65 system-ui;margin:40px;color:#111}pre{white-space:pre-wrap}h1,h2,h3{line-height:1.3}a{color:inherit}blockquote{border-left:2px solid #aaa;padding-left:16px}";+ target.head.appendChild(style);+ try {+ const doc = procedureMarkdownParser.parse(markdown);+ target.body.appendChild(DOMSerializer.fromSchema(doc.type.schema).serializeFragment(doc.content, { document: target }));+ frame.contentWindow.addEventListener("afterprint", () => frame.remove(), { once: true });+ frame.contentWindow.print();+ setTimeout(() => frame.remove(), 60000);+ } catch (error) { frame.remove(); throw error; }+}diff --git a/packages/workflows-ui/src/workflow-document-exports.tsx b/packages/workflows-ui/src/workflow-document-exports.tsxnew file mode 100644index 000000000..cd5891421--- /dev/null+++ b/packages/workflows-ui/src/workflow-document-exports.tsx@@ -0,0 +1,57 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com+"use client";+import { useEffect, useRef, useState } from "react";+import { Copy, Download, Printer, X } from "lucide-react";+import { downloadMarkdown, markdownFilename, printMarkdown, type DownloadDocument } from "./document-export";+import type { WorkflowEdit } from "./workflow-edits";+import type { WorkflowSecondaryAction } from "./workflow-more-actions";+import { workflowMarkdown } from "./workflow-markdown";+import styles from "./document-actions.module.css";++export function useWorkflowDocumentExports(draft: WorkflowEdit, download?: DownloadDocument) {+ const dialog = useRef<HTMLDialogElement>(null);+ const [fallback, setFallback] = useState("");+ const [status, setStatus] = useState("");+ const [error, setError] = useState("");+ const [busy, setBusy] = useState(false);+ useEffect(() => {+ if (!status) return;+ const timer = setTimeout(() => setStatus(""), 2500);+ return () => clearTimeout(timer);+ }, [status]);+ async function copy() {+ const markdown = workflowMarkdown(draft);+ setStatus(""); setError("");+ try { await navigator.clipboard.writeText(markdown); setStatus("Markdown copied"); }+ catch {+ setFallback(markdown);+ setError("Could not copy. Select and copy the text below.");+ dialog.current?.showModal();+ }+ }+ const actions: WorkflowSecondaryAction[] = [+ { label: "Copy Markdown", icon: Copy, separatorBefore: true, onSelect: () => void copy() },+ { label: "Download Markdown", icon: Download, disabled: busy, onSelect: async () => {+ setStatus(""); setError(""); setBusy(true);+ try { await downloadMarkdown(workflowMarkdown(draft), markdownFilename(draft.title), download); }+ catch { setError("Could not download. Your document is still open. Try again."); }+ finally { setBusy(false); }+ } },+ { label: "Print or save PDF", icon: Printer, onSelect: () => {+ setStatus(""); setError("");+ try { printMarkdown(draft.title, workflowMarkdown(draft)); }+ catch { setError("Could not open print preview. Try again."); }+ } },+ ];+ const feedback = <>+ {status && <p role="status">{status}</p>}+ {error && !fallback && <p role="alert" className={styles.error}>{error}</p>}+ <dialog ref={dialog} className={styles.dialog} aria-label="Copy workflow Markdown" onClose={() => { setFallback(""); setError(""); }}>+ <header><h2>Copy Markdown</h2><button type="button" aria-label="Close Markdown" onClick={() => dialog.current?.close()}><X size={18} /></button></header>+ <p role="alert">{error}</p>+ <textarea aria-label="Workflow Markdown" readOnly value={fallback} onFocus={event => event.target.select()} />+ </dialog>+ </>;+ return { actions, feedback };+}diff --git a/packages/workflows-ui/src/workflow-editor.tsx b/packages/workflows-ui/src/workflow-editor.tsxindex feea7cc08..80bec769a 100644--- a/packages/workflows-ui/src/workflow-editor.tsx+++ b/packages/workflows-ui/src/workflow-editor.tsx@@ -3,6 +3,8 @@"use client";import { Fragment, useEffect, useRef, useState, type ReactNode } from "react";import {+ Archive,+ ArchiveRestore,ArrowDown,ArrowUp,GripVertical,@@ -31,6 +33,8 @@ import { WorkflowVersionPanel } from "./workflow-version-panel";import { executionFields, variableId } from "./workflow-variables";import styles from "./workflow-editor.module.css";import { WorkflowMoreActions, type WorkflowSecondaryAction } from "./workflow-more-actions";+import { useWorkflowDocumentExports } from "./workflow-document-exports";+import type { DownloadDocument } from "./document-export";function Text(props: Parameters<typeof InlineText>[0] & { title?: boolean }) {return <InlineText {...props} className={props.title ? styles.title : undefined} />;@@ -66,11 +70,12 @@ export type WorkflowEditorOptions = {sessionRecovery?: boolean;saveDisabled?: boolean;};-export function WorkflowEditor({ workflow, save, actions, secondaryActions = [], renderSource, relatedWorkflows = [], openRelated, stepsOnly = false, singleCheck = false, initialDraft, onDraftChange, sessionRecovery = true, saveDisabled = false }: WorkflowEditorOptions & {+export function WorkflowEditor({ workflow, save, actions, secondaryActions = [], downloadDocument, renderSource, relatedWorkflows = [], openRelated, stepsOnly = false, singleCheck = false, initialDraft, onDraftChange, sessionRecovery = true, saveDisabled = false }: WorkflowEditorOptions & {workflow: WorkflowMap;save: (draft: WorkflowEdit) => Promise<WorkflowMap>;actions?: ReactNode;secondaryActions?: WorkflowSecondaryAction[];+ downloadDocument?: DownloadDocument;renderSource?: (stage: WorkflowStage, onImageLayoutChange?: (layout: NonNullable<WorkflowStage["imageLayout"]>) => void) => ReactNode;}) {const key = `screenpipe:workflow-edit:${workflow.id ?? workflow.title}`;@@ -83,6 +88,7 @@ export function WorkflowEditor({ workflow, save, actions, secondaryActions = [],} catch { /* Optional tab-local recovery. */ }return initial;});+ const exports = useWorkflowDocumentExports(draft, downloadDocument);const unchangedStages = draft.stages.length === workflow.stages.length && draft.stages.every((stage, index) => stage.sourceIndex === index && isUnchangedStage(stage, workflow.stages[index]));const [panel, setPanel] = useState<"variables" | "history" | "details" | null>(null);useEffect(()=>{@@ -320,6 +326,8 @@ export function WorkflowEditor({ workflow, save, actions, secondaryActions = [],{ label: "History", icon: History, shortcut: "H", expanded: panel === "history", onSelect: () => setPanel(panel === "history" ? null : "history") },{ label: "Workflow details", icon: Info, shortcut: "D", expanded: panel === "details", onSelect: () => setPanel(panel === "details" ? null : "details") },] : []),+ ...exports.actions,+ ...(!stepsOnly ? [{ label: draft.archived ? "Unarchive workflow" : "Archive workflow", icon: draft.archived ? ArchiveRestore : Archive, separatorBefore: true, disabled: !valid || dirty || saving || saveDisabled || !!error || draft.expected_revision !== (workflow.revision ?? 0), onSelect: () => change({ ...current.current, archived: !current.current.archived }) }] : []),{ label: "Undo last edit", icon: Undo2, separatorBefore: true, disabled: !history.length, onSelect: () => {update(history[history.length - 1]);setHistory(h => h.slice(0, -1));@@ -328,6 +336,7 @@ export function WorkflowEditor({ workflow, save, actions, secondaryActions = [],]} /></div></header>+ {exports.feedback}{error && (<p role="alert" className={styles.error}>{error} <button type="button" onClick={() => void submit()} disabled={saving}>Retry save</button>@@ -648,7 +657,7 @@ export function WorkflowEditor({ workflow, save, actions, secondaryActions = [],{panel === "details" && <aside className={styles.panel} aria-label="Workflow details"><h2>Workflow details</h2><p>{workflow.apps.join(" · ")}</p><p>{workflow.people?.join(" · ")}</p><p>{workflow.quality.reasons.join(" · ")}</p><label>Review status<select value={draft.reviewStatus ?? "needs-review"} onChange={e=>change({...draft,reviewStatus:e.target.value as WorkflowMap["reviewStatus"]})}><option value="needs-review">Needs review</option><option value="needs-edits">Needs edits</option><option value="reviewed">Reviewed</option></select></label><label>Review note<textarea maxLength={8000} value={draft.reviewNote ?? ""} onChange={e=>change({...draft,reviewNote:e.target.value})}/></label><small>Reviewing the instructions does not verify execution or time savings.</small>- <button type="button" onClick={()=>change({...draft,archived:!draft.archived})}>{draft.archived ? "Unarchive workflow" : "Archive workflow"}</button><p>{draft.archived ? "Archived. Still available in the Archived filter." : "Archiving keeps this workflow and its sources."}</p>+ <p>{draft.archived ? "Archived. Still available in the Archived filter." : "Archiving keeps this workflow and its sources."}</p></aside>}</div>{renderSource && <p className={styles.note}>@@ -665,22 +674,25 @@ export function WorkflowEditor({ workflow, save, actions, secondaryActions = [],/** Read-only workflows share the editor's document layout without mounting draft* recovery, autosave, or editable controls. Permission changes do not change the* reading experience. */-export function WorkflowDocument({ workflow, actions, secondaryActions = [], sourceLabel, renderSource }: {+export function WorkflowDocument({ workflow, actions, secondaryActions = [], downloadDocument, sourceLabel, renderSource }: {workflow: WorkflowMap;actions?: ReactNode;secondaryActions?: WorkflowSecondaryAction[];+ downloadDocument?: DownloadDocument;sourceLabel?: string;renderSource?: (stage: WorkflowStage, onImageLayoutChange?: (layout: NonNullable<WorkflowStage["imageLayout"]>) => void) => ReactNode;}) {const [selected, select] = useState("");+ const exports = useWorkflowDocumentExports(workflowEdit(workflow), downloadDocument);return <section className={styles.editor} aria-label="Workflow document" onClickCapture={event=>{const link=(event.target as Element).closest("a"); const id=variableId(link?.getAttribute("href") ?? "");if(id) {event.preventDefault();select(id);}}}><header className={styles.toolbar}><div><span>{sourceLabel}</span></div>- <div>{actions}<WorkflowMoreActions actions={secondaryActions} /></div>+ <div>{actions}<WorkflowMoreActions actions={[...secondaryActions, ...exports.actions.map((action, i) => i === 0 ? { ...action, separatorBefore: secondaryActions.length > 0 } : action)]} /></div></header>+ {exports.feedback}<div className={styles.intro}><div className={styles.titleRow}><h1 className={styles.title}>{workflow.title}</h1>diff --git a/packages/workflows-ui/src/workflow-markdown.ts b/packages/workflows-ui/src/workflow-markdown.tsnew file mode 100644index 000000000..6bbb7fd0d--- /dev/null+++ b/packages/workflows-ui/src/workflow-markdown.ts@@ -0,0 +1,24 @@+// screenpipe — AI that knows everything you've seen, said, or heard+// https://screenpipe.com+import type { WorkflowEdit } from "./workflow-edits";+import { executionFields, variableMarkdown } from "./workflow-variable-model";++/** Export authored instructions only, never captured evidence or review history. */+export function workflowMarkdown(draft: WorkflowEdit): string {+ const parts = [`# ${draft.title}`, draft.description];+ if (draft.trigger) parts.push(`## Trigger\n\n${draft.trigger}`);+ if (draft.outcome) parts.push(`## Outcome\n\n${draft.outcome}`);+ draft.stages.forEach((stage, index) => {+ parts.push(`## ${index + 1}. ${stage.name}`, stage.description);+ for (const block of stage.procedure) {+ parts.push(`### ${block.kind[0].toUpperCase()}${block.kind.slice(1)}\n\n${block.text}`);+ }+ for (const [field, label] of Object.entries(executionFields)) {+ const text = stage[field as keyof typeof executionFields];+ if (text) parts.push(`### ${label}\n\n${text}`);+ }+ if (stage.linkedWorkflowId) parts.push(`Linked workflow: ${stage.linkedWorkflowId}`);+ });+ parts.push(variableMarkdown(draft.variables));+ return parts.filter(Boolean).join("\n\n").trim() + "\n";+}diff --git a/packages/workflows-ui/src/workflow-more-actions.module.css b/packages/workflows-ui/src/workflow-more-actions.module.cssindex c80cfe7c5..e6e02f902 100644--- a/packages/workflows-ui/src/workflow-more-actions.module.css+++ b/packages/workflows-ui/src/workflow-more-actions.module.css@@ -3,7 +3,7 @@.root { position: relative; flex: 0 0 auto; }.root .trigger { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 8px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; }.root .trigger:hover, .root .trigger[aria-expanded="true"] { background: var(--soft); color: var(--ink); }-.root .menu { position: absolute; z-index: 20; top: calc(100% + 6px); right: 0; display: flex; flex-direction: column; box-sizing: border-box; width: 256px; max-width: calc(100vw - 32px); padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); box-shadow: 0 4px 16px #00000012; font-family: var(--heading-font); }+.root .menu { position: absolute; z-index: 20; top: calc(100% + 6px); right: 0; display: flex; flex-direction: column; box-sizing: border-box; width: 256px; max-height: min(520px, calc(100dvh - 160px)); overflow-y: auto; max-width: calc(100vw - 32px); padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--ink); box-shadow: 0 4px 16px #00000012; font-family: var(--heading-font); }.root .menu > button { display: flex; justify-content: flex-start; align-items: center; gap: 10px; width: 100%; min-height: 36px; padding: 8px 10px; border: 0; border-radius: 4px; background: transparent; color: var(--ink); font: inherit; font-size: 13px; text-align: left; cursor: pointer; }.root .menu > button:hover, .root .menu > button:focus-visible { background: var(--soft); }.root .menu > button:disabled { opacity: .4; cursor: default; }diff --git a/packages/workflows-ui/src/workflows-app.tsx b/packages/workflows-ui/src/workflows-app.tsxindex 5f4474e54..316b1d62a 100644--- a/packages/workflows-ui/src/workflows-app.tsx+++ b/packages/workflows-ui/src/workflows-app.tsx@@ -745,7 +745,7 @@ export function WorkflowDetail({ breadcrumb, relatedWorkflows, openRelated, edit<><button className={styles.backButton} onClick={() => navigate("workflows")}><ArrowLeft size={14} />All workflows</button>{breadcrumb}- {saveEdits ? <WorkflowEditor {...editorOptions} relatedWorkflows={relatedWorkflows} openRelated={openRelated} key={workflow.id || workflow.title} workflow={workflow} save={saveEdits} actions={workflowActions} secondaryActions={secondaryActions} renderSource={observationsAvailable ? (stage, onImageLayoutChange) => <WorkflowStepEvidence workflow={workflow} stage={stage} platform={platform} onImageLayoutChange={onImageLayoutChange} /> : undefined} /> : <WorkflowDocument workflow={workflow} actions={workflowActions} secondaryActions={secondaryActions} sourceLabel={sourceLabel}+ {saveEdits ? <WorkflowEditor {...editorOptions} relatedWorkflows={relatedWorkflows} openRelated={openRelated} key={workflow.id || workflow.title} workflow={workflow} save={saveEdits} actions={workflowActions} secondaryActions={secondaryActions} downloadDocument={platform.library?.downloadDocument} renderSource={observationsAvailable ? (stage, onImageLayoutChange) => <WorkflowStepEvidence workflow={workflow} stage={stage} platform={platform} onImageLayoutChange={onImageLayoutChange} /> : undefined} /> : <WorkflowDocument workflow={workflow} actions={workflowActions} secondaryActions={secondaryActions} downloadDocument={platform.library?.downloadDocument} sourceLabel={sourceLabel}renderSource={observationsAvailable ? stage => <WorkflowStepEvidence workflow={workflow} stage={stage} platform={platform} /> : undefined} />}<div className={styles.workflowNotes}><p className={styles.workflowReviewState}>{workflow.userEditedAt ? ui("Edited by you · sources kept as references") : workflow.evidenceStatus === "supported-steps" ? ui("Source-backed steps · not execution-tested") : ui("Needs review")}</p>