@blackbelt-technology/pi-dashboard-flows-plugin 0.5.3 → 0.6.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 (70) hide show
  1. package/package.json +48 -4
  2. package/src/AGENTS.md +8 -0
  3. package/src/__tests__/FlowGraph.test.ts +151 -5
  4. package/src/__tests__/FlowInputWiring.test.tsx +97 -0
  5. package/src/__tests__/FlowSummary.test.tsx +331 -0
  6. package/src/__tests__/FlowYamlPreview.test.tsx +75 -0
  7. package/src/__tests__/FlowsSessionStateContext.test.tsx +223 -0
  8. package/src/__tests__/FlowsUiStateContext.test.tsx +140 -0
  9. package/src/__tests__/authoring-renderers.test.tsx +190 -0
  10. package/src/__tests__/automation-actions.test.ts +117 -0
  11. package/src/__tests__/flow-agent-card-code-source.test.tsx +154 -0
  12. package/src/__tests__/flow-agent-cost.test.tsx +160 -0
  13. package/src/__tests__/flow-agent-error.test.ts +60 -0
  14. package/src/__tests__/flow-collapse-storage.test.ts +90 -0
  15. package/src/__tests__/flow-edges.test.ts +195 -0
  16. package/src/__tests__/flow-inputs.test.ts +69 -0
  17. package/src/__tests__/flow-reducer-bridge-contract.test.ts +108 -0
  18. package/src/__tests__/flow-reducer-seed-on-start.test.ts +61 -0
  19. package/src/__tests__/flow-yaml-parse.test.ts +124 -0
  20. package/src/__tests__/flows-for-cwd.test.ts +51 -0
  21. package/src/__tests__/flowsAvailability.test.ts +79 -0
  22. package/src/__tests__/manifest-discoverability.test.ts +97 -0
  23. package/src/__tests__/node-kind-reducer.test.ts +135 -0
  24. package/src/__tests__/plugin-action-handler.test.ts +54 -0
  25. package/src/__tests__/render-actions.test.ts +63 -0
  26. package/src/__tests__/session-flow-actions-edit.test.tsx +98 -0
  27. package/src/bridge/AGENTS.md +8 -0
  28. package/src/bridge/flow-question-adapter.ts +93 -0
  29. package/src/bridge/index.ts +30 -0
  30. package/src/client/AGENTS.md +32 -0
  31. package/src/client/FlowActivityBadge.tsx +41 -11
  32. package/src/client/FlowAgentCard.tsx +321 -61
  33. package/src/client/FlowAgentDetail.tsx +103 -154
  34. package/src/client/FlowAgentsToolRenderer.tsx +228 -0
  35. package/src/client/FlowAuthorPromptDialog.tsx +92 -0
  36. package/src/client/FlowDashboard.tsx +271 -43
  37. package/src/client/FlowGraph.tsx +425 -276
  38. package/src/client/FlowInputWiring.tsx +243 -0
  39. package/src/client/FlowLaunchDialog.tsx +52 -52
  40. package/src/client/FlowQuestionCard.tsx +216 -0
  41. package/src/client/FlowQuestionTranscriptPill.tsx +58 -0
  42. package/src/client/FlowSummary.tsx +285 -80
  43. package/src/client/FlowWriteToolRenderer.tsx +127 -0
  44. package/src/client/FlowYamlPopoverButton.tsx +110 -0
  45. package/src/client/FlowYamlPreview.tsx +67 -0
  46. package/src/client/FlowsCommandRoutes.tsx +237 -0
  47. package/src/client/FlowsSessionStateContext.tsx +142 -0
  48. package/src/client/FlowsSettings.tsx +68 -0
  49. package/src/client/FlowsUiStateContext.tsx +169 -0
  50. package/src/client/SessionFlowActions.tsx +172 -65
  51. package/src/client/flow-collapse-storage.ts +79 -0
  52. package/src/client/flow-edges.ts +173 -0
  53. package/src/client/flow-yaml-parse.ts +140 -0
  54. package/src/client/flowsAvailability.ts +44 -0
  55. package/src/client/index.tsx +95 -13
  56. package/src/client/shouldRender.ts +38 -0
  57. package/src/configSchema.json +14 -0
  58. package/src/flow-reducer.ts +94 -13
  59. package/src/i18n.ts +90 -0
  60. package/src/reducer.ts +5 -5
  61. package/src/server/AGENTS.md +10 -0
  62. package/src/server/automation-actions.ts +162 -0
  63. package/src/server/flow-inputs.ts +58 -0
  64. package/src/server/index.ts +171 -0
  65. package/src/server/render-actions.ts +88 -0
  66. package/src/server/state-store.ts +74 -0
  67. package/src/__tests__/ArchitectInputPrompt.test.tsx +0 -81
  68. package/src/__tests__/architect-reducer.test.ts +0 -307
  69. package/src/architect-reducer.ts +0 -386
  70. package/src/client/FlowArchitect.tsx +0 -622
