@blackbelt-technology/pi-dashboard-flows-plugin 0.11.0 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/README.md +5 -1
  2. package/package.json +23 -4
  3. package/src/bridge/flow-catalog-publisher.ts +138 -0
  4. package/src/bridge/flow-event-forward.ts +132 -0
  5. package/src/bridge/flow-files-reporter.ts +16 -14
  6. package/src/bridge/flow-open-tool.ts +124 -0
  7. package/src/bridge/flow-probe.ts +20 -0
  8. package/src/bridge/flow-tool-registry.ts +298 -0
  9. package/src/bridge/flow-tools-guideline.ts +52 -0
  10. package/src/bridge/index.ts +67 -10
  11. package/src/bridge/run-snapshot-reporter.ts +146 -0
  12. package/src/catalog-timings.ts +70 -0
  13. package/src/client/AskSession.tsx +82 -0
  14. package/src/client/FlowActionDialogs.tsx +143 -0
  15. package/src/client/FlowActivityBadge.tsx +42 -4
  16. package/src/client/FlowAgentCard.tsx +63 -8
  17. package/src/client/FlowAgentDetail.tsx +3 -5
  18. package/src/client/FlowDashboard.tsx +381 -273
  19. package/src/client/FlowEditMenu.tsx +69 -0
  20. package/src/client/FlowEditPopover.tsx +130 -0
  21. package/src/client/FlowGraph.tsx +127 -44
  22. package/src/client/FlowHeaderActions.tsx +83 -0
  23. package/src/client/FlowInputWiring.tsx +1 -1
  24. package/src/client/FlowOpenListener.tsx +82 -0
  25. package/src/client/FlowQuestionBlock.tsx +226 -0
  26. package/src/client/FlowStepCards.tsx +189 -0
  27. package/src/client/FlowSummary.tsx +72 -240
  28. package/src/client/FlowWriteToolRenderer.tsx +46 -17
  29. package/src/client/FlowYamlPopoverButton.tsx +2 -2
  30. package/src/client/FlowsContextGroup.tsx +156 -0
  31. package/src/client/FlowsSessionStateContext.tsx +202 -54
  32. package/src/client/FlowsSettings.tsx +145 -17
  33. package/src/client/SessionFlowActions.tsx +65 -10
  34. package/src/client/SessionFlowMenuClaim.tsx +48 -241
  35. package/src/client/ask-session-store.ts +243 -0
  36. package/src/client/flow-attach-store.ts +2 -0
  37. package/src/client/flow-card-grid.ts +2 -2
  38. package/src/client/flow-collapse-storage.ts +36 -6
  39. package/src/client/flow-edges.ts +91 -35
  40. package/src/client/flow-files.ts +16 -4
  41. package/src/client/flow-idle-state.ts +93 -37
  42. package/src/client/flowsActionsGate.ts +1 -1
  43. package/src/client/flowsAvailability.ts +8 -2
  44. package/src/client/index.tsx +13 -11
  45. package/src/client/shouldRender.ts +1 -1
  46. package/src/client/useEditModeState.ts +78 -0
  47. package/src/client/useFlowActions.tsx +191 -0
  48. package/src/client/useFlowCatalog.ts +69 -0
  49. package/src/client/useMinuteClock.ts +21 -0
  50. package/src/client/useRunReattach.ts +50 -0
  51. package/src/configSchema.json +37 -2
  52. package/src/flow-catalog-contract.ts +65 -0
  53. package/src/flow-questions.ts +138 -0
  54. package/src/flow-reducer.ts +434 -13
  55. package/src/flow-state-serialize.ts +132 -0
  56. package/src/i18n.ts +144 -6
  57. package/src/server/automation-actions.ts +4 -3
  58. package/src/server/edit-mode.ts +307 -0
  59. package/src/server/flow-catalog.ts +127 -0
  60. package/src/server/flow-control.ts +263 -0
  61. package/src/server/flow-files.ts +140 -14
  62. package/src/server/flow-open.ts +385 -0
  63. package/src/server/index.ts +112 -34
  64. package/src/server/render-actions.ts +3 -2
  65. package/src/server/state-store.ts +11 -5
  66. package/src/types.ts +180 -0
  67. package/src/bridge/flow-question-adapter.ts +0 -93
  68. package/src/client/FlowQuestionCard.tsx +0 -218
  69. package/src/client/FlowQuestionTranscriptPill.tsx +0 -58
  70. package/src/client/FlowsCommandRoutes.tsx +0 -245
  71. package/src/client/flow-yaml-parse.ts +0 -140
