@blackbelt-technology/pi-dashboard-flows-plugin 0.10.0 → 0.12.0

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 (72) hide show
  1. package/README.md +5 -1
  2. package/package.json +33 -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 +47 -9
  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 -18
  33. package/src/client/SessionFlowActions.tsx +65 -10
  34. package/src/client/SessionFlowMenuClaim.tsx +48 -248
  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-inputs.ts +56 -1
  63. package/src/server/flow-open.ts +385 -0
  64. package/src/server/index.ts +123 -40
  65. package/src/server/render-actions.ts +3 -2
  66. package/src/server/state-store.ts +11 -5
  67. package/src/types.ts +180 -0
  68. package/src/bridge/flow-question-adapter.ts +0 -93
  69. package/src/client/FlowQuestionCard.tsx +0 -218
  70. package/src/client/FlowQuestionTranscriptPill.tsx +0 -58
  71. package/src/client/FlowsCommandRoutes.tsx +0 -245
  72. package/src/client/flow-yaml-parse.ts +0 -140
@@ -1,34 +1,34 @@
1
- import {
2
- type InteractiveUiRequestSnapshot,
1
+ import {SettingsStatusPill,
3
2
  usePluginSend,
4
- useSessionData,
5
3
  useSessionEvents,
6
- useSessionInteractiveRequests,
7
4
  useT,
8
- useUiPrimitiveOrNull,
5
+ useUiPrimitiveOrNull
9
6
  } from "@blackbelt-technology/dashboard-plugin-runtime";
10
7
  import { BreadcrumbSlot } from "@blackbelt-technology/pi-dashboard-client-utils/extension-ui/BreadcrumbSlot";
11
8
  import { useMobile } from "@blackbelt-technology/pi-dashboard-client-utils/useMobile";
12
9
  import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
13
- import type { DashboardSession, FlowInfo, FlowState, ImageContent } from "@blackbelt-technology/pi-dashboard-shared/types.js";
14
- import { mdiChevronDown, mdiChevronRight, mdiChevronUp, mdiClose, mdiLoading, mdiPlay, mdiRobotOutline, mdiStop } from "@mdi/js";
10
+ import type { DashboardSession, ImageContent } from "@blackbelt-technology/pi-dashboard-shared/types.js";
11
+ import { mdiChevronDown, mdiChevronRight, mdiChevronUp, mdiClose, mdiCloseCircleOutline, mdiHelpCircleOutline, mdiLoading, mdiPlay, mdiStop } from "@mdi/js";
15
12
  import { Icon } from "@mdi/react";
16
- import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
17
- import { FlowAgentCard } from "./FlowAgentCard.js";
13
+ import React, { type ReactNode, useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
14
+ import { formatRemaining, nearestExpiry, openQuestions, waitingState } from "../flow-questions.js";
15
+ import type { FlowState } from "../types.js";
16
+ import { openQuestionIds } from "./ask-session-store.js";
18
17
  import { FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
18
+ import { FlowHeaderActions } from "./FlowHeaderActions.js";
19
19
  import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
20
- import { FlowQuestionCard } from "./FlowQuestionCard.js";
21
- import { FlowQuestionTranscriptPill } from "./FlowQuestionTranscriptPill.js";
22
- import { FlowSummary } from "./FlowSummary.js";
20
+ import { AskSessionButton, AskSessionProvider, useAskSessionApi } from "./AskSession.js";
21
+ import { FlowStepCards, stepStateCounts } from "./FlowStepCards.js";
22
+ import { FlowSummarySections, FlowSummaryStatus } from "./FlowSummary.js";
23
23
  import { type FlowsSessionState, useFlowsSessionState } from "./FlowsSessionStateContext.js";
24
24
  import { type FlowTab, FlowTabBar } from "./FlowTabBar.js";
25
25
  import { FlowYamlPopoverButton } from "./FlowYamlPopoverButton.js";
26
26
  import { clearAttachment, resolveBaseline, useFlowAttachment } from "./flow-attach-store.js";
27
- import { FLOW_CARD_GRID_CLASS, FLOW_CARD_GRID_CONTAINER_CLASS } from "./flow-card-grid.js";
28
27
  import { useFlowCollapsePersisted } from "./flow-collapse-storage.js";
29
- import { fetchFlowFile, type FlowNodeFiles, useFlowNodeFiles, withNodeFiles } from "./flow-files.js";
28
+ import { type FlowNodeFiles, fetchFlowFile, useFlowNodeFiles, withNodeFiles } from "./flow-files.js";
30
29
  import { buildIdleFlowState, type FlowAttachment, type FlowSlot, type IdleLoad, resolveFlowSlot } from "./flow-idle-state.js";
31
- import { makeSafeSend } from "./send-safe.js";
30
+ import { useFlowCatalog } from "./useFlowCatalog.js";
31
+ import { useMinuteClock } from "./useMinuteClock.js";
32
32
 
33
33
  /**
34
34
  * Selection survives run progress; it resets only when the displayed flow
@@ -66,24 +66,34 @@ function useOnEnterIdle(isIdle: boolean, onEnter: () => void) {
66
66
  }, [isIdle, onEnter]);
67
67
  }
68
68
 
69
- /** Idle header controls: rejection reason, Run, Close. */
69
+ /** Idle header controls: rejection reason, Run, Close (view-only: label, no Run). */
70
70
  function IdleControls({ idle }: { idle: FlowDashboardIdle }) {
71
71
  const t = useT();
72
72
  return (
73
73
  <>
74
+ {idle.viewOnly && (
75
+ <span
76
+ className="text-[11px] px-1.5 py-0.5 rounded border border-[var(--border-subtle)] text-[var(--text-secondary)] whitespace-nowrap"
77
+ data-testid="flow-view-only-label"
78
+ >
79
+ {t("flowViewOnlyLabel", undefined, "view only - not registered")}
80
+ </span>
81
+ )}
74
82
  {idle.rejectionReason && (
75
83
  <span className="text-[10px] text-red-400 truncate" data-testid="flow-run-rejected">
76
84
  {idle.rejectionReason}
77
85
  </span>
78
86
  )}
79
- <button
80
- onClick={(e) => { e.stopPropagation(); idle.onRun(); }}
81
- disabled={idle.runDisabled}
82
- className="text-[10px] px-1.5 py-0.5 rounded border border-blue-500/30 text-blue-400 hover:bg-blue-500/10 disabled:opacity-50 disabled:cursor-not-allowed"
83
- data-testid="flow-idle-run"
84
- >
85
- <Icon path={mdiPlay} size={0.4} className="inline mr-0.5" />{t("runFlow", undefined, "Run")}
86
- </button>
87
+ {!idle.viewOnly && (
88
+ <button
89
+ onClick={(e) => { e.stopPropagation(); idle.onRun(); }}
90
+ disabled={idle.runDisabled}
91
+ className="text-[10px] px-1.5 py-0.5 rounded border border-blue-500/30 text-blue-400 hover:bg-blue-500/10 disabled:opacity-50 disabled:cursor-not-allowed"
92
+ data-testid="flow-idle-run"
93
+ >
94
+ <Icon path={mdiPlay} size={0.4} className="inline mr-0.5" />{t("runFlow", undefined, "Run")}
95
+ </button>
96
+ )}
87
97
  <button
88
98
  onClick={(e) => { e.stopPropagation(); idle.onClose(); }}
89
99
  className="text-[10px] px-1.5 py-0.5 rounded border border-[var(--border-subtle)] text-[var(--text-tertiary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"
@@ -103,25 +113,82 @@ interface FlowDashboardIdle {
103
113
  runDisabled?: boolean;
104
114
  /** Reason of the latest rejected start for this flow, shown inline. */
105
115
  rejectionReason?: string;
116
+ /** Path-opened by the agent (`flow_open`): no Run, a view-only label. See change: add-flow-open-tool (D7). */
117
+ viewOnly?: boolean;
106
118
  }
107
119
 
108
- export function FlowDashboard({
120
+ type FlowDashboardProps = Parameters<typeof FlowDashboardPanel>[0];
121
+
122
+ /** Purple open-question pill: `? N question(s) · <nearest>`. The count is
123
+ * announced (`role="status"`); the time is not. See change: adopt-flow-parent-mailbox (D6). */
124
+ function QuestionPill({ count, remaining }: { count: number; remaining?: string | null }) {
125
+ const t = useT();
126
+ return (
127
+ <span
128
+ data-testid="flow-question-pill"
129
+ className="inline-flex items-center gap-0.5 rounded-full border border-[var(--tint-purple-border)] bg-[var(--tint-purple-bg)] px-1.5 py-px text-[10px] font-medium text-[var(--accent-purple-text)] shrink-0"
130
+ >
131
+ <Icon path={mdiHelpCircleOutline} size={0.42} />
132
+ <span role="status" aria-live="polite">
133
+ {count === 1
134
+ ? t("questionsOne", { n: count }, `${count} question`)
135
+ : t("questionsMany", { n: count }, `${count} questions`)}
136
+ </span>
137
+ {remaining ? <span>{` · ${remaining}`}</span> : null}
138
+ </span>
139
+ );
140
+ }
141
+
142
+ /** Collapsed-header **Ask session**: one request per open question not yet sent. */
143
+ function HeaderAskSession({ questionIds, testId }: { questionIds: readonly string[]; testId: string }) {
144
+ const api = useAskSessionApi();
145
+ if (!api || questionIds.length === 0) return null;
146
+ const unsent = api.unsent(questionIds);
147
+ return (
148
+ <AskSessionButton
149
+ size="line"
150
+ testId={testId}
151
+ view={{ note: "unread", disabled: unsent.length === 0, sent: false }}
152
+ onAsk={() => api.ask(unsent)}
153
+ />
154
+ );
155
+ }
156
+
157
+ export function FlowDashboard(props: FlowDashboardProps) {
158
+ // One Ask session binding per panel (cards + headers share it). Only with a
159
+ // session: the store folds that session's results. See change:
160
+ // adopt-flow-parent-mailbox (D5).
161
+ const { flowState, flowStates } = props;
162
+ const openIds = useMemo(
163
+ () => openQuestionIds([flowState, ...(flowStates?.values() ?? [])]),
164
+ [flowState, flowStates],
165
+ );
166
+ if (!props.sessionId) return <FlowDashboardPanel {...props} />;
167
+ return (
168
+ <AskSessionProvider sessionId={props.sessionId} openIds={openIds}>
169
+ <FlowDashboardPanel {...props} />
170
+ </AskSessionProvider>
171
+ );
172
+ }
173
+
174
+ function FlowDashboardPanel({
109
175
  flowState,
110
176
  flowStates,
111
177
  onAbort,
112
- onToggleAutonomous,
113
178
  onDismiss,
114
179
  onSendPrompt,
115
180
  session,
116
181
  sessionId,
117
182
  idle,
118
183
  nodeFiles,
184
+ headerActions,
119
185
  }: {
120
186
  flowState: FlowState;
121
187
  /** All flow states (one per distinct flow run this session) for tab navigation */
122
188
  flowStates?: Map<string, FlowState>;
123
- onAbort: () => void;
124
- onToggleAutonomous: () => void;
189
+ /** Abort; receives the run displayed when clicked (the slot run, or the
190
+ * selected tab's run). See change: fix-flow-reattach-per-run-state (D6). */
191
+ onAbort: (displayed: FlowState) => void;
125
192
  onDismiss: () => void;
126
193
  onSendPrompt?: (text: string, images?: import("@blackbelt-technology/pi-dashboard-shared/types.js").ImageContent[]) => void;
127
194
  /** Phase-2 decorator host — carries breadcrumb + agent-metric descriptors. */
@@ -134,18 +201,32 @@ export function FlowDashboard({
134
201
  idle?: FlowDashboardIdle;
135
202
  /** Reported agent / handler file paths, from the claim's poll. */
136
203
  nodeFiles?: FlowNodeFiles | null;
204
+ /** Header actions (Open flow… / Edit…, or Run again / Open / Edit for the
205
+ * completed summary). See change: flows-dock-chip-and-panel-actions. */
206
+ headerActions?: ReactNode;
137
207
  }) {
138
208
  const isMobile = useMobile();
139
209
  const t = useT();
210
+ // One panel for every phase: a completed flow renders here in `summary` mode
211
+ // (no separate FlowSummary shell). See change: unify-flow-rendering (D1).
212
+ const mode: "idle" | "live" | "summary" = idle ? "idle" : flowState.status === "running" ? "live" : "summary";
213
+ const isSummary = mode === "summary";
140
214
  const Dialog = useUiPrimitiveOrNull(UI_PRIMITIVE_KEYS.dialog);
141
215
  const [graphOpen, setGraphOpen] = useState(false);
142
- // Shared graph⇄card selection (live view parity with FlowSummary). See change:
216
+ // Shared graph⇄card selection. See change:
143
217
  // improve-flow-graph-dialog-and-card-interaction.
144
218
  const [selectedStepId, setSelectedStepId] = useState<string | null>(null);
145
219
  const rootRef = useRef<HTMLDivElement>(null);
146
220
  // Persisted per session so a collapsed dashboard stays collapsed across
147
- // remounts. See change: fix-flow-ui-graph-zoom-summary.
148
- const [collapsed, toggleCollapsed] = useFlowCollapsePersisted(sessionId, "dashboard");
221
+ // remounts. See change: fix-flow-ui-graph-zoom-summary. Completed panels use
222
+ // the `summary` key; the claim remounts on entering/leaving summary mode, so
223
+ // the right key is read on first render. See change: unify-flow-rendering (D1).
224
+ const [collapsed, toggleCollapsed] = useFlowCollapsePersisted(sessionId, isSummary ? "summary" : "dashboard");
225
+ // Agent cards section: collapsed by default, persisted per session. The
226
+ // graph is the primary view; a node click opens the section.
227
+ // See change: update-flows-plugin (D7).
228
+ const [cardsCollapsed, toggleCardsCollapsed] = useFlowCollapsePersisted(sessionId, "cards");
229
+ const cardsRegionId = `flow-agent-cards-${useId().replace(/:/g, "")}`;
149
230
  const [mobileExpanded, setMobileExpanded] = useState(false);
150
231
  const [activeTabId, setActiveTabId] = useState<string>(flowState.flowName);
151
232
  const [followMode, setFollowMode] = useState(true);
@@ -177,15 +258,30 @@ export function FlowDashboard({
177
258
  return flowState;
178
259
  }, [idle, flowStates, activeTabId, flowState]);
179
260
 
261
+ // A completed panel always shows the flow that completed — a manually
262
+ // selected tab cannot leak into it. See change: unify-flow-rendering (D1).
263
+ const shownState = isSummary ? flowState : displayState;
264
+
180
265
  // Agent / handler file paths so every card (idle, pending, running) can open
181
266
  // its file. See change: attach-flow-before-run.
182
- const agents = Array.from(withNodeFiles(displayState, nodeFiles ?? null).agents.values());
267
+ const agents = Array.from(withNodeFiles(shownState, nodeFiles ?? null).agents.values());
183
268
  const allAgents = Array.from(flowState.agents.values());
184
269
 
185
270
  const handleSelectStep = useCallback((stepId: string) => {
186
271
  setSelectedStepId((prev) => (prev === stepId ? null : stepId));
187
272
  }, []);
188
- useSelectionReset(displayState, selectedStepId, setSelectedStepId);
273
+ // Graph node click: toggle the selection AND open the Agent cards section
274
+ // (a second click clears the selection; the section stays open).
275
+ const cardsCollapsedRef = useRef(cardsCollapsed);
276
+ cardsCollapsedRef.current = cardsCollapsed;
277
+ const handleSelectNode = useCallback(
278
+ (stepId: string) => {
279
+ setSelectedStepId((prev) => (prev === stepId ? null : stepId));
280
+ if (cardsCollapsedRef.current) toggleCardsCollapsed();
281
+ },
282
+ [toggleCardsCollapsed],
283
+ );
284
+ useSelectionReset(shownState, selectedStepId, setSelectedStepId);
189
285
  // Entering idle (new attach / re-attach) starts fresh; leaving idle for live
190
286
  // keeps everything (same instance). See change: attach-flow-before-run (D2).
191
287
  const flowName = flowState.flowName;
@@ -205,37 +301,49 @@ export function FlowDashboard({
205
301
  window.addEventListener("keydown", onKey);
206
302
  return () => window.removeEventListener("keydown", onKey);
207
303
  }, [selectedStepId]);
208
- // Scroll the matching node + card into view on selection (counterpart sync).
304
+ // Scroll the matching node + card (or fan-out group) into view on selection
305
+ // (counterpart sync). Runs again once the Agent cards section opens. No
306
+ // smooth scroll under reduced motion.
209
307
  useEffect(() => {
210
308
  if (!selectedStepId || !rootRef.current) return;
211
309
  const esc = selectedStepId.replace(/["\\]/g, "\\$&");
310
+ const reduced =
311
+ typeof window !== "undefined" &&
312
+ typeof window.matchMedia === "function" &&
313
+ window.matchMedia("(prefers-reduced-motion: reduce)").matches;
314
+ const behavior: ScrollBehavior = reduced ? "auto" : "smooth";
212
315
  for (const attr of ["data-node", "data-step"]) {
213
316
  rootRef.current
214
317
  .querySelector(`[${attr}="${esc}"]`)
215
- ?.scrollIntoView({ block: "nearest", inline: "nearest" });
318
+ ?.scrollIntoView({ block: "nearest", inline: "nearest", behavior });
216
319
  }
217
- }, [selectedStepId]);
218
- const doneCount = allAgents.filter(a => a.status === "complete" || a.status === "error" || a.status === "blocked").length;
320
+ }, [selectedStepId, cardsCollapsed]);
321
+ const doneCount = allAgents.filter(a => a.status === "complete" || a.status === "error" || a.status === "blocked" || a.status === "skipped").length;
322
+ const counts = stepStateCounts(agents);
219
323
  const totalCount = allAgents.length;
220
- const isRunning = !idle && flowState.status === "running";
221
- const isComplete = !idle && !isRunning;
324
+ const isRunning = mode === "live";
222
325
  const progressText = idle
223
326
  ? t("flowNotStarted", undefined, "not started")
224
327
  : t("stepsCount", { done: doneCount, total: totalCount }, `${doneCount}/${totalCount} steps`);
225
328
 
226
- // After completion, show summary. Forward sessionId so the summary's per-session
227
- // collapse state persists (the hook no-ops without a session id).
228
- // See change: fix-flow-ui-graph-zoom-summary.
229
- if (isComplete) {
230
- return (
231
- <FlowSummary
232
- flowState={flowState}
233
- onDismiss={onDismiss}
234
- onSendPrompt={onSendPrompt}
235
- sessionId={sessionId}
236
- />
237
- );
238
- }
329
+ // Parent-mailbox questions: the run's open questions, the whole-run waiting
330
+ // state and one 30 s clock for every remaining time in this panel.
331
+ // See change: adopt-flow-parent-mailbox (D6).
332
+ const runOpen = isRunning ? openQuestions(flowState) : [];
333
+ const runOpenIds = runOpen.map((q) => q.id);
334
+ const shownOpen = openQuestions(shownState);
335
+ const waiting = isRunning ? waitingState(flowState) : null;
336
+ const now = useMinuteClock([...runOpen, ...shownOpen].some((q) => typeof q.expiresAt === "number"));
337
+ const remainingOf = (state: FlowState) => {
338
+ const at = nearestExpiry(state);
339
+ return at === undefined ? null : formatRemaining(at, now, t);
340
+ };
341
+ const runRemaining = runOpen.length > 0 ? remainingOf(flowState) : null;
342
+ const waitingText = waiting
343
+ ? waiting.kind === "waiting"
344
+ ? t("waitingForAnswer", undefined, "waiting for answer")
345
+ : t("nWaitingForAnswer", { n: waiting.n }, `${waiting.n} waiting for answer`)
346
+ : null;
239
347
 
240
348
  const handleTabClick = (tabId: string) => {
241
349
  setActiveTabId(tabId);
@@ -251,8 +359,9 @@ export function FlowDashboard({
251
359
  }
252
360
  };
253
361
 
254
- // Mobile collapsed bar
255
- if (isMobile && !mobileExpanded) {
362
+ // Mobile collapsed bar (not-started and running only; a completed flow
363
+ // renders its full panel).
364
+ if (isMobile && !mobileExpanded && !isSummary) {
256
365
  return (
257
366
  <div
258
367
  onClick={() => setMobileExpanded(true)}
@@ -261,20 +370,125 @@ export function FlowDashboard({
261
370
  <span className="text-blue-400 text-sm">π</span>
262
371
  <span className="text-sm text-[var(--text-primary)] truncate flex-1">
263
372
  {flowState.flowName} · {progressText}
373
+ {waitingText && <span className="ml-1.5 text-[var(--accent-purple-text)] font-medium">· {waitingText}</span>}
264
374
  </span>
375
+ {runOpen.length > 0 && <QuestionPill count={runOpen.length} remaining={runRemaining} />}
265
376
  <span className="text-[10px] text-[var(--text-tertiary)]">tap to expand</span>
266
377
  </div>
267
378
  );
268
379
  }
269
380
 
381
+ const graphBlock = (
382
+ <>
383
+ <FlowGraph
384
+ steps={flowStateToGraphSteps(shownState)}
385
+ fit
386
+ selectedStepId={selectedStepId}
387
+ onSelectStep={handleSelectNode}
388
+ onExpand={Dialog ? () => setGraphOpen(true) : undefined}
389
+ />
390
+ {shownState.flowSource && (
391
+ <div className="mt-1">
392
+ <FlowYamlPopoverButton
393
+ flowSource={shownState.flowSource}
394
+ flowName={shownState.flowName}
395
+ sessionId={sessionId}
396
+ />
397
+ </div>
398
+ )}
399
+ {/* Expanded graph — centered Dialog with pan/zoom. See change: show-flow-cards-in-summary. */}
400
+ {Dialog && (
401
+ <Dialog
402
+ open={graphOpen}
403
+ onClose={() => setGraphOpen(false)}
404
+ title={`Flow graph · ${shownState.flowName}`}
405
+ size="full"
406
+ >
407
+ {/* Non-fit (pan/zoom) graph fills the full-size dialog. See change:
408
+ improve-flow-graph-dialog-and-card-interaction. */}
409
+ <div style={{ height: "82vh", overflow: "hidden" }}>
410
+ <FlowGraph
411
+ steps={flowStateToGraphSteps(shownState)}
412
+ selectedStepId={selectedStepId}
413
+ onSelectStep={handleSelectNode}
414
+ />
415
+ </div>
416
+ </Dialog>
417
+ )}
418
+ </>
419
+ );
420
+
421
+ // Agent cards — every step card in a disclosure, collapsed by default
422
+ // (graph-first panel). The header summarises the step count and states so
423
+ // nothing hides silently. Geometry of the grid inside is unchanged (shared
424
+ // helper). See change: update-flows-plugin (D7).
425
+ const cardsSection = (
426
+ <div className="mt-2 rounded-lg border border-[var(--border-secondary)]" data-testid="flow-agent-cards-section">
427
+ <button
428
+ type="button"
429
+ data-testid="flow-agent-cards-toggle"
430
+ aria-expanded={!cardsCollapsed}
431
+ aria-controls={cardsRegionId}
432
+ onClick={toggleCardsCollapsed}
433
+ className="focus-ring w-full flex flex-wrap items-center gap-x-2 gap-y-1 min-h-[44px] sm:min-h-[32px] rounded-lg px-2 text-[12px] font-semibold text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"
434
+ >
435
+ <Icon path={cardsCollapsed ? mdiChevronRight : mdiChevronDown} size={0.6} className="text-[var(--text-secondary)]" />
436
+ <span>{t("agentCards", undefined, "Agent cards")}</span>
437
+ <span className="text-[var(--text-secondary)]" data-testid="flow-agent-cards-count">{counts.steps}</span>
438
+ <span className="flex flex-wrap items-center gap-1 font-normal">
439
+ {counts.done > 0 && <SettingsStatusPill tone="success">{t("cardsDone", { n: counts.done }, `${counts.done} done`)}</SettingsStatusPill>}
440
+ {counts.running > 0 && <SettingsStatusPill tone="info">{t("cardsRunning", { n: counts.running }, `${counts.running} running`)}</SettingsStatusPill>}
441
+ {counts.failed > 0 && <SettingsStatusPill tone="error">{t("cardsFailed", { n: counts.failed }, `${counts.failed} failed`)}</SettingsStatusPill>}
442
+ {counts.skipped > 0 && <SettingsStatusPill tone="neutral">{t("cardsSkipped", { n: counts.skipped }, `${counts.skipped} skipped`)}</SettingsStatusPill>}
443
+ {shownOpen.length > 0 && <QuestionPill count={shownOpen.length} remaining={remainingOf(shownState)} />}
444
+ </span>
445
+ </button>
446
+ <div id={cardsRegionId} hidden={cardsCollapsed} className="p-2 pt-0">
447
+ {!cardsCollapsed && (
448
+ <FlowStepCards
449
+ state={shownState}
450
+ agents={agents}
451
+ session={session}
452
+ sessionId={sessionId}
453
+ selectedStepId={selectedStepId}
454
+ onSelect={handleSelectStep}
455
+ now={now}
456
+ />
457
+ )}
458
+ </div>
459
+ </div>
460
+ );
461
+
270
462
  return (
271
463
  <div
272
464
  ref={rootRef}
273
465
  data-testid="flow-dashboard"
274
- data-flow-mode={idle ? "idle" : "live"}
466
+ data-flow-mode={mode}
275
467
  className="bg-[var(--bg-secondary)] border-b border-[var(--border-subtle)] px-3 py-2"
276
468
  >
277
469
  {/* Header */}
470
+ {isSummary ? (
471
+ <div className="flex items-center gap-2 mb-1.5">
472
+ {/* Minimal disclosure chevron, left of the flow name (not near Dismiss). */}
473
+ <button
474
+ onClick={toggleCollapsed}
475
+ data-testid="flow-summary-panel-toggle"
476
+ title={collapsed ? "Expand summary" : "Collapse summary"}
477
+ aria-expanded={!collapsed}
478
+ className="inline-flex -ml-0.5 text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"
479
+ >
480
+ <Icon path={collapsed ? mdiChevronRight : mdiChevronDown} size={0.6} />
481
+ </button>
482
+ <FlowSummaryStatus flowState={flowState} agents={agents} />
483
+ {headerActions}
484
+ <button
485
+ onClick={onDismiss}
486
+ className="text-[11px] px-1.5 py-0.5 rounded border border-[var(--border-subtle)] text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"
487
+ >
488
+ <Icon path={mdiCloseCircleOutline} size={0.4} className="inline mr-0.5" />Dismiss
489
+ </button>
490
+ </div>
491
+ ) : (
278
492
  <div className="flex items-center gap-2 mb-2">
279
493
  <span
280
494
  className="inline-flex text-[var(--text-tertiary)] cursor-pointer"
@@ -282,7 +496,17 @@ export function FlowDashboard({
282
496
  >
283
497
  <Icon path={collapsed ? mdiChevronRight : mdiChevronDown} size={0.6} />
284
498
  </span>
285
- {isRunning ? (
499
+ {/* Every working step waits on a question → a static purple `?`
500
+ replaces the spinner; mixed keeps the spinner. (D6) */}
501
+ {isRunning && waiting?.kind === "waiting" ? (
502
+ <Icon
503
+ path={mdiHelpCircleOutline}
504
+ size={0.55}
505
+ className="text-[var(--accent-purple-text)] shrink-0"
506
+ aria-label={t("waitingAria", undefined, "waiting for an answer")}
507
+ data-testid="flow-waiting-icon"
508
+ />
509
+ ) : isRunning ? (
286
510
  <Icon path={mdiLoading} size={0.55} className="text-blue-400 animate-spin shrink-0" />
287
511
  ) : (
288
512
  <span className="text-blue-400 text-sm font-medium">π</span>
@@ -290,24 +514,25 @@ export function FlowDashboard({
290
514
  <span className="text-sm text-[var(--text-primary)] truncate flex-1">
291
515
  {flowState.flowName}
292
516
  <span className="text-[var(--text-tertiary)] ml-1.5">{progressText}</span>
517
+ {waitingText && (
518
+ <span data-testid="flow-waiting-text" className="ml-1.5 text-[var(--accent-purple-text)] font-medium">
519
+ · {waitingText}
520
+ </span>
521
+ )}
293
522
  </span>
294
523
 
295
- {/* Controls */}
296
- <button
297
- onClick={(e) => { e.stopPropagation(); onToggleAutonomous(); }}
298
- className={`text-[10px] px-1.5 py-0.5 rounded border ${
299
- flowState.autonomousMode
300
- ? "border-green-500/40 text-green-400 bg-green-500/10"
301
- : "border-[var(--border-subtle)] text-[var(--text-tertiary)]"
302
- }`}
303
- title={t("toggleAutonomousMode", undefined, "Toggle autonomous mode")}
304
- >
305
- <Icon path={mdiRobotOutline} size={0.4} className="inline mr-0.5" />AUTO
306
- </button>
524
+ {/* Collapsed: the open-question pill and Ask session. (D6) */}
525
+ {collapsed && runOpen.length > 0 && (
526
+ <>
527
+ <QuestionPill count={runOpen.length} remaining={runRemaining} />
528
+ <HeaderAskSession questionIds={runOpenIds} testId="flow-header-ask-session" />
529
+ </>
530
+ )}
531
+ {headerActions}
307
532
  {idle && <IdleControls idle={idle} />}
308
533
  {isRunning && (
309
534
  <button
310
- onClick={(e) => { e.stopPropagation(); onAbort(); }}
535
+ onClick={(e) => { e.stopPropagation(); onAbort(shownState); }}
311
536
  className="text-[10px] px-1.5 py-0.5 rounded border border-red-500/30 text-red-400 hover:bg-red-500/10"
312
537
  title={t("abortFlow", undefined, "Abort flow")}
313
538
  >
@@ -323,8 +548,25 @@ export function FlowDashboard({
323
548
  </button>
324
549
  )}
325
550
  </div>
551
+ )}
326
552
 
327
- {/* DAG graph — structural minimap */}
553
+ {isSummary ? (
554
+ <>
555
+ {/* Completed panel: collapse unmounts the body. Everything UNDER the
556
+ graph lives in ONE fixed-height scroll box so the panel always
557
+ fits the viewport. See change: unify-flow-rendering (D1). */}
558
+ {!collapsed && (
559
+ <>
560
+ {graphBlock}
561
+ <div className="mt-2 overflow-y-auto" style={{ maxHeight: "48vh" }} data-testid="flow-summary-scrollbox">
562
+ {cardsSection}
563
+ <FlowSummarySections flowState={flowState} agents={agents} onSendPrompt={onSendPrompt} />
564
+ </div>
565
+ </>
566
+ )}
567
+ </>
568
+ ) : (
569
+ /* DAG graph — structural minimap */
328
570
  <div className={`group-collapse ${collapsed ? "collapsed" : "expanded"}`}>
329
571
  <div>
330
572
  {/* Tab bar for multi-flow navigation */}
@@ -339,192 +581,15 @@ export function FlowDashboard({
339
581
  {/* Phase-2 breadcrumb decorator slot. See change: add-extension-ui-decorations. */}
340
582
  <BreadcrumbSlot session={session} />
341
583
 
342
- {/* Pending flow-question card — head of the per-flow FIFO queue.
343
- See change: route-flow-asks-to-upper-slot. */}
344
- {sessionId && (
345
- <FlowQuestionsSection
346
- sessionId={sessionId}
347
- flowId={displayState.flowName}
348
- pendingOnly={!!idle}
349
- />
350
- )}
351
-
352
- <FlowGraph
353
- steps={flowStateToGraphSteps(displayState)}
354
- fit
355
- selectedStepId={selectedStepId}
356
- onSelectStep={handleSelectStep}
357
- onExpand={Dialog ? () => setGraphOpen(true) : undefined}
358
- />
359
- {displayState.flowSource && (
360
- <div className="mt-1">
361
- <FlowYamlPopoverButton
362
- flowSource={displayState.flowSource}
363
- flowName={displayState.flowName}
364
- sessionId={sessionId}
365
- />
366
- </div>
367
- )}
368
- {/* Expanded graph — centered Dialog with pan/zoom. See change: show-flow-cards-in-summary. */}
369
- {Dialog && (
370
- <Dialog
371
- open={graphOpen}
372
- onClose={() => setGraphOpen(false)}
373
- title={`Flow graph · ${displayState.flowName}`}
374
- size="full"
375
- >
376
- {/* Non-fit (pan/zoom) graph fills the full-size dialog. See change:
377
- improve-flow-graph-dialog-and-card-interaction. */}
378
- <div style={{ height: "82vh", overflow: "hidden" }}>
379
- <FlowGraph
380
- steps={flowStateToGraphSteps(displayState)}
381
- selectedStepId={selectedStepId}
382
- onSelectStep={handleSelectStep}
383
- />
384
- </div>
385
- </Dialog>
386
- )}
387
-
388
- {/* Agent card grid — detailed per-agent info. Geometry comes from the
389
- shared helper; the wrapper is the query container (design D1/D5). */}
390
- <div className={`${FLOW_CARD_GRID_CONTAINER_CLASS} mt-2`}>
391
- <div className={FLOW_CARD_GRID_CLASS}>
392
- {agents.map(agent => (
393
- <FlowAgentCard
394
- key={agent.stepId || agent.agentName}
395
- agent={agent}
396
- session={session}
397
- sessionId={sessionId}
398
- selected={selectedStepId === (agent.stepId || agent.agentName)}
399
- onSelect={handleSelectStep}
400
- />
401
- ))}
402
- </div>
403
- </div>
584
+ {graphBlock}
585
+ {cardsSection}
404
586
  </div>
405
587
  </div>
588
+ )}
406
589
  </div>
407
590
  );
408
591
  }
409
592
 
410
- /**
411
- * Renders the head of the per-flow `flow-question` queue. Derived from
412
- * the shell's active interactive UI requests, filtered by component
413
- * type `flow-question` and grouped by `flowId`. The first matching
414
- * request is the head; queue depth shown as a "+N more queued" badge
415
- * on the rendered card.
416
- *
417
- * Returns null when no flow-question is pending for `flowId`.
418
- *
419
- * See change: route-flow-asks-to-upper-slot.
420
- */
421
- /** Most recent N transcript entries kept visible. See change: fix-flows-plugin-polish (C3). */
422
- const FLOW_QUESTION_TRANSCRIPT_CAP = 10;
423
-
424
- /**
425
- * Renders the per-flow flow-question transcript above the agent grid.
426
- *
427
- * Includes ALL flow-question prompts for `flowId` — pending AND answered —
428
- * in insertion order (oldest first), capped at {@link FLOW_QUESTION_TRANSCRIPT_CAP}.
429
- * Pending entries render as the interactive `FlowQuestionCard`;
430
- * answered/cancelled/dismissed entries render as a collapsed
431
- * `FlowQuestionTranscriptPill`.
432
- *
433
- * Chat suppresses widget-bar prompts (B2) so the slot is the single visible
434
- * site — no double-render.
435
- *
436
- * See change: fix-flows-plugin-polish (C3).
437
- */
438
- function FlowQuestionsSection({
439
- sessionId,
440
- flowId,
441
- pendingOnly = false,
442
- }: {
443
- sessionId: string;
444
- flowId: string;
445
- /** Idle panel: only still-pending questions (no earlier-run transcript).
446
- * See change: attach-flow-before-run (D2). */
447
- pendingOnly?: boolean;
448
- }) {
449
- const requests = useSessionInteractiveRequests(sessionId);
450
- const send = usePluginSend();
451
- // Card callbacks cannot own the send promise — discard it explicitly.
452
- // See change: cleanup-client-plugin-promises.
453
- const dispatch = useMemo(() => makeSafeSend(send), [send]);
454
-
455
- const queue = useMemo<InteractiveUiRequestSnapshot[]>(() => {
456
- const out: InteractiveUiRequestSnapshot[] = [];
457
- for (const req of requests) {
458
- const cmp = req.params._promptBusComponent as
459
- | { type?: string; props?: { flowId?: unknown } }
460
- | undefined;
461
- if (cmp?.type !== "flow-question") continue;
462
- if (cmp?.props?.flowId !== flowId) continue;
463
- if (pendingOnly && req.status !== "pending") continue;
464
- out.push(req);
465
- }
466
- return out.slice(-FLOW_QUESTION_TRANSCRIPT_CAP);
467
- }, [requests, flowId, pendingOnly]);
468
-
469
- if (queue.length === 0) return null;
470
-
471
- const pendingCount = queue.filter((r) => r.status === "pending").length;
472
-
473
- return (
474
- <div data-testid="flow-questions-transcript" className="flex flex-col gap-1">
475
- {queue.map((req) => {
476
- const props =
477
- (req.params._promptBusComponent as { props?: Record<string, unknown> }).props ?? {};
478
- const question = typeof props.question === "string" ? props.question : "";
479
- if (req.status === "pending") {
480
- const submit = (answer: string) => {
481
- dispatch({
482
- type: "prompt_response",
483
- sessionId,
484
- promptId: req.requestId,
485
- answer,
486
- source: "dashboard-flow-question",
487
- });
488
- };
489
- const dismiss = () => {
490
- dispatch({ type: "prompt_cancel", sessionId, promptId: req.requestId });
491
- };
492
- return (
493
- <FlowQuestionCard
494
- key={req.requestId}
495
- sessionId={sessionId}
496
- promptId={req.requestId}
497
- flowId={typeof props.flowId === "string" ? props.flowId : flowId}
498
- stepId={typeof props.stepId === "string" ? props.stepId : ""}
499
- question={question}
500
- type={(props.type as FlowQuestionCardType) ?? "input"}
501
- options={Array.isArray(props.options) ? (props.options as string[]) : undefined}
502
- defaultValue={
503
- typeof props.defaultValue === "string" ? props.defaultValue : undefined
504
- }
505
- queueDepth={pendingCount}
506
- onSubmit={submit}
507
- onDismiss={dismiss}
508
- />
509
- );
510
- }
511
- const answer = typeof req.result === "string" ? req.result : undefined;
512
- return (
513
- <FlowQuestionTranscriptPill
514
- key={req.requestId}
515
- question={question}
516
- answer={answer}
517
- status={req.status}
518
- />
519
- );
520
- })}
521
- </div>
522
- );
523
- }
524
-
525
- type FlowQuestionCardType = "select" | "input" | "confirm" | "editor" | "multiselect";
526
-
527
- const EMPTY_FLOWS: FlowInfo[] = [];
528
593
  const LOADING: IdleLoad = Object.freeze({ kind: "loading" }) as IdleLoad;
529
594
 
530
595
  /**
@@ -541,6 +606,9 @@ function useAttachedFlowState(attachment: FlowAttachment | null, sessionId: stri
541
606
  const t = useT();
542
607
  const name = attachment?.name ?? "";
543
608
  const source = attachment?.source;
609
+ // View-only (path-opened) files are admitted on the plugin route only.
610
+ // See change: add-flow-open-tool (D7).
611
+ const noHostFallback = attachment?.viewOnly === true;
544
612
  const key = attachment ? `${attachment.id}\u0000${source ?? ""}` : "";
545
613
  const [state, setState] = useState<{ key: string; load: IdleLoad } | null>(null);
546
614
 
@@ -551,7 +619,7 @@ function useAttachedFlowState(attachment: FlowAttachment | null, sessionId: stri
551
619
  if (!cancelled) setState({ key, load: { kind: "error", message } });
552
620
  };
553
621
  // Plugin file endpoint (runtime-registered flow dirs) → host fallback.
554
- fetchFlowFile(sessionId, source)
622
+ fetchFlowFile(sessionId, source, { noHostFallback })
555
623
  .then((content) => {
556
624
  if (!cancelled) setState({ key, load: buildIdleFlowState(content, { name, source }) });
557
625
  })
@@ -559,7 +627,7 @@ function useAttachedFlowState(attachment: FlowAttachment | null, sessionId: stri
559
627
  return () => {
560
628
  cancelled = true;
561
629
  };
562
- }, [key, name, source, sessionId, reportReady]);
630
+ }, [key, name, source, sessionId, reportReady, noHostFallback]);
563
631
 
564
632
  if (!attachment) return LOADING;
565
633
  if (!source) {
@@ -687,10 +755,11 @@ function FlowSlotMessage({
687
755
  */
688
756
  export function FlowDashboardClaim({ session }: { session: DashboardSession }) {
689
757
  const sessionId = session.id;
690
- const { flowState, flowStates, lastFlowStartedAt, lastAutonomousMode, lastRejection } =
691
- useFlowsSessionState(sessionId);
758
+ const { flowState, flowStates, lastFlowStartedAt, lastRejection } = useFlowsSessionState(sessionId);
692
759
  const events = useSessionEvents(sessionId);
693
- const flowsList = useSessionData<FlowInfo[]>(sessionId, "flowsList") ?? EMPTY_FLOWS;
760
+ // Viewed session's flow panel: re-asks while the catalog is unknown.
761
+ // See change: flows-dock-chip-and-panel-actions (D3, D5).
762
+ const { flows: catalogFlows } = useFlowCatalog(sessionId, { autoAsk: true });
694
763
  const attachment = useFlowAttachment(sessionId);
695
764
  // Reported agent / handler file paths. Polling lives here (not in the panel)
696
765
  // because the panel does not render while the attached flow is loading or has
@@ -707,7 +776,7 @@ export function FlowDashboardClaim({ session }: { session: DashboardSession }) {
707
776
  attachment,
708
777
  idle: idleLoad,
709
778
  lastFlowStartedAt,
710
- flowsList,
779
+ flows: catalogFlows,
711
780
  });
712
781
 
713
782
  // Baseline from the first non-empty snapshot when attached on an empty
@@ -729,14 +798,7 @@ export function FlowDashboardClaim({ session }: { session: DashboardSession }) {
729
798
  const isIdle = slot.mode === "idle";
730
799
  const run = useIdleRun(isIdle, attachment?.id, attachedName, lastRejection);
731
800
 
732
- // AUTO shows the last known value (engine default on). Shallow override keeps
733
- // the memoized agents / dagSteps references. (D8)
734
- const idleFlowState = isIdle ? slot.flowState : undefined;
735
- const autonomousMode = lastAutonomousMode ?? true;
736
- const idleDisplayState = useMemo(
737
- () => (idleFlowState ? { ...idleFlowState, autonomousMode } : undefined),
738
- [idleFlowState, autonomousMode],
739
- );
801
+ const idleDisplayState = isIdle ? slot.flowState : undefined;
740
802
 
741
803
  if (typeof import.meta !== "undefined" && (import.meta as { env?: { DEV?: boolean } }).env?.DEV) {
742
804
  // eslint-disable-next-line no-console
@@ -749,18 +811,49 @@ export function FlowDashboardClaim({ session }: { session: DashboardSession }) {
749
811
  });
750
812
  }
751
813
 
752
- const flowControl = (action: string) => send({ type: "flow_control", sessionId, action });
814
+ // Flow commands go to the flows plugin server as plugin_action, which relays
815
+ // fixed pi events. See change: update-flows-plugin (D2).
816
+ const flowControl = (action: "flow.abort") =>
817
+ send({ type: "plugin_action", pluginId: "flows", sessionId, action });
818
+ // Abort also closes the slot run when it runs, has a runId and is the run
819
+ // displayed (no other tab selected), so it never reopens after a restart.
820
+ // A failed dismiss leaves the run visible until a dismiss event arrives.
821
+ // See change: fix-flow-reattach-per-run-state (D6).
822
+ const abort = (displayed: FlowState) => {
823
+ const sends = [flowControl("flow.abort")];
824
+ if (flowState?.status === "running" && flowState.runId && displayed === flowState) sends.push(dismissRun(flowState.runId));
825
+ for (const p of sends) {
826
+ void Promise.resolve(p).catch((err: unknown) => console.error("[flows-plugin] plugin send failed:", err));
827
+ }
828
+ };
829
+ // Dismiss names the run so the bridge persists it and replay keeps it gone.
830
+ // See change: persist-flow-run-close (D3, D4).
831
+ const dismissRun = (runId: string | undefined) =>
832
+ send({ type: "plugin_action", pluginId: "flows", sessionId, action: "flow.dismiss-summary", ...(runId ? { payload: { runId } } : {}) });
753
833
  const detach = () => {
754
834
  if (attachment) clearAttachment(sessionId, attachment.id);
755
835
  };
836
+ // Idle Close also dismisses the finished run the slot would fall back to, so
837
+ // the slot ends empty and (with a runId) stays empty after replay; a run
838
+ // without runId gets the legacy live-only clear-all. (D5)
839
+ const closeIdle = () => {
840
+ detach();
841
+ if (flowState && flowState.status !== "running") void dismissRun(flowState.runId);
842
+ };
756
843
 
757
844
  if (slot.mode === "none") return null;
758
845
 
759
846
  if (slot.mode === "loading" || slot.mode === "error") {
847
+ // A view-only definition the server no longer admits (e.g. after a restart):
848
+ // the agent can open it again. See change: add-flow-open-tool (D7).
849
+ const reopen =
850
+ slot.error?.kind === "load" && attachment?.viewOnly
851
+ ? ` · ${t("flowViewOnlyReopenHint", undefined, "ask the agent to open it again")}`
852
+ : "";
760
853
  return (
761
854
  <FlowSlotMessage
762
855
  name={attachedName ?? ""}
763
- message={slotMessage(slot, t)}
856
+ message={slotMessage(slot, t) + reopen}
764
857
  tone={slot.mode === "error" ? "error" : "muted"}
765
858
  onClose={detach}
766
859
  />
@@ -768,30 +861,39 @@ export function FlowDashboardClaim({ session }: { session: DashboardSession }) {
768
861
  }
769
862
 
770
863
  const shown = idleDisplayState ?? slot.flowState!;
771
- const flowInfo = flowsList.find((f) => f.name === shown.flowName);
864
+ const flowInfo = catalogFlows.find((f) => f.name === shown.flowName);
865
+ const headerVariant = isIdle ? "idle" : shown.status === "running" ? "live" : "summary";
772
866
 
773
867
  return (
774
868
  <>
775
869
  <FlowDashboard
776
- key={shown.flowName}
870
+ key={`${shown.flowName}:${headerVariant === "summary" ? "summary" : "active"}`}
777
871
  flowState={shown}
778
872
  flowStates={isIdle ? undefined : (flowStates as Map<string, FlowState>)}
779
873
  session={session}
780
874
  sessionId={sessionId}
781
875
  nodeFiles={nodeFiles}
876
+ headerActions={
877
+ <FlowHeaderActions
878
+ sessionId={sessionId}
879
+ flowName={shown.flowName}
880
+ variant={headerVariant}
881
+ viewOnly={isIdle && attachment?.viewOnly === true}
882
+ />
883
+ }
782
884
  idle={
783
885
  isIdle
784
886
  ? {
785
887
  onRun: run.open,
786
- onClose: detach,
888
+ onClose: closeIdle,
787
889
  runDisabled: run.pending,
788
890
  rejectionReason: run.rejectionReason,
891
+ viewOnly: attachment?.viewOnly === true,
789
892
  }
790
893
  : undefined
791
894
  }
792
- onAbort={() => flowControl("abort")}
793
- onToggleAutonomous={() => flowControl("toggle_autonomous")}
794
- onDismiss={() => flowControl("dismiss_summary")}
895
+ onAbort={abort}
896
+ onDismiss={() => dismissRun(shown.runId)}
795
897
  onSendPrompt={(text: string, images?: ImageContent[]) =>
796
898
  send({ type: "send_prompt", sessionId, text, images })
797
899
  }
@@ -806,7 +908,13 @@ export function FlowDashboardClaim({ session }: { session: DashboardSession }) {
806
908
  // Own the promise: a failed send yields no rejection event, so
807
909
  // re-enable Run here. See change: attach-flow-before-run (D7).
808
910
  void Promise.resolve(
809
- send({ type: "flow_management", sessionId, action: "run", flowName: shown.flowName, task: task || undefined }),
911
+ send({
912
+ type: "plugin_action",
913
+ pluginId: "flows",
914
+ sessionId,
915
+ action: "flow.run",
916
+ payload: { flowName: shown.flowName, ...(task ? { task } : {}) },
917
+ }),
810
918
  ).catch((err: unknown) => {
811
919
  console.error("[flows-plugin] plugin send failed:", err);
812
920
  run.sendFailed(submission);