#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Show the pipelines running on editor import and export (#7942)
Anthony Stirlingf685de11f371
diff --git a/app/proprietary/src/test/java/stirling/software/proprietary/formdetection/service/FormDetectionModelManagerTest.java b/app/proprietary/src/test/java/stirling/software/proprietary/formdetection/service/FormDetectionModelManagerTest.javaindex 7f68036842..457747f426 100644--- a/app/proprietary/src/test/java/stirling/software/proprietary/formdetection/service/FormDetectionModelManagerTest.java+++ b/app/proprietary/src/test/java/stirling/software/proprietary/formdetection/service/FormDetectionModelManagerTest.java@@ -393,10 +393,12 @@ class FormDetectionModelManagerTest {@Testvoid gatesTheToolWhileASwitchIsDownloading(@TempDir Path dir) throws Exception {+ CountDownLatch downloadStarted = new CountDownLatch(1);CountDownLatch releaseDownload = new CountDownLatch(1);server.createContext("/switch.onnx",ex -> {+ downloadStarted.countDown();try {releaseDownload.await();} catch (InterruptedException ignored) {@@ -418,6 +420,7 @@ class FormDetectionModelManagerTest {m.startInstall("test-model");try {+ assertTrue(downloadStarted.await(5, TimeUnit.SECONDS), "download did not start");assertFalse(m.isReady(), "a download is not something the tool can serve from");Mockito.verify(ep).disableEndpoint("form-detection", DisableReason.DEPENDENCY);} finally {diff --git a/frontend/editor/public/locales/en-US/translation.toml b/frontend/editor/public/locales/en-US/translation.tomlindex 8934ec90b3..9f459a4184 100644--- a/frontend/editor/public/locales/en-US/translation.toml+++ b/frontend/editor/public/locales/en-US/translation.toml@@ -7237,6 +7237,20 @@ partialOutputsUnavailable = "Some policy outputs are no longer available to downrunNotFound = "The enforcement run could no longer be found."timedOut = "Enforcement timed out before the run could finish."+[policies.editorPanel]+collapse = "Hide pipelines"+empty = "Nothing runs on import or export yet"+expand = "Show pipelines"+openProcessor = "Open the PDF Processor"+rowFailed = "{{label}} - last run failed"+rowIdle = "{{label}} runs automatically"+rowRunning = "{{label}} is running now"+runsToday_one = "{{count}} run today"+runsToday_other = "{{count}} runs today"+title = "PDF Processor"+triggerExport = "Runs on export"+triggerImport = "Runs on import"+[policies.enforcement]applying = "Applying {{names}}"applyingProgress = "Applying {{names}} ({{done}} of {{total}})"diff --git a/frontend/editor/src/core/components/policies/EditorPipelinesPanel.tsx b/frontend/editor/src/core/components/policies/EditorPipelinesPanel.tsxnew file mode 100644index 0000000000..9f7c1f4c4f--- /dev/null+++ b/frontend/editor/src/core/components/policies/EditorPipelinesPanel.tsx@@ -0,0 +1,3 @@+export function EditorPipelinesPanel() {+ return null;+}diff --git a/frontend/editor/src/core/components/tools/RightSidebar.tsx b/frontend/editor/src/core/components/tools/RightSidebar.tsxindex 98e49217d9..5f8eeff919 100644--- a/frontend/editor/src/core/components/tools/RightSidebar.tsx+++ b/frontend/editor/src/core/components/tools/RightSidebar.tsx@@ -4,6 +4,8 @@ import { useToolWorkflow } from "@app/contexts/ToolWorkflowContext";import { useSidebarContext } from "@app/contexts/SidebarContext";import { useIsMobile } from "@app/hooks/useIsMobile";import ToolPanel from "@app/components/tools/ToolPanel";+import { usePoliciesEnabled } from "@app/components/policies/usePoliciesEnabled";+import { EditorPipelinesPanel } from "@app/components/policies/EditorPipelinesPanel";import { ToolIcon } from "@app/components/shared/ToolIcon";import { ToolPanelHeader } from "@app/components/shared/ToolPanelHeader";import { ActionIcon } from "@app/ui/ActionIcon";@@ -28,6 +30,7 @@ export default function RightSidebar() {const { sidebarRefs } = useSidebarContext();const { toolPanelRef, quickAccessRef } = sidebarRefs;const isMobile = useIsMobile();+ const policiesEnabled = usePoliciesEnabled();const {leftPanelView,@@ -110,6 +113,7 @@ export default function RightSidebar() {}}><>+ {policiesEnabled && <EditorPipelinesPanel />}{activeTool ? (<ToolPanelHeadericon={diff --git a/frontend/editor/src/proprietary/components/policies/EditorPipelinesPanel.css b/frontend/editor/src/proprietary/components/policies/EditorPipelinesPanel.cssnew file mode 100644index 0000000000..f795977199--- /dev/null+++ b/frontend/editor/src/proprietary/components/policies/EditorPipelinesPanel.css@@ -0,0 +1,157 @@+.editor-pipelines {+ flex: 0 0 auto;+ padding: 0.375rem 0.5rem 0.5rem;+ border-bottom: 1px solid var(--c-border-subtle);+ background: var(--c-surface-sunken);+}++.editor-pipelines__head {+ display: flex;+ align-items: center;+ gap: 0.25rem;+ min-height: 2rem;+ padding-inline-start: 0.25rem;+}++.editor-pipelines__toggle {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ flex: 1 1 auto;+ min-width: 0;+ padding: 0;+ background: none;+ border: 0;+ color: inherit;+ font: inherit;+ text-align: start;+ cursor: pointer;+}++.editor-pipelines__toggle:disabled {+ cursor: default;+}++.editor-pipelines__title {+ font-size: 0.8125rem;+ font-weight: 600;+ letter-spacing: -0.01em;+ color: var(--c-text);+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+}++.editor-pipelines__chevron {+ margin-inline-start: auto;+ flex-shrink: 0;+ color: var(--c-text-muted);+ transition: transform 0.15s ease;+}++.editor-pipelines__chevron[data-open="true"] {+ transform: rotate(180deg);+}++.editor-pipelines__empty {+ margin: 0.125rem 0 0 0.25rem;+ font-size: 0.75rem;+ color: var(--c-text-muted);+}++.editor-pipelines__list {+ list-style: none;+ margin: 0.125rem 0 0;+ padding: 0;+}++.editor-pipelines__row {+ display: flex;+ align-items: center;+ gap: 0.5rem;+ width: 100%;+ padding: 0.1875rem 0.375rem;+ border: 0;+ border-radius: 0.375rem;+ background: none;+ color: inherit;+ font: inherit;+ text-align: start;+}++button.editor-pipelines__row {+ cursor: pointer;+}++button.editor-pipelines__row:hover,+button.editor-pipelines__row:focus-visible {+ background: var(--c-hover);+}++.editor-pipelines__row-icon {+ display: inline-flex;+ flex-shrink: 0;+ color: var(--c-success);+}++.editor-pipelines__row-label {+ flex: 0 1 auto;+ min-width: 0;+ font-size: 0.8125rem;+ color: var(--c-text);+ white-space: nowrap;+ overflow: hidden;+ text-overflow: ellipsis;+}++.editor-pipelines__row-trigger {+ flex-shrink: 0;+ color: var(--c-text-subtle);+}++.editor-pipelines__row-count {+ margin-inline-start: auto;+ flex-shrink: 0;+ font-size: 0.6875rem;+ font-variant-numeric: tabular-nums;+ color: var(--c-text-muted);+}++.editor-pipelines__dot {+ flex-shrink: 0;+ width: 0.4375rem;+ height: 0.4375rem;+ border-radius: 50%;+ background: var(--c-success-solid);+}++.editor-pipelines__row-trigger + .editor-pipelines__dot {+ margin-inline-start: auto;+}++.editor-pipelines__dot[data-state="running"] {+ animation: editor-pipelines-dot-pulse 2.4s ease-in-out infinite;+}++.editor-pipelines__dot[data-state="failed"] {+ background: var(--c-danger-solid);+}++@keyframes editor-pipelines-dot-pulse {+ 0%,+ 100% {+ opacity: 1;+ }+ 50% {+ opacity: 0.35;+ }+}++@media (prefers-reduced-motion: reduce) {+ .editor-pipelines__dot[data-state="running"] {+ animation: none;+ }+ .editor-pipelines__chevron {+ transition: none;+ }+}diff --git a/frontend/editor/src/proprietary/components/policies/EditorPipelinesPanel.stories.tsx b/frontend/editor/src/proprietary/components/policies/EditorPipelinesPanel.stories.tsxnew file mode 100644index 0000000000..a7e20659a5--- /dev/null+++ b/frontend/editor/src/proprietary/components/policies/EditorPipelinesPanel.stories.tsx@@ -0,0 +1,91 @@+import type { Meta, StoryObj } from "@storybook/react-vite";+import {+ EditorPipelinesPanelView,+ type EditorPipelinesPanelViewProps,+} from "@app/components/policies/EditorPipelinesPanel";+import type { EditorPipeline } from "@app/components/policies/useEditorPipelines";++const pipeline = (over: Partial<EditorPipeline>): EditorPipeline => ({+ policyKey: "classification",+ label: "Classification",+ runOn: "upload",+ running: false,+ failed: false,+ runsToday: 0,+ ...over,+});++const meta: Meta<typeof EditorPipelinesPanelView> = {+ title: "Policies/EditorPipelinesPanel",+ component: EditorPipelinesPanelView,+ parameters: { layout: "padded" },+ decorators: [+ (Story) => (+ <div style={{ width: "18.5rem", background: "var(--c-surface)" }}>+ <Story />+ </div>+ ),+ ],+};+export default meta;+type Story = StoryObj<typeof EditorPipelinesPanelView>;++const withDefaults = (+ props: Partial<EditorPipelinesPanelViewProps>,+): EditorPipelinesPanelViewProps => {+ const onImport = props.onImport ?? [];+ const onExport = props.onExport ?? [];+ return {+ onImport,+ onExport,+ total: onImport.length + onExport.length,+ onOpenProcessor: () => {},+ ...props,+ };+};++export const Default: Story = {+ args: withDefaults({+ onImport: [+ pipeline({ runsToday: 12 }),+ pipeline({ policyKey: "ingestion", label: "Ingestion", runsToday: 12 }),+ ],+ onExport: [+ pipeline({+ policyKey: "security",+ label: "Security",+ runOn: "export",+ runsToday: 3,+ }),+ ],+ }),+};++export const Running: Story = {+ args: withDefaults({+ onImport: [pipeline({ running: true, runsToday: 4 })],+ onExport: [+ pipeline({+ policyKey: "security",+ label: "Security",+ runOn: "export",+ runsToday: 1,+ }),+ ],+ }),+};++export const LastRunFailed: Story = {+ args: withDefaults({+ onImport: [pipeline({ failed: true, runsToday: 6 })],+ }),+};++export const Empty: Story = { args: withDefaults({}) };++export const WithoutPortalAccess: Story = {+ args: withDefaults({+ onImport: [pipeline({ runsToday: 12 })],+ onOpenProcessor: null,+ }),+};diff --git a/frontend/editor/src/proprietary/components/policies/EditorPipelinesPanel.tsx b/frontend/editor/src/proprietary/components/policies/EditorPipelinesPanel.tsxnew file mode 100644index 0000000000..2a6c7fedd3--- /dev/null+++ b/frontend/editor/src/proprietary/components/policies/EditorPipelinesPanel.tsx@@ -0,0 +1,199 @@+import { useState } from "react";+import { useTranslation } from "react-i18next";+import { useNavigate } from "react-router-dom";+import ExpandMoreIcon from "@mui/icons-material/ExpandMore";+import OpenInNewIcon from "@mui/icons-material/OpenInNew";+import InputOutlinedIcon from "@mui/icons-material/InputOutlined";+import OutputOutlinedIcon from "@mui/icons-material/OutputOutlined";+import { usePortalAccess } from "@app/hooks/usePortalAccess";+import { useNavigationActions } from "@app/contexts/NavigationContext";+import { PORTAL_BASENAME } from "@app/routes/portalBasename";+import { saveEditorReturnPath } from "@app/services/workbenchSession";+import { policyCategoryIcon } from "@app/components/policies/policyCategoryIcon";+import {+ useEditorPipelines,+ type EditorPipeline,+ type EditorPipelines,+} from "@app/components/policies/useEditorPipelines";+import { ActionIcon } from "@app/ui/ActionIcon";+import "@app/components/policies/EditorPipelinesPanel.css";++const PIPELINES_PATH = `${PORTAL_BASENAME}/pipelines`;+const ICON_SIZE = "1.05rem";+const TRIGGER_SX = { fontSize: "0.8125rem" } as const;++function rowState(pipeline: EditorPipeline): "running" | "failed" | "idle" {+ if (pipeline.running) return "running";+ return pipeline.failed ? "failed" : "idle";+}++function PipelineRow({+ pipeline,+ onOpen,+}: {+ pipeline: EditorPipeline;+ onOpen: (() => void) | null;+}) {+ const { t } = useTranslation();+ const state = rowState(pipeline);+ const label =+ state === "running"+ ? t("policies.editorPanel.rowRunning", "{{label}} is running now", {+ label: pipeline.label,+ })+ : state === "failed"+ ? t("policies.editorPanel.rowFailed", "{{label}} - last run failed", {+ label: pipeline.label,+ })+ : t("policies.editorPanel.rowIdle", "{{label}} runs automatically", {+ label: pipeline.label,+ });+ const trigger =+ pipeline.runOn === "export"+ ? t("policies.editorPanel.triggerExport", "Runs on export")+ : t("policies.editorPanel.triggerImport", "Runs on import");+ const TriggerIcon =+ pipeline.runOn === "export" ? OutputOutlinedIcon : InputOutlinedIcon;++ const body = (+ <>+ <span className="editor-pipelines__row-icon" aria-hidden>+ {policyCategoryIcon(pipeline.policyKey, ICON_SIZE)}+ </span>+ <span className="editor-pipelines__row-label">{pipeline.label}</span>+ <TriggerIcon+ className="editor-pipelines__row-trigger"+ sx={TRIGGER_SX}+ titleAccess={trigger}+ />+ {pipeline.runsToday > 0 && (+ <span+ className="editor-pipelines__row-count"+ title={t("policies.editorPanel.runsToday", "{{count}} runs today", {+ count: pipeline.runsToday,+ })}+ >+ {pipeline.runsToday}+ </span>+ )}+ <span className="editor-pipelines__dot" data-state={state} aria-hidden />+ </>+ );++ return (+ <li>+ {onOpen ? (+ <button+ type="button"+ className="editor-pipelines__row"+ onClick={onOpen}+ title={label}+ >+ {body}+ </button>+ ) : (+ <div className="editor-pipelines__row" title={label}>+ {body}+ </div>+ )}+ </li>+ );+}++export interface EditorPipelinesPanelViewProps extends EditorPipelines {+ onOpenProcessor: (() => void) | null;+}++export function EditorPipelinesPanelView({+ onImport,+ onExport,+ total,+ onOpenProcessor,+}: EditorPipelinesPanelViewProps) {+ const { t } = useTranslation();+ const [open, setOpen] = useState(false);++ return (+ <section className="editor-pipelines">+ <div className="editor-pipelines__head">+ <button+ type="button"+ className="editor-pipelines__toggle"+ onClick={() => setOpen((v) => !v)}+ aria-expanded={open}+ disabled={total === 0}+ title={+ open+ ? t("policies.editorPanel.collapse", "Hide pipelines")+ : t("policies.editorPanel.expand", "Show pipelines")+ }+ >+ <span className="editor-pipelines__title">+ {t("policies.editorPanel.title", "PDF Processor")}+ </span>+ {total > 0 && (+ <ExpandMoreIcon+ className="editor-pipelines__chevron"+ data-open={open}+ sx={{ fontSize: "1.1rem" }}+ />+ )}+ </button>+ {onOpenProcessor && (+ <ActionIcon+ variant="tertiary"+ size="md"+ shape="circle"+ onClick={onOpenProcessor}+ aria-label={t(+ "policies.editorPanel.openProcessor",+ "Open the PDF Processor",+ )}+ >+ <OpenInNewIcon sx={{ fontSize: "1rem" }} />+ </ActionIcon>+ )}+ </div>++ {total === 0 ? (+ <p className="editor-pipelines__empty">+ {t(+ "policies.editorPanel.empty",+ "Nothing runs on import or export yet",+ )}+ </p>+ ) : (+ open && (+ <ul className="editor-pipelines__list">+ {[...onImport, ...onExport].map((pipeline) => (+ <PipelineRow+ key={pipeline.policyKey}+ pipeline={pipeline}+ onOpen={onOpenProcessor}+ />+ ))}+ </ul>+ )+ )}+ </section>+ );+}++export function EditorPipelinesPanel() {+ const pipelines = useEditorPipelines();+ const portalAccess = usePortalAccess();+ const navigate = useNavigate();+ const { actions } = useNavigationActions();++ const openProcessor = portalAccess+ ? () =>+ actions.requestNavigation(() => {+ saveEditorReturnPath();+ navigate(PIPELINES_PATH);+ })+ : null;++ return (+ <EditorPipelinesPanelView {...pipelines} onOpenProcessor={openProcessor} />+ );+}diff --git a/frontend/editor/src/proprietary/components/policies/useEditorPipelines.test.tsx b/frontend/editor/src/proprietary/components/policies/useEditorPipelines.test.tsxnew file mode 100644index 0000000000..cbf0724cfb--- /dev/null+++ b/frontend/editor/src/proprietary/components/policies/useEditorPipelines.test.tsx@@ -0,0 +1,132 @@+import { describe, it, expect, beforeEach, vi } from "vitest";+import { renderHook, act } from "@testing-library/react";+import {+ recordRunStart,+ resetPolicyRuns,+ updateRun,+} from "@app/components/policies/policyRunStore";+import type { PolicyState } from "@app/types/policies";++const cache = vi.hoisted(() => ({ value: {} as Record<string, PolicyState> }));++vi.mock("@app/services/policyStorage", () => ({+ loadPolicies: () => cache.value,+ onPoliciesChange: () => () => {},+}));+vi.mock("@app/services/policyCatalog", () => ({+ loadPolicyCatalog: () => ({+ categories: [+ { id: "classification", label: "Classification" },+ { id: "security", label: "Security" },+ ],+ }),+}));++import { useEditorPipelines } from "@app/components/policies/useEditorPipelines";++const policy = (over: Partial<PolicyState> = {}): PolicyState => ({+ configured: true,+ enabled: true,+ backendId: "be-1",+ runsOnEditor: true,+ sources: [],+ scopeTypes: [],+ reviewerEmail: "",+ fieldValues: {},+ ...over,+});++const run = (policyKey: string, startedAt: number) => ({+ runId: `run-${policyKey}-${startedAt}`,+ policyKey,+ fileId: "file-1",+ fileName: "doc.pdf",+ fileSize: 1,+ target: "server" as never,+ status: "PENDING" as const,+ outputs: [],+ error: null,+ startedAt,+});++describe("useEditorPipelines", () => {+ beforeEach(() => {+ resetPolicyRuns();+ cache.value = {};+ });++ it("splits the editor's pipelines by the event that fires them", () => {+ cache.value = {+ classification: policy({ backendId: "be-c" }),+ security: policy({ backendId: "be-s", runOn: "export" }),+ };+ const { result } = renderHook(() => useEditorPipelines());++ expect(result.current.onImport.map((p) => p.label)).toEqual([+ "Classification",+ ]);+ expect(result.current.onExport.map((p) => p.label)).toEqual(["Security"]);+ expect(result.current.total).toBe(2);+ });++ it("omits policies the engines would not run on this editor", () => {+ cache.value = {+ unconfigured: policy({ configured: false }),+ paused: policy({ enabled: false }),+ serverOnly: policy({ runsOnEditor: false }),+ neverPersisted: policy({ backendId: undefined }),+ };+ const { result } = renderHook(() => useEditorPipelines());++ expect(result.current.total).toBe(0);+ });++ it("orders each group by the chain order the engines dispatch in", () => {+ cache.value = {+ second: policy({ backendId: "be-2", order: 2, name: "Second" }),+ first: policy({ backendId: "be-1", order: 1, name: "First" }),+ };+ const { result } = renderHook(() => useEditorPipelines());++ expect(result.current.onImport.map((p) => p.label)).toEqual([+ "First",+ "Second",+ ]);+ });++ it("reports a pipeline as running while one of its runs is in flight", () => {+ cache.value = { classification: policy({ backendId: "be-c" }) };+ const { result, rerender } = renderHook(() => useEditorPipelines());+ expect(result.current.onImport[0].running).toBe(false);++ act(() => recordRunStart(run("classification", Date.now())));+ rerender();++ expect(result.current.onImport[0].running).toBe(true);+ });++ it("flags a pipeline whose most recent settled run failed", () => {+ cache.value = { classification: policy({ backendId: "be-c" }) };+ const { result, rerender } = renderHook(() => useEditorPipelines());++ const record = run("classification", Date.now());+ act(() => recordRunStart(record));+ act(() => updateRun(record.runId, { status: "FAILED" }));+ rerender();++ expect(result.current.onImport[0].failed).toBe(true);+ expect(result.current.onImport[0].running).toBe(false);+ });++ it("counts only runs recorded since local midnight", () => {+ cache.value = { classification: policy({ backendId: "be-c" }) };+ const yesterday = new Date().setHours(0, 0, 0, 0) - 60_000;+ const { result, rerender } = renderHook(() => useEditorPipelines());++ act(() => recordRunStart(run("classification", yesterday)));+ act(() => recordRunStart(run("classification", Date.now())));+ rerender();++ expect(result.current.onImport[0].runsToday).toBe(1);+ });+});diff --git a/frontend/editor/src/proprietary/components/policies/useEditorPipelines.ts b/frontend/editor/src/proprietary/components/policies/useEditorPipelines.tsnew file mode 100644index 0000000000..cf14a91754--- /dev/null+++ b/frontend/editor/src/proprietary/components/policies/useEditorPipelines.ts@@ -0,0 +1,93 @@+/**+ * The editor's live pipelines split by trigger, for the tool sidebar panel. Reads the+ * policy cache directly; usePolicies would refire a backend reconcile on every mount.+ */+import { useEffect, useMemo, useState } from "react";+import { loadPolicies, onPoliciesChange } from "@app/services/policyStorage";+import { loadPolicyCatalog } from "@app/services/policyCatalog";+import { editorTriggerOf, type PolicyRunOn } from "@app/policies/runOn";+import {+ usePolicyRuns,+ isRunInFlight,+ type PolicyRunRecord,+} from "@app/components/policies/policyRunStore";+import type { PoliciesByKey } from "@app/types/policies";++export interface EditorPipeline {+ policyKey: string;+ label: string;+ runOn: PolicyRunOn;+ running: boolean;+ failed: boolean;+ runsToday: number;+}++export interface EditorPipelines {+ onImport: EditorPipeline[];+ onExport: EditorPipeline[];+ total: number;+}++function pipelineLabel(+ policyKey: string,+ policies: PoliciesByKey,+ categoryLabels: Map<string, string>,+): string {+ return (+ categoryLabels.get(policyKey) ?? policies[policyKey]?.name ?? policyKey+ );+}++/** Runs arrive newest-first from the store, so settled[0] is the last finished run. */+function describeRuns(runs: PolicyRunRecord[], since: number) {+ const running = runs.some(isRunInFlight);+ const settled = runs.filter((r) => !isRunInFlight(r));+ return {+ running,+ failed: !running && settled[0]?.status === "FAILED",+ runsToday: runs.filter((r) => r.startedAt >= since).length,+ };+}++export function useEditorPipelines(): EditorPipelines {+ const [policies, setPolicies] = useState<PoliciesByKey>(loadPolicies);+ useEffect(() => onPoliciesChange(() => setPolicies(loadPolicies())), []);+ const runs = usePolicyRuns();++ return useMemo(() => {+ const categoryLabels = new Map(+ loadPolicyCatalog().categories.map((c) => [c.id, c.label]),+ );+ const startOfDay = new Date().setHours(0, 0, 0, 0);+ const runsByPolicy = new Map<string, PolicyRunRecord[]>();+ for (const run of runs) {+ const bucket = runsByPolicy.get(run.policyKey);+ if (bucket) bucket.push(run);+ else runsByPolicy.set(run.policyKey, [run]);+ }++ const onImport: EditorPipeline[] = [];+ const onExport: EditorPipeline[] = [];+ const entries = Object.entries(policies).sort(+ ([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0),+ );++ for (const [policyKey, state] of entries) {+ const runOn = editorTriggerOf(state);+ if (!runOn) continue;+ const pipeline: EditorPipeline = {+ policyKey,+ label: pipelineLabel(policyKey, policies, categoryLabels),+ runOn,+ ...describeRuns(runsByPolicy.get(policyKey) ?? [], startOfDay),+ };+ (runOn === "export" ? onExport : onImport).push(pipeline);+ }++ return {+ onImport,+ onExport,+ total: onImport.length + onExport.length,+ };+ }, [policies, runs]);+}diff --git a/frontend/editor/src/proprietary/components/policies/usePolicyLocalPasses.ts b/frontend/editor/src/proprietary/components/policies/usePolicyLocalPasses.tsindex 2f819f7d87..d41798b443 100644--- a/frontend/editor/src/proprietary/components/policies/usePolicyLocalPasses.ts+++ b/frontend/editor/src/proprietary/components/policies/usePolicyLocalPasses.ts@@ -20,6 +20,7 @@ import {type LocalPass,} from "@app/components/policies/policyLocalPass";import { policyRequiresAiEngine } from "@app/data/classificationPolicy";+import { editorTriggerOf } from "@app/policies/runOn";import type { StirlingFileStub } from "@app/types/fileContext";/** Files processed per idle pass, so a large upload drains over several ticks instead of janking. */@@ -52,13 +53,7 @@ export function usePolicyLocalPasses(): void {const passes = useMemo<ActivePass[]>(() => {const out: ActivePass[] = [];for (const [policyKey, s] of Object.entries(policies)) {- const active =- s.configured &&- s.enabled &&- s.backendId &&- s.runsOnEditor &&- (s.runOn ?? "upload") === "upload";- if (!active) continue;+ if (editorTriggerOf(s) !== "upload") continue;const pass = localPassFor(policyKey);if (!pass) continue;out.push({diff --git a/frontend/editor/src/proprietary/data/classificationPolicy.ts b/frontend/editor/src/proprietary/data/classificationPolicy.tsindex eb7811dd94..2ac4544141 100644--- a/frontend/editor/src/proprietary/data/classificationPolicy.ts+++ b/frontend/editor/src/proprietary/data/classificationPolicy.ts@@ -15,6 +15,7 @@import type { ClassificationConfidence } from "@app/types/fileContext";import type { PoliciesByKey } from "@app/types/policies";+import { editorTriggerOf } from "@app/policies/runOn";/** Key of the built-in Classification policy. */export const CLASSIFICATION_POLICY_KEY = "classification";@@ -54,12 +55,7 @@ export function orderedRewritingPolicies(policies: PoliciesByKey): string[] {return Object.entries(policies).filter(([id, s]) =>- s.configured &&- s.enabled &&- Boolean(s.backendId) &&- s.runsOnEditor &&- (s.runOn ?? "upload") === "upload" &&- policyDeliversOutputFiles(id),+ editorTriggerOf(s) === "upload" && policyDeliversOutputFiles(id),).sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0)).map(([id]) => id);diff --git a/frontend/editor/src/proprietary/policies/runOn.ts b/frontend/editor/src/proprietary/policies/runOn.tsindex 456e092cdb..dbc6580ebf 100644--- a/frontend/editor/src/proprietary/policies/runOn.ts+++ b/frontend/editor/src/proprietary/policies/runOn.ts@@ -1,5 +1,7 @@/** Per-category default for the editor event a policy enforces on. */+import type { PolicyState } from "@app/types/policies";+export type PolicyRunOn = "upload" | "export";const DEFAULT_RUN_ON: Record<string, PolicyRunOn> = {@@ -21,3 +23,15 @@ export function resolveRunOn(if (value === "export" || value === "upload") return value;return defaultRunOn(policyKey);}++/**+ * The editor event this policy fires on, or null when the editor never runs it.+ * runOn is already resolved by codec.ts, so an unset value means "upload".+ */+export function editorTriggerOf(+ state: PolicyState | undefined,+): PolicyRunOn | null {+ if (!state?.configured || !state.enabled || !state.backendId) return null;+ if (!state.runsOnEditor) return null;+ return state.runOn === "export" ? "export" : "upload";+}diff --git a/frontend/editor/src/proprietary/services/policyExport.ts b/frontend/editor/src/proprietary/services/policyExport.tsindex f13c2ca197..1be2bdebd3 100644--- a/frontend/editor/src/proprietary/services/policyExport.ts+++ b/frontend/editor/src/proprietary/services/policyExport.ts@@ -13,6 +13,7 @@import { loadPolicies } from "@app/services/policyStorage";import { assertFilesNotBlocked } from "@app/services/policyFileGuard";import { loadPolicyCatalog } from "@app/services/policyCatalog";+import { editorTriggerOf } from "@app/policies/runOn";import { policyAcceptsFile } from "@app/services/policyInput";import { splitFileName } from "@app/utils/fileUtils";import {@@ -66,14 +67,7 @@ function activeExportPolicies(): ExportPolicy[] {);return (Object.entries(loadPolicies())- .filter(- ([, s]) =>- s.configured &&- s.enabled &&- s.backendId &&- s.runsOnEditor &&- s.runOn === "export",- )+ .filter(([, s]) => editorTriggerOf(s) === "export")// Same team-wide run order the upload path uses: enforcement is not commutative (a watermark// then a flatten is not a flatten then a watermark), so both paths must agree on the sequence..sort(([, a], [, b]) => (a.order ?? 0) - (b.order ?? 0))