@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
@@ -0,0 +1,54 @@
1
+ /**
2
+ * flows-plugin plugin_action handler — the production wiring that replaced the
3
+ * v1 logging stub. `flow.run` emits the `flow:run` event pi-flows consumes;
4
+ * `flow.new` launches the manage-flows skill; a missing sessionId is a guarded
5
+ * no-op. See change: fix-plugin-action-fanout-and-handlers.
6
+ */
7
+ import { describe, expect, it, vi } from "vitest";
8
+ import { registerPlugin } from "../server/index.js";
9
+
10
+ type Handler = (msg: unknown) => void;
11
+
12
+ async function setup() {
13
+ const emitEventToSession = vi.fn(() => true);
14
+ const sendToSession = vi.fn(() => true);
15
+ let handler: Handler | undefined;
16
+ const ctx = {
17
+ logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
18
+ broadcastToSubscribers: vi.fn(),
19
+ emitEventToSession,
20
+ sendToSession,
21
+ provide: vi.fn(),
22
+ consume: vi.fn(),
23
+ sessionManager: { listActive: () => [], listAll: () => [] },
24
+ fastify: { get: vi.fn() },
25
+ registerBrowserHandler: (type: string, h: Handler) => {
26
+ if (type === "plugin_action") handler = h;
27
+ },
28
+ } as unknown as Parameters<typeof registerPlugin>[0];
29
+
30
+ await registerPlugin(ctx);
31
+ if (!handler) throw new Error("plugin_action handler not registered");
32
+ return { handler, emitEventToSession, sendToSession, ctx };
33
+ }
34
+
35
+ describe("flows plugin_action handler", () => {
36
+ it("flow.run emits flow:run into the target session (not a stub)", async () => {
37
+ const { handler, emitEventToSession } = await setup();
38
+ handler({ pluginId: "flows", sessionId: "s1", action: "flow.run", payload: { flow: "ns:build", task: "do it" } });
39
+ expect(emitEventToSession).toHaveBeenCalledWith("s1", "flow:run", { flowName: "ns:build", task: "do it" });
40
+ });
41
+
42
+ it("flow.new launches the manage-flows skill via sendToSession", async () => {
43
+ const { handler, sendToSession } = await setup();
44
+ handler({ pluginId: "flows", sessionId: "s1", action: "flow.new" });
45
+ expect(sendToSession).toHaveBeenCalledWith("s1", "/skill:manage-flows");
46
+ });
47
+
48
+ it("ignores a mismatched pluginId (defense-in-depth) and guards missing sessionId", async () => {
49
+ const { handler, emitEventToSession } = await setup();
50
+ handler({ pluginId: "goal", sessionId: "s1", action: "flow.run", payload: { flow: "ns:x" } });
51
+ handler({ pluginId: "flows", action: "flow.run", payload: { flow: "ns:x" } });
52
+ expect(emitEventToSession).not.toHaveBeenCalled();
53
+ });
54
+ });
@@ -0,0 +1,63 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { renderSessionFlowActions } from "../server/render-actions.js";
3
+ import type { FlowInfo, CommandInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
4
+
5
+ const cmd = (name: string): CommandInfo => ({ name }) as CommandInfo;
6
+ const flow = (name: string, description = ""): FlowInfo =>
7
+ ({ name, description }) as FlowInfo;
8
+
9
+ describe("renderSessionFlowActions", () => {
10
+ it("returns null when no flows and no /flows:new command", () => {
11
+ const result = renderSessionFlowActions({ flows: [], commands: [] });
12
+ expect(result).toBeNull();
13
+ });
14
+
15
+ it("renders flows as action items with dataAction descriptors", () => {
16
+ const result = renderSessionFlowActions({
17
+ flows: [flow("alpha", "desc-a"), flow("beta", "desc-b")],
18
+ commands: [],
19
+ });
20
+ expect(result).not.toBeNull();
21
+ expect(result!.primitive).toBe("ui:action-list");
22
+ const actions = (result!.props as { actions: any[] }).actions;
23
+ expect(actions).toHaveLength(2);
24
+ expect(actions[0].label).toBe("alpha");
25
+ expect(actions[0].tooltip).toBe("desc-a");
26
+ expect(actions[0].dataAction).toEqual({
27
+ pluginId: "flows",
28
+ action: "flow.run",
29
+ payload: { flow: "alpha" },
30
+ });
31
+ });
32
+
33
+ it("appends + New Flow item when flows:new command is available", () => {
34
+ const result = renderSessionFlowActions({
35
+ flows: [flow("alpha")],
36
+ commands: [cmd("flows:new")],
37
+ });
38
+ const actions = (result!.props as { actions: any[] }).actions;
39
+ expect(actions).toHaveLength(2);
40
+ expect(actions[1].label).toBe("+ New Flow");
41
+ expect(actions[1].dataAction.action).toBe("flow.new");
42
+ });
43
+
44
+ it("renders ONLY + New Flow when no flows but command available", () => {
45
+ const result = renderSessionFlowActions({
46
+ flows: [],
47
+ commands: [cmd("flows:new")],
48
+ });
49
+ const actions = (result!.props as { actions: any[] }).actions;
50
+ expect(actions).toHaveLength(1);
51
+ expect(actions[0].label).toBe("+ New Flow");
52
+ });
53
+
54
+ it("returns null intent is JSON-serializable when not null", () => {
55
+ const result = renderSessionFlowActions({
56
+ flows: [flow("alpha")],
57
+ commands: [cmd("flows:new")],
58
+ });
59
+ expect(() => JSON.stringify(result)).not.toThrow();
60
+ const roundtrip = JSON.parse(JSON.stringify(result));
61
+ expect(roundtrip.primitive).toBe("ui:action-list");
62
+ });
63
+ });
@@ -0,0 +1,98 @@
1
+ /**
2
+ * SessionFlowActions edit-mode gating + New/Edit launcher.
3
+ * The New/Edit button shows only when editMode is on. Selecting a flow (or
4
+ * "+ New flow") opens an intent-capture dialog; submitting it invokes
5
+ * onEditFlow(name|undefined, instruction) so the claim can send
6
+ * `/skill:manage-flows ...`. See change: rework-flows-plugin-for-new-pi-flows.
7
+ */
8
+ import React from "react";
9
+ import { describe, it, expect, afterEach, vi } from "vitest";
10
+ import { render, cleanup, fireEvent } from "@testing-library/react";
11
+ import {
12
+ UiPrimitiveProvider,
13
+ createUiPrimitiveRegistry,
14
+ registerUiPrimitive,
15
+ } from "@blackbelt-technology/dashboard-plugin-runtime";
16
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
17
+ import type { FlowInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
18
+ import { SessionFlowActions } from "../client/SessionFlowActions.js";
19
+
20
+ const registry = createUiPrimitiveRegistry();
21
+ registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.confirmDialog, (() => null) as never);
22
+ // Stub Dialog primitive used by FlowAuthorPromptDialog: render children + Footer/Cancel.
23
+ const Dialog = (({ children }: { children: React.ReactNode }) => <div>{children}</div>) as never;
24
+ (Dialog as unknown as { Footer: React.FC<{ children: React.ReactNode }>; Cancel: React.FC<{ onClick: () => void }> }).Footer =
25
+ ({ children }) => <div>{children}</div>;
26
+ (Dialog as unknown as { Footer: React.FC; Cancel: React.FC<{ onClick: () => void }> }).Cancel =
27
+ ({ onClick }) => <button onClick={onClick}>Cancel</button>;
28
+ registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.dialog, Dialog);
29
+ // Stub SearchableSelectDialog: render each option as a button that selects it.
30
+ registerUiPrimitive(
31
+ registry,
32
+ UI_PRIMITIVE_KEYS.searchableSelectDialog,
33
+ (({ options, onSelect }: { options: Array<{ value: string; label: string }>; onSelect: (v: string) => void }) => (
34
+ <div data-testid="picker">
35
+ {options.map((o) => (
36
+ <button key={o.value} onClick={() => onSelect(o.value)}>{o.label}</button>
37
+ ))}
38
+ </div>
39
+ )) as never,
40
+ );
41
+
42
+ const flows: FlowInfo[] = [{ name: "invoice-research" } as FlowInfo];
43
+
44
+ function renderActions(props: Partial<React.ComponentProps<typeof SessionFlowActions>>) {
45
+ return render(
46
+ <UiPrimitiveProvider value={registry}>
47
+ <SessionFlowActions
48
+ flows={flows}
49
+ editMode={false}
50
+ onFlowAction={() => {}}
51
+ onEditFlow={() => {}}
52
+ {...props}
53
+ />
54
+ </UiPrimitiveProvider>,
55
+ );
56
+ }
57
+
58
+ afterEach(() => cleanup());
59
+
60
+ describe("SessionFlowActions edit mode", () => {
61
+ it("hides New / Edit when edit mode is off", () => {
62
+ const { queryByTestId } = renderActions({ editMode: false });
63
+ expect(queryByTestId("flows-new-edit-button")).toBeNull();
64
+ });
65
+
66
+ it("shows New / Edit when edit mode is on", () => {
67
+ const { getByTestId } = renderActions({ editMode: true });
68
+ expect(getByTestId("flows-new-edit-button")).toBeTruthy();
69
+ });
70
+
71
+ it("editing a flow prompts for an instruction, then calls onEditFlow(name, instruction)", () => {
72
+ const onEditFlow = vi.fn();
73
+ const { getByTestId, getByText } = renderActions({ editMode: true, onEditFlow });
74
+ fireEvent.click(getByTestId("flows-new-edit-button"));
75
+ fireEvent.click(getByText("invoice-research"));
76
+ // Intent dialog appears; edit instruction is optional → submit empty.
77
+ const submit = getByTestId("flow-author-submit");
78
+ expect(submit).toBeTruthy();
79
+ fireEvent.click(submit);
80
+ expect(onEditFlow).toHaveBeenCalledWith("invoice-research", "");
81
+ });
82
+
83
+ it("new flow requires a description before onEditFlow(undefined, text) fires", () => {
84
+ const onEditFlow = vi.fn();
85
+ const { getByTestId, getByText, getByPlaceholderText } = renderActions({ editMode: true, onEditFlow });
86
+ fireEvent.click(getByTestId("flows-new-edit-button"));
87
+ fireEvent.click(getByText("+ New flow"));
88
+ const submit = getByTestId("flow-author-submit") as HTMLButtonElement;
89
+ // Required: disabled until text entered.
90
+ expect(submit.disabled).toBe(true);
91
+ fireEvent.change(getByPlaceholderText(/Research an invoice/), {
92
+ target: { value: "Summarize PRs" },
93
+ });
94
+ expect(submit.disabled).toBe(false);
95
+ fireEvent.click(submit);
96
+ expect(onEditFlow).toHaveBeenCalledWith(undefined, "Summarize PRs");
97
+ });
98
+ });
@@ -0,0 +1,8 @@
1
+ # DOX — packages/flows-plugin/src/bridge
2
+
3
+ Files in this directory. One row per source file.
4
+
5
+ | File | Purpose |
6
+ |------|---------|
7
+ | `flow-question-adapter.ts` | PromptBus adapter claiming flow-tagged prompts for upper-slot render. Exports `FlowQuestionAdapter` implementing `PromptAdapter` (`name="flow-question"`, `priority=100`). `onRequest` returns claim with `component.type="flow-question"` + `placement="widget-bar"` only when `prompt.metadata.flowId` present; else null. `onResponse`/`onCancel` no-op. Structurally typed against `packages/extension/src/prompt-bus.ts` shapes. Beats `DashboardDefaultAdapter` (priority 9999). |
8
+ | `index.ts` | flows-plugin bridge entry. Default-export `activate(ctx)` emits `prompt:register-adapter` with fresh `FlowQuestionAdapter` via `pi.events.emit`. Auto-registered at `~/.pi/agent/settings.json#dashboardPluginBridges` (key `dashboard-flows`) by dashboard `registerAllPluginBridges`. Narrow: no other behavior. |
@@ -0,0 +1,93 @@
1
+ /**
2
+ * FlowQuestionAdapter — PromptBus adapter that claims prompts originating
3
+ * inside a running flow step (carrying `metadata.flowId`) so they render
4
+ * in the FlowDashboard's upper slot instead of the chat stream.
5
+ *
6
+ * Lives in the flows-plugin bridge entry. Auto-loaded by pi when the
7
+ * dashboard server registers the plugin's bridge path into pi's
8
+ * `settings.json#dashboardPluginBridges` + `packages[]` via the standard
9
+ * `discoverPlugins → registerAllPluginBridges` pipeline.
10
+ *
11
+ * Registration: the bridge entry (`./index.ts`) emits
12
+ * `pi.events.emit("prompt:register-adapter", new FlowQuestionAdapter())`.
13
+ * The main dashboard bridge listens for that event and calls
14
+ * `promptBus.registerAdapter(adapter)` (see `packages/extension/src/bridge.ts`
15
+ * around the `prompt:register-adapter` handler). PromptBus sorts adapters by
16
+ * `priority` (lower first); we use 100 so this adapter beats
17
+ * `DashboardDefaultAdapter` (priority 9999).
18
+ *
19
+ * See change: route-flow-asks-to-upper-slot.
20
+ */
21
+
22
+ // Structural typing — avoid a hard dep on the main bridge package. The shape
23
+ // matches `PromptAdapter` / `PromptRequest` / `PromptClaim` /
24
+ // `PromptResponse` in `packages/extension/src/prompt-bus.ts` byte-for-byte.
25
+
26
+ interface PromptRequest {
27
+ id: string;
28
+ pipeline: string;
29
+ type: "select" | "input" | "confirm" | "editor" | "multiselect";
30
+ question: string;
31
+ options?: string[];
32
+ defaultValue?: string;
33
+ metadata?: Record<string, unknown>;
34
+ }
35
+
36
+ interface PromptResponse {
37
+ id: string;
38
+ answer?: string;
39
+ cancelled?: boolean;
40
+ source: string;
41
+ }
42
+
43
+ interface PromptComponent {
44
+ type: string;
45
+ props: Record<string, unknown>;
46
+ }
47
+
48
+ interface PromptClaim {
49
+ component?: PromptComponent;
50
+ placement?: "widget-bar" | "inline" | "overlay";
51
+ }
52
+
53
+ interface PromptAdapter {
54
+ name: string;
55
+ priority?: number;
56
+ onRequest(prompt: PromptRequest): PromptClaim | null | undefined | void;
57
+ onResponse(response: PromptResponse): void;
58
+ onCancel(id: string): void;
59
+ }
60
+
61
+ export class FlowQuestionAdapter implements PromptAdapter {
62
+ readonly name = "flow-question";
63
+ readonly priority = 100;
64
+
65
+ onRequest(prompt: PromptRequest): PromptClaim | null {
66
+ const flowId = prompt.metadata?.flowId;
67
+ if (typeof flowId !== "string" || flowId.length === 0) return null;
68
+ const stepId = typeof prompt.metadata?.stepId === "string" ? prompt.metadata.stepId : "";
69
+ return {
70
+ component: {
71
+ type: "flow-question",
72
+ props: {
73
+ flowId,
74
+ stepId,
75
+ question: prompt.question,
76
+ type: prompt.type,
77
+ options: prompt.options,
78
+ defaultValue: prompt.defaultValue,
79
+ },
80
+ },
81
+ placement: "widget-bar",
82
+ };
83
+ }
84
+
85
+ onResponse(_response: PromptResponse): void {
86
+ // No adapter-owned UI to dismiss — the client tears down the card on
87
+ // submit; the bus broadcasts `prompt_dismiss` for all listeners.
88
+ }
89
+
90
+ onCancel(_id: string): void {
91
+ // No adapter-owned UI to dismiss.
92
+ }
93
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * flows-plugin · bridge entry.
3
+ *
4
+ * Auto-registered at `~/.pi/agent/settings.json#dashboardPluginBridges`
5
+ * (key: `dashboard-flows`) when the dashboard server discovers the plugin
6
+ * manifest and runs `registerAllPluginBridges`. The path is mirrored into
7
+ * the top-level `packages[]` array so pi-coding-agent loads it as a pi
8
+ * extension on the next session start.
9
+ *
10
+ * Behavior: on activation, emit a `prompt:register-adapter` event with
11
+ * a fresh `FlowQuestionAdapter`. The main dashboard bridge listens for
12
+ * that event and calls `promptBus.registerAdapter(adapter)` — see the
13
+ * existing handler in `packages/extension/src/bridge.ts`. PromptBus
14
+ * sorts adapters by `priority`; `FlowQuestionAdapter` (priority 100)
15
+ * therefore claims flow-tagged prompts before `DashboardDefaultAdapter`
16
+ * (priority 9999).
17
+ *
18
+ * No other behavior here — this entry is intentionally narrow.
19
+ *
20
+ * See change: route-flow-asks-to-upper-slot.
21
+ */
22
+ import { FlowQuestionAdapter } from "./flow-question-adapter.js";
23
+
24
+ export default function activate(ctx: unknown): void {
25
+ const c = ctx as { pi?: { events?: { emit: (name: string, payload: unknown) => void } }; events?: unknown };
26
+ const pi = c?.pi ?? c;
27
+ const events = (pi as { events?: { emit: (name: string, payload: unknown) => void } })?.events;
28
+ if (!events || typeof events.emit !== "function") return;
29
+ events.emit("prompt:register-adapter", new FlowQuestionAdapter());
30
+ }
@@ -0,0 +1,32 @@
1
+ # DOX — packages/flows-plugin/src/client
2
+
3
+ Files in this directory. One row per source file.
4
+
5
+ | File | Purpose |
6
+ |------|---------|
7
+ | `flow-collapse-storage.ts` | Per-session persisted collapse state for flow panels. Exports `FlowCollapseKind`, `flowCollapseKey`, `usePersistedToggle`, `useFlowCollapsePersisted`, `FLOW_SHOW_ERROR_ROUTES_KEY`. localStorage keyed by session id; failures degrade to in-memory. Mirrors `useSidebarState.ts` try/catch-swallow. |
8
+ | `flow-edges.ts` | Shared flow-edge derivation. Exports `FlowEdgeKind`, `FlowEdgeStep`, `FlowEdge`, `deriveFlowEdges`. One rule for live `FlowGraph` + static `flow_write` Mermaid snapshot. Classes: `sequential`, `branch`, `route`, `implicit`. Tags `on_error` route topology (`returning`/`terminal`) via reachability. |
9
+ | `flow-yaml-parse.ts` | Shallow client YAML→steps parser (`parseFlowYaml`) + Mermaid generator (`flowToMermaid`). Extracts id/type/blockedBy/branches + counts. Node-shape glyphs per kind; forward edges from blockedBy, backward branch edges dashed. Graceful null on parse failure. See change: rework-flows-plugin-for-new-pi-flows. |
10
+ | `FlowActivityBadge.tsx` | Running-flow status pill. Exports `FlowActivityBadge`, `FlowActivityBadgeProps`. Maps `FlowStatus` → icon+color; shows agent count when running; renders inline Abort button when `onAbort` provided. Consumed by `SessionFlowActions`. |
11
+ | `FlowAgentCard.tsx` | Step card. nodeKind badge (⌗ code, ◈ code-decision, ◇ fork). Code Log preview from `flow_assistant_text` detailHistory. Outputs KV chips. Chosen-branch line + ↻ loop pill. Soft (amber)/hard (red) outcome. Handler target line. See change: rework-flows-plugin-for-new-pi-flows. Code/code-decision nodes now render `mdiCodeBraces` button (gated `isCodeKind && agent.codeTarget`) opening `ui:dialog`; fetches handler `.ts` via `GET /api/pi-resource-file?path=<codeTarget>` (codeTarget absolute, passed verbatim); renders content wrapped in fenced ```ts block via `ui:markdown-content` (Prism highlight). Mirrors agent `sourcePath` doc-icon path; `codeSourceOpen`/`codeSourceState` state. Keeps `‹› {codeTarget}` text line. See change: open-code-handler-from-flow-card. Exports `formatCost(n)` (`$` + `n>=1?2dp:4dp`, pi-flows parity); complete-state stats line appends ` · $cost` between tokens and duration when `agent.cost != null && > 0`. See change: surface-flow-agent-cost. |
12
+ | `FlowAgentDetail.tsx` | Thin adapter shim over `MinimalChatView`. Exports `FlowAgentDetail`. Maps `FlowAgentState` → `MinimalChatViewProps` (status, `detailHistory` entries, summary footer). Preserves `agent`/`onBack` API for `FlowAgentCard` detail dialog. Imports `formatCost` from `FlowAgentCard`; passes `meta.cost` (pre-formatted string) when `agent.cost != null && > 0`. See change: surface-flow-agent-cost. |
13
+ | `FlowAgentsToolRenderer.tsx` | `tool-renderer` for `flow_agents`. `list` → catalog names + count. `write` → success/failure from `{written,diagnostics,error}`. Args-backed "View agent file" toggle. See change: rework-flows-plugin-for-new-pi-flows. |
14
+ | `FlowAuthorPromptDialog.tsx` | Intent-capture dialog for `/skill:manage-flows` launcher. Exports `FlowAuthorPromptDialog`. Two-step pattern: asks what flow should do (new, required) or what to change (edit, optional). Forwards instruction to manage-flows prompt. |
15
+ | `FlowDashboard.tsx` | Live running-flow panel. Exports `FlowDashboard`, `FlowDashboardClaim`. Renders header (collapse/AUTO/Abort), `FlowTabBar` multi-flow nav, `BreadcrumbSlot`, `FlowQuestionsSection`, `FlowGraph` + expanded dialog, `FlowAgentCard` grid. Forwards to `FlowSummary` on completion. Claim self-derives state via `useFlowsSessionState`. |
16
+ | `FlowGraph.tsx` | dagre SVG graph. `mapStepType` → canonical set (agent/fork/code/code-decision/flow-ref); legacy conditional/agent-loop-decision/loop REMOVED. `architectStepsToGraphSteps` REMOVED. See change: rework-flows-plugin-for-new-pi-flows. |
17
+ | `FlowLaunchDialog.tsx` | Run-flow task-capture dialog. Exports `FlowLaunchDialog`. Renders `GateSlot` decorator; `aggregateGateState` disables Run button when extension gates flow unavailable. Forwards task to `onSubmit`. |
18
+ | `FlowQuestionCard.tsx` | Pending `flow-question` prompt card rendered in FlowDashboard upper slot. Exports `FlowQuestionCard`, `FlowQuestionCardProps`. Routes by `type` (`confirm`/`select`/`multiselect`/`input`/`editor`) to inline renderers. Dispatches `prompt_response`/`prompt_cancel` via callbacks. Shows queue-depth badge. |
19
+ | `FlowQuestionTranscriptPill.tsx` | Collapsed pill for answered/cancelled flow-question in upper-slot transcript. Exports `FlowQuestionTranscriptPill`, `FlowQuestionTranscriptPillProps`. Renders status icon + question + answer (multiselect JSON array compacted). Pending head rendered by `FlowQuestionCard`. |
20
+ | `flowsAvailability.ts` | Flow-event probe. Exports `sessionHasFlowEvents(id)` (ref-memoized, sticky-true) + `__resetFlowsAvailabilityForTests`. Availability cache/subscriber (`computeAvailability`, `getFlowsAvailabilitySync`, `installFlowsAvailabilitySubscriber`) retired. See change: fix-empty-flows-subcard. |
21
+ | `FlowsCommandRoutes.tsx` | Slash-command route components for `/flows`, `/flows:new`, `/flows:edit`, `/flows:delete`. Exports `FlowsListRoute`, `FlowsNewRoute`, `FlowsEditRoute`, `FlowsDeleteRoute`. Each renders launcher/picker/dialog, dispatches `flow_management` via `usePluginSend`, calls `onClose` on dismissal. Replaces App.tsx flow dialog blocks. |
22
+ | `FlowsSessionStateContext.tsx` | Plugin-internal per-session flow state derivation. Exports `FlowsSessionState`, `reduceFlowsSessionState`, `useFlowsSessionState`. Reduces `useSessionEvents` stream via `reduceFlowEvent` into `{ flowState, flowStates }`. `useMemo`-stable; returns frozen `EMPTY_STATE` when no flow activity. Dev-only diagnostic counter. |
23
+ | `FlowsSettings.tsx` | `settings-section` (tab general, draft page plugins). Global edit-mode default via `usePluginConfig`/`plugin_config_write`/`useSettingsDraftSource`. Config `{ editFlow?: boolean }`, default off. See change: rework-flows-plugin-for-new-pi-flows. |
24
+ | `FlowsUiStateContext.tsx` | Plugin-internal UI selection state, module-level store + `useSyncExternalStore`. Exports `FlowsUiState`, `FlowsUiActions`, `getFlowsUiStateSnapshot`, `useFlowsUiState`, `useFlowsUiActions`, `__resetFlowsUiStateForTests`. Holds `sourceOpenAgent`, `flowYamlPreview`; `dismissAll` unifies cleanup. Snapshot used by manifest predicates. |
25
+ | `FlowSummary.tsx` | Completed-flow summary panel. Exports `FlowSummary`, `FlowSummaryClaim`. Renders status header (panel collapse persisted via `useFlowCollapsePersisted`), `FlowGraph` + expanded dialog, frozen `FlowAgentCard` grid, collapsible `FlowSummaryRow` summaries, next-step button. Claim self-derives state, dispatches `dismiss_summary`. |
26
+ | `FlowTabBar.tsx` | Multi-flow tab navigation bar. Exports `FlowTab`, `FlowTabBar`. Renders one tab per concurrent flow; FOLLOW toggle auto-switches to latest active flow. Returns null for single flow. |
27
+ | `FlowWriteToolRenderer.tsx` | `tool-renderer` for `flow_write`. Renders real result contract `{written,name,namespace,command,path,diagnostics}`. Success: command + counts + Mermaid snapshot (via `ui:markdown-content`) parsed from tool args. Failure: diagnostics verbatim. Args-backed "View flow YAML" toggle. See change: rework-flows-plugin-for-new-pi-flows. |
28
+ | `FlowYamlPopoverButton.tsx` | Paper-icon button opening popover with flow YAML. Exports `FlowYamlPopoverButton`. Fetches `/api/pi-resource-file?path=`, renders via `ui:markdown-content` in `yaml` fence. State machine `idle`/`loading`/`loaded`/`error`. Used by `FlowDashboard` + `FlowSummary`. |
29
+ | `FlowYamlPreview.tsx` | Content-view claim renderer for flow YAML preview, gated by `isFlowYamlPreviewActive` predicate. Exports `FlowYamlPreviewClaim`. Reads `flowYamlPreview` from `FlowsUiStateContext`; back action clears preview + `sourceOpenAgent` + calls `onClose`. Replaces App.tsx `MarkdownPreviewView` call site. |
30
+ | `index.tsx` | Re-export barrel: `FlowDashboard`, `FlowAgentCard`, `FlowAgentDetail`, `FlowSummary`, `FlowGraph`, `FlowActivityBadge`, `FlowLaunchDialog`, `FlowTabBar`, `SessionFlowActions`, `FlowWriteToolRenderer`, `FlowAgentsToolRenderer`, `FlowsSettings`. Architect exports REMOVED. See change: rework-flows-plugin-for-new-pi-flows. |
31
+ | `SessionFlowActions.tsx` | Subcard actions. Run / New-Edit (gated on editMode) / Delete / Abort. New/Edit launcher → `onEditFlow` → claim sends `send_prompt /skill:edit-flow [name]`. Claim reconciles global edit-mode default to session via `flow_management{action:set-edit-mode,enabled}` on availability. Architect/new/edit command deps REMOVED. See change: rework-flows-plugin-for-new-pi-flows. |
32
+ | `shouldRender.ts` | Manifest-level sync predicate `shouldRenderFlowsSubcard(session)` for `session-card-flows` claim. Reads live `getSessionData(flowsList)` + `getPluginConfig(flows).editFlow` + `sessionHasFlowEvents` — matches the claim render condition. See change: fix-empty-flows-subcard. |
@@ -1,7 +1,20 @@
1
- import React, { type ReactNode } from "react";
2
- import { Icon } from "@mdi/react";
3
- import { mdiLoading, mdiCheckCircle, mdiAlertCircle, mdiStopCircle } from "@mdi/js";
1
+ /**
2
+ * FlowActivityBadge — renderer for the running-flow status pill.
3
+ *
4
+ * Previously claimed the `session-card-badge` slot (which the shell
5
+ * mounts inside the WORKSPACE subcard — wrong place for flow status).
6
+ * The slot claim was dropped in `fix-flows-plugin-polish`; the badge
7
+ * is now consumed only by `SessionFlowActions` (rendered inside the
8
+ * `session-card-flows` slot, i.e. the FLOWS subcard).
9
+ *
10
+ * See change: fix-flows-plugin-polish (A5).
11
+ */
12
+
13
+ import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
4
14
  import type { FlowStatus } from "@blackbelt-technology/pi-dashboard-shared/types.js";
15
+ import { mdiAlertCircle, mdiCheckCircle, mdiLoading, mdiStop, mdiStopCircle } from "@mdi/js";
16
+ import { Icon } from "@mdi/react";
17
+ import React, { type ReactNode } from "react";
5
18
 
6
19
  const statusConfig: Record<string, { icon: ReactNode; color: string }> = {
7
20
  running: { icon: <Icon path={mdiLoading} size={0.45} className="animate-spin" />, color: "text-blue-400" },
@@ -10,24 +23,30 @@ const statusConfig: Record<string, { icon: ReactNode; color: string }> = {
10
23
  aborted: { icon: <Icon path={mdiStopCircle} size={0.45} />, color: "text-orange-400" },
11
24
  };
12
25
 
26
+ export interface FlowActivityBadgeProps {
27
+ flowName: string;
28
+ agentsDone?: number;
29
+ agentsTotal?: number;
30
+ status?: FlowStatus;
31
+ /** When provided AND status === "running", renders an "Abort" button after the badge. */
32
+ onAbort?: () => void;
33
+ }
34
+
13
35
  export function FlowActivityBadge({
14
36
  flowName,
15
37
  agentsDone,
16
38
  agentsTotal,
17
39
  status,
18
- }: {
19
- flowName: string;
20
- agentsDone?: number;
21
- agentsTotal?: number;
22
- status?: FlowStatus;
23
- }) {
40
+ onAbort,
41
+ }: FlowActivityBadgeProps) {
42
+ const t = useT();
24
43
  const { icon, color } = statusConfig[status ?? "running"] ?? statusConfig.running;
25
44
  const isRunning = status === "running";
26
45
 
27
46
  return (
28
- <div className={`text-[11px] mt-0.5 ml-4 flex items-center gap-1 ${color}`}>
47
+ <div className={`text-[11px] flex items-center gap-1 ${color}`}>
29
48
  <span className="inline-flex">{icon}</span>
30
- <span className="truncate">
49
+ <span className="truncate flex-1 min-w-0">
31
50
  {flowName}
32
51
  {isRunning && agentsTotal != null && agentsTotal > 0 && (
33
52
  <span className="text-[var(--text-secondary)]"> · {agentsDone ?? 0}/{agentsTotal} agents</span>
@@ -36,6 +55,17 @@ export function FlowActivityBadge({
36
55
  <span className="text-[var(--text-secondary)]"> · {status}</span>
37
56
  )}
38
57
  </span>
58
+ {isRunning && onAbort && (
59
+ <button
60
+ type="button"
61
+ onClick={(e) => { e.stopPropagation(); onAbort(); }}
62
+ className="inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[10px] rounded border border-red-500/40 text-red-400 hover:bg-red-500/10 transition-colors flex-shrink-0"
63
+ title={t("abortRunningFlow", undefined, "Abort running flow")}
64
+ >
65
+ <Icon path={mdiStop} size={0.4} />
66
+ {t("abort", undefined, "Abort")}
67
+ </button>
68
+ )}
39
69
  </div>
40
70
  );
41
71
  }