@blackbelt-technology/pi-dashboard-flows-plugin 0.6.1 → 0.8.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 (39) hide show
  1. package/package.json +13 -5
  2. package/src/client/FlowAgentCard.tsx +24 -17
  3. package/src/client/FlowAgentDetail.tsx +1 -1
  4. package/src/client/FlowDashboard.tsx +6 -2
  5. package/src/client/FlowInputWiring.tsx +2 -2
  6. package/src/client/FlowsCommandRoutes.tsx +13 -5
  7. package/src/client/FlowsSettings.tsx +4 -4
  8. package/src/client/SessionFlowActions.tsx +9 -4
  9. package/src/client/format-cost.ts +21 -0
  10. package/src/client/send-safe.ts +19 -0
  11. package/src/AGENTS.md +0 -8
  12. package/src/__tests__/FlowGraph.test.ts +0 -305
  13. package/src/__tests__/FlowInputWiring.test.tsx +0 -97
  14. package/src/__tests__/FlowSummary.test.tsx +0 -331
  15. package/src/__tests__/FlowYamlPreview.test.tsx +0 -75
  16. package/src/__tests__/FlowsSessionStateContext.test.tsx +0 -223
  17. package/src/__tests__/FlowsUiStateContext.test.tsx +0 -140
  18. package/src/__tests__/authoring-renderers.test.tsx +0 -190
  19. package/src/__tests__/automation-actions.test.ts +0 -117
  20. package/src/__tests__/flow-agent-card-code-source.test.tsx +0 -154
  21. package/src/__tests__/flow-agent-cost.test.tsx +0 -160
  22. package/src/__tests__/flow-agent-error.test.ts +0 -60
  23. package/src/__tests__/flow-collapse-storage.test.ts +0 -90
  24. package/src/__tests__/flow-edges.test.ts +0 -195
  25. package/src/__tests__/flow-inputs.test.ts +0 -69
  26. package/src/__tests__/flow-reducer-bridge-contract.test.ts +0 -108
  27. package/src/__tests__/flow-reducer-seed-on-start.test.ts +0 -61
  28. package/src/__tests__/flow-yaml-parse.test.ts +0 -124
  29. package/src/__tests__/flows-for-cwd.test.ts +0 -51
  30. package/src/__tests__/flowsAvailability.test.ts +0 -79
  31. package/src/__tests__/manifest-discoverability.test.ts +0 -97
  32. package/src/__tests__/node-kind-reducer.test.ts +0 -135
  33. package/src/__tests__/plugin-action-handler.test.ts +0 -54
  34. package/src/__tests__/reducer-parity.test.ts +0 -106
  35. package/src/__tests__/render-actions.test.ts +0 -63
  36. package/src/__tests__/session-flow-actions-edit.test.tsx +0 -98
  37. package/src/bridge/AGENTS.md +0 -8
  38. package/src/client/AGENTS.md +0 -32
  39. package/src/server/AGENTS.md +0 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blackbelt-technology/pi-dashboard-flows-plugin",
3
- "version": "0.6.1",
3
+ "version": "0.8.0",
4
4
  "description": "Flow rendering plugin for pi-dashboard — pi-flows event reaction (FlowDashboard, FlowAgentCard, FlowArchitect, etc.)",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -27,7 +27,12 @@
27
27
  }
28
28
  },
29
29
  "files": [
30
- "src/"
30
+ "src/",
31
+ "!**/AGENTS.md",
32
+ "!**/*.AGENTS.md",
33
+ "!**/__tests__",
34
+ "!**/*.test.ts",
35
+ "!**/*.test.tsx"
31
36
  ],
32
37
  "pi-dashboard-plugin": {
33
38
  "id": "flows",
@@ -83,9 +88,12 @@
83
88
  },
