@blackbelt-technology/pi-dashboard-flows-plugin 0.5.4 → 0.6.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 (66) hide show
  1. package/package.json +25 -16
  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 +2 -39
  8. package/src/__tests__/authoring-renderers.test.tsx +190 -0
  9. package/src/__tests__/automation-actions.test.ts +117 -0
  10. package/src/__tests__/flow-agent-card-code-source.test.tsx +154 -0
  11. package/src/__tests__/flow-agent-cost.test.tsx +160 -0
  12. package/src/__tests__/flow-agent-error.test.ts +60 -0
  13. package/src/__tests__/flow-collapse-storage.test.ts +90 -0
  14. package/src/__tests__/flow-edges.test.ts +195 -0
  15. package/src/__tests__/flow-inputs.test.ts +69 -0
  16. package/src/__tests__/flow-reducer-bridge-contract.test.ts +108 -0
  17. package/src/__tests__/flow-reducer-seed-on-start.test.ts +61 -0
  18. package/src/__tests__/flow-yaml-parse.test.ts +124 -0
  19. package/src/__tests__/flows-for-cwd.test.ts +51 -0
  20. package/src/__tests__/flowsAvailability.test.ts +51 -64
  21. package/src/__tests__/node-kind-reducer.test.ts +135 -0
  22. package/src/__tests__/plugin-action-handler.test.ts +54 -0
  23. package/src/__tests__/session-flow-actions-edit.test.tsx +98 -0
  24. package/src/bridge/AGENTS.md +8 -0
  25. package/src/client/AGENTS.md +32 -0
  26. package/src/client/FlowActivityBadge.tsx +8 -5
  27. package/src/client/FlowAgentCard.tsx +231 -110
  28. package/src/client/FlowAgentDetail.tsx +20 -12
  29. package/src/client/FlowAgentsToolRenderer.tsx +228 -0
  30. package/src/client/FlowAuthorPromptDialog.tsx +92 -0
  31. package/src/client/FlowDashboard.tsx +88 -23
  32. package/src/client/FlowGraph.tsx +420 -275
  33. package/src/client/FlowInputWiring.tsx +243 -0
  34. package/src/client/FlowLaunchDialog.tsx +48 -54
  35. package/src/client/FlowQuestionCard.tsx +6 -3
  36. package/src/client/FlowSummary.tsx +252 -69
  37. package/src/client/FlowWriteToolRenderer.tsx +127 -0
  38. package/src/client/FlowYamlPopoverButton.tsx +26 -25
  39. package/src/client/FlowYamlPreview.tsx +9 -7
  40. package/src/client/FlowsSessionStateContext.tsx +14 -33
  41. package/src/client/FlowsSettings.tsx +68 -0
  42. package/src/client/SessionFlowActions.tsx +92 -76
  43. package/src/client/flow-collapse-storage.ts +79 -0
  44. package/src/client/flow-edges.ts +173 -0
  45. package/src/client/flow-yaml-parse.ts +140 -0
  46. package/src/client/flowsAvailability.ts +28 -87
  47. package/src/client/index.tsx +27 -32
  48. package/src/client/shouldRender.ts +24 -12
  49. package/src/configSchema.json +14 -0
  50. package/src/flow-reducer.ts +94 -13
  51. package/src/i18n.ts +90 -0
  52. package/src/reducer.ts +5 -5
  53. package/src/server/AGENTS.md +10 -0
  54. package/src/server/automation-actions.ts +162 -0
  55. package/src/server/flow-inputs.ts +58 -0
  56. package/src/server/index.ts +93 -9
  57. package/src/server/state-store.ts +3 -14
  58. package/src/__tests__/ArchitectInputPrompt.test.tsx +0 -81
  59. package/src/__tests__/architect-reducer.test.ts +0 -307
  60. package/src/architect-reducer.ts +0 -386
  61. package/src/client/FlowAgentPopoutClaim.tsx +0 -66
  62. package/src/client/FlowAgentPopoutPage.tsx +0 -177
  63. package/src/client/FlowArchitect.tsx +0 -699
  64. package/src/client/FlowArchitectPopoutClaim.tsx +0 -52
  65. package/src/client/FlowArchitectPopoutPage.tsx +0 -133
  66. package/src/client/popout-url.ts +0 -59
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Shared flow-edge derivation. ONE rule, consumed by both the live `FlowGraph`
3
+ * (running runs, from `dagSteps`) and the static `flow_write` Mermaid snapshot
4
+ * (from parsed YAML), so the two views never drift on what an edge is.
5
+ *
6
+ * Edge classes:
7
+ * - `sequential` — `blockedBy` dependency
8
+ * - `branch` — decision `branches` (fork / agent-decision / code-decision)
9
+ * - `route` — `on_complete` / `on_error` cross-segment routing
10
+ * - `implicit` — a step after a separator with no `blockedBy` (segment fall-through)
11
+ *
12
+ * The function derives only the classes its input carries: the live caller
13
+ * passes `branches` but not `onComplete`/`onError` (pi-flows omits those from
14
+ * `flow:flow-started`), so `route` edges appear only in the static caller.
15
+ *
16
+ * See change: improve-flow-ui.
17
+ */
18
+
19
+ export type FlowEdgeKind = "sequential" | "branch" | "route" | "implicit";
20
+
21
+ export interface FlowEdgeStep {
22
+ id: string;
23
+ /** Node kind (`agent` | `fork` | `agent-decision` | `code` | `code-decision`). */
24
+ type: string;
25
+ blockedBy: string[];
26
+ /** Decision branch label → target step id. */
27
+ branches?: Record<string, string>;
28
+ onComplete?: string;
29
+ onError?: string;
30
+ }
31
+
32
+ export interface FlowEdge {
33
+ from: string;
34
+ to: string;
35
+ label?: string;
36
+ kind: FlowEdgeKind;
37
+ /** Target declared at or before the source → render as backward/loop edge. */
38
+ backward: boolean;
39
+ /** Set only on `route` edges labeled `on_error`. `returning` = the handler's
40
+ * forward closure rejoins the main flow (live control flow → render as a loop
41
+ * arc); `terminal` = the handler is a sink that never rejoins (→ collapse into
42
+ * a tail sink node). Mirrors the engine, which keeps running every step
43
+ * reachable from an on_error target after routing to it. */
44
+ routeTopology?: "returning" | "terminal";
45
+ }
46
+
47
+ /** Derive the canonical edge set for a flow. Pure; order-sensitive (array index
48
+ * defines forward/backward). Skips edges whose endpoints are not in `steps`,
49
+ * and collapses duplicate `{from,to}` pairs (labeled branch/route wins). */
50
+ /** Separator node types that close a DAG segment and open the next. A
51
+ * no-blockedBy step falling through from one of these is the only `implicit`
52
+ * edge the engine actually serializes. (`flow-ref` is NOT a separator.) The
53
+ * set covers both raw stepTypes (static YAML preview) and the live graph's
54
+ * mapped types, where `agent-decision` collapses to `fork`. */
55
+ const SEPARATOR_TYPES = new Set(["fork", "agent-decision", "code-decision"]);
56
+
57
+ export function deriveFlowEdges(steps: FlowEdgeStep[]): FlowEdge[] {
58
+ const order = new Map(steps.map((s, i) => [s.id, i]));
59
+ const has = (id: string) => order.has(id);
60
+ const edges: FlowEdge[] = [];
61
+
62
+ const add = (from: string, to: string, kind: FlowEdgeKind, label?: string): void => {
63
+ if (!has(from) || !has(to)) return;
64
+ const backward = (order.get(to) ?? 0) <= (order.get(from) ?? 0);
65
+ const existing = edges.find((e) => e.from === from && e.to === to);
66
+ if (existing) {
67
+ // De-dup: prefer the labeled branch/route classification over a plain
68
+ // sequential/implicit edge for the same pair.
69
+ const labeled = kind === "branch" || kind === "route";
70
+ const existingLabeled = existing.kind === "branch" || existing.kind === "route";
71
+ if (labeled && !existingLabeled) {
72
+ existing.kind = kind;
73
+ existing.label = label;
74
+ existing.backward = backward;
75
+ }
76
+ return;
77
+ }
78
+ edges.push({ from, to, kind, label, backward });
79
+ };
80
+
81
+ // 1. Sequential edges (blockedBy).
82
+ for (const s of steps) {
83
+ for (const dep of s.blockedBy) add(dep, s.id, "sequential");
84
+ }
85
+
86
+ // 2. Decision-branch edges.
87
+ for (const s of steps) {
88
+ if (!s.branches) continue;
89
+ for (const [label, target] of Object.entries(s.branches)) {
90
+ add(s.id, target, "branch", label);
91
+ }
92
+ }
93
+
94
+ // 3. Routing edges (on_complete / on_error).
95
+ for (const s of steps) {
96
+ if (s.onComplete) add(s.id, s.onComplete, "route", "on_complete");
97
+ if (s.onError) add(s.id, s.onError, "route", "on_error");
98
+ }
99
+
100
+ // 4. Implicit-segment edges. The engine wave scheduler runs EVERY step whose
101
+ // blockedBy is satisfied at once — a step with no blockedBy is a root that
102
+ // fires in wave 1, in parallel with its siblings. Inter-segment ordering is
103
+ // enforced only by SEPARATOR steps (fork / agent-decision / code-decision),
104
+ // which close one segment and open the next. So a no-blockedBy step with no
105
+ // incoming edge falls through ONLY from the most recent separator (placing it
106
+ // after that boundary); two such roots after the same separator are parallel
107
+ // siblings and both fan out from it (never chained to each other). Roots
108
+ // before any separator stay un-parented → same rank → parallel.
109
+ const incoming = new Set(edges.map((e) => e.to));
110
+ let lastSeparator: string | undefined;
111
+ for (const curr of steps) {
112
+ const fallsThrough = curr.blockedBy.length === 0 && !incoming.has(curr.id);
113
+ if (fallsThrough && lastSeparator && lastSeparator !== curr.id) {
114
+ add(lastSeparator, curr.id, "implicit");
115
+ incoming.add(curr.id);
116
+ }
117
+ if (SEPARATOR_TYPES.has(curr.type)) lastSeparator = curr.id;
118
+ }
119
+
120
+ // 5. on_error route topology. The engine keeps running everything reachable
121
+ // from an on_error target. A handler is `returning` when its forward
122
+ // closure rejoins the source or the source's success continuation
123
+ // (live control flow → loop arc); `terminal` otherwise (a sink).
124
+ classifyRouteTopology(edges);
125
+
126
+ return edges;
127
+ }
128
+
129
+ /** Tag each `on_error` route edge with `routeTopology`. Pure: reachability over
130
+ * the flow edges EXCLUDING on_error routes (those are what we classify). A
131
+ * handler is `returning` when its forward closure reaches the route source or
132
+ * any node on the source's success continuation; else `terminal`. */
133
+ function classifyRouteTopology(edges: FlowEdge[]): void {
134
+ const errorRoutes = edges.filter((e) => e.kind === "route" && e.label === "on_error");
135
+ if (errorRoutes.length === 0) return;
136
+
137
+ const adj = new Map<string, string[]>();
138
+ for (const e of edges) {
139
+ if (e.kind === "route" && e.label === "on_error") continue; // exclude the edges under test
140
+ const list = adj.get(e.from);
141
+ if (list) list.push(e.to);
142
+ else adj.set(e.from, [e.to]);
143
+ }
144
+
145
+ const cache = new Map<string, Set<string>>();
146
+ const reach = (start: string): Set<string> => {
147
+ const cached = cache.get(start);
148
+ if (cached) return cached;
149
+ const seen = new Set<string>();
150
+ const stack = [start];
151
+ while (stack.length) {
152
+ const n = stack.pop() as string;
153
+ if (seen.has(n)) continue;
154
+ seen.add(n);
155
+ for (const m of adj.get(n) ?? []) stack.push(m);
156
+ }
157
+ cache.set(start, seen);
158
+ return seen;
159
+ };
160
+
161
+ for (const e of errorRoutes) {
162
+ const fromClosure = reach(e.from); // source + its success continuation
163
+ const handlerClosure = reach(e.to); // handler + its forward closure
164
+ let returning = false;
165
+ for (const n of handlerClosure) {
166
+ if (n !== e.to && (n === e.from || fromClosure.has(n))) {
167
+ returning = true;
168
+ break;
169
+ }
170
+ }
171
+ e.routeTopology = returning ? "returning" : "terminal";
172
+ }
173
+ }
@@ -0,0 +1,140 @@
1
+ /**
2
+ * Shallow client-side parser for a flow YAML document, used by the
3
+ * `flow_write` tool renderer to build a Mermaid snapshot + step/agent/code
4
+ * counts from the tool ARGS (the submitted `content`). The tool result
5
+ * carries no parsed steps, so we parse the args here.
6
+ *
7
+ * Intentionally shallow + graceful: it extracts only what the snapshot needs
8
+ * (id, type, blockedBy, branches) and returns null on any parse failure so the
9
+ * renderer degrades to the plain success state without erroring.
10
+ *
11
+ * See change: rework-flows-plugin-for-new-pi-flows.
12
+ */
13
+ import { parse as parseYaml } from "yaml";
14
+ import { deriveFlowEdges, type FlowEdgeStep } from "./flow-edges.js";
15
+
16
+ export interface ParsedFlowStep {
17
+ id: string;
18
+ /** Node kind from the flow `type:` field (agent | code | code-decision | …). */
19
+ type: string;
20
+ blockedBy: string[];
21
+ /** Decision branch label → target step id (code-decision / agent-decision). */
22
+ branches?: Record<string, string>;
23
+ onComplete?: string;
24
+ onError?: string;
25
+ }
26
+
27
+ export interface ParsedFlow {
28
+ name?: string;
29
+ steps: ParsedFlowStep[];
30
+ counts: { total: number; agents: number; code: number };
31
+ }
32
+
33
+ function asStringArray(v: unknown): string[] {
34
+ if (Array.isArray(v)) return v.filter((x): x is string => typeof x === "string");
35
+ if (typeof v === "string") return [v];
36
+ return [];
37
+ }
38
+
39
+ /** Parse a flow YAML string into a shallow step model. Returns null on failure. */
40
+ export function parseFlowYaml(content: string): ParsedFlow | null {
41
+ let doc: unknown;
42
+ try {
43
+ doc = parseYaml(content);
44
+ } catch {
45
+ return null;
46
+ }
47
+ if (!doc || typeof doc !== "object") return null;
48
+ const root = doc as Record<string, unknown>;
49
+ const rawSteps = root.steps;
50
+ if (!Array.isArray(rawSteps)) return null;
51
+
52
+ const steps: ParsedFlowStep[] = [];
53
+ for (const rs of rawSteps) {
54
+ if (!rs || typeof rs !== "object") continue;
55
+ const s = rs as Record<string, unknown>;
56
+ const id = typeof s.id === "string" ? s.id : undefined;
57
+ if (!id) continue;
58
+ const type = typeof s.type === "string" ? s.type : "agent";
59
+ const branchesRaw = s.branches;
60
+ let branches: Record<string, string> | undefined;
61
+ if (branchesRaw && typeof branchesRaw === "object" && !Array.isArray(branchesRaw)) {
62
+ branches = {};
63
+ for (const [k, v] of Object.entries(branchesRaw as Record<string, unknown>)) {
64
+ if (typeof v === "string") branches[k] = v;
65
+ }
66
+ }
67
+ steps.push({
68
+ id,
69
+ type,
70
+ blockedBy: asStringArray(s.blockedBy),
71
+ branches,
72
+ onComplete: typeof s.on_complete === "string" ? s.on_complete : undefined,
73
+ onError: typeof s.on_error === "string" ? s.on_error : undefined,
74
+ });
75
+ }
76
+ if (steps.length === 0) return null;
77
+
78
+ const agents = steps.filter((s) => s.type === "agent" || s.type === "agent-decision").length;
79
+ const code = steps.filter((s) => s.type === "code" || s.type === "code-decision").length;
80
+
81
+ return {
82
+ name: typeof root.name === "string" ? root.name : undefined,
83
+ steps,
84
+ counts: { total: steps.length, agents, code },
85
+ };
86
+ }
87
+
88
+ /** Mermaid node shape per node type, mirroring the live FlowGraph glyphs. */
89
+ function nodeShape(type: string, id: string, label: string): string {
90
+ switch (type) {
91
+ case "code": return `${id}[["⌗ ${label}"]]`;
92
+ case "code-decision": return `${id}{"◈ ${label}"}`;
93
+ case "agent-decision":
94
+ case "fork": return `${id}{"◇ ${label}"}`;
95
+ default: return `${id}(["${label}"])`;
96
+ }
97
+ }
98
+
99
+ /** Build a `graph LR` Mermaid string from a parsed flow. Edges come from the
100
+ * shared `deriveFlowEdges` (blockedBy + branches + on_complete/on_error +
101
+ * implicit-segment), so the snapshot matches the live FlowGraph. Backward
102
+ * edges (loops) render dashed. See change: improve-flow-ui. */
103
+ export function flowToMermaid(flow: ParsedFlow): string {
104
+ const lines: string[] = ["graph LR"];
105
+ for (const s of flow.steps) {
106
+ lines.push(` ${nodeShape(s.type, s.id, s.id)}`);
107
+ }
108
+ const edges = deriveFlowEdges(
109
+ flow.steps.map((s): FlowEdgeStep => ({
110
+ id: s.id,
111
+ type: s.type,
112
+ blockedBy: s.blockedBy,
113
+ branches: s.branches,
114
+ onComplete: s.onComplete,
115
+ onError: s.onError,
116
+ })),
117
+ );
118
+ for (const e of edges) {
119
+ if (e.kind === "route" && e.label === "on_error") {
120
+ // Topology-distinct on_error, mirroring the live FlowGraph: ↺ returning
121
+ // (handler rejoins the flow — a recovery loop) vs ⊗ terminal (a sink/exit).
122
+ // Always dashed so it reads as an exception edge, never the happy path.
123
+ const marker = e.routeTopology === "terminal" ? "⊗" : "↺";
124
+ lines.push(` ${e.from} -. "on_error ${marker}" .-> ${e.to}`);
125
+ } else {
126
+ // `on_complete` is the happy-path default — render unlabeled so an
127
+ // on_complete-wired flow's spine reads as plain arrows, not repeated
128
+ // labels (matches the live FlowGraph). See change: fix-flow-ui-graph-zoom-summary.
129
+ const lbl = e.label === "on_complete" ? undefined : e.label;
130
+ if (e.backward) {
131
+ lines.push(` ${e.from} -. "${lbl ?? ""} ↺" .-> ${e.to}`);
132
+ } else if (lbl) {
133
+ lines.push(` ${e.from} -->|${lbl}| ${e.to}`);
134
+ } else {
135
+ lines.push(` ${e.from} --> ${e.to}`);
136
+ }
137
+ }
138
+ }
139
+ return lines.join("\n");
140
+ }
@@ -1,103 +1,44 @@
1
1
  /**
2
- * Per-session sync availability cache for flows-plugin's
3
- * `shouldRenderFlowsSubcard` predicate.
2
+ * Flow-event probe backing part of flows-plugin's `shouldRenderFlowsSubcard`
3
+ * predicate.
4
4
  *
5
- * The MEMORY/honcho path uses a global boolean (extension installed or not).
6
- * Flow availability is per-session: session A may have `flowsList`, session
7
- * B may not. The cache is therefore keyed by sessionId.
5
+ * The former per-session availability cache (populated from `commandsList` via a
6
+ * module-level subscriber) is retired: the gate now reads live per-session-data
7
+ * + plugin config directly in `shouldRender.ts`, so a mirrored cache is no
8
+ * longer needed. Only the flow-event memo survives here.
8
9
  *
9
- * Population is driven by a module-level subscriber attached to the runtime's
10
- * `subscribeSessionDataKey` API at plugin-client-entry load. Each
11
- * `publishSessionData` for `flowsList` or `commandsList` recomputes
12
- * availability for that session and writes to the cache.
13
- *
14
- * The cache is closed-by-default: `getFlowsAvailabilitySync` returns `false`
15
- * for sessions the subscriber hasn't observed yet. This prevents a
16
- * subcard-flicker on first paint (hidden → visible is fine, visible → hidden
17
- * would be jarring). See change: add-flows-subcard (design.md Decision 3).
18
- */
19
- import {
20
- getSessionData,
21
- subscribeSessionDataKey,
22
- } from "@blackbelt-technology/dashboard-plugin-runtime";
23
- import type { CommandInfo, FlowInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
24
-
25
- const availability = new Map<string, boolean>();
26
-
27
- /**
28
- * Sync readable accessor for `shouldRenderFlowsSubcard`. Returns `false`
29
- * for sessions whose availability has not been observed yet.
30
- */
31
- export function getFlowsAvailabilitySync(sessionId: string): boolean {
32
- return availability.get(sessionId) ?? false;
33
- }
34
-
35
- /**
36
- * Set the cached availability for a session. Exposed for tests and for the
37
- * module-level subscriber installed by `installFlowsAvailabilitySubscriber`.
38
- */
39
- export function setFlowsAvailability(sessionId: string, has: boolean): void {
40
- availability.set(sessionId, has);
41
- }
42
-
43
- /**
44
- * Compute availability from the published per-session-data store values.
45
- * Pure helper — no side effects.
10
+ * See change: fix-empty-flows-subcard.
46
11
  */
47
- function computeAvailability(
48
- flows: FlowInfo[] | undefined,
49
- commands: CommandInfo[] | undefined,
50
- ): boolean {
51
- const hasFlows = Array.isArray(flows) && flows.length > 0;
52
- const hasFlowsNew = Array.isArray(commands) && commands.some((c) => c.name === "flows:new");
53
- return hasFlows || hasFlowsNew;
54
- }
12
+ import { getSessionEvents } from "@blackbelt-technology/dashboard-plugin-runtime";
13
+ import { isFlowEvent } from "../reducer.js";
55
14
 
56
- let installed = false;
57
- let unsubscribers: Array<() => void> = [];
15
+ // Per-session memo for "has this session seen any flow event?". Keyed on the
16
+ // session-events array reference (stable until the next publish) so the scan
17
+ // runs only when the event list grows; once true it stays true (flow events
18
+ // are append-only). Lets the FLOWS subcard reattach on cold load after replay,
19
+ // where the `flowsList`/`commandsList` availability signal is NOT replayed and
20
+ // is closed-by-default. See change: replay-persisted-flow-runs (task 5.5).
21
+ const flowEventMemo = new Map<string, { ref: readonly unknown[]; has: boolean }>();
58
22
 
59
23
  /**
60
- * Install a module-level subscriber that updates the availability cache on
61
- * every `flowsList` / `commandsList` publish. Idempotent: subsequent calls
62
- * return the same unsubscribe function and do not multiply listeners.
63
- *
64
- * Called once at flows-plugin client-entry load.
24
+ * True when the session's replayed/live event stream contains any `flow_*`
25
+ * event. Synchronous, cheap (ref-memoized + sticky-true), safe to call from
26
+ * the `shouldRenderFlowsSubcard` predicate.
65
27
  */
66
- export function installFlowsAvailabilitySubscriber(): () => void {
67
- if (installed) {
68
- return uninstall;
69
- }
70
- installed = true;
71
-
72
- const recompute = (sessionId: string): void => {
73
- const flows = getSessionData<FlowInfo[]>(sessionId, "flowsList");
74
- const commands = getSessionData<CommandInfo[]>(sessionId, "commandsList");
75
- setFlowsAvailability(sessionId, computeAvailability(flows, commands));
76
- };
77
-
78
- unsubscribers.push(
79
- subscribeSessionDataKey("flowsList", (sessionId) => recompute(sessionId)),
80
- );
81
- unsubscribers.push(
82
- subscribeSessionDataKey("commandsList", (sessionId) => recompute(sessionId)),
83
- );
84
-
85
- return uninstall;
86
- }
87
-
88
- function uninstall(): void {
89
- for (const u of unsubscribers) u();
90
- unsubscribers = [];
91
- installed = false;
28
+ export function sessionHasFlowEvents(sessionId: string): boolean {
29
+ const events = getSessionEvents(sessionId);
30
+ const cached = flowEventMemo.get(sessionId);
31
+ if (cached && (cached.has || cached.ref === events)) return cached.has;
32
+ const has = events.some((e) => isFlowEvent((e as { eventType: string }).eventType));
33
+ flowEventMemo.set(sessionId, { ref: events, has });
34
+ return has;
92
35
  }
93
36
 
94
37
  /**
95
- * Test-only: reset cache + install guard so test cases can re-install the
96
- * subscriber from scratch.
38
+ * Test-only: clear the flow-event memo so cases start from a clean slate.
97
39
  *
98
40
  * @internal
99
41
  */
100
42
  export function __resetFlowsAvailabilityForTests(): void {
101
- availability.clear();
102
- uninstall();
43
+ flowEventMemo.clear();
103
44
  }
@@ -11,21 +11,13 @@
11
11
 
12
12
  // Existing presentation components — still used directly by App.tsx
13
13
  // during the cutover (Part H removes those call sites).
14
- export { FlowDashboard } from "./FlowDashboard.js";
14
+ // i18n catalog — merged under `plugin.flows.*` by the shell via the
15
+ // manifest's `i18nCatalog: "catalog"` declaration. See change: make-all-ui-text-i18n.
16
+ export { catalog } from "../i18n.js";
17
+ export { FlowActivityBadge } from "./FlowActivityBadge.js";
15
18
  export { FlowAgentCard } from "./FlowAgentCard.js";
16
19
  export { FlowAgentDetail } from "./FlowAgentDetail.js";
17
- export { FlowAgentPopoutPage } from "./FlowAgentPopoutPage.js";
18
- export { FlowAgentPopoutClaim } from "./FlowAgentPopoutClaim.js";
19
- export { FlowArchitectPopoutPage } from "./FlowArchitectPopoutPage.js";
20
- export { FlowArchitectPopoutClaim } from "./FlowArchitectPopoutClaim.js";
21
- export { FlowSummary } from "./FlowSummary.js";
22
- export { FlowGraph, flowStateToGraphSteps, architectStepsToGraphSteps, computeLayout } from "./FlowGraph.js";
23
- export { FlowArchitect, FlowArchitectDetail, ArchitectInputPrompt } from "./FlowArchitect.js";
24
- export { FlowActivityBadge } from "./FlowActivityBadge.js";
25
- export { FlowLaunchDialog } from "./FlowLaunchDialog.js";
26
- export { FlowTabBar } from "./FlowTabBar.js";
27
- export { SessionFlowActions } from "./SessionFlowActions.js";
28
-
20
+ export { FlowAgentsToolRenderer } from "./FlowAgentsToolRenderer.js";
29
21
  // Slot-claim wrappers — the plugin's manifest references these.
30
22
  // Each derives state from the plugin-internal contexts and dispatches
31
23
  // via pluginContext.send. See change: pluginize-flows-via-registry.
@@ -33,12 +25,23 @@ export { SessionFlowActions } from "./SessionFlowActions.js";
33
25
  // session-card-badge claim was dropped because the badge belongs in the
34
26
  // FLOWS subcard, not WORKSPACE. SessionFlowActions now renders the badge
35
27
  // directly via the FlowActivityBadge component.
36
- export { FlowDashboardClaim } from "./FlowDashboard.js";
37
- export { FlowArchitectClaim } from "./FlowArchitect.js";
28
+ export { FlowDashboard, FlowDashboardClaim } from "./FlowDashboard.js";
29
+ export { computeLayout, FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
30
+ // Input-wiring editor claimed into automation-plugin's `automation-action-editor`
31
+ // slot for `flows.run`. See change: wire-flow-inputs-in-automation.
32
+ export { FlowInputWiring, FlowInputWiringClaim } from "./FlowInputWiring.js";
33
+ export { FlowLaunchDialog } from "./FlowLaunchDialog.js";
34
+ export { FlowSummary, FlowSummaryClaim } from "./FlowSummary.js";
35
+ export type { FlowsPluginConfig } from "./FlowsSettings.js";
38
36
 
39
- export { FlowSummaryClaim } from "./FlowSummary.js";
37
+ // Settings section (global edit-mode default) — manifest `settings-section` claim.
38
+ export { FlowsSettings } from "./FlowsSettings.js";
39
+ export { FlowTabBar } from "./FlowTabBar.js";
40
+ // Authoring tool-renderers (main-session timeline) — referenced by the
41
+ // manifest's `tool-renderer` claims. See change: rework-flows-plugin-for-new-pi-flows.
42
+ export { FlowWriteToolRenderer } from "./FlowWriteToolRenderer.js";
40
43
  export { FlowYamlPreviewClaim } from "./FlowYamlPreview.js";
41
- export { SessionFlowActionsClaim } from "./SessionFlowActions.js";
44
+ export { SessionFlowActions, SessionFlowActionsClaim } from "./SessionFlowActions.js";
42
45
 
43
46
  // Manifest-level shouldRender predicate for the `session-card-flows` claim.
44
47
  // See change: add-flows-subcard.
@@ -54,17 +57,17 @@ export { shouldRenderFlowsSubcard } from "./shouldRender.js";
54
57
  // Restore the exports here if/when the dashboard re-introduces command-route
55
58
  // claims for flows.
56
59
 
60
+ export type { FlowsSessionState } from "./FlowsSessionStateContext.js";
57
61
  // Plugin-internal state hooks. Components consume these in place of
58
62
  // props that previously came from App.tsx. See change:
59
63
  // pluginize-flows-via-registry.
60
64
  export {
61
- useFlowsSessionState,
62
65
  reduceFlowsSessionState,
66
+ useFlowsSessionState,
63
67
  } from "./FlowsSessionStateContext.js";
64
- export type { FlowsSessionState } from "./FlowsSessionStateContext.js";
65
- import { getFlowsUiStateSnapshot } from "./FlowsUiStateContext.js";
66
- import { installFlowsAvailabilitySubscriber } from "./flowsAvailability.js";
68
+
67
69
  import { registerPromptComponent } from "@blackbelt-technology/dashboard-plugin-runtime";
70
+ import { getFlowsUiStateSnapshot } from "./FlowsUiStateContext.js";
68
71
 
69
72
  // Register the `flow-question` prompt component type so the shell knows to
70
73
  // route flow-tagged prompts to the widget-bar placement instead of inline
@@ -72,19 +75,11 @@ import { registerPromptComponent } from "@blackbelt-technology/dashboard-plugin-
72
75
  // entries without throwing. See change: route-flow-asks-to-upper-slot.
73
76
  registerPromptComponent({ type: "flow-question", placement: "widget-bar" });
74
77
 
75
- // Install the per-session flows-availability subscriber once at module
76
- // load. The subscriber populates the sync cache that
77
- // `shouldRenderFlowsSubcard` reads. Idempotent (guarded inside the
78
- // installer). See change: add-flows-subcard (design.md Decision 3 —
79
- // module-level subscriber breaks the chicken-and-egg cycle between
80
- // the predicate and the component it gates).
81
- installFlowsAvailabilitySubscriber();
82
- export {
83
- useFlowsUiState,
78
+ export type { FlowsUiActions, FlowsUiState } from "./FlowsUiStateContext.js";
79
+ export {getFlowsUiStateSnapshot,
84
80
  useFlowsUiActions,
81
+ useFlowsUiState
85
82
  } from "./FlowsUiStateContext.js";
86
- export { getFlowsUiStateSnapshot } from "./FlowsUiStateContext.js";
87
- export type { FlowsUiState, FlowsUiActions } from "./FlowsUiStateContext.js";
88
83
 
89
84
  // hasActiveFlow predicate removed: the manifest no longer references
90
85
  // it because FlowActivityBadgeClaim self-gates inside the component
@@ -2,25 +2,37 @@
2
2
  * Manifest-level `shouldRender` callback for flows-plugin's
3
3
  * `session-card-flows` claim (`SessionFlowActionsClaim`).
4
4
  *
5
- * Returns `false` when the session has no flows AND no `flows:new` command.
6
- * The shell's `FlowsSubcard` wrapper gates on `useSlotHasClaimsForSession`,
7
- * which consults this predicate, so the subcard hides cleanly when there's
8
- * nothing to render.
5
+ * Returns the SAME boolean the claim uses to decide it renders content:
6
+ * `flowsList non-empty OR edit mode on OR a flow event exists`. This keeps the
7
+ * subcard's visibility gate and the claim's render condition in lockstep, so the
8
+ * shell's `FlowsSubcard` wrapper (which gates on `useSlotHasClaimsForSession`,
9
+ * consulting this predicate) never paints an empty panel when the claim would
10
+ * render `null`.
9
11
  *
10
- * Must be synchronous (manifest-level `shouldRender` contract). Reads from the
11
- * sync cache populated by the module-level subscriber installed at plugin
12
- * registration (`installFlowsAvailabilitySubscriber`). Default is `false`
13
- * (closed-by-default) until the first `flowsList` or `commandsList` publish
14
- * arrives for the session — prevents flicker on cold boot.
12
+ * Must be synchronous and side-effect-free (manifest-level `shouldRender`
13
+ * contract). Reads live per-session-data (`getSessionData`) + plugin config
14
+ * (`getPluginConfig`) directly — the same synchronous sources the claim reads —
15
+ * instead of a mirrored availability cache. Closed-by-default holds: on cold
16
+ * boot `flowsList` is empty, edit mode off, no events → `false` → hidden, then
17
+ * visible once flows populate (the acceptable hidden→visible direction).
15
18
  *
16
- * See change: add-flows-subcard.
19
+ * See change: fix-empty-flows-subcard.
17
20
  */
21
+ import { getSessionData } from "@blackbelt-technology/dashboard-plugin-runtime";
22
+ import { getPluginConfig } from "@blackbelt-technology/dashboard-plugin-runtime/context";
18
23
  import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
19
- import { getFlowsAvailabilitySync } from "./flowsAvailability.js";
24
+ import type { FlowInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
25
+ import { sessionHasFlowEvents } from "./flowsAvailability.js";
20
26
 
21
27
  export function shouldRenderFlowsSubcard(
22
28
  session: DashboardSession | null | undefined,
23
29
  ): boolean {
24
30
  if (!session) return false;
25
- return getFlowsAvailabilitySync(session.id);
31
+ const flows = getSessionData<FlowInfo[]>(session.id, "flowsList");
32
+ const editMode = (getPluginConfig("flows") as { editFlow?: boolean }).editFlow ?? false;
33
+ return (
34
+ (Array.isArray(flows) && flows.length > 0) ||
35
+ editMode ||
36
+ sessionHasFlowEvents(session.id)
37
+ );
26
38
  }
@@ -0,0 +1,14 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "title": "Flows plugin configuration",
4
+ "description": "Per-plugin (global) configuration for the flows-plugin. The edit-mode default is reconciled down to each session (via flow:set-edit-mode) when that session's flows plugin becomes available. See change: rework-flows-plugin-for-new-pi-flows.",
5
+ "type": "object",
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "editFlow": {
9
+ "type": "boolean",
10
+ "default": false,
11
+ "description": "Global default for pi-flows `flows.editFlow`. When on, the main session sees the edit-flow skill and the flow_agents / flow_write authoring tools."
12
+ }
13
+ }
14
+ }