@@ -0,0 +1,69 @@
1
+ /**
2
+ * The pencil (Edit…) button shared by the dock chip and both flow panel
3
+ * headers. Its authoring popover (`FlowEditPopover.tsx`) is a lazy chunk
4
+ * loaded on first open. The caller owns `open` so it can feed it to
5
+ * `useFlowActions({ menuOpen })` (edit mode is re-read on each closed → open
6
+ * transition); opening also asks the session for its catalog.
7
+ *
8
+ * See change: flows-dock-chip-and-panel-actions (D7).
9
+ */
10
+ import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
11
+ import { mdiPencil } from "@mdi/js";
12
+ import { Icon } from "@mdi/react";
13
+ import { lazy, Suspense, useRef } from "react";
14
+ import type { FlowActions } from "./useFlowActions.js";
15
+
16
+ const FlowEditPopover = lazy(() => import("./FlowEditPopover.js").then((m) => ({ default: m.FlowEditPopover })));
17
+
18
+ /** Shared look for the small header / chip icon buttons (24 px dock minimum). */
19
+ export const FLOW_ICON_BUTTON_CLASS =
20
+ "inline-flex items-center justify-center min-h-6 min-w-6 h-6 w-6 rounded text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)] disabled:opacity-40 disabled:cursor-not-allowed disabled:hover:bg-transparent focus-ring";
21
+
22
+ export function FlowEditMenu({
23
+ actions,
24
+ open,
25
+ onOpenChange,
26
+ testIdPrefix,
27
+ }: {
28
+ actions: FlowActions;
29
+ open: boolean;
30
+ onOpenChange: (open: boolean) => void;
31
+ testIdPrefix: string;
32
+ }) {
33
+ const t = useT();
34
+ const btnRef = useRef<HTMLButtonElement>(null);
35
+ const label = t("editFlowsButton", undefined, "Edit…");
36
+
37
+ const close = (refocus: boolean) => {
38
+ onOpenChange(false);
39
+ if (refocus) btnRef.current?.focus();
40
+ };
41
+
42
+ return (
43
+ <>
44
+ <button
45
+ ref={btnRef}
46
+ type="button"
47
+ data-testid={`${testIdPrefix}-button`}
48
+ aria-label={label}
49
+ title={label}
50
+ aria-haspopup="menu"
51
+ aria-expanded={open}
52
+ onClick={(e) => {
53
+ e.stopPropagation();
54
+ // Opening asks the session for its catalog too (spec: flows-catalog).
55
+ if (!open) actions.refreshCatalog();
56
+ onOpenChange(!open);
57
+ }}
58
+ className={FLOW_ICON_BUTTON_CLASS}
59
+ >
60
+ <Icon path={mdiPencil} size={0.6} aria-hidden="true" />
61
+ </button>
62
+ {open && btnRef.current && (
63
+ <Suspense fallback={null}>
64
+ <FlowEditPopover actions={actions} anchorEl={btnRef.current} onClose={close} testIdPrefix={testIdPrefix} />
65
+ </Suspense>
66
+ )}
67
+ </>
68
+ );
69
+ }
@@ -0,0 +1,130 @@
1
+ /**
2
+ * The pencil popover body (authoring items + per-project edit-mode item) for
3
+ * `FlowEditMenu`. Click-only, so it is a lazy chunk loaded the first time the
4
+ * pencil opens; the eager dock chip stays small. Uses the host `ui:popover`.
5
+ *
6
+ * - edit mode unknown → a loading line, no authoring items;
7
+ * - off → only "Turn on edit mode for this project";
8
+ * - on → Edit…, New flow…, Delete… (only with `flows:delete`), then
9
+ * "Turn off edit mode for this project".
10
+ *
11
+ * Keyboard: focus moves to the first item, ArrowUp/Down move, Escape (via the
12
+ * popover) closes and returns focus to the pencil.
13
+ * See change: flows-dock-chip-and-panel-actions (D7).
14
+ */
15
+ import { useT, useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
16
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
17
+ import { mdiDeleteOutline, mdiPencilOff, mdiPencilOutline, mdiPlus } from "@mdi/js";
18
+ import { Icon } from "@mdi/react";
19
+ import { type KeyboardEvent, useCallback, useEffect, useRef } from "react";
20
+ import type { FlowActions } from "./useFlowActions.js";
21
+
22
+ export function FlowEditPopover({
23
+ actions,
24
+ anchorEl,
25
+ onClose,
26
+ testIdPrefix,
27
+ }: {
28
+ actions: FlowActions;
29
+ anchorEl: HTMLElement;
30
+ /** `refocus` = return focus to the pencil (Escape / outside click). */
31
+ onClose: (refocus: boolean) => void;
32
+ testIdPrefix: string;
33
+ }) {
34
+ const t = useT();
35
+ const Popover = useUiPrimitive(UI_PRIMITIVE_KEYS.popover);
36
+ const menuRef = useRef<HTMLDivElement | null>(null);
37
+ const label = t("editFlowsButton", undefined, "Edit…");
38
+ const pick = (fn: () => void) => () => {
39
+ onClose(false);
40
+ fn();
41
+ };
42
+
43
+ // The popover stays `visibility: hidden` until it has positioned itself, and
44
+ // a hidden element cannot take focus: retry for a few frames.
45
+ const focusFirst = useCallback(() => {
46
+ let frames = 0;
47
+ const attempt = () => {
48
+ const menu = menuRef.current;
49
+ if (!menu || menu.contains(document.activeElement)) return;
50
+ const first = menu.querySelector<HTMLElement>('[role="menuitem"]');
51
+ first?.focus();
52
+ if (first && document.activeElement !== first && frames++ < 10) requestAnimationFrame(attempt);
53
+ };
54
+ attempt();
55
+ }, []);
56
+ const setMenuEl = useCallback(
57
+ (el: HTMLDivElement | null) => {
58
+ menuRef.current = el;
59
+ if (el) focusFirst();
60
+ },
61
+ [focusFirst],
62
+ );
63
+ useEffect(() => {
64
+ focusFirst();
65
+ }, [actions.editMode, focusFirst]);
66
+
67
+ const onKeyDown = (e: KeyboardEvent<HTMLDivElement>) => {
68
+ if (e.key !== "ArrowDown" && e.key !== "ArrowUp") return;
69
+ const items = Array.from(menuRef.current?.querySelectorAll<HTMLElement>('[role="menuitem"]') ?? []);
70
+ if (items.length === 0) return;
71
+ e.preventDefault();
72
+ const i = items.indexOf(document.activeElement as HTMLElement);
73
+ const next = e.key === "ArrowDown" ? (i + 1) % items.length : (i - 1 + items.length) % items.length;
74
+ items[next]?.focus();
75
+ };
76
+
77
+ const editMode = actions.editMode;
78
+ const item = (id: string, text: string, icon: string, onClick: () => void, title?: string) => (
79
+ <button
80
+ key={id}
81
+ type="button"
82
+ role="menuitem"
83
+ data-testid={`${testIdPrefix}-${id}`}
84
+ title={title}
85
+ onClick={pick(onClick)}
86
+ className="flex w-full min-h-7 items-center gap-2 rounded px-2 text-left text-xs text-[var(--text-primary)] hover:bg-[var(--bg-hover)] focus:bg-[var(--bg-hover)] focus:outline-none"
87
+ >
88
+ <Icon path={icon} size={0.55} aria-hidden="true" />
89
+ {text}
90
+ </button>
91
+ );
92
+
93
+ return (
94
+ <Popover anchorEl={anchorEl} onDismiss={() => onClose(true)}>
95
+ <div
96
+ ref={setMenuEl}
97
+ role="menu"
98
+ aria-label={label}
99
+ data-testid={`${testIdPrefix}-popover`}
100
+ onKeyDown={onKeyDown}
101
+ className="min-w-[220px] rounded-md border border-[var(--border-subtle)] bg-[var(--bg-secondary)] p-1 shadow-lg"
102
+ >
103
+ {editMode === undefined ? (
104
+ <p data-testid={`${testIdPrefix}-loading`} className="px-2 py-1.5 text-xs text-[var(--text-secondary)]">
105
+ {t("editModeLoading", undefined, "Checking edit mode…")}
106
+ </p>
107
+ ) : (
108
+ <>
109
+ {editMode && item("edit", t("editFlowItem", undefined, "Edit…"), mdiPencilOutline, actions.edit)}
110
+ {editMode && item("new", t("newFlowItem", undefined, "New flow…"), mdiPlus, actions.newFlow)}
111
+ {editMode && actions.canDelete && item("delete", `${t("delete", undefined, "Delete")}…`, mdiDeleteOutline, actions.remove)}
112
+ {item(
113
+ "edit-mode",
114
+ editMode
115
+ ? t("projectEditModeOff", undefined, "Turn off edit mode for this project")
116
+ : t("projectEditModeOn", undefined, "Turn on edit mode for this project"),
117
+ editMode ? mdiPencilOff : mdiPencilOutline,
118
+ () => actions.setEditMode(!editMode),
119
+ t(
120
+ "projectEditModeHint",
121
+ undefined,
122
+ "Writes flows.editFlow to this project's .pi/settings.json. The project value then overrides the global default.",
123
+ ),
124
+ )}
125
+ </>
126
+ )}
127
+ </div>
128
+ </Popover>
129
+ );
130
+ }
@@ -3,8 +3,9 @@ import { useT, useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-run
3
3
  // Stays as a direct import. See add-plugin-ui-primitive-registry Decision 4.
4
4
  import { useZoomPan } from "@blackbelt-technology/pi-dashboard-client-utils/useZoomPan";
5
5
  import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
6
- import type { FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
7
- import { mdiCallSplit, mdiCodeTags, mdiRobotOutline, mdiSourceBranch } from "@mdi/js";
6
+ import { stepAsks } from "../flow-questions.js";
7
+ import type { FlowState } from "../types.js";
8
+ import { mdiCallSplit, mdiCodeTags, mdiHelpCircleOutline, mdiRobotOutline, mdiSourceBranch } from "@mdi/js";
8
9
  import { graphlib } from "dagre-d3-es";
9
10
  import { layout as dagreLayout } from "dagre-d3-es/src/dagre/index.js";
10
11
  import { useEffect, useMemo, useRef, useState } from "react";
@@ -46,9 +47,18 @@ export function mapStepType(stepType: string | undefined): FlowStepType | undefi
46
47
  export interface FlowGraphStep {
47
48
  id: string;
48
49
  label: string;
49
- status: "pending" | "running" | "complete" | "error" | "blocked";
50
+ status: "pending" | "running" | "complete" | "error" | "blocked" | "skipped";
51
+ /** Short status word shown AFTER the name (never instead of it): `skipped`,
52
+ * a fan-out `xN (k failed)` count, or a decision's chosen routes. Colour is
53
+ * never the sole channel. See change: update-flows-plugin (D6). */
54
+ statusWord?: string;
50
55
  blockedBy: string[];
51
56
  type?: FlowStepType;
57
+ /** RAW engine step type (`agent` | `fork` | `agent-decision` | `code` |
58
+ * `code-decision`) fed to `deriveFlowEdges`. `type` is the display mapping,
59
+ * which merges `agent-decision` into `fork`; fall-through needs them apart.
60
+ * Absent → falls back to `type`. See change: fix-flow-graph-engine-order. */
61
+ kind?: string;
52
62
  /** Decision branch label → target step id (fork / agent-decision / code-decision). */
53
63
  branches?: Record<string, string>;
54
64
  /** Success route target (`on_complete`). Present on the static preview path and,
@@ -56,6 +66,10 @@ export interface FlowGraphStep {
56
66
  onComplete?: string;
57
67
  /** Error route target (`on_error`). Drives returning-loop vs terminal-sink rendering. */
58
68
  onError?: string;
69
+ /** The step (or one of its fan-out items) has an open parent-mailbox question.
70
+ * Restyles the node only; never adds nodes, edges or status words.
71
+ * See change: adopt-flow-parent-mailbox (D3). */
72
+ asking?: boolean;
59
73
  }
60
74
 
61
75
  // ── Data converters ────────────────────────────────────────────────
@@ -64,6 +78,23 @@ export interface FlowGraphStep {
64
78
  * Uses dagSteps when available, falls back to agents map for backward compat.
65
79
  * Implicit-segment + branch edges are derived later by `deriveFlowEdges` in
66
80
  * computeLayout; here we only carry `blockedBy` + `branches`. */
81
+ /** Status word for a step: skipped / fan-out count / chosen decision routes. */
82
+ function graphStatusWord(flowState: FlowState, stepId: string, status: FlowGraphStep["status"]): string | undefined {
83
+ if (status === "skipped") return "skipped";
84
+ const items = flowState.groups?.[stepId]?.filter(Boolean);
85
+ const card = flowState.agents.get(stepId);
86
+ const count = Math.max(items?.length ?? 0, card?.itemCount ?? 0);
87
+ if (items && items.length > 0) {
88
+ const failed = items.filter((i) => i.status === "error").length;
89
+ return failed > 0 ? `x${count} (${failed} failed)` : `x${count}`;
90
+ }
91
+ const decision = flowState.decisions?.[stepId];
92
+ if (decision && !decision.routeError && decision.routes && decision.routes.length > 0) {
93
+ return decision.routes.map((r) => r.branch).join(", ");
94
+ }
95
+ return undefined;
96
+ }
97
+
67
98
  export function flowStateToGraphSteps(flowState: FlowState): FlowGraphStep[] {
68
99
  if (flowState.dagSteps && flowState.dagSteps.length > 0) {
69
100
  const stepStatus = new Map<string, FlowGraphStep["status"]>();
@@ -72,21 +103,30 @@ export function flowStateToGraphSteps(flowState: FlowState): FlowGraphStep[] {
72
103
  if (agent.stepId) stepStatus.set(agent.stepId, agent.status);
73
104
  stepStatus.set(agent.agentName, agent.status);
74
105
  }
106
+ // Card-less steps an unchosen decision route skipped.
107
+ for (const id of flowState.skippedSteps ?? []) if (!stepStatus.has(id)) stepStatus.set(id, "skipped");
75
108
 
76
109
  const allStepIds = new Set(flowState.dagSteps.map(s => s.id));
77
- return flowState.dagSteps.map(step => ({
110
+ return flowState.dagSteps.map(step => {
111
+ const status = stepStatus.get(step.id) || stepStatus.get(step.agent || "") || "pending";
112
+ const statusWord = graphStatusWord(flowState, step.id, status);
113
+ return {
78
114
  id: step.id,
79
115
  label: step.id,
80
- status: stepStatus.get(step.id) || stepStatus.get(step.agent || "") || "pending",
116
+ status,
117
+ ...(statusWord ? { statusWord } : {}),
118
+ ...(stepAsks(flowState, step.id) ? { asking: true } : {}),
81
119
  blockedBy: step.blockedBy.filter(dep => allStepIds.has(dep)),
82
120
  type: mapStepType(step.stepType),
121
+ ...(step.stepType ? { kind: step.stepType } : {}),
83
122
  branches: step.branches,
84
123
  // Forward/error routing (present once pi-flows emits it on flow:flow-started)
85
124
  // so on_complete-wired flows draw `route` edges live. See change:
86
125
  // fix-flow-ui-graph-zoom-summary.
87
126
  onComplete: step.onComplete,
88
127
  onError: step.onError,
89
- }));
128
+ };
129
+ });
90
130
  }
91
131
 
92
132
  // Fallback: build from agents map (backward compat for old events without dagSteps)
@@ -107,8 +147,10 @@ export function flowStateToGraphSteps(flowState: FlowState): FlowGraphStep[] {
107
147
  interface PositionedNode {
108
148
  id: string;
109
149
  label: string;
150
+ statusWord?: string;
110
151
  status: FlowGraphStep["status"];
111
152
  type?: FlowStepType;
153
+ asking?: boolean;
112
154
  x: number;
113
155
  y: number;
114
156
  width: number;
@@ -161,6 +203,14 @@ const STATUS_COLORS: Record<string, { border: string; fill: string; text: string
161
203
  blocked: { border: "#f97316", fill: "#2a1a00", text: "#f97316" },
162
204
  };
163
205
 
206
+ /** Asking colour set (open question): purple border (loop-edge hue), dark
207
+ * purple fill, light purple label + `?` icon. Label-on-fill contrast
208
+ * label on fill ≈ 6.5:1 (WCAG AA). The graph canvas is theme-independent.
209
+ * See change: adopt-flow-parent-mailbox (D3). */
210
+ /** Loop-edge purple, shared by loop edges, their markers and asking borders. */
211
+ const LOOP_PURPLE = "#a855f7";
212
+ const ASKING_COLORS = { border: LOOP_PURPLE, fill: "#2a0f3a", text: "#c084fc" } as const;
213
+
164
214
  function getEdgeColor(sourceStatus: string, targetStatus: string): { stroke: string; animated: boolean; dashed: boolean } {
165
215
  if (sourceStatus === "complete" && targetStatus === "running") {
166
216
  return { stroke: "#eab308", animated: true, dashed: false };
@@ -204,7 +254,7 @@ export function computeLayout(
204
254
  const flowEdges = deriveFlowEdges(
205
255
  steps.map((s): FlowEdgeStep => ({
206
256
  id: s.id,
207
- type: s.type ?? "agent",
257
+ type: s.kind ?? s.type ?? "agent",
208
258
  blockedBy: s.blockedBy,
209
259
  branches: s.branches,
210
260
  onComplete: s.onComplete,
@@ -213,30 +263,43 @@ export function computeLayout(
213
263
  );
214
264
 
215
265
  const isOnError = (e: FlowEdge) => e.kind === "route" && e.label === "on_error";
216
- const onErrorEdges = flowEdges.filter(isOnError);
217
- const terminalHandlerIds = new Set(
218
- onErrorEdges.filter(e => e.routeTopology === "terminal").map(e => e.to),
219
- );
220
266
 
221
- // A node reached ONLY via on_error routes is an error-only handler (returning
222
- // or terminal). Roots (no incoming edge at all) are NOT error-only.
223
- const incoming = new Map<string, FlowEdge[]>();
224
- for (const e of flowEdges) {
225
- const list = incoming.get(e.to);
226
- if (list) list.push(e); else incoming.set(e.to, [e]);
267
+ // Error-only = reachable only through on_error routes: ≥1 incoming edge, and
268
+ // not reached by non-error edges from a root (or the first declared step, the
269
+ // engine's entry) — every incoming edge is on_error or leaves another
270
+ // error-only node. Roots are never error-only. Only error-only nodes are
271
+ // pooled into the sink or hidden; any success-reached node stays normal.
272
+ const hasIncoming = new Set(flowEdges.map(e => e.to));
273
+ const successReached = new Set<string>();
274
+ const frontier = steps.filter((s, i) => i === 0 || !hasIncoming.has(s.id)).map(s => s.id);
275
+ while (frontier.length) {
276
+ const n = frontier.pop() as string;
277
+ if (successReached.has(n)) continue;
278
+ successReached.add(n);
279
+ for (const e of flowEdges) if (e.from === n && !isOnError(e)) frontier.push(e.to);
227
280
  }
228
- const isErrorOnly = (id: string) => {
229
- const inc = incoming.get(id) ?? [];
230
- return inc.length > 0 && inc.every(isOnError);
231
- };
281
+ const errorOnly = new Set(steps.map(s => s.id).filter(id => !successReached.has(id)));
232
282
 
233
- // Terminal handlers collapse into ONE sink (excluded as real nodes). When the
234
- // error layer is hidden, every error-only node leaves too — graph height then
235
- // matches a flow with no on_error declared (zero footprint).
236
- const excluded = new Set<string>(terminalHandlerIds);
237
- if (!showErrorRoutes) {
238
- for (const s of steps) if (isErrorOnly(s.id)) excluded.add(s.id);
283
+ // Terminal error-only handlers + their error-only tail collapse into ONE sink
284
+ // (handler-then-tail order). Terminal routes to any other target are drawn as
285
+ // error edges to the real node.
286
+ const pooled: string[] = [];
287
+ const pool = (id: string) => { if (!pooled.includes(id)) pooled.push(id); };
288
+ for (const e of flowEdges) {
289
+ if (!isOnError(e) || e.routeTopology !== "terminal" || !errorOnly.has(e.to) || pooled.includes(e.to)) continue;
290
+ const stack = [e.to];
291
+ while (stack.length) {
292
+ const n = stack.shift() as string;
293
+ if (pooled.includes(n)) continue;
294
+ pool(n);
295
+ for (const out of flowEdges) if (out.from === n && errorOnly.has(out.to)) stack.push(out.to);
296
+ }
239
297
  }
298
+ const terminalHandlerIds = new Set(pooled);
299
+
300
+ // Shown: pooled nodes leave the layout (the sink stands for them). Hidden:
301
+ // every error-only node leaves, with on_error edges and edges leaving them.
302
+ const excluded = new Set<string>(showErrorRoutes ? pooled : errorOnly);
240
303
  const laidOutSteps = steps.filter(s => !excluded.has(s.id));
241
304
  const laidOutIds = new Set(laidOutSteps.map(s => s.id));
242
305
 
@@ -252,7 +315,9 @@ export function computeLayout(
252
315
  // (dummy nodes) so a polyline goes AROUND nodes instead of through them — this
253
316
  // is what eliminates the old hand-routed legs that sliced across node boxes.
254
317
  // Terminal on_error edges are redirected to the collapsed sink node.
255
- const g = new graphlib.Graph().setDefaultEdgeLabel(() => ({}));
318
+ // Multigraph: a fall-through and an on_error route on the same pair are both
319
+ // routed. Edges are named by kind+label and read back by name.
320
+ const g = new graphlib.Graph({ multigraph: true }).setDefaultEdgeLabel(() => ({}));
256
321
  // Flatter layout: tighter vertical node gap + small edgesep packs the graph
257
322
  // (edges may overlap slightly — acceptable) so it reads more horizontal.
258
323
  g.setGraph({ rankdir: "LR", nodesep: 12, edgesep: 8, ranksep: 46, marginx: 16, marginy: 16, acyclicer: "greedy" });
@@ -261,20 +326,21 @@ export function computeLayout(
261
326
  if (haveSink) g.setNode(SINK_ID, { width: SINK_W, height: NODE_HEIGHT });
262
327
 
263
328
  interface EdgeSpec {
264
- from: string; to: string; dTo: string; label?: string;
329
+ from: string; to: string; dTo: string; name: string; label?: string;
265
330
  kind: FlowEdgeKind; isError: boolean; isReturning: boolean; isLoop: boolean;
266
331
  }
267
332
  const specs: EdgeSpec[] = [];
268
333
  for (const e of flowEdges) {
269
334
  const err = isOnError(e);
270
335
  if (err && !showErrorRoutes) continue;
271
- const terminal = err && e.routeTopology === "terminal";
272
- const dTo = terminal ? SINK_ID : e.to;
336
+ const toSink = err && haveSink && terminalHandlerIds.has(e.to);
337
+ const dTo = toSink ? SINK_ID : e.to;
273
338
  if (!laidOutIds.has(e.from)) continue;
274
339
  if (dTo !== SINK_ID && !laidOutIds.has(dTo)) continue;
275
- g.setEdge(e.from, dTo, e.label ? { width: e.label.length * 6 + 6, height: 12 } : {});
340
+ const name = `${e.kind}:${e.label ?? ""}`;
341
+ g.setEdge(e.from, dTo, e.label ? { width: e.label.length * 6 + 6, height: 12 } : {}, name);
276
342
  specs.push({
277
- from: e.from, to: e.to, dTo, label: e.label, kind: e.kind,
343
+ from: e.from, to: e.to, dTo, name, label: e.label, kind: e.kind,
278
344
  isError: err, isReturning: err && e.routeTopology === "returning", isLoop: !!e.backward,
279
345
  });
280
346
  }
@@ -286,6 +352,8 @@ export function computeLayout(
286
352
  return {
287
353
  id: step.id,
288
354
  label: step.label,
355
+ ...(step.statusWord ? { statusWord: step.statusWord } : {}),
356
+ ...(step.asking ? { asking: true } : {}),
289
357
  status: step.status,
290
358
  type: step.type,
291
359
  x: n.x - NODE_WIDTH / 2,
@@ -298,7 +366,7 @@ export function computeLayout(
298
366
  // Every edge rendered from dagre's routed waypoints (multi-segment, node-aware).
299
367
  const edges: PositionedEdge[] = [];
300
368
  for (const s of specs) {
301
- const ed = g.edge(s.from, s.dTo);
369
+ const ed = g.edge(s.from, s.dTo, s.name);
302
370
  if (!ed?.points) continue;
303
371
  edges.push({
304
372
  source: s.from,
@@ -322,7 +390,7 @@ export function computeLayout(
322
390
  y: sn.y - NODE_HEIGHT / 2,
323
391
  width: SINK_W,
324
392
  height: NODE_HEIGHT,
325
- handlers: Array.from(terminalHandlerIds),
393
+ handlers: pooled,
326
394
  };
327
395
  }
328
396
 
@@ -488,7 +556,7 @@ export function FlowGraph({ steps, fit = false, onExpand, selectedStepId, onSele
488
556
  style={{ display: "block", overflow: "visible" }}
489
557
  >
490
558
  <defs>
491
- {["#444", "#666", "#22c55e", "#eab308", "#ef4444", "#a855f7"].map((color) => (
559
+ {["#444", "#666", "#22c55e", "#eab308", "#ef4444", LOOP_PURPLE].map((color) => (
492
560
  <marker
493
561
  key={color}
494
562
  id={`arrow-${color.replace("#", "")}`}
@@ -515,7 +583,7 @@ export function FlowGraph({ steps, fit = false, onExpand, selectedStepId, onSele
515
583
  stroke = "#ef4444";
516
584
  dash = "5 4";
517
585
  } else if (edge.isLoop) {
518
- stroke = "#a855f7";
586
+ stroke = LOOP_PURPLE;
519
587
  dash = "5 3";
520
588
  } else {
521
589
  const c = getEdgeColor(edge.sourceStatus, edge.targetStatus);
@@ -530,9 +598,13 @@ export function FlowGraph({ steps, fit = false, onExpand, selectedStepId, onSele
530
598
  const label = edge.isError
531
599
  ? `on_error ${edge.isReturning ? "↺" : "⊗"}`
532
600
  : edge.label === "on_complete" ? undefined : edge.label;
533
- const labelColor = edge.isError ? "#ef4444" : edge.isLoop ? "#a855f7" : "#888";
601
+ const labelColor = edge.isError ? "#ef4444" : edge.isLoop ? LOOP_PURPLE : "#888";
534
602
  return (
535
- <g key={`edge-${i}`}>
603
+ <g
604
+ key={`edge-${i}`}
605
+ data-edge={`${edge.source}>${edge.target}`}
606
+ data-edge-kind={edge.isError ? "on_error" : edge.kind}
607
+ >
536
608
  <path
537
609
  d={buildEdgePath(edge.points)}
538
610
  fill="none"
@@ -621,7 +693,8 @@ export function FlowGraph({ steps, fit = false, onExpand, selectedStepId, onSele
621
693
 
622
694
  {/* Nodes */}
623
695
  {layout.nodes.map((node) => {
624
- const style = STATUS_COLORS[node.status] || STATUS_COLORS.pending;
696
+ // Skipped = the pending style; the word "skipped" carries the meaning.
697
+ const style = node.asking ? ASKING_COLORS : STATUS_COLORS[node.status] || STATUS_COLORS.pending;
625
698
  const isRunning = node.status === "running";
626
699
  // Per-kind visual: mdi icon + accent matching the cards (code=cyan,
627
700
  // fork=amber, agent=green/status). Border/fill stay status-driven.
@@ -633,7 +706,9 @@ export function FlowGraph({ steps, fit = false, onExpand, selectedStepId, onSele
633
706
  const iconScale = ICON_SIZE / 24;
634
707
  const labelX = node.x + 7 + ICON_SIZE + 4;
635
708
  const availW = node.x + node.width - labelX - 8;
636
- const naturalW = node.label.length * FONT_SIZE * 0.6;
709
+ // Name first, then the short status word (` · skipped`, ` · x3`).
710
+ const wordText = node.statusWord ? ` · ${node.statusWord}` : "";
711
+ const naturalW = (node.label.length + wordText.length) * FONT_SIZE * 0.6;
637
712
  const labelFontSize = naturalW > availW
638
713
  ? Math.max(7, FONT_SIZE * (availW / naturalW))
639
714
  : FONT_SIZE;
@@ -643,6 +718,8 @@ export function FlowGraph({ steps, fit = false, onExpand, selectedStepId, onSele
643
718
  <g
644
719
  key={node.id}
645
720
  data-node={node.id}
721
+ data-status={node.status}
722
+ {...(node.asking ? { "data-asking": "" } : {})}
646
723
  style={{ cursor: onSelectStep ? "pointer" : "default" }}
647
724
  className={`${isRunning ? "flow-node-running" : ""}${isSelected ? " flow-node-selected" : ""}`.trim()}
648
725
  onClick={onSelectStep ? () => onSelectStep(node.id) : undefined}
@@ -685,11 +762,12 @@ export function FlowGraph({ steps, fit = false, onExpand, selectedStepId, onSele
685
762
  fill={accent}
686
763
  />
687
764
  )}
688
- {/* mdi kind icon (24-unit path scaled), tinted by accent or status. */}
765
+ {/* mdi kind icon (24-unit path scaled), tinted by accent or status.
766
+ An asking node shows a purple `?` instead (stripe kept). */}
689
767
  <path
690
- d={visual.icon}
768
+ d={node.asking ? mdiHelpCircleOutline : visual.icon}
691
769
  transform={`translate(${iconX}, ${iconY}) scale(${iconScale})`}
692
- fill={accent ?? style.text}
770
+ fill={node.asking ? ASKING_COLORS.text : (accent ?? style.text)}
693
771
  />
694
772
  <text
695
773
  x={labelX}
@@ -701,6 +779,11 @@ export function FlowGraph({ steps, fit = false, onExpand, selectedStepId, onSele
701
779
  fontFamily="system-ui, -apple-system, sans-serif"
702
780
  >
703
781
  {node.label}
782
+ {wordText && (
783
+ <tspan data-status-word="" fillOpacity={0.85}>
784
+ {wordText}
785
+ </tspan>
786
+ )}
704
787
  </text>
705
788
  </g>
706
789
  );
@@ -0,0 +1,83 @@
1
+ /**
2
+ * Flow panel header actions, rendered by `FlowDashboardClaim` into the live,
3
+ * opened-not-started and completed headers (the panels take them as a
4
+ * `headerActions` node so they stay host-context free):
5
+ *
6
+ * - `summary` (completed): Run again (hidden when the catalog no longer lists
7
+ * the flow), Open flow… (hidden when the catalog is empty), Edit…;
8
+ * - `live` (running): Open flow… (disabled, "A flow is running"), Edit…;
9
+ * - `idle` (opened, not started): Open flow… (swap the opened flow), Edit…
10
+ * (omitted for a view-only, path-opened flow — see change: add-flow-open-tool).
11
+ *
12
+ * Run again / Open flow… are disabled with "A flow is running" while any flow
13
+ * in the session runs; hidden wins over disabled. Visible while collapsed.
14
+ *
15
+ * See change: flows-dock-chip-and-panel-actions (D6, D9).
16
+ */
17
+ import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
18
+ import { mdiEyeOutline, mdiReplay } from "@mdi/js";
19
+ import { Icon } from "@mdi/react";
20
+ import { useState } from "react";
21
+ import { FLOW_ICON_BUTTON_CLASS, FlowEditMenu } from "./FlowEditMenu.js";
22
+ import { FlowActionDialogs, useFlowActions } from "./useFlowActions.js";
23
+
24
+ export type FlowHeaderVariant = "summary" | "live" | "idle";
25
+
26
+ export function FlowHeaderActions({
27
+ sessionId,
28
+ flowName,
29
+ variant,
30
+ viewOnly = false,
31
+ }: {
32
+ sessionId: string;
33
+ flowName: string;
34
+ variant: FlowHeaderVariant;
35
+ /** Path-opened flow (not registered): no Edit… menu. */
36
+ viewOnly?: boolean;
37
+ }) {
38
+ const t = useT();
39
+ const [editOpen, setEditOpen] = useState(false);
40
+ const actions = useFlowActions(sessionId, { menuOpen: editOpen });
41
+ const runningReason = t("openFlowDisabledRunning", undefined, "A flow is running");
42
+ const openLabel = t("openFlowButton", undefined, "Open flow…");
43
+ const runAgainLabel = t("runAgainButton", undefined, "Run again");
44
+
45
+ const disabled = actions.anyRunning || variant === "live";
46
+ const showRunAgain = variant === "summary" && actions.flows.some((f) => f.name === flowName);
47
+ const showOpen = actions.hasFlows;
48
+
49
+ return (
50
+ <span className="inline-flex items-center gap-0.5" data-testid={`flow-header-actions-${variant}`} onClick={(e) => e.stopPropagation()}>
51
+ {showRunAgain && (
52
+ <button
53
+ type="button"
54
+ data-testid="flow-header-run-again"
55
+ aria-label={runAgainLabel}
56
+ title={disabled ? runningReason : runAgainLabel}
57
+ disabled={disabled}
58
+ onClick={() => actions.runFlow(flowName)}
59
+ className={FLOW_ICON_BUTTON_CLASS}
60
+ >
61
+ <Icon path={mdiReplay} size={0.6} aria-hidden="true" />
62
+ </button>
63
+ )}
64
+ {showOpen && (
65
+ <button
66
+ type="button"
67
+ data-testid="flow-header-open"
68
+ aria-label={openLabel}
69
+ title={disabled ? runningReason : openLabel}
70
+ disabled={disabled}
71
+ onClick={actions.open}
72
+ className={FLOW_ICON_BUTTON_CLASS}
73
+ >
74
+ <Icon path={mdiEyeOutline} size={0.6} aria-hidden="true" />
75
+ </button>
76
+ )}
77
+ {!viewOnly && (
78
+ <FlowEditMenu actions={actions} open={editOpen} onOpenChange={setEditOpen} testIdPrefix="flow-header-edit" />
79
+ )}
80
+ <FlowActionDialogs actions={actions} />
81
+ </span>
82
+ );
83
+ }
@@ -2,7 +2,7 @@
2
2
  * Input-wiring editor for the `flows.run` automation action.
3
3
  *
4
4
  * Claimed into the automation-plugin's `automation-action-editor` slot
5
- * (keyed by `config.actionId: "flows.run"`). The create-automation dialog
5
+ * (keyed by `config.actionId: "flows.run"`). The inline automation editor
6
6
  * renders it additively below the generic flow + task form.
7
7
  *
8
8
  * Reads the selected flow's declared `inputs:` schema read-only from