@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,82 @@
1
+ /**
2
+ * Always-mounted, zero-UI receiver of the agent `flow_open` pin (D6).
3
+ *
4
+ * Claimed on `shell-headless`, so every connected browser stores the pin even
5
+ * when the session is off screen or on the mobile layout (where the session
6
+ * card action bar is not mounted). On `flows_open` it writes the attachment
7
+ * with the SERVER-stamped baseline (call time, same host clock as event
8
+ * timestamps — a flow started later consumes it), expands the flow panel like
9
+ * Open flow… does, and acknowledges `flows_open_ack {sessionId, requestId}`.
10
+ * A bounded module-level requestId set (128) stops double handling per tab.
11
+ *
12
+ * Manifest claim: `{ "slot": "shell-headless", "component": "FlowOpenListener" }`.
13
+ * See change: add-flow-open-tool.
14
+ */
15
+ import { usePluginMessage, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime";
16
+ import { newAttachmentId, setAttachment } from "./flow-attach-store.js";
17
+ import { setFlowCollapsed } from "./flow-collapse-storage.js";
18
+
19
+ const FLOWS_OPEN_FRAME = "flows_open";
20
+ const FLOWS_OPEN_ACK = "flows_open_ack";
21
+ const MAX_SEEN_REQUESTS = 128;
22
+
23
+ interface FlowsOpenFrame {
24
+ sessionId?: unknown;
25
+ requestId?: unknown;
26
+ attachment?: { name?: unknown; source?: unknown; viewOnly?: unknown; baselineStartedAt?: unknown };
27
+ }
28
+
29
+ const seen = new Set<string>();
30
+
31
+ /** Record a requestId; false when already handled. Oldest evicted past the bound. */
32
+ function markSeen(requestId: string): boolean {
33
+ if (seen.has(requestId)) return false;
34
+ seen.add(requestId);
35
+ while (seen.size > MAX_SEEN_REQUESTS) {
36
+ const oldest = seen.values().next().value;
37
+ if (oldest === undefined) break;
38
+ seen.delete(oldest);
39
+ }
40
+ return true;
41
+ }
42
+
43
+ /** Store one pin; returns the ack to send, or null for a malformed / duplicate frame. */
44
+ function applyFlowsOpen(msg: FlowsOpenFrame): { type: string; sessionId: string; requestId: string } | null {
45
+ const { sessionId, requestId, attachment: a } = msg ?? {};
46
+ if (typeof sessionId !== "string" || !sessionId || typeof requestId !== "string" || !requestId) return null;
47
+ if (!a || typeof a.name !== "string" || !a.name) return null;
48
+ if (!markSeen(requestId)) return null;
49
+ setAttachment(sessionId, {
50
+ id: newAttachmentId(),
51
+ name: a.name,
52
+ source: typeof a.source === "string" ? a.source : undefined,
53
+ baselineStartedAt: typeof a.baselineStartedAt === "number" && Number.isFinite(a.baselineStartedAt) ? a.baselineStartedAt : null,
54
+ ...(a.viewOnly === true ? { viewOnly: true as const } : {}),
55
+ });
56
+ setFlowCollapsed(sessionId, ["dashboard"], false);
57
+ return { type: FLOWS_OPEN_ACK, sessionId, requestId };
58
+ }
59
+
60
+ export function FlowOpenListener(): null {
61
+ const send = usePluginSend();
62
+ usePluginMessage<FlowsOpenFrame>(FLOWS_OPEN_FRAME, (msg) => {
63
+ const ack = applyFlowsOpen(msg);
64
+ if (!ack) return;
65
+ try {
66
+ void send(ack);
67
+ } catch {
68
+ /* no socket: the server counts no ack */
69
+ }
70
+ });
71
+ return null;
72
+ }
73
+
74
+ /** Test-only: forget handled requestIds. */
75
+ export function __resetFlowOpenSeenForTests(): void {
76
+ seen.clear();
77
+ }
78
+
79
+ /** Test-only: number of remembered requestIds. */
80
+ export function __flowOpenSeenSizeForTests(): number {
81
+ return seen.size;
82
+ }
@@ -0,0 +1,226 @@
1
+ /**
2
+ * Question block inside an asking agent card, styled like the card's
3
+ * program-log block (`ui:log-block`): an inset panel with an uppercase header
4
+ * (`QUESTION · <remaining>` + chevron), a body and a footer.
5
+ *
6
+ * - Collapsed: the question clamped to two lines (full text in `title`) and an
7
+ * options summary (inline when 1–4 of ≤ 16 chars, else `N options`, else
8
+ * `free answer`).
9
+ * - Expanded: full text, numbered options and a Context section (collapsed by
10
+ * default) in a bounded scroll box. Context renders as React text nodes only.
11
+ * - Footer: the note (`unread` / `sent` / `no confirmation`) and **Ask session**.
12
+ *
13
+ * Colours come from theme tokens (`--accent-purple-text`, `--tint-purple-*`,
14
+ * `tint-action-purple`). See change: adopt-flow-parent-mailbox (D4, D5).
15
+ */
16
+ import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
17
+ import { mdiChevronDown, mdiChevronRight, mdiChevronUp, mdiHelpCircleOutline } from "@mdi/js";
18
+ import { Icon } from "@mdi/react";
19
+ import { useState } from "react";
20
+ import { formatRemaining, optionsSummary } from "../flow-questions.js";
21
+ import type { FlowQuestionContext, FlowQuestionState } from "../types.js";
22
+ import { AskSessionButton, useAskSessionApi } from "./AskSession.js";
23
+ import type { AskView } from "./ask-session-store.js";
24
+
25
+ const asText = (v: unknown): string => {
26
+ if (typeof v === "string") return v;
27
+ try {
28
+ return JSON.stringify(v) ?? String(v);
29
+ } catch {
30
+ return String(v);
31
+ }
32
+ };
33
+
34
+ interface ContextRows {
35
+ values: Array<[string, string]>;
36
+ files: Array<{ path: string; added?: number; removed?: number }>;
37
+ upstream: Array<[string, string]>;
38
+ fromAsker: string[];
39
+ }
40
+
41
+ /** Normalise a question's context block into text rows. */
42
+ function contextRows(ctx: FlowQuestionContext): ContextRows {
43
+ const values = ctx.values && typeof ctx.values === "object" ? Object.entries(ctx.values).map(([k, v]) => [k, asText(v)] as [string, string]) : [];
44
+ const files = Array.isArray(ctx.changes)
45
+ ? ctx.changes.map((c) => ({
46
+ path: typeof c?.path === "string" ? c.path : asText(c),
47
+ ...(typeof c?.added === "number" ? { added: c.added } : {}),
48
+ ...(typeof c?.removed === "number" ? { removed: c.removed } : {}),
49
+ }))
50
+ : [];
51
+ let upstream: Array<[string, string]> = [];
52
+ if (Array.isArray(ctx.upstream)) {
53
+ upstream = ctx.upstream.map((u, i) => {
54
+ const o = (u ?? {}) as Record<string, unknown>;
55
+ const step = typeof o.stepId === "string" ? o.stepId : typeof o.step === "string" ? o.step : String(i + 1);
56
+ return [step, asText(o.summary ?? u)];
57
+ });
58
+ } else if (ctx.upstream && typeof ctx.upstream === "object") {
59
+ upstream = Object.entries(ctx.upstream).map(([k, v]) => [k, asText(v)]);
60
+ }
61
+ const fromAsker = [ctx.payload !== undefined ? asText(ctx.payload) : "", typeof ctx.text === "string" ? ctx.text : ""].filter(Boolean);
62
+ return { values, files, upstream, fromAsker };
63
+ }
64
+
65
+ function ContextSection({ ctx }: { ctx: FlowQuestionContext }) {
66
+ const t = useT();
67
+ const [open, setOpen] = useState(false);
68
+ const rows = contextRows(ctx);
69
+ return (
70
+ <div data-testid="flow-question-context" className="mt-1 rounded border border-[var(--border-subtle)]">
71
+ <button
72
+ type="button"
73
+ aria-expanded={open}
74
+ onClick={(e) => {
75
+ e.stopPropagation();
76
+ setOpen((v) => !v);
77
+ }}
78
+ className="focus-ring w-full flex items-center gap-1 px-1 py-0.5 text-[11px] text-[var(--text-secondary)]"
79
+ >
80
+ <Icon path={open ? mdiChevronDown : mdiChevronRight} size={0.45} />
81
+ <span>{t("questionContext", undefined, "Context")}</span>
82
+ <span data-testid="flow-question-context-summary" className="text-[var(--text-tertiary)]">
83
+ {t(
84
+ "contextSummary",
85
+ { values: rows.values.length, files: rows.files.length, upstream: rows.upstream.length },
86
+ `${rows.values.length} values · ${rows.files.length} files · ${rows.upstream.length} upstream`,
87
+ )}
88
+ </span>
89
+ </button>
90
+ {open && (
91
+ <div className="px-2 pb-1.5 flex flex-col gap-1 text-[11px] leading-[14px]">
92
+ {rows.values.length > 0 && <div className="text-[var(--text-tertiary)]">{t("contextRunValues", undefined, "Run context")}</div>}
93
+ {rows.values.map(([k, v]) => (
94
+ <div key={k} className="font-mono break-words">
95
+ <span className="text-[var(--text-secondary)]">{k}</span> = <span className="text-[var(--text-primary)]">{v}</span>
96
+ </div>
97
+ ))}
98
+ {rows.files.length > 0 && (
99
+ <div className="text-[var(--text-tertiary)] mt-0.5">{t("contextChangedFiles", undefined, "Changed files")}</div>
100
+ )}
101
+ {rows.files.map((f, i) => (
102
+ <div key={`${f.path}:${i}`} data-testid="flow-question-context-file" className="font-mono flex gap-2 min-w-0">
103
+ <span className="truncate text-[var(--text-secondary)]" title={f.path}>
104
+ {f.path}
105
+ </span>
106
+ {f.added !== undefined && <span className="text-[var(--severity-success-fg)] shrink-0">+{f.added}</span>}
107
+ {f.removed !== undefined && <span className="text-[var(--severity-error-fg)] shrink-0">-{f.removed}</span>}
108
+ </div>
109
+ ))}
110
+ {rows.upstream.length > 0 && <div className="text-[var(--text-tertiary)] mt-0.5">{t("contextUpstream", undefined, "Upstream")}</div>}
111
+ {rows.upstream.map(([s, text]) => (
112
+ <div key={s} className="break-words">
113
+ <span className="font-mono text-[var(--text-secondary)]">{s}</span>: {text}
114
+ </div>
115
+ ))}
116
+ {rows.fromAsker.length > 0 && (
117
+ <div className="text-[var(--text-tertiary)] mt-0.5">{t("contextFromAsker", undefined, "From the asker")}</div>
118
+ )}
119
+ {rows.fromAsker.map((text, i) => (
120
+ <div key={i} className="whitespace-pre-wrap break-words">
121
+ {text}
122
+ </div>
123
+ ))}
124
+ </div>
125
+ )}
126
+ </div>
127
+ );
128
+ }
129
+
130
+ type Translate = ReturnType<typeof useT>;
131
+
132
+ /** Footer note of one question. */
133
+ function noteText(view: AskView | null, t: Translate): string {
134
+ if (view?.note === "sent") return t("askNoteSent", undefined, "sent");
135
+ if (view?.note === "no-confirmation") return t("askNoteNoConfirmation", undefined, "no confirmation");
136
+ return t("askNoteUnread", undefined, "unread");
137
+ }
138
+
139
+ /** Expanded body: full text, numbered options, the Context section. */
140
+ function FullQuestion({ q }: { q: FlowQuestionState }) {
141
+ const t = useT();
142
+ const options = q.options ?? [];
143
+ return (
144
+ <div data-testid="flow-question-full" className="max-h-32 overflow-auto flex flex-col gap-1">
145
+ <div className="whitespace-pre-wrap break-words text-[var(--text-primary)]">{q.question}</div>
146
+ {options.length > 0 ? (
147
+ <ol className="list-decimal pl-4">
148
+ {options.map((o, i) => (
149
+ <li key={`${i}:${o}`} className="break-words">
150
+ {o}
151
+ </li>
152
+ ))}
153
+ </ol>
154
+ ) : (
155
+ <div className="text-[var(--text-tertiary)]">{t("freeAnswer", undefined, "free answer")}</div>
156
+ )}
157
+ {q.context && <ContextSection ctx={q.context} />}
158
+ </div>
159
+ );
160
+ }
161
+
162
+ /** Collapsed body: two-line clamp + options summary. */
163
+ function ClampedQuestion({ q }: { q: FlowQuestionState }) {
164
+ const t = useT();
165
+ const options = q.options ?? [];
166
+ return (
167
+ <>
168
+ <div data-testid="flow-question-text" className="line-clamp-2 break-words text-[var(--text-primary)]" title={q.question}>
169
+ {q.question}
170
+ </div>
171
+ <div
172
+ data-testid="flow-question-options"
173
+ className={`truncate text-[var(--text-tertiary)] ${options.length > 0 ? "font-mono" : ""}`}
174
+ title={options.length > 0 ? options.join("\n") : undefined}
175
+ >
176
+ {optionsSummary(options, t)}
177
+ </div>
178
+ </>
179
+ );
180
+ }
181
+
182
+ export function FlowQuestionBlock({ q, now }: { q: FlowQuestionState; now: number }) {
183
+ const t = useT();
184
+ const api = useAskSessionApi();
185
+ const [expanded, setExpanded] = useState(false);
186
+ const view = api ? api.view(q.id) : null;
187
+ const remaining = typeof q.expiresAt === "number" ? formatRemaining(q.expiresAt, now, t) : null;
188
+ return (
189
+ <div
190
+ data-testid="flow-card-question"
191
+ data-question={q.id}
192
+ className="mt-2 border border-[var(--tint-purple-border)] rounded-lg bg-[var(--bg-tertiary)] overflow-hidden"
193
+ >
194
+ <button
195
+ type="button"
196
+ aria-expanded={expanded}
197
+ data-testid="flow-question-toggle"
198
+ title={expanded ? t("hideFullQuestion", undefined, "Hide full question") : t("showFullQuestion", undefined, "Show full question")}
199
+ onClick={(e) => {
200
+ e.stopPropagation();
201
+ setExpanded((v) => !v);
202
+ }}
203
+ className="focus-ring w-full flex items-center gap-1.5 px-2 py-1 border-b border-[var(--border-primary)] text-[11px] font-bold uppercase tracking-wide text-[var(--accent-purple-text)]"
204
+ >
205
+ <Icon path={mdiHelpCircleOutline} size={0.45} />
206
+ <span>{t("questionHeader", undefined, "QUESTION")}</span>
207
+ {remaining && (
208
+ <span data-testid="flow-question-remaining" className="font-normal normal-case tracking-normal text-[var(--text-tertiary)]">
209
+ · {remaining}
210
+ </span>
211
+ )}
212
+ <span className="flex-1" />
213
+ <Icon path={expanded ? mdiChevronUp : mdiChevronDown} size={0.6} className="text-[var(--text-tertiary)]" />
214
+ </button>
215
+ <div className="px-2.5 py-1.5 text-[11px] leading-relaxed text-[var(--text-secondary)]">
216
+ {expanded ? <FullQuestion q={q} /> : <ClampedQuestion q={q} />}
217
+ </div>
218
+ <div className="flex items-center gap-2 px-2 py-1 border-t border-[var(--border-primary)]">
219
+ <span data-testid="flow-question-note" className="flex-1 min-w-0 truncate text-[11px] text-[var(--text-tertiary)]">
220
+ {noteText(view, t)}
221
+ </span>
222
+ <AskSessionButton view={view} onAsk={() => api?.ask([q.id])} testId="flow-question-ask" />
223
+ </div>
224
+ </div>
225
+ );
226
+ }
@@ -0,0 +1,189 @@
1
+ /**
2
+ * Step card renderer shared by the live panel's Agent cards section:
3
+ *
4
+ * - a fan-out step renders as ONE group card (header: name, `fan-out xN`,
5
+ * ok / failed pills) holding one `FlowAgentCard` per item;
6
+ * - a decision step shows its chosen routes (with item counts) and a
7
+ * "not taken" chip per unchosen branch, or its route error;
8
+ * - a skipped step carries a `skipped` pill and a dimmed card.
9
+ *
10
+ * Pills are the one ui-contract status pill (`SettingsStatusPill`), so state
11
+ * is never colour-only. Approved mock: mockups/2026-11-04-flows-plugin-update
12
+ * frame 1. See change: update-flows-plugin (D6, task 4.5).
13
+ */
14
+ import { SettingsStatusPill, useT } from "@blackbelt-technology/dashboard-plugin-runtime";
15
+ import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
16
+ import React from "react";
17
+ import { openQuestionsFor, questionHistoryFor } from "../flow-questions.js";
18
+ import type { FlowAgentState, FlowState } from "../types.js";
19
+ import { FlowAgentCard } from "./FlowAgentCard.js";
20
+ import { FLOW_CARD_GRID_CLASS, FLOW_CARD_GRID_CONTAINER_CLASS } from "./flow-card-grid.js";
21
+
22
+ interface CardCommon {
23
+ session?: Pick<DashboardSession, "uiDecorators">;
24
+ sessionId?: string;
25
+ selectedStepId: string | null;
26
+ onSelect: (stepId: string) => void;
27
+ /** Clock for question countdowns (one per panel). See change: adopt-flow-parent-mailbox. */
28
+ now?: number;
29
+ }
30
+
31
+ /** Branch labels of a decision step that were not chosen. */
32
+ function notTakenLabels(state: FlowState, stepId: string): string[] {
33
+ const d = state.decisions?.[stepId];
34
+ if (!d || d.routeError) return [];
35
+ const branches = state.dagSteps?.find((s) => s.id === stepId)?.branches ?? {};
36
+ const chosen = new Set((d.routes ?? []).map((r) => r.branch));
37
+ return Object.keys(branches).filter((label) => !chosen.has(label));
38
+ }
39
+
40
+ function DecisionRoutes({ state, stepId }: { state: FlowState; stepId: string }) {
41
+ const t = useT();
42
+ const d = state.decisions?.[stepId];
43
+ if (!d) return null;
44
+ if (d.routeError) {
45
+ return (
46
+ <div data-testid="flow-decision-error" className="flex flex-wrap gap-1 px-1">
47
+ <SettingsStatusPill tone="error">{d.routeError}</SettingsStatusPill>
48
+ </div>
49
+ );
50
+ }
51
+ return (
52
+ <div data-testid="flow-decision-routes" className="flex flex-wrap gap-1 px-1">
53
+ {(d.routes ?? []).map((r) => (
54
+ <SettingsStatusPill key={r.branch} tone="success">
55
+ {r.itemCount !== undefined ? `${r.branch} x${r.itemCount}` : r.branch}
56
+ </SettingsStatusPill>
57
+ ))}
58
+ {notTakenLabels(state, stepId).map((label) => (
59
+ <SettingsStatusPill key={label} tone="neutral">
60
+ {t("routeNotTaken", { label }, `${label}: not taken`)}
61
+ </SettingsStatusPill>
62
+ ))}
63
+ </div>
64
+ );
65
+ }
66
+
67
+ function GroupCard({
68
+ parent,
69
+ items,
70
+ state,
71
+ ...common
72
+ }: CardCommon & { parent: FlowAgentState; items: FlowAgentState[]; state: FlowState }) {
73
+ const t = useT();
74
+ const stepId = parent.stepId || parent.agentName;
75
+ const present = items.filter(Boolean);
76
+ const total = Math.max(present.length, parent.itemCount ?? 0);
77
+ const ok = present.filter((i) => i.status === "complete").length;
78
+ const failed = present.filter((i) => i.status === "error").length;
79
+ const selected = common.selectedStepId === stepId;
80
+ return (
81
+ <div
82
+ data-step={stepId}
83
+ data-testid="flow-group-card"
84
+ className={`col-span-full rounded-xl border p-2 flex flex-col gap-2 ${
85
+ selected ? "border-[var(--accent-primary)]" : "border-[var(--border-secondary)]"
86
+ }`}
87
+ >
88
+ <div className="flex flex-wrap items-center gap-2 text-xs">
89
+ <button
90
+ type="button"
91
+ className="font-medium text-[var(--text-primary)] focus-ring rounded"
92
+ onClick={() => common.onSelect(stepId)}
93
+ >
94
+ {parent.label || stepId}
95
+ </button>
96
+ <SettingsStatusPill tone="neutral">{t("fanOutCount", { n: total }, `fan-out x${total}`)}</SettingsStatusPill>
97
+ <SettingsStatusPill tone="success">{t("itemsOk", { n: ok }, `${ok} ok`)}</SettingsStatusPill>
98
+ {failed > 0 && <SettingsStatusPill tone="error">{t("itemsFailed", { n: failed }, `${failed} failed`)}</SettingsStatusPill>}
99
+ {parent.status === "skipped" && <SettingsStatusPill tone="neutral">{t("stepSkipped", undefined, "skipped")}</SettingsStatusPill>}
100
+ </div>
101
+ <div className="grid gap-2 grid-cols-[repeat(auto-fill,minmax(170px,1fr))]">
102
+ {present.map((item) => (
103
+ <div key={item.itemKey} data-item={item.itemKey}>
104
+ <FlowAgentCard
105
+ agent={{ ...item, label: item.label ?? item.itemKey }}
106
+ session={common.session}
107
+ sessionId={common.sessionId}
108
+ openQuestions={openQuestionsFor(state, stepId, item.itemIndex)}
109
+ questionHistory={questionHistoryFor(state, stepId, item.itemIndex)}
110
+ now={common.now}
111
+ />
112
+ </div>
113
+ ))}
114
+ </div>
115
+ <DecisionRoutes state={state} stepId={stepId} />
116
+ </div>
117
+ );
118
+ }
119
+
120
+ function StepCard({ agent, state, ...common }: CardCommon & { agent: FlowAgentState; state: FlowState }) {
121
+ const t = useT();
122
+ const stepId = agent.stepId || agent.agentName;
123
+ const card = (
124
+ <FlowAgentCard
125
+ agent={agent}
126
+ session={common.session}
127
+ sessionId={common.sessionId}
128
+ selected={common.selectedStepId === stepId}
129
+ onSelect={common.onSelect}
130
+ openQuestions={openQuestionsFor(state, stepId)}
131
+ questionHistory={questionHistoryFor(state, stepId)}
132
+ now={common.now}
133
+ />
134
+ );
135
+ if (agent.status === "skipped") {
136
+ return (
137
+ <div data-testid="flow-skipped-card" className="relative">
138
+ <div className="opacity-60">{card}</div>
139
+ <span className="absolute top-1.5 right-1.5">
140
+ <SettingsStatusPill tone="neutral">{t("stepSkipped", undefined, "skipped")}</SettingsStatusPill>
141
+ </span>
142
+ </div>
143
+ );
144
+ }
145
+ if (state.decisions?.[stepId]) {
146
+ return (
147
+ <div className="flex flex-col gap-1">
148
+ {card}
149
+ <DecisionRoutes state={state} stepId={stepId} />
150
+ </div>
151
+ );
152
+ }
153
+ return card;
154
+ }
155
+
156
+ /** Every step card of `state`, in step order (a fan-out group is one entry). */
157
+ export function FlowStepCards({ state, agents, ...common }: CardCommon & { state: FlowState; agents: FlowAgentState[] }) {
158
+ return (
159
+ <div className={FLOW_CARD_GRID_CONTAINER_CLASS}>
160
+ <div className={FLOW_CARD_GRID_CLASS}>
161
+ {agents.map((agent) => {
162
+ const stepId = agent.stepId || agent.agentName;
163
+ const items = state.groups?.[stepId];
164
+ if (items && (items.length > 0 || agent.itemCount !== undefined)) {
165
+ return <GroupCard key={stepId} parent={agent} items={items} state={state} {...common} />;
166
+ }
167
+ return <StepCard key={stepId} agent={agent} state={state} {...common} />;
168
+ })}
169
+ </div>
170
+ </div>
171
+ );
172
+ }
173
+
174
+ /** Header summary of the Agent cards section: step count + state counts. */
175
+ export function stepStateCounts(agents: readonly FlowAgentState[]): {
176
+ steps: number;
177
+ done: number;
178
+ running: number;
179
+ failed: number;
180
+ skipped: number;
181
+ } {
182
+ return {
183
+ steps: agents.length,
184
+ done: agents.filter((a) => a.status === "complete").length,
185
+ running: agents.filter((a) => a.status === "running").length,
186
+ failed: agents.filter((a) => a.status === "error").length,
187
+ skipped: agents.filter((a) => a.status === "skipped").length,
188
+ };
189
+ }