@blackbelt-technology/pi-dashboard-flows-plugin 0.8.0 → 0.10.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.
@@ -8,6 +8,8 @@ import { FlowAgentCard } from "./FlowAgentCard.js";
8
8
  import { FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
9
9
  import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
10
10
  import { FlowYamlPopoverButton } from "./FlowYamlPopoverButton.js";
11
+ import { FLOW_CARD_GRID_CLASS, FLOW_CARD_GRID_CONTAINER_CLASS } from "./flow-card-grid.js";
12
+ import { useFlowNodeFiles, withNodeFiles } from "./flow-files.js";
11
13
  import { useFlowCollapsePersisted } from "./flow-collapse-storage.js";
12
14
 
13
15
 
@@ -52,7 +54,10 @@ export function FlowSummary({
52
54
  // improve-flow-graph-dialog-and-card-interaction.
53
55
  const [selectedStepId, setSelectedStepId] = useState<string | null>(null);
54
56
  const rootRef = useRef<HTMLDivElement>(null);
55
- const agents = Array.from(flowState.agents.values());
57
+ // Agent / handler file paths for the frozen cards' file buttons.
58
+ // See change: attach-flow-before-run.
59
+ const nodeFiles = useFlowNodeFiles(sessionId ?? session?.id);
60
+ const agents = Array.from(withNodeFiles(flowState, nodeFiles).agents.values());
56
61
  // Only summary-bearing agents are listed in the Summaries subsection (others
57
62
  // stay in the frozen cards + graph). See change: fix-flow-ui-graph-zoom-summary.
58
63
  const summarised = agents.filter(a => a.summary);
@@ -137,6 +142,7 @@ export function FlowSummary({
137
142
  <FlowYamlPopoverButton
138
143
  flowSource={flowState.flowSource}
139
144
  flowName={flowState.flowName}
145
+ sessionId={sessionId ?? session?.id}
140
146
  />
141
147
  </div>
142
148
  )}
@@ -145,22 +151,22 @@ export function FlowSummary({
145
151
  the whole panel always fits the viewport (no page scroll). The summaries
146
152
  section and each agent row stay independently collapsible inside it. */}
147
153
  <div className="mt-2 overflow-y-auto" style={{ maxHeight: "48vh" }} data-testid="flow-summary-scrollbox">
148
- {/* Frozen agent cards — read-only. */}
154
+ {/* Frozen agent cards — read-only. Same grid geometry as the live panel
155
+ (shared helper); the wrapper is the query container (design D1/D5). */}
149
156
  {agents.length > 0 && (
150
- <div
151
- className="grid gap-2"
152
- style={{ gridTemplateColumns: `repeat(auto-fill, minmax(200px, 1fr))` }}
153
- >
154
- {agents.map(agent => (
155
- <FlowAgentCard
156
- key={agent.stepId || agent.agentName}
157
- agent={agent}
158
- session={session}
159
- sessionId={sessionId ?? session?.id}
160
- selected={selectedStepId === (agent.stepId || agent.agentName)}
161
- onSelect={handleSelectStep}
162
- />
163
- ))}
157
+ <div className={FLOW_CARD_GRID_CONTAINER_CLASS}>
158
+ <div className={FLOW_CARD_GRID_CLASS}>
159
+ {agents.map(agent => (
160
+ <FlowAgentCard
161
+ key={agent.stepId || agent.agentName}
162
+ agent={agent}
163
+ session={session}
164
+ sessionId={sessionId ?? session?.id}
165
+ selected={selectedStepId === (agent.stepId || agent.agentName)}
166
+ onSelect={handleSelectStep}
167
+ />
168
+ ))}
169
+ </div>
164
170
  </div>
165
171
  )}
166
172
 
@@ -1,110 +1,45 @@
1
1
  /**
2
- * FlowYamlPopoverButton — paper-icon button that opens a popover anchored
3
- * to itself, fetches the flow's YAML at `/api/pi-resource-file?path=...`,
4
- * and renders it inside the popover via the `ui:markdown-content` primitive
5
- * (wrapped in a `yaml` code fence for syntax highlighting).
2
+ * FlowYamlPopoverButton — paper-icon button that opens the flow's YAML in the
3
+ * host's built-in editor (Split view) via `useOpenFileInEditor`. Hidden without
4
+ * a session (no editor to target).
6
5
  *
7
- * Used by `FlowDashboard` (live flow) and `FlowSummary` (completed flow).
6
+ * Used by `FlowDashboard` (live / idle flow) and `FlowSummary` (completed flow).
8
7
  *
9
8
  * The flow's YAML path is emitted by pi-flows in the `flow:flow-started`
10
- * event (see `packages/pi-flows/extensions/flow-engine/flow-tui.ts:487` —
11
- * `source: flow.source`) and stored on `FlowState.flowSource` by the flow
12
- * reducer.
9
+ * event (`source: flow.source`) and stored on `FlowState.flowSource` by the
10
+ * flow reducer; an attached idle flow carries it from `flowsList`.
13
11
  *
14
- * See change: add-ui-popover-primitive.
12
+ * See change: add-ui-popover-primitive, attach-flow-before-run.
15
13
  */
16
- import React, { useEffect, useState } from "react";
17
- import { Icon } from "@mdi/react";
14
+ import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
18
15
  import { mdiFileDocumentOutline } from "@mdi/js";
19
- import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
20
- import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
21
-
22
- type YamlFetchState =
23
- | { kind: "idle" }
24
- | { kind: "loading" }
25
- | { kind: "loaded"; content: string }
26
- | { kind: "error"; error: string };
16
+ import { Icon } from "@mdi/react";
17
+ import { useOpenFileInEditor } from "./flow-files.js";
27
18
 
28
19
  export function FlowYamlPopoverButton({
29
20
  flowSource,
30
21
  flowName,
22
+ sessionId,
31
23
  }: {
32
24
  flowSource: string;
33
25
  flowName: string;
26
+ /** Owning session — the editor to open the YAML in. */
27
+ sessionId?: string;
34
28
  }) {
35
- const Dialog = useUiPrimitive(UI_PRIMITIVE_KEYS.dialog);
36
- const MarkdownContent = useUiPrimitive(UI_PRIMITIVE_KEYS.markdownContent);
37
- const [open, setOpen] = useState(false);
38
- const [state, setState] = useState<YamlFetchState>({ kind: "idle" });
39
-
40
- // Deps include only `open` + `flowSource`. Including state.kind would
41
- // cause cleanup to fire on the idle→loading transition, self-cancelling
42
- // the fetch. Same pattern as `usePiResourceFileFetch` in the client.
43
- useEffect(() => {
44
- if (!open) return;
45
- let cancelled = false;
46
- setState({ kind: "loading" });
47
- fetch(`/api/pi-resource-file?path=${encodeURIComponent(flowSource)}`)
48
- .then(async (r) => {
49
- const json = await r.json();
50
- if (cancelled) return;
51
- if (json?.success && typeof json?.data?.content === "string") {
52
- setState({ kind: "loaded", content: json.data.content });
53
- } else {
54
- setState({
55
- kind: "error",
56
- error: typeof json?.error === "string" ? json.error : "Failed to read flow YAML",
57
- });
58
- }
59
- })
60
- .catch((err) => {
61
- if (!cancelled) setState({ kind: "error", error: String(err) });
62
- });
63
- return () => {
64
- cancelled = true;
65
- };
66
- }, [open, flowSource]);
67
-
29
+ const t = useT();
30
+ const openInEditor = useOpenFileInEditor(sessionId);
31
+ if (!openInEditor) return null;
68
32
  return (
69
- <>
70
- <button
71
- onClick={(e) => {
72
- e.stopPropagation();
73
- setOpen((prev) => !prev);
74
- }}
75
- className={`transition-colors p-0.5 rounded inline-flex items-center ${
76
- open
77
- ? "text-blue-400 bg-blue-400/10"
78
- : "text-[var(--text-tertiary)] hover:text-blue-400 hover:bg-[var(--bg-surface)]"
79
- }`}
80
- title={open ? "Close flow YAML" : `View ${flowName} YAML`}
81
- >
82
- <Icon path={mdiFileDocumentOutline} size={0.5} />
83
- </button>
84
- <Dialog
85
- open={open}
86
- onClose={() => setOpen(false)}
87
- title={`${flowName} · YAML`}
88
- size="lg"
89
- >
90
- {/* Pinned path header; YAML scrolls inside a fixed-height region so the
91
- dialog stays a fixed size. See change:
92
- improve-flow-graph-dialog-and-card-interaction. */}
93
- <div className="text-[11px] text-[var(--text-tertiary)] font-mono break-all" title={flowSource}>
94
- {flowSource}
95
- </div>
96
- <div className="h-[60vh] overflow-y-auto">
97
- {state.kind === "loading" && (
98
- <div className="text-xs text-[var(--text-muted)]">Loading…</div>
99
- )}
100
- {state.kind === "error" && (
101
- <div className="text-xs text-red-400">⚠ {state.error}</div>
102
- )}
103
- {state.kind === "loaded" && (
104
- <MarkdownContent content={"```yaml\n" + state.content + "\n```"} />
105
- )}
106
- </div>
107
- </Dialog>
108
- </>
33
+ <button
34
+ type="button"
35
+ onClick={(e) => {
36
+ e.stopPropagation();
37
+ openInEditor(flowSource);
38
+ }}
39
+ className="transition-colors p-0.5 rounded inline-flex items-center text-[var(--text-tertiary)] hover:text-blue-400 hover:bg-[var(--bg-surface)]"
40
+ title={t("openFlowYamlInEditor", { name: flowName }, `Open ${flowName} YAML in editor`)}
41
+ >
42
+ <Icon path={mdiFileDocumentOutline} size={0.5} />
43
+ </button>
109
44
  );
110
45
  }
@@ -24,13 +24,15 @@
24
24
  *
25
25
  * See change: pluginize-flows-via-registry.
26
26
  */
27
- import { useMemo } from "react";
27
+
28
+ import { useSessionEvents } from "@blackbelt-technology/dashboard-plugin-runtime";
28
29
  import type {
29
- FlowState,
30
30
  DashboardEvent,
31
+ FlowState,
31
32
  } from "@blackbelt-technology/pi-dashboard-shared/types.js";
32
- import { useSessionEvents } from "@blackbelt-technology/dashboard-plugin-runtime";
33
+ import { useMemo } from "react";
33
34
  import { isFlowEvent, reduceFlowEvent } from "../reducer.js";
35
+ import { toEventTime } from "./flow-idle-state.js";
34
36
 
35
37
  /** Shape exposed to flows-plugin components for a single session. */
36
38
  export interface FlowsSessionState {
@@ -42,6 +44,14 @@ export interface FlowsSessionState {
42
44
  * (FlowDashboard's multi-flow tab bar).
43
45
  */
44
46
  flowStates: ReadonlyMap<string, FlowState>;
47
+ /** Epoch ms of the newest `flow_started` in the stream (attach baseline /
48
+ * consumption clock). See change: attach-flow-before-run (D4). */
49
+ lastFlowStartedAt?: number;
50
+ /** Latest autonomous mode seen (`flow_started.autonomousMode` or
51
+ * `flow_autonomous_changed.enabled`), captured even with no flowState (D8). */
52
+ lastAutonomousMode?: boolean;
53
+ /** Latest start pi-flows refused (`flow_complete` status `rejected`) (D7). */
54
+ lastRejection?: { flowName: string; reason?: string; timestamp: number };
45
55
  }
46
56
 
47
57
  const EMPTY_STATE: FlowsSessionState = Object.freeze({
@@ -70,6 +80,9 @@ export function reduceFlowsSessionState(
70
80
  let flowState: FlowState | null = null;
71
81
  let flowStates: Map<string, FlowState> = new Map();
72
82
  let flowStatesMutated = false;
83
+ let lastFlowStartedAt: number | undefined;
84
+ let lastAutonomousMode: boolean | undefined;
85
+ let lastRejection: FlowsSessionState["lastRejection"];
73
86
 
74
87
  // Diagnostic counter for C1 — see fix-flows-plugin-polish. Gated to dev.
75
88
  let flowEventCount = 0;
@@ -77,6 +90,20 @@ export function reduceFlowsSessionState(
77
90
  for (const event of events) {
78
91
  if (isFlowEvent(event.eventType)) {
79
92
  flowEventCount++;
93
+ const data = event.data ?? {};
94
+ if (event.eventType === "flow_started") {
95
+ const ts = toEventTime(event.timestamp);
96
+ if (lastFlowStartedAt === undefined || ts > lastFlowStartedAt) lastFlowStartedAt = ts;
97
+ if (typeof data.autonomousMode === "boolean") lastAutonomousMode = data.autonomousMode;
98
+ } else if (event.eventType === "flow_autonomous_changed") {
99
+ if (typeof data.enabled === "boolean") lastAutonomousMode = data.enabled;
100
+ } else if (event.eventType === "flow_complete" && data.status === "rejected") {
101
+ lastRejection = {
102
+ flowName: String(data.flowName ?? ""),
103
+ reason: typeof data.reason === "string" ? data.reason : undefined,
104
+ timestamp: toEventTime(event.timestamp),
105
+ };
106
+ }
80
107
  flowState = reduceFlowEvent(flowState, event);
81
108
  if (flowState) {
82
109
  if (!flowStatesMutated) {
@@ -109,13 +136,22 @@ export function reduceFlowsSessionState(
109
136
  }
110
137
  }
111
138
 
112
- if (flowState === null && flowStates.size === 0) {
139
+ if (
140
+ flowState === null &&
141
+ flowStates.size === 0 &&
142
+ lastFlowStartedAt === undefined &&
143
+ lastAutonomousMode === undefined &&
144
+ lastRejection === undefined
145
+ ) {
113
146
  return EMPTY_STATE;
114
147
  }
115
148
 
116
149
  return {
117
150
  flowState,
118
151
  flowStates,
152
+ lastFlowStartedAt,
153
+ lastAutonomousMode,
154
+ lastRejection,
119
155
  };
120
156
  }
121
157
 
@@ -10,7 +10,7 @@
10
10
  * panel's Save). See change: rework-flows-plugin-for-new-pi-flows.
11
11
  */
12
12
 
13
- import { useSettingsDraftSource, useT } from "@blackbelt-technology/dashboard-plugin-runtime";
13
+ import { ToggleField, useSettingsDraftSource, useT } from "@blackbelt-technology/dashboard-plugin-runtime";
14
14
  import { usePluginConfig, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime/context";
15
15
  import type React from "react";
16
16
  import { useCallback, useRef, useState } from "react";
@@ -40,29 +40,26 @@ export function FlowsSettings(): React.ReactElement {
40
40
  const reset = useCallback(() => setEditFlow(baseRef.current), []);
41
41
  useSettingsDraftSource({ id: "plugin:flows", isDirty, commit, reset });
42
42
 
43
+ const codeCls = "font-mono text-[12px] text-[var(--text-primary)]";
43
44
  return (
44
45
  // No self-header: the host owns identity + status chrome (design D1).
45
- <div>
46
- <p className="text-xs text-[var(--text-tertiary)] mb-3">
47
- Multi-agent workflow orchestration. Applies globally; sessions inherit this default.
46
+ <div className="space-y-3">
47
+ <p className="text-xs text-[var(--text-secondary)]">
48
+ {t("settingsIntro", undefined, "Multi-agent workflows. This is the default for every session.")}
48
49
  </p>
49
- <label className="flex gap-2.5 items-start text-[13px] cursor-pointer">
50
- <input
51
- type="checkbox"
52
- checked={editFlow}
53
- onChange={(e) => setEditFlow(e.target.checked)}
54
- className="mt-0.5"
55
- data-testid="flows-edit-mode-toggle"
56
- />
57
- <span>
58
- <span className="font-medium">{t("editModeLabel", undefined, "Edit mode")}</span>
59
- {" — allow the main session to author flows & agents"}
60
- <span className="block text-[11px] text-[var(--text-muted)] mt-0.5">
61
- Activates <code>flow_agents</code> / <code>flow_write</code> and makes the
62
- edit-flow skill model-visible. Off by default.
63
- </span>
64
- </span>
65
- </label>
50
+ <ToggleField
51
+ label={t("editModeLabel", undefined, "Edit mode")}
52
+ hint={
53
+ <>
54
+ {t("editModeHintPre", undefined, "Lets the main session create and change flows and agents. Turns on")}{" "}
55
+ <code className={codeCls}>flow_agents</code> / <code className={codeCls}>flow_write</code>{" "}
56
+ {t("editModeHintPost", undefined, "and the edit-flow skill. Off by default.")}
57
+ </>
58
+ }
59
+ value={editFlow}
60
+ onChange={setEditFlow}
61
+ testIds={{ control: "flows-edit-mode-toggle" }}
62
+ />
66
63
  </div>
67
64
  );
68
65
  }
@@ -1,289 +1,55 @@
1
- import {
2
- usePluginSend,
3
- useSessionData,
4
- useT,
5
- useUiPrimitive,
6
- } from "@blackbelt-technology/dashboard-plugin-runtime";
7
- import { usePluginConfig } from "@blackbelt-technology/dashboard-plugin-runtime/context";
8
- import type { UiSelectOption as SelectOption } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
9
- import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
10
- import type {
11
- CommandInfo,
12
- DashboardSession,
13
- FlowInfo,
14
- FlowState,
15
- } from "@blackbelt-technology/pi-dashboard-shared/types.js";
16
- import { mdiPencil, mdiPlay } from "@mdi/js";
17
- import { Icon } from "@mdi/react";
18
- import React, { useEffect, useMemo, useRef, useState } from "react";
1
+ import { usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime";
2
+ import type { DashboardSession, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
3
+ import React from "react";
19
4
  import { FlowActivityBadge } from "./FlowActivityBadge.js";
20
- import { FlowAuthorPromptDialog } from "./FlowAuthorPromptDialog.js";
21
- import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
22
5
  import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
23
- import type { FlowsPluginConfig } from "./FlowsSettings.js";
24
- import { makeSafeSend } from "./send-safe.js";
25
6
 
7
+ /**
8
+ * FLOWS-subcard body: flow STATUS only — `FlowActivityBadge` (with Abort while
9
+ * running) when the session has a flow state, else null. The flow actions
10
+ * (Run / Open / New-Edit / Delete), their dialogs and the edit-mode reconcile
11
+ * live in `SessionFlowMenuClaim`. See change: add-session-actions-flyout (D12).
12
+ */
26
13
  export function SessionFlowActions({
27
- flows,
28
- editMode,
29
- hasFlowsDelete,
30
- onFlowAction,
31
- onEditFlow,
32
14
  flowState,
33
15
  onAbortFlow,
34
16
  }: {
35
- flows: FlowInfo[];
36
- /** Edit-mode on → show the New / Edit launcher (authoring via the skill). */
37
- editMode: boolean;
38
- hasFlowsDelete?: boolean;
39
- onFlowAction: (action: string, opts?: { flowName?: string; task?: string; description?: string }) => void;
40
- /**
41
- * Launch the manage-flows skill for an existing flow (name) or a new flow
42
- * (undefined), carrying the user's stated intent (description for new, change
43
- * instruction for edit; empty string when none given).
44
- */
45
- onEditFlow: (flowName: string | undefined, instruction: string) => void;
46
- /** Current flow state for this session. Drives the status pill rendered above the action buttons. */
17
+ /** Current flow state for this session. Drives the status pill. */
47
18
  flowState?: FlowState | null;
48
19
  /** Dispatch flow_control abort. Called by the running-flow pill's Abort button. */
49
20
  onAbortFlow?: () => void;
50
21
  }) {
51
- const t = useT();
52
- const ConfirmDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.confirmDialog);
53
- const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
54
- const [pickerOpen, setPickerOpen] = useState(false);
55
- const [editPickerOpen, setEditPickerOpen] = useState(false);
56
- // After picking from the edit launcher, capture intent before launching the skill.
57
- const [authorTarget, setAuthorTarget] = useState<{ mode: "new" | "edit"; flowName?: string } | null>(null);
58
- const [deletePickerOpen, setDeletePickerOpen] = useState(false);
59
- const [deleteFlowName, setDeleteFlowName] = useState<string | null>(null);
60
- const [selectedFlow, setSelectedFlow] = useState<FlowInfo | null>(null);
61
-
62
22
  // Compute running-flow badge inputs from flowState (when present).
63
23
  // See change: fix-flows-plugin-polish (A5 + A6).
64
- const badgeProps = flowState
65
- ? (() => {
66
- const agents = flowState.agents;
67
- const total = agents.size;
68
- const done = Array.from(agents.values()).filter(
69
- (a) => a.status === "complete" || a.status === "error" || a.status === "blocked",
70
- ).length;
71
- return {
72
- flowName: flowState.flowName,
73
- agentsDone: done,
74
- agentsTotal: total,
75
- status: flowState.status,
76
- };
77
- })()
78
- : null;
79
-
80
- if (flows.length === 0 && !editMode && !badgeProps) return null;
81
-
82
- const flowOptions: SelectOption[] = flows.map((f) => ({
83
- value: f.name,
84
- label: f.name,
85
- description: f.description,
86
- }));
87
- // Edit launcher options: existing flows + a "new flow" sentinel.
88
- const editOptions: SelectOption[] = [
89
- { value: "__new__", label: t("newFlowOption", undefined, "+ New flow"), description: t("newFlowOptionDesc", undefined, "Author a new flow with the edit-flow skill") },
90
- ...flowOptions,
91
- ];
92
-
24
+ if (!flowState) return null;
25
+ const agents = flowState.agents;
26
+ const done = Array.from(agents.values()).filter(
27
+ (a) => a.status === "complete" || a.status === "error" || a.status === "blocked",
28
+ ).length;
93
29
  return (
94
- <>
95
- <div className="flex flex-col gap-1.5">
96
- {badgeProps && (
97
- <FlowActivityBadge
98
- {...badgeProps}
99
- onAbort={badgeProps.status === "running" ? onAbortFlow : undefined}
100
- />
101
- )}
102
- <div className="flex items-center gap-1.5 flex-wrap">
103
- {flows.length > 0 && (
104
- <button
105
- onClick={(e) => { e.stopPropagation(); setPickerOpen(true); }}
106
- className="text-[10px] px-1.5 py-0.5 rounded border border-blue-500/30 text-blue-400 hover:bg-blue-500/10"
107
- >
108
- <Icon path={mdiPlay} size={0.4} className="inline mr-0.5" />{t("runFlowButton", undefined, "Run Flow...")}
109
- </button>
110
- )}
111
- {editMode && (
112
- <button
113
- onClick={(e) => { e.stopPropagation(); setEditPickerOpen(true); }}
114
- className="text-[10px] px-1.5 py-0.5 rounded border border-purple-500/30 text-purple-400 hover:bg-purple-500/10"
115
- data-testid="flows-new-edit-button"
116
- >
117
- <Icon path={mdiPencil} size={0.4} className="inline mr-0.5" />{t("newEditButton", undefined, "New / Edit…")}
118
- </button>
119
- )}
120
- {hasFlowsDelete && flows.length > 0 && (
121
- <button
122
- onClick={(e) => { e.stopPropagation(); setDeletePickerOpen(true); }}
123
- className="text-[10px] px-1.5 py-0.5 rounded border border-[var(--border-subtle)] text-[var(--text-tertiary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)]"
124
- >
125
- &#215; {t("delete", undefined, "Delete")}
126
- </button>
127
- )}
128
- </div>
129
- </div>
130
-
131
- {/* Run: pick flow → task dialog */}
132
- {pickerOpen && (
133
- <SearchableSelectDialog
134
- title={t("runFlowDialogTitle", undefined, "Run Flow")}
135
- options={flowOptions}
136
- placeholder={t("searchFlows", undefined, "Search flows...")}
137
- emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
138
- onSelect={(value) => {
139
- const flow = flows.find(f => f.name === value);
140
- if (flow) setSelectedFlow(flow);
141
- setPickerOpen(false);
142
- }}
143
- onCancel={() => setPickerOpen(false)}
144
- />
145
- )}
146
-
147
- {selectedFlow && (
148
- <FlowLaunchDialog
149
- flowName={selectedFlow.name}
150
- description={selectedFlow.description}
151
- onSubmit={(task) => {
152
- onFlowAction("run", { flowName: selectedFlow.name, task: task || undefined });
153
- setSelectedFlow(null);
154
- }}
155
- onCancel={() => setSelectedFlow(null)}
156
- />
157
- )}
158
-
159
- {/* New / Edit: pick an existing flow or "new" → launch the edit-flow skill */}
160
- {editPickerOpen && (
161
- <SearchableSelectDialog
162
- title={t("newEditFlowTitle", undefined, "New / Edit flow")}
163
- options={editOptions}
164
- placeholder={t("pickFlowToEdit", undefined, "Pick a flow to edit, or + New flow…")}
165
- emptyMessage={t("noFlowsYet", undefined, "No flows yet — pick + New flow")}
166
- onSelect={(value) => {
167
- setAuthorTarget(
168
- value === "__new__" ? { mode: "new" } : { mode: "edit", flowName: value },
169
- );
170
- setEditPickerOpen(false);
171
- }}
172
- onCancel={() => setEditPickerOpen(false)}
173
- />
174
- )}
175
-
176
- {/* New / Edit: capture intent → launch the manage-flows skill */}
177
- {authorTarget && (
178
- <FlowAuthorPromptDialog
179
- mode={authorTarget.mode}
180
- flowName={authorTarget.flowName}
181
- onSubmit={(instruction) => {
182
- onEditFlow(authorTarget.flowName, instruction);
183
- setAuthorTarget(null);
184
- }}
185
- onCancel={() => setAuthorTarget(null)}
186
- />
187
- )}
188
-
189
- {/* Delete: pick flow → confirm dialog */}
190
- {deletePickerOpen && (
191
- <SearchableSelectDialog
192
- title={t("deleteFlowTitle", undefined, "Delete Flow")}
193
- options={flowOptions}
194
- placeholder={t("searchFlows", undefined, "Search flows...")}
195
- emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
196
- onSelect={(value) => {
197
- setDeleteFlowName(value);
198
- setDeletePickerOpen(false);
199
- }}
200
- onCancel={() => setDeletePickerOpen(false)}
201
- />
202
- )}
203
-
204
- {deleteFlowName && (
205
- <ConfirmDialog
206
- message={t("deleteFlowConfirm", { name: deleteFlowName }, `Delete flow "${deleteFlowName}"? This will remove the flow file and any associated agents.`)}
207
- confirmLabel={t("delete", undefined, "Delete")}
208
- onConfirm={() => {
209
- onFlowAction("delete", { flowName: deleteFlowName });
210
- setDeleteFlowName(null);
211
- }}
212
- onCancel={() => setDeleteFlowName(null)}
213
- />
214
- )}
215
- </>
30
+ <FlowActivityBadge
31
+ flowName={flowState.flowName}
32
+ agentsDone={done}
33
+ agentsTotal={agents.size}
34
+ status={flowState.status}
35
+ onAbort={flowState.status === "running" ? onAbortFlow : undefined}
36
+ />
216
37
  );
217
38
  }
218
39
 
219
40
  /**
220
- * Slot-consumer wrapper for the `session-card-action-bar` claim.
221
- * Reads per-session `flows_list` and `commands_list` from the plugin-
222
- * runtime per-session-data store (mirrored by the shell on every
223
- * `flows_list` / `commands_list` browser-protocol message). Dispatches
224
- * via pluginContext.send. See change: pluginize-flows-via-registry.
225
- *
226
- * Returns null when the session has no flows AND no `flows:new`
227
- * command — this matches the shell's previous gate at
228
- * SessionCard.tsx:651 (`flows && onFlowAction && ...`).
41
+ * Slot-consumer wrapper for the `session-card-flows` claim (FLOWS subcard).
42
+ * Reads the per-session flow state and dispatches abort via pluginContext.send.
43
+ * Visibility is gated by `shouldRenderFlowsSubcard` (any flow event). See change:
44
+ * pluginize-flows-via-registry, add-session-actions-flyout.
229
45
  */
230
46
  export function SessionFlowActionsClaim({ session }: { session: DashboardSession }) {
231
- const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
232
- const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
233
47
  const { flowState } = useFlowsSessionState(session.id);
234
48
  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]);
239
- const config = usePluginConfig<FlowsPluginConfig>();
240
- const editMode = config.editFlow ?? false;
241
-
242
- const hasFlowsDelete = commands.some((c) => c.name === "flows:delete");
243
-
244
- // Reconcile the GLOBAL edit-mode default down to this session once its flows
245
- // plugin is available (flowsList observed). pi-flows persists it to the
246
- // project .pi/settings.json. Idempotent — re-emits only when the default
247
- // changes. See change: rework-flows-plugin-for-new-pi-flows (D4).
248
- const reconciledRef = useRef<boolean | null>(null);
249
- useEffect(() => {
250
- if (flows.length === 0) return; // wait until flows-plugin is available
251
- if (reconciledRef.current === editMode) return;
252
- reconciledRef.current = editMode;
253
- dispatch({ type: "flow_management", sessionId: session.id, action: "set-edit-mode", enabled: editMode });
254
- }, [flows.length, editMode, session.id, dispatch]);
255
-
256
- // Render when there's a flow active OR action buttons are available.
257
- if (flows.length === 0 && !editMode && !flowState) return null;
258
-
259
49
  return (
260
50
  <SessionFlowActions
261
- flows={flows}
262
- editMode={editMode}
263
- hasFlowsDelete={hasFlowsDelete}
264
51
  flowState={flowState}
265
52
  onAbortFlow={() => send({ type: "flow_control", sessionId: session.id, action: "abort" })}
266
- onEditFlow={(flowName, instruction) => {
267
- const intent = instruction.trim();
268
- // New flow: instruction describes what to build. Edit: flow name is
269
- // token-1 (the skill reads that file), instruction follows on a new line.
270
- const text = flowName
271
- ? intent
272
- ? `/skill:manage-flows ${flowName}\n\n${intent}`
273
- : `/skill:manage-flows ${flowName}`
274
- : `/skill:manage-flows ${intent}`;
275
- dispatch({ type: "send_prompt", sessionId: session.id, text });
276
- }}
277
- onFlowAction={(action, opts) =>
278
- send({
279
- type: "flow_management",
280
- sessionId: session.id,
281
- action,
282
- flowName: opts?.flowName,
283
- task: opts?.task,
284
- description: opts?.description,
285
- })
286
- }
287
53
  />
288
54
  );
289
55
  }