84
89
  "//deps-rationale": "client-utils retained for hooks (useMobile, useZoomPan) and Phase-2 extension-ui slot consumers (AgentMetricSlot, BreadcrumbSlot, GateSlot, aggregateGateState helper). All UI primitive components (AgentCardShell, MarkdownContent, ConfirmDialog, DialogPortal, SearchableSelectDialog, ZoomControls, format-tokens, format-duration) flow through the UI primitive registry per add-plugin-ui-primitive-registry.",
85
90
  "dependencies": {
86
- "@blackbelt-technology/dashboard-plugin-runtime": "^0.6.1",
87
- "@blackbelt-technology/pi-dashboard-client-utils": "^0.6.1",
88
- "@blackbelt-technology/pi-dashboard-shared": "^0.6.1",
91
+ "@blackbelt-technology/dashboard-plugin-runtime": "^0.8.0",
92
+ "@blackbelt-technology/pi-dashboard-client-utils": "^0.8.0",
93
+ "@blackbelt-technology/pi-dashboard-shared": "^0.8.0",
94
+ "@mdi/js": "^7.4.47",
95
+ "@mdi/react": "^1.6.1",
96
+ "dagre-d3-es": "^7.0.14",
89
97
  "yaml": "^2.9.0"
90
98
  },
91
99
  "devDependencies": {
@@ -1,4 +1,4 @@
1
- import { useT, useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
1
+ import { useT, useUiPrimitive, useUiPrimitiveOrNull } from "@blackbelt-technology/dashboard-plugin-runtime";
2
2
  // AgentMetricSlot is a slot CONSUMER (Phase-2 decorator slot), not a primitive
3
3
  // — it stays as a direct import. See add-plugin-ui-primitive-registry Decision 4.
4
4
  import { AgentMetricSlot } from "@blackbelt-technology/pi-dashboard-client-utils/extension-ui/AgentMetricSlot";
@@ -8,6 +8,7 @@ import { mdiCallSplit, mdiCodeBraces, mdiCodeTags, mdiEyeOffOutline, mdiEyeOutli
8
8
  import { Icon } from "@mdi/react";
9
9
  import React, { useEffect, useState } from "react";
10
10
  import { FlowAgentDetail } from "./FlowAgentDetail.js";
11
+ import { formatCost } from "./format-cost.js";
11
12
 
12
13
  /**
13
14
  * State of the agent-source fetch for the document-icon popover.
@@ -19,14 +20,6 @@ import { FlowAgentDetail } from "./FlowAgentDetail.js";
19
20
  *
20
21
  * See change: add-ui-popover-primitive.
21
22
  */
22
- /**
23
- * Format an accumulated USD cost, matching the pi-flows TUI precision
24
- * (`agent-card.ts`): two decimals at or above $1, four decimals sub-dollar.
25
- * Exported so `FlowAgentDetail` renders identical values (DRY, D4).
26
- */
27
- export function formatCost(n: number): string {
28
- return `$${n >= 1 ? n.toFixed(2) : n.toFixed(4)}`;
29
- }
30
23
 
31
24
  type AgentSourceState =
32
25
  | { kind: "idle" }
@@ -53,6 +46,9 @@ export function FlowAgentCard({
53
46
  const stepId = agent.stepId || agent.agentName;
54
47
  const t = useT();
55
48
  const AgentCardShell = useUiPrimitive(UI_PRIMITIVE_KEYS.agentCard);
49
+ // Soft lookup: production registers `logBlock` (main.tsx); when absent the
50
+ // code-node preview falls back to the padded placeholder below.
51
+ const LogBlock = useUiPrimitiveOrNull(UI_PRIMITIVE_KEYS.logBlock);
56
52
  const formatTokens = useUiPrimitive(UI_PRIMITIVE_KEYS.formatTokens);
57
53
  const formatDuration = useUiPrimitive(UI_PRIMITIVE_KEYS.formatDuration);
58
54
  const Dialog = useUiPrimitive(UI_PRIMITIVE_KEYS.dialog);
@@ -219,14 +215,22 @@ export function FlowAgentCard({
219
215
  {/* Body: code nodes show a Log preview (program logs); agent nodes
220
216
  show their recent tool calls. */}
221
217
  {isCodeKind ? (
222
- <div className="mt-1 space-y-0">
223
- {logLines.slice(-3).map((line, i) => (
224
- <div key={i} className="text-[10px] text-[var(--text-tertiary)] truncate font-mono" title={line}>{line}</div>
225
- ))}
226
- {Array.from({ length: Math.max(0, 3 - Math.min(3, logLines.length)) }).map((_, i) => (
227
- <div key={`pad-${i}`} className="text-[10px]">&nbsp;</div>
228
- ))}
229
- </div>
218
+ logLines.length > 0 && LogBlock ? (
219
+ <div className="mt-1">
220
+ <LogBlock
221
+ label={t("programLog", undefined, "Program log")}
222
+ text={logLines.join("\n")}
223
+ preview
224
+ previewLines={3}
225
+ />
226
+ </div>
227
+ ) : (
228
+ <div className="mt-1 space-y-0">
229
+ {Array.from({ length: 3 }).map((_, i) => (
230
+ <div key={`pad-${i}`} className="text-[10px]">&nbsp;</div>
231
+ ))}
232
+ </div>
233
+ )
230
234
  ) : (
231
235
  <div className="mt-1 space-y-0">
232
236
  {agent.recentTools.map((tool, i) => (
@@ -377,6 +381,9 @@ export function FlowAgentCard({
377
381
  size="lg"
378
382
  flush
379
383
  >
384
+ {/* STAYS: a DEFINITE height pin, not a duplicated flex context —
385
+ the popout keeps a stable height as the transcript grows.
386
+ See change: fix-flush-dialog-scroll-and-close-collision. */}
380
387
  <div className="h-[70vh] overflow-hidden flex flex-col">
381
388
  <FlowAgentDetail
382
389
  agent={agent}
@@ -21,7 +21,7 @@ import type {
21
21
  FlowDetailEntry,
22
22
  } from "@blackbelt-technology/pi-dashboard-shared/types.js";
23
23
  import React from "react";
24
- import { formatCost } from "./FlowAgentCard.js";
24
+ import { formatCost } from "./format-cost.js";
25
25
 
26
26
  function mapFlowStatus(status: FlowAgentStatus): MinimalChatStatus {
27
27
  switch (status) {
@@ -15,6 +15,7 @@ import React, { useCallback, useEffect, useMemo, useRef, useState } from "react"
15
15
  import { FlowAgentCard } from "./FlowAgentCard.js";
16
16
  import { FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
17
17
  import { FlowQuestionCard } from "./FlowQuestionCard.js";
18
+ import { makeSafeSend } from "./send-safe.js";
18
19
  import { FlowQuestionTranscriptPill } from "./FlowQuestionTranscriptPill.js";
19
20
  import { FlowSummary } from "./FlowSummary.js";
20
21
  import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
@@ -337,6 +338,9 @@ function FlowQuestionsSection({
337
338
  }) {
338
339
  const requests = useSessionInteractiveRequests(sessionId);
339
340
  const send = usePluginSend();
341
+ // Card callbacks cannot own the send promise — discard it explicitly.
342
+ // See change: cleanup-client-plugin-promises.
343
+ const dispatch = useMemo(() => makeSafeSend(send), [send]);
340
344
 
341
345
  const queue = useMemo<InteractiveUiRequestSnapshot[]>(() => {
342
346
  const out: InteractiveUiRequestSnapshot[] = [];
@@ -363,7 +367,7 @@ function FlowQuestionsSection({
363
367
  const question = typeof props.question === "string" ? props.question : "";
364
368
  if (req.status === "pending") {
365
369
  const submit = (answer: string) => {
366
- send({
370
+ dispatch({
367
371
  type: "prompt_response",
368
372
  sessionId,
369
373
  promptId: req.requestId,
@@ -372,7 +376,7 @@ function FlowQuestionsSection({
372
376
  });
373
377
  };
374
378
  const dismiss = () => {
375
- send({ type: "prompt_cancel", sessionId, promptId: req.requestId });
379
+ dispatch({ type: "prompt_cancel", sessionId, promptId: req.requestId });
376
380
  };
377
381
  return (
378
382
  <FlowQuestionCard
@@ -181,7 +181,7 @@ export function FlowInputWiring({ payload, onChange, cwd }: FlowInputWiringProps
181
181
  className={`px-2 text-[10px] ${
182
182
  boundToTrigger
183
183
  ? "text-[var(--text-secondary)]"
184
- : "bg-[var(--accent,#6366f1)] text-white"
184
+ : "bg-[var(--accent-solid)] text-white"
185
185
  }`}
186
186
  >
187
187
  literal
@@ -192,7 +192,7 @@ export function FlowInputWiring({ payload, onChange, cwd }: FlowInputWiringProps
192
192
  onClick={() => setInput(f.name, TRIGGER_TOKEN)}
193
193
  className={`border-l border-[var(--border-secondary)] px-2 text-[10px] ${
194
194
  boundToTrigger
195
- ? "bg-[var(--accent,#6366f1)] text-white"
195
+ ? "bg-[var(--accent-solid)] text-white"
196
196
  : "text-[var(--text-secondary)]"
197
197
  }`}
198
198
  >
@@ -24,16 +24,21 @@ import {
24
24
  useSessionData,
25
25
  } from "@blackbelt-technology/dashboard-plugin-runtime";
26
26
  import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
27
+ import { makeSafeSend, type PluginSend } from "./send-safe.js";
27
28
 
28
29
  // ── Helpers ────────────────────────────────────────────────────────
29
30
 
31
+ // Every flow action routes through here, so the discard is stated once at the
32
+ // shared seam rather than at each of the five call sites. A dropped
33
+ // `flow_management` message otherwise leaves the UI showing a run the server
34
+ // never started. See change: cleanup-client-plugin-promises.
30
35
  function dispatchFlowAction(
31
- send: (msg: unknown) => void,
36
+ send: PluginSend,
32
37
  sessionId: string,
33
38
  action: string,
34
39
  opts?: { flowName?: string; task?: string; description?: string },
35
40
  ): void {
36
- send({
41
+ makeSafeSend(send)({
37
42
  type: "flow_management",
38
43
  sessionId,
39
44
  action,
@@ -59,6 +64,9 @@ interface RouteProps {
59
64
  export function FlowsListRoute({ session, onClose }: RouteProps) {
60
65
  const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
61
66
  const send = usePluginSend();
67
+ // Dialog `onSelect` cannot own the send promise — discard it explicitly.
68
+ // See change: cleanup-client-plugin-promises.
69
+ const dispatch = makeSafeSend(send);
62
70
  const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
63
71
  const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
64
72
  const [launchTarget, setLaunchTarget] = useState<FlowInfo | null>(null);
@@ -112,17 +120,17 @@ export function FlowsListRoute({ session, onClose }: RouteProps) {
112
120
  // Send the user to the /flows:new route via pluginRouter.
113
121
  // Until pluginRouter wiring lands, just open the new dialog
114
122
  // inline by closing this and dispatching the new command.
115
- send({ type: "send_prompt", sessionId: session.id, text: "/flows:new" });
123
+ dispatch({ type: "send_prompt", sessionId: session.id, text: "/flows:new" });
116
124
  onClose();
117
125
  return;
118
126
  }
119
127
  if (value === "__edit__") {
120
- send({ type: "send_prompt", sessionId: session.id, text: "/flows:edit" });
128
+ dispatch({ type: "send_prompt", sessionId: session.id, text: "/flows:edit" });
121
129
  onClose();
122
130
  return;
123
131
  }
124
132
  if (value === "__delete__") {
125
- send({ type: "send_prompt", sessionId: session.id, text: "/flows:delete" });
133
+ dispatch({ type: "send_prompt", sessionId: session.id, text: "/flows:delete" });
126
134
  onClose();
127
135
  return;
128
136
  }
@@ -38,11 +38,11 @@ export function FlowsSettings(): React.ReactElement {
38
38
  await send({ type: "plugin_config_write", id: "flows", config: { editFlow: valuesRef.current } });
39
39
  }, [send]);
40
40
  const reset = useCallback(() => setEditFlow(baseRef.current), []);
41
- useSettingsDraftSource({ id: "plugin:flows", page: "plugins", isDirty, commit, reset });
41
+ useSettingsDraftSource({ id: "plugin:flows", isDirty, commit, reset });
42
42
 
43
43
  return (
44
- <section className="border border-[var(--border-primary)] rounded-lg p-4">
45
- <h3 className="text-sm font-semibold mb-0.5">{t("flowsHeading", undefined, "Flows")}</h3>
44
+ // No self-header: the host owns identity + status chrome (design D1).
45
+ <div>
46
46
  <p className="text-xs text-[var(--text-tertiary)] mb-3">
47
47
  Multi-agent workflow orchestration. Applies globally; sessions inherit this default.
48
48
  </p>
@@ -63,6 +63,6 @@ export function FlowsSettings(): React.ReactElement {
63
63
  </span>
64
64
  </span>
65
65
  </label>
66
- </section>
66
+ </div>
67
67
  );
68
68
  }
@@ -15,12 +15,13 @@ import type {
15
15
  } from "@blackbelt-technology/pi-dashboard-shared/types.js";
16
16
  import { mdiPencil, mdiPlay } from "@mdi/js";
17
17
  import { Icon } from "@mdi/react";
18
- import React, { useEffect, useRef, useState } from "react";
18
+ import React, { useEffect, useMemo, useRef, useState } from "react";
19
19
  import { FlowActivityBadge } from "./FlowActivityBadge.js";
20
20
  import { FlowAuthorPromptDialog } from "./FlowAuthorPromptDialog.js";
21
21
  import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
22
22
  import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
23
23
  import type { FlowsPluginConfig } from "./FlowsSettings.js";
24
+ import { makeSafeSend } from "./send-safe.js";
24
25
 
25
26
  export function SessionFlowActions({
26
27
  flows,
@@ -231,6 +232,10 @@ export function SessionFlowActionsClaim({ session }: { session: DashboardSession
231
232
  const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
232
233
  const { flowState } = useFlowsSessionState(session.id);
233
234
  const send = usePluginSend();
235
+ // The edit-mode reconcile effect and the author-prompt handler cannot own the
236
+ // send promise — discard it explicitly.
237
+ // See change: cleanup-client-plugin-promises.
238
+ const dispatch = useMemo(() => makeSafeSend(send), [send]);
234
239
  const config = usePluginConfig<FlowsPluginConfig>();
235
240
  const editMode = config.editFlow ?? false;
236
241
 
@@ -245,8 +250,8 @@ export function SessionFlowActionsClaim({ session }: { session: DashboardSession
245
250
  if (flows.length === 0) return; // wait until flows-plugin is available
246
251
  if (reconciledRef.current === editMode) return;
247
252
  reconciledRef.current = editMode;
248
- send({ type: "flow_management", sessionId: session.id, action: "set-edit-mode", enabled: editMode });
249
- }, [flows.length, editMode, session.id, send]);
253
+ dispatch({ type: "flow_management", sessionId: session.id, action: "set-edit-mode", enabled: editMode });
254
+ }, [flows.length, editMode, session.id, dispatch]);
250
255
 
251
256
  // Render when there's a flow active OR action buttons are available.
252
257
  if (flows.length === 0 && !editMode && !flowState) return null;
@@ -267,7 +272,7 @@ export function SessionFlowActionsClaim({ session }: { session: DashboardSession
267
272
  ? `/skill:manage-flows ${flowName}\n\n${intent}`
268
273
  : `/skill:manage-flows ${flowName}`
269
274
  : `/skill:manage-flows ${intent}`;
270
- send({ type: "send_prompt", sessionId: session.id, text });
275
+ dispatch({ type: "send_prompt", sessionId: session.id, text });
271
276
  }}
272
277
  onFlowAction={(action, opts) =>
273
278
  send({
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Accumulated-USD cost formatting — a leaf module with no dependencies.
3
+ *
4
+ * Extracted from `FlowAgentCard.tsx` to break the import cycle
5
+ * `FlowAgentCard -> FlowAgentDetail -> FlowAgentCard`: the card renders the
6
+ * detail view, and the detail view only needed the card for this formatter.
7
+ * A currency formatter living in a card component was incidental placement.
8
+ *
9
+ * See change: cleanup-import-cycles (D2).
10
+ */
11
+
12
+ /**
13
+ * Format an accumulated USD cost, matching the pi-flows TUI precision
14
+ * (`agent-card.ts`): two decimals at or above $1, four decimals sub-dollar.
15
+ *
16
+ * The sub-dollar branch is load-bearing — flow agent costs are routinely well
17
+ * below $1, where 2 decimals would collapse distinct values to `$0.00`.
18
+ */
19
+ export function formatCost(n: number): string {
20
+ return `$${n >= 1 ? n.toFixed(2) : n.toFixed(4)}`;
21
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Discard-with-a-stated-handler wrapper around the plugin send primitive.
3
+ *
4
+ * A plugin message dispatched from an event handler or effect has no caller to
5
+ * own its promise. Wrapping it here keeps the discard explicit and routes the
6
+ * rejection to the package's logging path, so a dropped message is observable
7
+ * instead of leaving the UI showing a change the server never applied.
8
+ *
9
+ * See change: cleanup-client-plugin-promises (design D1).
10
+ */
11
+ export type PluginSend = (message: unknown) => void | Promise<void>;
12
+
13
+ export function makeSafeSend(send: PluginSend): (message: unknown) => void {
14
+ return (message: unknown): void => {
15
+ void Promise.resolve(send(message)).catch((err: unknown) => {
16
+ console.error("[flows-plugin] plugin send failed:", err);
17
+ });
18
+ };
19
+ }
package/src/AGENTS.md DELETED
@@ -1,8 +0,0 @@
1
- # DOX — packages/flows-plugin/src
2
-
3
- Files in this directory. One row per source file.
4
-
5
- | File | Purpose |
6
- |------|---------|
7
- | `flow-reducer.ts` | Flow event fold. Reads `nodeKind` at `flow_agent_started` (decided once; agent-card fallback), `typedOutputs`/`branch`/`outcome` at complete, code target from `data.target`, `cost` from `result.cost` (verbatim, undefined when absent; see change surface-flow-agent-cost). Pre-lists code/code-decision steps as pending cards. `flow_complete` non-success downgrades in-flight cards to error/hard. See change: rework-flows-plugin-for-new-pi-flows. |
8
- | `reducer.ts` | Re-export barrel for `isFlowEvent`, `reduceFlowEvent`. Architect reducer exports REMOVED (flow-architect deleted upstream). See change: rework-flows-plugin-for-new-pi-flows. L1/L2 reducer coverage: `__tests__/flow-reducer-seed-on-start.test.ts` (missing-start -> null; start-then-progression advances status + agents to terminal) and `__tests__/flow-reducer-bridge-contract.test.ts` (CONTRACT-PINNED: event types read from the bridge `FLOW_EVENT_MAP` values, never hand-typed; core lifecycle reduces to terminal, reducer never throws on any mapped `flow_*`, passthrough leaves state unchanged). See change: add-flow-plugin-e2e-tests. |