@blackbelt-technology/pi-dashboard-flows-plugin 0.5.3 → 0.5.4

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 (35) hide show
  1. package/package.json +39 -4
  2. package/src/__tests__/FlowsSessionStateContext.test.tsx +260 -0
  3. package/src/__tests__/FlowsUiStateContext.test.tsx +140 -0
  4. package/src/__tests__/flowsAvailability.test.ts +92 -0
  5. package/src/__tests__/manifest-discoverability.test.ts +97 -0
  6. package/src/__tests__/render-actions.test.ts +63 -0
  7. package/src/bridge/flow-question-adapter.ts +93 -0
  8. package/src/bridge/index.ts +30 -0
  9. package/src/client/FlowActivityBadge.tsx +36 -9
  10. package/src/client/FlowAgentCard.tsx +180 -41
  11. package/src/client/FlowAgentDetail.tsx +95 -154
  12. package/src/client/FlowAgentPopoutClaim.tsx +66 -0
  13. package/src/client/FlowAgentPopoutPage.tsx +177 -0
  14. package/src/client/FlowArchitect.tsx +297 -220
  15. package/src/client/FlowArchitectPopoutClaim.tsx +52 -0
  16. package/src/client/FlowArchitectPopoutPage.tsx +133 -0
  17. package/src/client/FlowDashboard.tsx +194 -31
  18. package/src/client/FlowGraph.tsx +6 -2
  19. package/src/client/FlowLaunchDialog.tsx +8 -2
  20. package/src/client/FlowQuestionCard.tsx +213 -0
  21. package/src/client/FlowQuestionTranscriptPill.tsx +58 -0
  22. package/src/client/FlowSummary.tsx +43 -21
  23. package/src/client/FlowYamlPopoverButton.tsx +109 -0
  24. package/src/client/FlowYamlPreview.tsx +65 -0
  25. package/src/client/FlowsCommandRoutes.tsx +237 -0
  26. package/src/client/FlowsSessionStateContext.tsx +161 -0
  27. package/src/client/FlowsUiStateContext.tsx +169 -0
  28. package/src/client/SessionFlowActions.tsx +96 -5
  29. package/src/client/flowsAvailability.ts +103 -0
  30. package/src/client/index.tsx +94 -7
  31. package/src/client/popout-url.ts +59 -0
  32. package/src/client/shouldRender.ts +26 -0
  33. package/src/server/index.ts +87 -0
  34. package/src/server/render-actions.ts +88 -0
  35. package/src/server/state-store.ts +85 -0
@@ -1,194 +1,122 @@
1
- import React, { useState } from "react";
1
+ import React, { useRef, useState } from "react";
2
2
  import { Icon } from "@mdi/react";
3
3
  import {
4
4
  mdiChevronRight,
5
5
  mdiChevronDown,
6
6
  mdiLoading,
7
- mdiArrowLeft,
8
7
  mdiFileDocumentOutline,
9
8
  mdiEyeOutline,
10
9
  mdiEyeOffOutline,
10
+ mdiOpenInNew,
11
11
  } from "@mdi/js";
12
12
  import type {
13
13
  ArchitectState,
14
+ ArchitectPhase,
14
15
  ArchitectPrompt,
15
16
  ArchitectAgentEntry,
17
+ DashboardSession,
16
18
  FlowDetailEntry,
17
19
  } from "@blackbelt-technology/pi-dashboard-shared/types.js";