@@ -1,14 +1,19 @@
1
- import React, { useState, type ReactNode } from "react";
1
+ import { usePluginSend, useUiPrimitive, useUiPrimitiveOrNull } from "@blackbelt-technology/dashboard-plugin-runtime";
2
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
3
+ import type { DashboardSession, FlowAgentState, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
4
+ import { mdiAlertCircle, mdiCheckCircle, mdiChevronDown, mdiChevronRight, mdiCircleOutline, mdiCloseCircle, mdiCloseCircleOutline, mdiStopCircle } from "@mdi/js";
2
5
  import { Icon } from "@mdi/react";
3
- import { mdiCloseCircleOutline, mdiCheckCircle, mdiAlertCircle, mdiStopCircle, mdiCloseCircle, mdiCircleOutline, mdiChevronRight, mdiChevronDown, mdiFileDocumentOutline } from "@mdi/js";
4
- import type { FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
6
+ import { type ReactNode, useCallback, useEffect, useRef, useState } from "react";
7
+ import { FlowAgentCard } from "./FlowAgentCard.js";
5
8
  import { FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
9
+ import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
10
+ import { FlowYamlPopoverButton } from "./FlowYamlPopoverButton.js";
11
+ import { useFlowCollapsePersisted } from "./flow-collapse-storage.js";
12
+
13
+
14
+ // formatDuration moved to registry primitive lookup inside FlowSummary
15
+ // (PH-2 fix from validation report).
6
16
 
7
- function formatDuration(ms: number): string {
8
- const sec = Math.floor(ms / 1000);
9
- const min = Math.floor(sec / 60);
10
- return min > 0 ? `${min}m ${sec % 60}s` : `${sec}s`;
11
- }
12
17
 
13
18
  const statusConfig: Record<string, { icon: ReactNode; label: string; color: string }> = {
14
19
  success: { icon: <Icon path={mdiCheckCircle} size={0.55} />, label: "complete", color: "text-green-400" },
@@ -18,33 +23,87 @@ const statusConfig: Record<string, { icon: ReactNode; label: string; color: stri
18
23
 
19
24
  export function FlowSummary({
20
25
  flowState,
21
- onAgentClick,
22
26
  onDismiss,
23
27
  onSendPrompt,
24
- onViewYaml,
28
+ session,
29
+ sessionId,
25
30
  }: {
26
31
  flowState: FlowState;
27
- onAgentClick: (agentName: string) => void;
28
32
  onDismiss: () => void;
29
33
  onSendPrompt?: (text: string) => void;
30
- onViewYaml?: () => void;
34
+ /** Parent session — threaded to the frozen cards for their detail/popout affordances. */
35
+ session?: DashboardSession;
36
+ sessionId?: string;
31
37
  }) {
38
+ const formatDuration = useUiPrimitive(UI_PRIMITIVE_KEYS.formatDuration);
39
+ const Dialog = useUiPrimitiveOrNull(UI_PRIMITIVE_KEYS.dialog);
32
40
  const [collapsed, setCollapsed] = useState(false);
41
+ // Whole-panel collapse (distinct from the footer `collapsed` above, which only
42
+ // hides the Summaries list). Shrinks the completed-flow summary to its header
43
+ // bar, mirroring FlowDashboard's collapse affordance. See change: improve-flow-graph-fidelity.
44
+ // Persisted per session so a collapsed panel stays collapsed across remounts.
45
+ // See change: fix-flow-ui-graph-zoom-summary.
46
+ const [panelCollapsed, togglePanelCollapsed] = useFlowCollapsePersisted(
47
+ sessionId ?? session?.id,
48
+ "summary",
49
+ );
50
+ const [graphOpen, setGraphOpen] = useState(false);
51
+ // Shared graph⇄card selection (ephemeral). See change:
52
+ // improve-flow-graph-dialog-and-card-interaction.
53
+ const [selectedStepId, setSelectedStepId] = useState<string | null>(null);
54
+ const rootRef = useRef<HTMLDivElement>(null);
33
55
  const agents = Array.from(flowState.agents.values());
56
+ // Only summary-bearing agents are listed in the Summaries subsection (others
57
+ // stay in the frozen cards + graph). See change: fix-flow-ui-graph-zoom-summary.
58
+ const summarised = agents.filter(a => a.summary);
34
59
  const { icon, label, color } = statusConfig[flowState.status] ?? statusConfig.success;
35
60
  const totalDuration = flowState.flowResult?.totalDuration as number | undefined;
36
61
  const totalFiles = agents.reduce((sum, a) => sum + (a.files?.length ?? 0), 0);
37
62
 
63
+ const handleSelectStep = useCallback((stepId: string) => {
64
+ setSelectedStepId((prev) => (prev === stepId ? null : stepId));
65
+ }, []);
66
+
67
+ // Reset selection when the agent set changes (selection is ephemeral).
68
+ useEffect(() => {
69
+ setSelectedStepId(null);
70
+ }, [flowState.agents]);
71
+
72
+ // Esc clears selection (the Dialog handles its own Esc independently).
73
+ useEffect(() => {
74
+ if (!selectedStepId) return;
75
+ const onKey = (e: KeyboardEvent) => {
76
+ if (e.key === "Escape") setSelectedStepId(null);
77
+ };
78
+ window.addEventListener("keydown", onKey);
79
+ return () => window.removeEventListener("keydown", onKey);
80
+ }, [selectedStepId]);
81
+
82
+ // Scroll the matching node + card into view on selection (counterpart sync).
83
+ useEffect(() => {
84
+ if (!selectedStepId || !rootRef.current) return;
85
+ const esc = selectedStepId.replace(/["\\]/g, "\\$&");
86
+ for (const attr of ["data-node", "data-step"]) {
87
+ rootRef.current
88
+ .querySelector(`[${attr}="${esc}"]`)
89
+ ?.scrollIntoView({ block: "nearest", inline: "nearest" });
90
+ }
91
+ }, [selectedStepId]);
92
+
38
93
  return (
39
- <div className="bg-[var(--bg-secondary)] border-b border-[var(--border-subtle)] px-3 py-2">
94
+ <div ref={rootRef} className="bg-[var(--bg-secondary)] border-b border-[var(--border-subtle)] px-3 py-2">
40
95
  {/* Header */}
41
96
  <div className="flex items-center gap-2 mb-1.5">
42
- <span
43
- className="inline-flex text-[var(--text-tertiary)] cursor-pointer"
44
- onClick={() => setCollapsed(!collapsed)}
97
+ {/* Minimal disclosure chevron, left of the flow name (not near Dismiss). */}
98
+ <button
99
+ onClick={togglePanelCollapsed}
100
+ data-testid="flow-summary-panel-toggle"
101
+ title={panelCollapsed ? "Expand summary" : "Collapse summary"}
102
+ aria-expanded={!panelCollapsed}
103
+ className="inline-flex -ml-0.5 text-[var(--text-tertiary)] hover:text-[var(--text-primary)]"
45
104
  >
46
- <Icon path={collapsed ? mdiChevronRight : mdiChevronDown} size={0.6} />
47
- </span>
105
+ <Icon path={panelCollapsed ? mdiChevronRight : mdiChevronDown} size={0.6} />
106
+ </button>
48
107
  <span className={`${color} inline-flex`}>{icon}</span>
49
108
  <span className="text-sm text-[var(--text-primary)] flex-1">
50
109
  {flowState.flowName} {label}
@@ -62,76 +121,222 @@ export function FlowSummary({
62
121
  </button>
63
122
  </div>
64
123
 
65
- {/* DAG graph + Agent list -- collapsible */}
66
- <div className={`group-collapse ${collapsed ? "collapsed" : "expanded"}`}>
67
- <div>
68
- {/* DAG graph showing final state */}
69
- <FlowGraph
70
- steps={flowStateToGraphSteps(flowState)}
124
+ {!panelCollapsed && (<>
125
+ {/* Flow graph — bounded + fit-to-window; ⤢ expand opens the centered Dialog
126
+ with pan/zoom. Bounded so it cannot be dragged over the cards/summaries.
127
+ See change: show-flow-cards-in-summary. */}
128
+ <FlowGraph
129
+ steps={flowStateToGraphSteps(flowState)}
130
+ fit
131
+ selectedStepId={selectedStepId}
132
+ onSelectStep={handleSelectStep}
133
+ onExpand={Dialog ? () => setGraphOpen(true) : undefined}
134
+ />
135
+ {flowState.flowSource && (
136
+ <div className="mt-1">
137
+ <FlowYamlPopoverButton
138
+ flowSource={flowState.flowSource}
139
+ flowName={flowState.flowName}
71
140
  />
72
- {onViewYaml && (
73
- <div className="mt-1">
74
- <button
75
- onClick={onViewYaml}
76
- className="text-[var(--text-tertiary)] hover:text-blue-400 transition-colors p-0.5 rounded hover:bg-[var(--bg-surface)] inline-flex items-center"
77
- title="View flow YAML"
78
- >
79
- <Icon path={mdiFileDocumentOutline} size={0.5} />
80
- </button>
141
+ </div>
142
+ )}
143
+
144
+ {/* Everything UNDER the graph lives in ONE fixed-height scrollable box so
145
+ the whole panel always fits the viewport (no page scroll). The summaries
146
+ section and each agent row stay independently collapsible inside it. */}
147
+ <div className="mt-2 overflow-y-auto" style={{ maxHeight: "48vh" }} data-testid="flow-summary-scrollbox">
148
+ {/* Frozen agent cards — read-only. */}
149
+ {agents.length > 0 && (
150
+ <div
151
+ className="grid gap-2"
152
+ style={{ gridTemplateColumns: `repeat(auto-fill, minmax(200px, 1fr))` }}
153
+ >
154
+ {agents.map(agent => (
155
+ <FlowAgentCard
156
+ key={agent.stepId || agent.agentName}
157
+ agent={agent}
158
+ session={session}
159
+ sessionId={sessionId ?? session?.id}
160
+ selected={selectedStepId === (agent.stepId || agent.agentName)}
161
+ onSelect={handleSelectStep}
162
+ />
163
+ ))}
164
+ </div>
165
+ )}
166
+
167
+ {/* Summaries — collapsible; each row expands inline. Only agents with
168
+ summary text are listed; the subsection is hidden when none qualify
169
+ (summary-less steps remain visible in the frozen cards above + graph).
170
+ See change: fix-flow-ui-graph-zoom-summary. */}
171
+ {summarised.length > 0 && (
172
+ <div className="mt-2 pt-1.5 border-t border-[var(--border-subtle)]">
173
+ <div
174
+ data-testid="flow-summary-toggle"
175
+ className="flex items-center gap-1.5 text-[11px] text-[var(--text-tertiary)] cursor-pointer mb-1 hover:text-[var(--text-primary)]"
176
+ onClick={() => setCollapsed(!collapsed)}
177
+ >
178
+ <Icon path={collapsed ? mdiChevronRight : mdiChevronDown} size={0.5} />
179
+ <span>Summaries ({summarised.length})</span>
81
180
  </div>
82
- )}
181
+ {!collapsed && (
182
+ <div className="space-y-0.5" data-testid="flow-summaries">
183
+ {summarised.map(agent => (
184
+ <FlowSummaryRow key={agent.stepId || agent.agentName} agent={agent} />
185
+ ))}
186
+ </div>
187
+ )}
188
+ </div>
189
+ )}
83
190
 
84
- {/* Per-agent status list */}
85
- <div className="space-y-0.5">
86
- {agents.map(agent => {
87
- const agentIconPath = agent.status === "complete" ? mdiCheckCircle
88
- : agent.status === "error" ? mdiCloseCircle
89
- : agent.status === "blocked" ? mdiAlertCircle
90
- : mdiCircleOutline;
91
- const agentColor = agent.status === "complete" ? "text-green-400"
92
- : agent.status === "error" ? "text-red-400"
93
- : agent.status === "blocked" ? "text-orange-400"
94
- : "text-[var(--text-tertiary)]";
95
- const fileCount = agent.files?.length ?? 0;
96
-
97
- return (
98
- <div
99
- key={agent.stepId || agent.agentName}
100
- onClick={() => onAgentClick(agent.stepId || agent.agentName)}
101
- className="flex items-center gap-1.5 text-[11px] cursor-pointer hover:bg-[var(--bg-tertiary)] rounded px-1 py-0.5"
102
- >
103
- <span className={`${agentColor} inline-flex`}><Icon path={agentIconPath} size={0.45} /></span>
104
- <span className="text-[var(--text-primary)]">{agent.label || agent.stepId || agent.agentName}</span>
105
- {(agent.stepType === "fork" || agent.stepType === "agent-decision") && (
106
- <span className="text-[9px] text-amber-400/60">◇</span>
107
- )}
108
- {agent.stepType === "agent-loop-decision" && (
109
- <span className="text-[9px] text-purple-400/60">↻</span>
110
- )}
111
- {fileCount > 0 && (
112
- <span className="text-[var(--text-muted)]">({fileCount} files)</span>
113
- )}
114
- {agent.summary && (
115
- <span className="text-[var(--text-tertiary)] truncate flex-1">{agent.summary}</span>
116
- )}
117
- </div>
118
- );
119
- })}
191
+ {/* Next step suggestion */}
192
+ {flowState.nextStep && onSendPrompt && (
193
+ <div className="mt-1.5 pt-1.5 border-t border-[var(--border-subtle)]">
194
+ <button
195
+ onClick={() => onSendPrompt(`/${flowState.nextStep}`)}
196
+ className="text-[11px] px-2 py-1 rounded border border-blue-500/30 text-blue-400 hover:bg-blue-500/10"
197
+ >
198
+ Next: /{flowState.nextStep}
199
+ </button>
120
200
  </div>
121
- </div>
201
+ )}
122
202
  </div>
123
203
 
124
- {/* Next step suggestion */}
125
- {flowState.nextStep && onSendPrompt && (
126
- <div className="mt-1.5 pt-1.5 border-t border-[var(--border-subtle)]">
127
- <button
128
- onClick={() => onSendPrompt(`/${flowState.nextStep}`)}
129
- className="text-[11px] px-2 py-1 rounded border border-blue-500/30 text-blue-400 hover:bg-blue-500/10"
130
- >
131
- Next: /{flowState.nextStep}
132
- </button>
204
+ {/* Expanded graph — centered Dialog with pan/zoom (OUTSIDE the scroll box). */}
205
+ {Dialog && (
206
+ <Dialog
207
+ open={graphOpen}
208
+ onClose={() => setGraphOpen(false)}
209
+ title={`Flow graph · ${flowState.flowName}`}
210
+ size="full"
211
+ >
212
+ {/* Non-fit (pan/zoom) graph fills the full-size dialog; no inner
213
+ height cap so the horizontal DAG gets a wide stage. See change:
214
+ improve-flow-graph-dialog-and-card-interaction. */}
215
+ <div style={{ height: "82vh", overflow: "hidden" }}>
216
+ <FlowGraph
217
+ steps={flowStateToGraphSteps(flowState)}
218
+ selectedStepId={selectedStepId}
219
+ onSelectStep={handleSelectStep}
220
+ />
221
+ </div>
222
+ </Dialog>
223
+ )}
224
+ </>)}
225
+ </div>
226
+ );
227
+ }
228
+
229
+ /**
230
+ * One expandable per-agent row. Collapsed: status icon + label + badges +
231
+ * file count + truncated summary peek (matches prior behaviour). Expanded:
232
+ * full summary (markdown), typed-output chips, file list, soft/hard outcome.
233
+ * Mirrors the ToolCallStep chevron idiom; failed steps auto-expand.
234
+ * See change: expandable-flow-summary-rows.
235
+ */
236
+ function FlowSummaryRow({ agent }: { agent: FlowAgentState }) {
237
+ const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
238
+ const fileCount = agent.files?.length ?? 0;
239
+ const outputs = agent.typedOutputs
240
+ ? Object.entries(agent.typedOutputs).filter(([k]) => k !== "branch")
241
+ : [];
242
+ const hasDetail = !!agent.summary || fileCount > 0 || outputs.length > 0;
243
+ const [open, setOpen] = useState(agent.status === "error");
244
+
245
+ const agentIconPath = agent.status === "complete" ? mdiCheckCircle
246
+ : agent.status === "error" ? mdiCloseCircle
247
+ : agent.status === "blocked" ? mdiAlertCircle
248
+ : mdiCircleOutline;
249
+ const agentColor = agent.status === "complete" ? "text-green-400"
250
+ : agent.status === "error" ? "text-red-400"
251
+ : agent.status === "blocked" ? "text-orange-400"
252
+ : "text-[var(--text-tertiary)]";
253
+
254
+ return (
255
+ <div>
256
+ {/* Header row */}
257
+ <div
258
+ className={`flex items-center gap-1.5 text-[11px] hover:bg-[var(--bg-tertiary)] rounded px-1 py-0.5 ${hasDetail ? "cursor-pointer" : ""}`}
259
+ onClick={hasDetail ? () => setOpen(!open) : undefined}
260
+ >
261
+ <span className="inline-flex w-[11px] justify-center text-[var(--text-muted)]">
262
+ {hasDetail ? <Icon path={open ? mdiChevronDown : mdiChevronRight} size={0.45} /> : null}
263
+ </span>
264
+ <span className={`${agentColor} inline-flex`}><Icon path={agentIconPath} size={0.45} /></span>
265
+ <span className="text-[var(--text-primary)]">{agent.label || agent.stepId || agent.agentName}</span>
266
+ {(agent.stepType === "fork" || agent.stepType === "agent-decision") && (
267
+ <span className="text-[9px] text-amber-400/60">◇</span>
268
+ )}
269
+ {agent.stepType === "agent-loop-decision" && (
270
+ <span className="text-[9px] text-purple-400/60">↻</span>
271
+ )}
272
+ {fileCount > 0 && (
273
+ <span className="text-[var(--text-muted)]">({fileCount} files)</span>
274
+ )}
275
+ {!open && agent.summary && (
276
+ <span className="text-[var(--text-tertiary)] truncate flex-1">{agent.summary}</span>
277
+ )}
278
+ </div>
279
+
280
+ {/* Expanded body */}
281
+ {open && hasDetail && (
282
+ <div className="ml-[22px] mt-0.5 mb-1 pl-2.5 pr-2 py-1.5 border-l-2 border-[var(--border-primary)] bg-[var(--bg-surface)] rounded-r flex flex-col gap-1.5">
283
+ {agent.summary && (
284
+ <div className="text-[11px] text-[var(--text-secondary)]">
285
+ <MarkdownContent content={agent.summary} />
286
+ </div>
287
+ )}
288
+ {outputs.length > 0 && (
289
+ <div className="flex flex-wrap gap-1">
290
+ {outputs.map(([k, v]) => (
291
+ <span key={k} className="text-[10px] font-mono bg-[var(--bg-secondary)] border border-[var(--border-subtle)] rounded px-1 py-0.5 truncate max-w-[160px]" title={`${k}: ${v}`}>
292
+ <span className="text-cyan-400">{k}</span>: {v}
293
+ </span>
294
+ ))}
295
+ </div>
296
+ )}
297
+ {fileCount > 0 && (
298
+ <div className="flex flex-wrap gap-x-2 gap-y-0.5 text-[10px] font-mono text-[var(--text-tertiary)]">
299
+ {agent.files?.map((f) => (
300
+ <span key={f} title={f}>{f}</span>
301
+ ))}
302
+ </div>
303
+ )}
304
+ {agent.status === "error" && agent.outcome === "soft" && (
305
+ <div className="text-[10px] text-amber-400">⚠ soft-failed — routed to on_error</div>
306
+ )}
307
+ {agent.status === "error" && agent.outcome === "hard" && (
308
+ <div className="text-[10px] text-red-400">✕ hard-failed — halted flow</div>
309
+ )}
133
310
  </div>
134
311
  )}
135
312
  </div>
136
313
  );
137
314
  }
315
+
316
+ /**
317
+ * Slot-consumer wrapper for the `content-inline-footer` claim. Self-
318
+ * derives flow state, dispatches dismissal via pluginContext.send,
319
+ * navigates agent detail via the plugin-internal UI state context.
320
+ * Returns null when no flow is active. See change:
321
+ * pluginize-flows-via-registry.
322
+ */
323
+ export function FlowSummaryClaim({ session }: { session: DashboardSession }) {
324
+ const { flowState } = useFlowsSessionState(session.id);
325
+ const send = usePluginSend();
326
+
327
+ if (!flowState) return null;
328
+
329
+ return (
330
+ <FlowSummary
331
+ flowState={flowState}
332
+ session={session}
333
+ sessionId={session.id}
334
+ onDismiss={() =>
335
+ send({ type: "flow_control", sessionId: session.id, action: "dismiss_summary" })
336
+ }
337
+ onSendPrompt={(text) =>
338
+ send({ type: "send_prompt", sessionId: session.id, text })
339
+ }
340
+ />
341
+ );
342
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Tool renderer for the `flow_write` authoring tool (main-session timeline).
3
+ *
4
+ * Renders from the real tool contract: result JSON is
5
+ * `{ written, name, namespace, command, path, diagnostics[] }` (success) or
6
+ * `{ written:false, diagnostics[] }` / `{ written:false, error }` (failure).
7
+ * The result carries no parsed steps, so the Mermaid snapshot + step/agent/code
8
+ * counts are parsed client-side from the tool ARGS (`toolInput.content`).
9
+ *
10
+ * See change: rework-flows-plugin-for-new-pi-flows.
11
+ */
12
+
13
+ import { useT, useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
14
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
15
+ import React, { useMemo, useState } from "react";
16
+ import { flowToMermaid, parseFlowYaml } from "./flow-yaml-parse.js";
17
+
18
+ interface FlowWriteResult {
19
+ written?: boolean;
20
+ name?: string;
21
+ namespace?: string;
22
+ command?: string;
23
+ path?: string;
24
+ diagnostics?: Array<{ message?: string } | string>;
25
+ error?: string;
26
+ }
27
+
28
+ function safeParse(result: string | undefined): FlowWriteResult | null {
29
+ if (!result) return null;
30
+ try { return JSON.parse(result) as FlowWriteResult; } catch { return null; }
31
+ }
32
+
33
+ function diagText(d: { message?: string } | string): string {
34
+ return typeof d === "string" ? d : (d.message ?? JSON.stringify(d));
35
+ }
36
+
37
+ export function FlowWriteToolRenderer({
38
+ toolInput,
39
+ status,
40
+ result,
41
+ }: {
42
+ toolName: string;
43
+ toolInput: Record<string, unknown>;
44
+ sessionId: string;
45
+ status?: "running" | "complete" | "error";
46
+ result?: string;
47
+ }) {
48
+ const t = useT();
49
+ const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
50
+ const [showYaml, setShowYaml] = useState(false);
51
+
52
+ const content = typeof toolInput.content === "string" ? toolInput.content : "";
53
+ const parsed = safeParse(result);
54
+ const flow = useMemo(() => (content ? parseFlowYaml(content) : null), [content]);
55
+ const mermaidMd = useMemo(
56
+ () => (flow ? "```mermaid\n" + flowToMermaid(flow) + "\n```" : null),
57
+ [flow],
58
+ );
59
+
60
+ const diagnostics = (parsed?.diagnostics ?? []).map(diagText);
61
+ const written = parsed?.written === true;
62
+ const isError = status === "error" || parsed?.written === false;
63
+
64
+ return (
65
+ <div className="border border-[var(--border-primary)] rounded-md bg-[var(--bg-secondary)] p-3 text-xs">
66
+ <div className="flex items-center gap-2">
67
+ <span className="text-[var(--accent-blue,#0969da)]">⇆</span>
68
+ <span className="font-semibold">flow_write</span>
69
+ {status === "running" && <span className="text-[var(--text-muted)]">writing…</span>}
70
+ {written && parsed?.command && (
71
+ <span className="font-mono text-green-400">/{parsed.command}</span>
72
+ )}
73
+ {written && <span className="text-[var(--text-muted)]">registered</span>}
74
+ {isError && <span className="text-red-400">not written — validation failed</span>}
75
+ </div>
76
+
77
+ {/* Counts parsed from args */}
78
+ {written && flow && (
79
+ <div className="mt-1 text-[var(--text-tertiary)]">
80
+ {flow.counts.total} steps · {flow.counts.agents} agents, {flow.counts.code} code
81
+ </div>
82
+ )}
83
+
84
+ {/* Mermaid snapshot from args */}
85
+ {written && mermaidMd && (
86
+ <div className="mt-2">
87
+ <div className="text-[10px] uppercase tracking-wide text-[var(--text-muted)] mb-1">{t("flowGraph", undefined, "Flow graph")}</div>
88
+ <MarkdownContent content={mermaidMd} />
89
+ </div>
90
+ )}
91
+
92
+ {/* Validation failure — diagnostics verbatim */}
93
+ {isError && (
94
+ <div className="mt-2">
95
+ <div className="text-[10px] uppercase tracking-wide text-red-400 mb-1">{t("result", undefined, "Result")}</div>
96
+ <pre className="font-mono text-[11px] text-red-400 whitespace-pre-wrap">
97
+ {diagnostics.length > 0 ? diagnostics.join("\n") : (parsed?.error ?? "Unknown error")}
98
+ </pre>
99
+ </div>
100
+ )}
101
+
102
+ {/* Non-fatal diagnostics on success */}
103
+ {written && diagnostics.length > 0 && (
104
+ <div className="mt-2 text-[11px] text-amber-400">
105
+ {diagnostics.map((d, i) => <div key={i}>⚠ {d}</div>)}
106
+ </div>
107
+ )}
108
+
109
+ {/* View flow YAML (the submitted args) */}
110
+ {content && (
111
+ <div className="mt-2">
112
+ <button
113
+ onClick={() => setShowYaml((v) => !v)}
114
+ className="text-[11px] text-[var(--text-tertiary)] hover:text-blue-400 font-mono"
115
+ >
116
+ {showYaml ? "▾" : "▸"} View flow YAML {parsed?.path ? `· ${parsed.path.split("/").pop()}` : ""}
117
+ </button>
118
+ {showYaml && (
119
+ <pre className="mt-1 font-mono text-[11px] bg-[var(--bg-surface)] border border-[var(--border-subtle)] rounded p-2 overflow-auto max-h-[260px] whitespace-pre">
120
+ {content}
121
+ </pre>
122
+ )}
123
+ </div>
124
+ )}
125
+ </div>
126
+ );
127
+ }
@@ -0,0 +1,110 @@
1
+ /**
2
+ * FlowYamlPopoverButton — paper-icon button that opens a popover anchored
3
+ * to itself, fetches the flow's YAML at `/api/pi-resource-file?path=...`,
4
+ * and renders it inside the popover via the `ui:markdown-content` primitive
5
+ * (wrapped in a `yaml` code fence for syntax highlighting).
6
+ *
7
+ * Used by `FlowDashboard` (live flow) and `FlowSummary` (completed flow).
8
+ *
9
+ * The flow's YAML path is emitted by pi-flows in the `flow:flow-started`
10
+ * event (see `packages/pi-flows/extensions/flow-engine/flow-tui.ts:487` —
11
+ * `source: flow.source`) and stored on `FlowState.flowSource` by the flow
12
+ * reducer.
13
+ *
14
+ * See change: add-ui-popover-primitive.
15
+ */
16
+ import React, { useEffect, useState } from "react";
17
+ import { Icon } from "@mdi/react";
18
+ import { mdiFileDocumentOutline } from "@mdi/js";
19
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
20
+ import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
21
+
22
+ type YamlFetchState =
23
+ | { kind: "idle" }
24
+ | { kind: "loading" }
25
+ | { kind: "loaded"; content: string }
26
+ | { kind: "error"; error: string };
27
+
28
+ export function FlowYamlPopoverButton({
29
+ flowSource,
30
+ flowName,
31
+ }: {
32
+ flowSource: string;
33
+ flowName: string;
34
+ }) {
35
+ const Dialog = useUiPrimitive(UI_PRIMITIVE_KEYS.dialog);
36
+ const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
37
+ const [open, setOpen] = useState(false);
38
+ const [state, setState] = useState<YamlFetchState>({ kind: "idle" });
39
+
40
+ // Deps include only `open` + `flowSource`. Including state.kind would
41
+ // cause cleanup to fire on the idle→loading transition, self-cancelling
42
+ // the fetch. Same pattern as `usePiResourceFileFetch` in the client.
43
+ useEffect(() => {
44
+ if (!open) return;
45
+ let cancelled = false;
46
+ setState({ kind: "loading" });
47
+ fetch(`/api/pi-resource-file?path=${encodeURIComponent(flowSource)}`)
48
+ .then(async (r) => {
49
+ const json = await r.json();
50
+ if (cancelled) return;
51
+ if (json?.success && typeof json?.data?.content === "string") {
52
+ setState({ kind: "loaded", content: json.data.content });
53
+ } else {
54
+ setState({
55
+ kind: "error",
56
+ error: typeof json?.error === "string" ? json.error : "Failed to read flow YAML",
57
+ });
58
+ }
59
+ })
60
+ .catch((err) => {
61
+ if (!cancelled) setState({ kind: "error", error: String(err) });
62
+ });
63
+ return () => {
64
+ cancelled = true;
65
+ };
66
+ }, [open, flowSource]);
67
+
68
+ return (
69
+ <>
70
+ <button
71
+ onClick={(e) => {
72
+ e.stopPropagation();
73
+ setOpen((prev) => !prev);
74
+ }}
75
+ className={`transition-colors p-0.5 rounded inline-flex items-center ${
76
+ open
77
+ ? "text-blue-400 bg-blue-400/10"
78
+ : "text-[var(--text-tertiary)] hover:text-blue-400 hover:bg-[var(--bg-surface)]"
79
+ }`}
80
+ title={open ? "Close flow YAML" : `View ${flowName} YAML`}
81
+ >
82
+ <Icon path={mdiFileDocumentOutline} size={0.5} />
83
+ </button>
84
+ <Dialog
85
+ open={open}
86
+ onClose={() => setOpen(false)}
87
+ title={`${flowName} · YAML`}
88
+ size="lg"
89
+ >
90
+ {/* Pinned path header; YAML scrolls inside a fixed-height region so the
91
+ dialog stays a fixed size. See change:
92
+ improve-flow-graph-dialog-and-card-interaction. */}
93
+ <div className="text-[11px] text-[var(--text-tertiary)] font-mono break-all" title={flowSource}>
94
+ {flowSource}
95
+ </div>
96
+ <div className="h-[60vh] overflow-y-auto">
97
+ {state.kind === "loading" && (
98
+ <div className="text-xs text-[var(--text-muted)]">Loading…</div>
99
+ )}
100
+ {state.kind === "error" && (
101
+ <div className="text-xs text-red-400">⚠ {state.error}</div>
102
+ )}
103
+ {state.kind === "loaded" && (
104
+ <MarkdownContent content={"```yaml\n" + state.content + "\n```"} />
105
+ )}
106
+ </div>
107
+ </Dialog>
108
+ </>
109
+ );
110
+ }