18
- import { MarkdownContent } from "../../../client/src/components/MarkdownContent.js";
20
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
21
+ import { useUiPrimitive, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime";
22
+ import {
23
+ MinimalChatView,
24
+ type MinimalChatEntry,
25
+ type MinimalChatStatus,
26
+ } from "@blackbelt-technology/pi-dashboard-client-utils/minimal-chat";
19
27
  import { FlowGraph, architectStepsToGraphSteps } from "./FlowGraph.js";
20
- import { AgentCardShell } from "../../../client/src/components/AgentCardShell.js";
21
-
22
- // ── Detail view (reuses same patterns as FlowAgentDetail) ─────────
23
-
24
- function extractInputPreview(toolName: string, input: unknown): string {
25
- if (!input || typeof input !== "object") return "";
26
- const inp = input as Record<string, unknown>;
27
- switch (toolName.toLowerCase()) {
28
- case "read":
29
- case "write":
30
- case "edit":
31
- return String(inp.file_path || inp.path || "");
32
- case "bash":
33
- return String(inp.command || "").slice(0, 80);
34
- case "grep":
35
- return String(inp.pattern || "").slice(0, 40);
36
- default:
37
- return JSON.stringify(input).slice(0, 60);
28
+ import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
29
+ import { buildFlowArchitectPopoutUrl } from "./popout-url.js";
30
+ import {
31
+ useFlowsUiState,
32
+ useFlowsUiActions,
33
+ } from "./FlowsUiStateContext.js";
34
+
35
+ // ── Architect detail view ─────────────────────────────────────────────────
36
+ //
37
+ // Shim over `MinimalChatView`. Inline `ToolCallEntry` / `TextEntry` /
38
+ // `ThinkingEntry` / `extractInputPreview` were removed in
39
+ // `fix-flows-plugin-polish` (A1) — the architect now uses the same
40
+ // timeline renderer as `FlowAgentDetail` and `SubagentDetailView`.
41
+ //
42
+ // See change: fix-flows-plugin-polish (A1).
43
+
44
+ function mapArchitectPhase(phase: ArchitectPhase): MinimalChatStatus {
45
+ switch (phase) {
46
+ case "context":
47
+ case "designing":
48
+ return "running";
49
+ case "preview":
50
+ return "running";
51
+ case "complete":
52
+ return "complete";
53
+ case "cancelled":
54
+ return "error";
55
+ default: {
56
+ const _exhaustive: never = phase;
57
+ void _exhaustive;
58
+ return "pending";
59
+ }
38
60
  }
39
61
  }
40
62
 
41
- function ToolCallEntry({
42
- entry,
43
- }: {
44
- entry: FlowDetailEntry & { kind: "tool" };
45
- }) {
46
- const preview = extractInputPreview(entry.toolName, entry.input);
47
- const hasOutput = entry.output !== undefined;
48
- const [expanded, setExpanded] = React.useState(false);
49
-
50
- return (
51
- <div
52
- className={`border-l-2 pl-3 py-1.5 ${entry.isError ? "border-red-500/50" : "border-purple-500/30"}`}
53
- >
54
- <div
55
- className="flex items-center gap-1.5 cursor-pointer"
56
- onClick={() => hasOutput && setExpanded(!expanded)}
57
- >
58
- <span
59
- className={`text-xs font-mono ${entry.isError ? "text-red-400" : "text-purple-400"}`}
60
- >
61
- {entry.toolName}
62
- </span>
63
- <span className="text-xs text-[var(--text-tertiary)] truncate">
64
- {preview}
65
- </span>
66
- {hasOutput && (
67
- <span className="text-[10px] text-[var(--text-muted)] ml-auto flex-shrink-0">
68
- {expanded ? "▾" : "▸"}
69
- </span>
70
- )}
71
- </div>
72
- {expanded && hasOutput && (
73
- <pre className="text-[11px] text-[var(--text-secondary)] mt-1 overflow-x-auto max-h-48 overflow-y-auto whitespace-pre-wrap break-words bg-[var(--bg-tertiary)] rounded p-2">
74
- {typeof entry.output === "string"
75
- ? entry.output
76
- : JSON.stringify(entry.output, null, 2)}
77
- </pre>
78
- )}
79
- </div>
80
- );
81
- }
82
-
83
- function TextEntry({ text }: { text: string }) {
84
- return (
85
- <div className="py-1.5 pl-3">
86
- <MarkdownContent content={text} />
87
- </div>
88
- );
89
- }
90
-
91
- function ThinkingEntry({ text }: { text: string }) {
92
- const [expanded, setExpanded] = React.useState(false);
93
- return (
94
- <div className="py-1 pl-3">
95
- <div
96
- className="flex items-center gap-1 cursor-pointer text-[11px] text-purple-400/70"
97
- onClick={() => setExpanded(!expanded)}
98
- >
99
- <span>{expanded ? "▾" : "▸"}</span>
100
- <span>Thinking</span>
101
- </div>
102
- {expanded && (
103
- <pre className="text-[11px] text-[var(--text-muted)] mt-1 whitespace-pre-wrap break-words max-h-64 overflow-y-auto">
104
- {text}
105
- </pre>
106
- )}
107
- </div>
108
- );
63
+ function mapArchitectEntries(detailHistory: FlowDetailEntry[]): MinimalChatEntry[] {
64
+ return detailHistory.map((e) => {
65
+ switch (e.kind) {
66
+ case "tool":
67
+ return {
68
+ kind: "tool",
69
+ toolName: e.toolName,
70
+ input: e.input,
71
+ output: e.output,
72
+ isError: e.isError,
73
+ };
74
+ case "text":
75
+ return { kind: "text", text: e.text };
76
+ case "thinking":
77
+ return { kind: "thinking", text: e.text };
78
+ case "error":
79
+ return { kind: "error", text: e.text };
80
+ default: {
81
+ const _exhaustive: never = e;
82
+ void _exhaustive;
83
+ return { kind: "error", text: "(unknown entry)" };
84
+ }
85
+ }
86
+ });
109
87
  }
110
88
 
111
89
  export function FlowArchitectDetail({
112
90
  state,
113
91
  onBack,
92
+ sessionId,
114
93
  }: {
115
94
  state: ArchitectState;
116
- onBack: () => void;
95
+ onBack?: () => void;
96
+ /** Forwarded to MinimalChatView so per-tool renderers can build session-scoped links. */
97
+ sessionId?: string;
117
98
  }) {
118
- const isActive = state.phase === "context" || state.phase === "designing";
119
- const detailRef = React.useRef<HTMLDivElement>(null);
120
-
121
- // Auto-scroll to bottom as new entries arrive
122
- React.useEffect(() => {
123
- if (detailRef.current) {
124
- detailRef.current.scrollTop = detailRef.current.scrollHeight;
125
- }
126
- }, [state.detailHistory.length]);
99
+ const status = mapArchitectPhase(state.phase);
100
+ const entries = mapArchitectEntries(state.detailHistory);
101
+ const modeLabel = state.architectMode === "edit" ? "Edit" : "New";
102
+ const iterationSuffix = state.iteration > 1 ? ` · Iter ${state.iteration}` : "";
127
103
 
128
104
  return (
129
- <div className="flex flex-col h-full overflow-hidden">
130
- {/* Header */}
131
- <div className="px-3 py-2 border-b border-[var(--border-subtle)] bg-[var(--bg-secondary)] flex items-center gap-2">
132
- <button
133
- onClick={onBack}
134
- className="text-[var(--text-tertiary)] hover:text-[var(--text-primary)] transition-colors"
135
- >
136
- <Icon path={mdiArrowLeft} size={0.7} />
137
- </button>
138
- {isActive ? (
139
- <Icon
140
- path={mdiLoading}
141
- size={0.55}
142
- className="text-purple-400 animate-spin"
143
- />
144
- ) : (
145
- <span className="text-purple-400">◇</span>
146
- )}
147
- <span className="text-sm font-medium text-[var(--text-primary)]">
148
- Flow Architect
149
- </span>
150
- {state.flowName && (
151
- <span className="text-[11px] text-[var(--text-tertiary)]">
152
- {state.flowName}
153
- </span>
154
- )}
155
- <span className="text-[11px] text-[var(--text-muted)] ml-auto">
156
- {state.architectMode === "edit" ? "Edit" : "New"}
157
- {state.iteration > 1 && ` · Iteration ${state.iteration}`}
158
- </span>
159
- </div>
160
-
161
- {/* Detail history */}
162
- <div
163
- ref={detailRef}
164
- className="flex-1 overflow-y-auto px-3 py-2 space-y-0.5"
165
- >
166
- {state.detailHistory.length === 0 ? (
167
- <div className="text-sm text-[var(--text-muted)] py-4 text-center">
168
- {isActive ? "Working..." : "No activity yet"}
169
- </div>
170
- ) : (
171
- state.detailHistory.map((entry, i) => {
172
- switch (entry.kind) {
173
- case "tool":
174
- return <ToolCallEntry key={i} entry={entry} />;
175
- case "text":
176
- return <TextEntry key={i} text={entry.text} />;
177
- case "thinking":
178
- return <ThinkingEntry key={i} text={entry.text} />;
179
- case "error":
180
- return (
181
- <div key={i} className="py-1.5 pl-3 text-sm text-red-400">
182
- {entry.text}
183
- </div>
184
- );
185
- default:
186
- return null;
187
- }
188
- })
189
- )}
190
- </div>
191
- </div>
105
+ <MinimalChatView
106
+ title="Flow Architect"
107
+ subtitle={state.flowName || undefined}
108
+ status={status}
109
+ entries={entries}
110
+ mode="popout"
111
+ onBack={onBack}
112
+ sessionId={sessionId}
113
+ meta={{ modelName: `${modeLabel}${iterationSuffix}` }}
114
+ emptyMessage={
115
+ state.phase === "context" || state.phase === "designing"
116
+ ? "Working…"
117
+ : "No activity yet"
118
+ }
119
+ />
192
120
  );
193
121
  }
194
122
 
@@ -328,11 +256,21 @@ const AGENT_STATUS_MAP: Record<
328
256
 
329
257
  function ArchitectAgentCard({
330
258
  agent,
331
- onViewSource,
332
259
  }: {
333
260
  agent: ArchitectAgentEntry;
334
- onViewSource?: () => void;
335
261
  }) {
262
+ const AgentCardShell = useUiPrimitive(UI_PRIMITIVE_KEYS.agentCard);
263
+ const Popover = useUiPrimitive(UI_PRIMITIVE_KEYS.popover);
264
+ const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
265
+ const sourceButtonRef = useRef<HTMLButtonElement | null>(null);
266
+ const [sourceOpen, setSourceOpen] = useState(false);
267
+
268
+ // Architect's custom agents carry their raw markdown inline on the
269
+ // ArchitectAgentEntry (set by the architect-reducer when capturing
270
+ // `agent_write` events). No REST fetch needed — just render in a
271
+ // popover anchored to the doc button.
272
+ const hasSource = Boolean(agent.source);
273
+
336
274
  return (
337
275
  <AgentCardShell
338
276
  name={agent.name}
@@ -342,39 +280,110 @@ function ArchitectAgentCard({
342
280
  <span className="text-[10px] text-[var(--text-muted)] truncate">
343
281
  {agent.type === "custom" ? "custom agent" : agent.type}
344
282
  </span>
345
- {onViewSource && (
346
- <button
347
- onClick={(e) => {
348
- e.stopPropagation();
349
- onViewSource();
350
- }}
351
- className="text-[var(--text-tertiary)] hover:text-purple-400 transition-colors p-0.5 rounded hover:bg-[var(--bg-surface)]"
352
- title={`View ${agent.name} source`}
353
- >
354
- <Icon path={mdiFileDocumentOutline} size={0.5} />
355
- </button>
283
+ {hasSource && (
284
+ <>
285
+ <button
286
+ ref={sourceButtonRef}
287
+ onClick={(e) => {
288
+ e.stopPropagation();
289
+ setSourceOpen((prev) => !prev);
290
+ }}
291
+ className={`transition-colors p-0.5 rounded ${
292
+ sourceOpen
293
+ ? "text-purple-400 bg-purple-400/10"
294
+ : "text-[var(--text-tertiary)] hover:text-purple-400 hover:bg-[var(--bg-surface)]"
295
+ }`}
296
+ title={sourceOpen ? `Close ${agent.name} source` : `View ${agent.name} source`}
297
+ >
298
+ <Icon path={mdiFileDocumentOutline} size={0.5} />
299
+ </button>
300
+ {sourceOpen && sourceButtonRef.current && (
301
+ <Popover
302
+ anchorEl={sourceButtonRef.current}
303
+ onDismiss={() => setSourceOpen(false)}
304
+ >
305
+ <div
306
+ className="w-[640px] max-w-[90vw] max-h-[70vh] overflow-auto bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md shadow-xl p-3"
307
+ onClick={(e) => e.stopPropagation()}
308
+ >
309
+ <div className="text-[11px] text-[var(--text-tertiary)] mb-2 font-mono">
310
+ {agent.name}
311
+ </div>
312
+ <MarkdownContent content={agent.source!} />
313
+ </div>
314
+ </Popover>
315
+ )}
316
+ </>
356
317
  )}
357
318
  </div>
358
319
  </AgentCardShell>
359
320
  );
360
321
  }
361
322
 
362
- /** Small icon button for viewing files (YAML, agent source, etc.) */
363
- function ViewFileButton({
323
+ /**
324
+ * Small icon button that opens a popover anchored to itself, showing the
325
+ * given markdown/YAML `content`. Replaces the previous callback-based
326
+ * ViewFileButton that routed via the dormant FlowYamlPreview slot.
327
+ *
328
+ * See change: add-ui-popover-primitive.
329
+ */
330
+ function ViewFilePopoverButton({
364
331
  title,
365
- onClick,
332
+ content,
333
+ filename,
334
+ language,
366
335
  }: {
367
336
  title: string;
368
- onClick: () => void;
337
+ content: string;
338
+ /** Path/filename shown as a small caption above the content. */
339
+ filename?: string;
340
+ /** Hint for code fence (e.g. "yaml", "markdown"). When omitted we render raw. */
341
+ language?: string;
369
342
  }) {
343
+ const Popover = useUiPrimitive(UI_PRIMITIVE_KEYS.popover);
344
+ const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
345
+ const ref = useRef<HTMLButtonElement | null>(null);
346
+ const [open, setOpen] = useState(false);
347
+
348
+ // Wrap raw YAML/text in a code fence so MarkdownContent renders it as a
349
+ // syntax-highlighted block. Already-markdown content is shown verbatim.
350
+ const rendered = language
351
+ ? "```" + language + "\n" + content + "\n```"
352
+ : content;
353
+
370
354
  return (
371
- <button
372
- onClick={onClick}
373
- className="text-[var(--text-tertiary)] hover:text-purple-400 transition-colors p-0.5 rounded hover:bg-[var(--bg-surface)] inline-flex items-center"
374
- title={title}
375
- >
376
- <Icon path={mdiFileDocumentOutline} size={0.5} />
377
- </button>
355
+ <>
356
+ <button
357
+ ref={ref}
358
+ onClick={(e) => {
359
+ e.stopPropagation();
360
+ setOpen((prev) => !prev);
361
+ }}
362
+ className={`transition-colors p-0.5 rounded inline-flex items-center ${
363
+ open
364
+ ? "text-purple-400 bg-purple-400/10"
365
+ : "text-[var(--text-tertiary)] hover:text-purple-400 hover:bg-[var(--bg-surface)]"
366
+ }`}
367
+ title={title}
368
+ >
369
+ <Icon path={mdiFileDocumentOutline} size={0.5} />
370
+ </button>
371
+ {open && ref.current && (
372
+ <Popover anchorEl={ref.current} onDismiss={() => setOpen(false)}>
373
+ <div
374
+ className="w-[640px] max-w-[90vw] max-h-[70vh] overflow-auto bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md shadow-xl p-3"
375
+ onClick={(e) => e.stopPropagation()}
376
+ >
377
+ {filename && (
378
+ <div className="text-[11px] text-[var(--text-tertiary)] mb-2 font-mono truncate" title={filename}>
379
+ {filename}
380
+ </div>
381
+ )}
382
+ <MarkdownContent content={rendered} />
383
+ </div>
384
+ </Popover>
385
+ )}
386
+ </>
378
387
  );
379
388
  }
380
389
 
@@ -383,21 +392,33 @@ function ViewFileButton({
383
392
  export function FlowArchitect({
384
393
  state,
385
394
  onAbort,
386
- onClick,
387
- isDetailOpen,
388
395
  onPromptRespond,
389
- onViewYaml,
390
- onViewAgentSource,
396
+ sessionId,
391
397
  }: {
392
398
  state: ArchitectState;
393
399
  onAbort: () => void;
394
- onClick?: () => void;
395
- isDetailOpen?: boolean;
396
400
  onPromptRespond?: (promptId: string, answer: string) => void;
397
- onViewYaml?: () => void;
398
- onViewAgentSource?: (agentName: string, source: string) => void;
401
+ /** Session id — threaded so the popout button can build a URL.
402
+ See change: fix-flows-plugin-polish (A4). */
403
+ sessionId?: string;
399
404
  }) {
405
+ const popoutUrl = buildFlowArchitectPopoutUrl(sessionId);
406
+ const popoutEnabled = popoutUrl !== null;
407
+ const handlePopout = React.useCallback(
408
+ (e: React.MouseEvent) => {
409
+ e.stopPropagation();
410
+ if (popoutUrl) window.open(popoutUrl, "_blank", "noopener");
411
+ },
412
+ [popoutUrl],
413
+ );
400
414
  const [collapsed, setCollapsed] = useState(false);
415
+ // Popover state for the architect-detail view. Lives in this component
416
+ // so the eye button (the anchor) and the Popover share the same scope.
417
+ // Replaces the old `content-view` slot claim + global UI-state flag.
418
+ // See change: add-ui-popover-primitive.
419
+ const [detailOpen, setDetailOpen] = useState(false);
420
+ const detailButtonRef = useRef<HTMLButtonElement | null>(null);
421
+ const Popover = useUiPrimitive(UI_PRIMITIVE_KEYS.popover);
401
422
  const isActive = state.phase === "context" || state.phase === "designing";
402
423
  const isPreview = state.phase === "preview";
403
424
  const customAgents = state.agents.filter((a) => a.type === "custom");
@@ -422,7 +443,7 @@ export function FlowArchitect({
422
443
  <span className="text-purple-400 text-sm font-medium">π</span>
423
444
  )}
424
445
  <span className="text-sm text-[var(--text-primary)] truncate flex-1">
425
- Flow Architect
446
+ Flow Architect{" "}
426
447
  <span className="text-[var(--text-tertiary)] ml-1.5">
427
448
  {state.phase === "context"
428
449
  ? "Analyzing conversation..."
@@ -529,8 +550,13 @@ export function FlowArchitect({
529
550
  {state.flowWriteStatus === "validation-error" ? "✗" : "✓"}
530
551
  </span>
531
552
  )}
532
- {onViewYaml && state.flowYamlContent && (
533
- <ViewFileButton title="View flow YAML" onClick={onViewYaml} />
553
+ {state.flowYamlContent && (
554
+ <ViewFilePopoverButton
555
+ title="View flow YAML"
556
+ content={state.flowYamlContent}
557
+ filename={state.flowName ? `${state.flowName}.yaml` : "flow.yaml"}
558
+ language="yaml"
559
+ />
534
560
  )}
535
561
  </div>
536
562
  </div>
@@ -550,15 +576,7 @@ export function FlowArchitect({
550
576
  }}
551
577
  >
552
578
  {customAgents.map((agent) => (
553
- <ArchitectAgentCard
554
- key={agent.name}
555
- agent={agent}
556
- onViewSource={
557
- agent.source && onViewAgentSource
558
- ? () => onViewAgentSource(agent.name, agent.source!)
559
- : undefined
560
- }
561
- />
579
+ <ArchitectAgentCard key={agent.name} agent={agent} />
562
580
  ))}
563
581
  </div>
564
582
  </div>
@@ -582,21 +600,54 @@ export function FlowArchitect({
582
600
  </div>
583
601
  ))}
584
602
  </div>
585
- <div className="flex items-center gap-2 mt-1">
586
- {onClick && (
587
- <button
588
- onClick={onClick}
589
- className={`transition-colors p-0.5 rounded inline-flex items-center ${
590
- isDetailOpen
591
- ? "text-purple-400 bg-purple-400/10"
592
- : "text-[var(--text-tertiary)] hover:text-purple-400 hover:bg-[var(--bg-surface)]"
593
- }`}
594
- title={isDetailOpen ? "Close architect detail" : "View full architect detail"}
595
- >
596
- <Icon path={isDetailOpen ? mdiEyeOffOutline : mdiEyeOutline} size={0.5} />
597
- </button>
598
- )}
603
+ <div className="flex items-center gap-1.5 mt-1">
604
+ <button
605
+ type="button"
606
+ onClick={handlePopout}
607
+ disabled={!popoutEnabled}
608
+ data-testid="flow-architect-popout-button"
609
+ className={`transition-colors px-1.5 py-0.5 rounded text-[11px] inline-flex items-center gap-1 border ${
610
+ popoutEnabled
611
+ ? "border-[var(--border-subtle)] text-[var(--text-tertiary)] hover:text-purple-400 hover:border-purple-400/40 hover:bg-purple-400/10"
612
+ : "border-[var(--border-subtle)] text-[var(--text-muted)] opacity-50 cursor-not-allowed"
613
+ }`}
614
+ title={popoutEnabled ? "Open Flow Architect in new tab" : "Popout unavailable (no session context)"}
615
+ >
616
+ <Icon path={mdiOpenInNew} size={0.55} />
617
+ <span className="text-[10px]">Popout</span>
618
+ </button>
619
+ <button
620
+ ref={detailButtonRef}
621
+ type="button"
622
+ onClick={() => setDetailOpen((prev) => !prev)}
623
+ className={`transition-colors px-1.5 py-0.5 rounded text-[11px] inline-flex items-center gap-1 border ${
624
+ detailOpen
625
+ ? "text-purple-400 bg-purple-400/10 border-purple-400/40"
626
+ : "border-[var(--border-subtle)] text-[var(--text-tertiary)] hover:text-purple-400 hover:border-purple-400/40 hover:bg-purple-400/10"
627
+ }`}
628
+ title={detailOpen ? "Close architect detail" : "View full architect detail"}
629
+ >
630
+ <Icon path={detailOpen ? mdiEyeOffOutline : mdiEyeOutline} size={0.55} />
631
+ <span className="text-[10px]">Details</span>
632
+ </button>
599
633
  </div>
634
+ {detailOpen && detailButtonRef.current && (
635
+ <Popover
636
+ anchorEl={detailButtonRef.current}
637
+ onDismiss={() => setDetailOpen(false)}
638
+ >
639
+ {/* `overflow-hidden` on the wrapper + the inner MinimalChatView's
640
+ `overflow-y-auto` body produces an inner scrollbar (not an
641
+ outer one). See change: fix-flows-plugin-polish (scrollbar fix). */}
642
+ <div className="w-[640px] max-w-[90vw] h-[70vh] overflow-hidden bg-[var(--bg-secondary)] border border-[var(--border-primary)] rounded-md shadow-xl">
643
+ <FlowArchitectDetail
644
+ state={state}
645
+ onBack={() => setDetailOpen(false)}
646
+ sessionId={sessionId}
647
+ />
648
+ </div>
649
+ </Popover>
650
+ )}
600
651
  </div>
601
652
  </div>
602
653
  </div>
@@ -620,3 +671,29 @@ export function FlowArchitect({
620
671
  </div>
621
672
  );
622
673
  }
674
+
675
+ /**
676
+ * Slot-consumer wrapper for the `content-header-sticky` claim.
677
+ * Self-derives architect state and dispatches via pluginContext.send.
678
+ * Returns null when no architect is active. See change:
679
+ * pluginize-flows-via-registry.
680
+ */
681
+ export function FlowArchitectClaim({ session }: { session: DashboardSession }) {
682
+ const { architectState } = useFlowsSessionState(session.id);
683
+ const send = usePluginSend();
684
+
685
+ if (!architectState) return null;
686
+
687
+ return (
688
+ <FlowArchitect
689
+ state={architectState}
690
+ sessionId={session.id}
691
+ onAbort={() =>
692
+ send({ type: "flow_control", sessionId: session.id, action: "abort" })
693
+ }
694
+ onPromptRespond={(promptId, answer) =>
695
+ send({ type: "architect_prompt_response", sessionId: session.id, promptId, answer })
696
+ }
697
+ />
698
+ );
699
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * FlowArchitectPopoutClaim — slot-claim wrapper for the
3
+ * `shell-overlay-route` registration `/session/:sid/architect`.
4
+ *
5
+ * Reads architect state via the plugin's `useFlowsSessionState`,
6
+ * cold-open subscribes, renders `FlowArchitectPopoutPage`.
7
+ *
8
+ * See change: fix-flows-plugin-polish (A4).
9
+ */
10
+ import React, { useEffect, useRef } from "react";
11
+ import {
12
+ usePluginSend,
13
+ useShellConnectionStatus,
14
+ } from "@blackbelt-technology/dashboard-plugin-runtime";
15
+ import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
16
+ import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
17
+ import { FlowArchitectPopoutPage } from "./FlowArchitectPopoutPage.js";
18
+
19
+ export interface FlowArchitectPopoutClaimProps {
20
+ params: Record<string, string>;
21
+ session?: DashboardSession;
22
+ onBack: () => void;
23
+ }
24
+
25
+ export function FlowArchitectPopoutClaim({ params, session, onBack }: FlowArchitectPopoutClaimProps) {
26
+ const sessionId = params.sid ?? "";
27
+ const send = usePluginSend();
28
+ const { architectState } = useFlowsSessionState(sessionId);
29
+ const connectionStatus = useShellConnectionStatus();
30
+
31
+ // Cold-open subscribe exactly once, AFTER the WebSocket is open.
32
+ // See change: fix-flows-plugin-polish (popout cold-open subscribe).
33
+ const subscribedRef = useRef(false);
34
+ useEffect(() => {
35
+ if (!sessionId || subscribedRef.current) return;
36
+ if (connectionStatus !== "connected") return;
37
+ subscribedRef.current = true;
38
+ send({ type: "subscribe", sessionId, lastSeq: 0 });
39
+ }, [sessionId, send, connectionStatus]);
40
+
41
+ const subscriptionResolved = !!session || architectState !== null;
42
+
43
+ return (
44
+ <FlowArchitectPopoutPage
45
+ sessionId={sessionId}
46
+ architectState={architectState ?? undefined}
47
+ subscriptionResolved={subscriptionResolved}
48
+ parentLabel={session?.cwd}
49
+ onBack={onBack}
50
+ />
51
+ );
52
+ }