@blackbelt-technology/pi-dashboard-flows-plugin 0.9.0 → 0.11.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.
package/package.json CHANGED
@@ -1,7 +1,10 @@
1
1
  {
2
2
  "name": "@blackbelt-technology/pi-dashboard-flows-plugin",
3
- "version": "0.9.0",
3
+ "version": "0.11.0",
4
4
  "description": "Flow rendering plugin for pi-dashboard — pi-flows event reaction (FlowDashboard, FlowAgentCard, FlowArchitect, etc.)",
5
+ "keywords": [
6
+ "pi-dashboard-plugin"
7
+ ],
5
8
  "license": "MIT",
6
9
  "publishConfig": {
7
10
  "access": "public"
@@ -37,6 +40,13 @@
37
40
  "pi-dashboard-plugin": {
38
41
  "id": "flows",
39
42
  "displayName": "Flows",
43
+ "eventTypes": [
44
+ "flow_*"
45
+ ],
46
+ "emits": [
47
+ "flow:run",
48
+ "dashboard-flows:report-files"
49
+ ],
40
50
  "i18nCatalog": "catalog",
41
51
  "priority": 100,
42
52
  "configSchema": "./src/configSchema.json",
@@ -49,18 +59,25 @@
49
59
  "component": "SessionFlowActionsClaim",
50
60
  "shouldRender": "shouldRenderFlowsSubcard"
51
61
  },
62
+ {
63
+ "slot": "session-card-action-bar",
64
+ "component": "SessionFlowMenuClaim"
65
+ },
52
66
  {
53
67
  "slot": "content-header-sticky",
54
- "component": "FlowDashboardClaim"
68
+ "component": "FlowDashboardClaim",
69
+ "module": "./src/client/FlowDashboard.tsx"
55
70
  },
56
71
  {
57
72
  "slot": "content-view",
58
73
  "component": "FlowYamlPreviewClaim",
74
+ "module": "./src/client/FlowYamlPreview.tsx",
59
75
  "predicate": "isFlowYamlPreviewActive"
60
76
  },
61
77
  {
62
78
  "slot": "tool-renderer",
63
79
  "component": "FlowWriteToolRenderer",
80
+ "module": "./src/client/FlowWriteToolRenderer.tsx",
64
81
  "toolName": "flow_write"
65
82
  },
66
83
  {
@@ -71,11 +88,13 @@
71
88
  {
72
89
  "slot": "settings-section",
73
90
  "component": "FlowsSettings",
91
+ "module": "./src/client/FlowsSettings.tsx",
74
92
  "tab": "general"
75
93
  },
76
94
  {
77
95
  "slot": "automation-action-editor",
78
96
  "component": "FlowInputWiringClaim",
97
+ "module": "./src/client/FlowInputWiring.tsx",
79
98
  "config": {
80
99
  "actionId": "flows.run"
81
100
  }
@@ -89,9 +108,9 @@
89
108
  },
90
109
  "//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.",
91
110
  "dependencies": {
92
- "@blackbelt-technology/dashboard-plugin-runtime": "^0.9.0",
93
- "@blackbelt-technology/pi-dashboard-client-utils": "^0.9.0",
94
- "@blackbelt-technology/pi-dashboard-shared": "^0.9.0",
111
+ "@blackbelt-technology/dashboard-plugin-runtime": "^0.11.0",
112
+ "@blackbelt-technology/pi-dashboard-client-utils": "^0.11.0",
113
+ "@blackbelt-technology/pi-dashboard-shared": "^0.11.0",
95
114
  "@fastify/rate-limit": "^11.2.0",
96
115
  "@mdi/js": "^7.4.47",
97
116
  "@mdi/react": "^1.6.1",
@@ -17,10 +17,10 @@ import { Icon } from "@mdi/react";
17
17
  import React, { type ReactNode } from "react";
18
18
 
19
19
  const statusConfig: Record<string, { icon: ReactNode; color: string }> = {
20
- running: { icon: <Icon path={mdiLoading} size={0.45} className="animate-spin" />, color: "text-blue-400" },
21
- success: { icon: <Icon path={mdiCheckCircle} size={0.45} />, color: "text-green-400" },
22
- error: { icon: <Icon path={mdiAlertCircle} size={0.45} />, color: "text-red-400" },
23
- aborted: { icon: <Icon path={mdiStopCircle} size={0.45} />, color: "text-orange-400" },
20
+ running: { icon: <Icon path={mdiLoading} size={0.45} className="animate-spin" />, color: "text-[var(--accent-blue-text)]" },
21
+ success: { icon: <Icon path={mdiCheckCircle} size={0.45} />, color: "text-[var(--accent-green-text)]" },
22
+ error: { icon: <Icon path={mdiAlertCircle} size={0.45} />, color: "text-[var(--accent-red-text)]" },
23
+ aborted: { icon: <Icon path={mdiStopCircle} size={0.45} />, color: "text-[var(--accent-orange-text)]" },
24
24
  };
25
25
 
26
26
  export interface FlowActivityBadgeProps {
@@ -59,7 +59,7 @@ export function FlowActivityBadge({
59
59
  <button
60
60
  type="button"
61
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"
62
+ className="inline-flex items-center gap-0.5 px-1.5 py-0.5 text-[12px] rounded border border-[var(--tint-red-border)] text-[var(--tint-red-fg)] bg-[var(--tint-red-bg)] hover:brightness-110 transition-colors flex-shrink-0"
63
63
  title={t("abortRunningFlow", undefined, "Abort running flow")}
64
64
  >
65
65
  <Icon path={mdiStop} size={0.4} />
@@ -1,8 +1,9 @@
1
- import React, { useState, useRef, useEffect } from "react";
2
- import { Icon } from "@mdi/react";
3
- import { mdiPencil } from "@mdi/js";
4
- import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
5
1
  import { useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
2
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
3
+ import { mdiPencil } from "@mdi/js";
4
+ import { Icon } from "@mdi/react";
5
+ import type React from "react";
6
+ import { useEffect, useRef, useState } from "react";
6
7
 
7
8
  /**
8
9
  * Intent-capture step for the manage-flows authoring launcher.
@@ -49,6 +49,8 @@ export function FlowQuestionCard({
49
49
  return (
50
50
  <div
51
51
  data-testid="flow-question-card"
52
+ data-widget-bar-slot=""
53
+ tabIndex={-1}
52
54
  className="mt-2 mb-2 p-3 border border-purple-500/40 bg-purple-500/5 rounded"
53
55
  >
54
56
  <div className="flex items-start gap-2 mb-2">
@@ -10,8 +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";
14
- import { usePluginConfig, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime/context";
13
+ import { ToggleField, usePluginConfig, usePluginSend, useSettingsDraftSource, useT } from "@blackbelt-technology/dashboard-plugin-runtime";
15
14
  import type React from "react";
16
15
  import { useCallback, useRef, useState } from "react";
17
16
 
@@ -40,29 +39,26 @@ export function FlowsSettings(): React.ReactElement {
40
39
  const reset = useCallback(() => setEditFlow(baseRef.current), []);
41
40
  useSettingsDraftSource({ id: "plugin:flows", isDirty, commit, reset });
42
41
 
42
+ const codeCls = "font-mono text-[12px] text-[var(--text-primary)]";
43
43
  return (
44
44
  // 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.
45
+ <div className="space-y-3">
46
+ <p className="text-xs text-[var(--text-secondary)]">
47
+ {t("settingsIntro", undefined, "Multi-agent workflows. This is the default for every session.")}
48
48
  </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>
49
+ <ToggleField
50
+ label={t("editModeLabel", undefined, "Edit mode")}
51
+ hint={
52
+ <>
53
+ {t("editModeHintPre", undefined, "Lets the main session create and change flows and agents. Turns on")}{" "}
54
+ <code className={codeCls}>flow_agents</code> / <code className={codeCls}>flow_write</code>{" "}
55
+ {t("editModeHintPost", undefined, "and the edit-flow skill. Off by default.")}
56
+ </>
57
+ }
58
+ value={editFlow}
59
+ onChange={setEditFlow}
60
+ testIds={{ control: "flows-edit-mode-toggle" }}
61
+ />
66
62
  </div>
67
63
  );
68
64
  }
@@ -1,358 +1,55 @@
1
- import {
2
- usePluginSend,
3
- useSessionData,
4
- useSessionEvents,
5
- useT,
6
- useUiPrimitive,
7
- } from "@blackbelt-technology/dashboard-plugin-runtime";
8
- import { usePluginConfig } from "@blackbelt-technology/dashboard-plugin-runtime/context";
9
- import type { UiSelectOption as SelectOption } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
10
- import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
11
- import type {
12
- CommandInfo,
13
- DashboardSession,
14
- FlowInfo,
15
- FlowState,
16
- } from "@blackbelt-technology/pi-dashboard-shared/types.js";
17
- import { mdiEyeOutline, mdiPencil, mdiPlay } from "@mdi/js";
18
- import { Icon } from "@mdi/react";
19
- 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";
20
4
  import { FlowActivityBadge } from "./FlowActivityBadge.js";
21
- import { FlowAuthorPromptDialog } from "./FlowAuthorPromptDialog.js";
22
- import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
23
5
  import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
24
- import type { FlowsPluginConfig } from "./FlowsSettings.js";
25
- import { newAttachmentId, setAttachment } from "./flow-attach-store.js";
26
- import { makeSafeSend } from "./send-safe.js";
27
-
28
- /** Open flow… — disabled (with tooltip) while any flow runs. See change:
29
- * attach-flow-before-run (D7). */
30
- function OpenFlowButton({ disabled, onClick }: { disabled: boolean; onClick: () => void }) {
31
- const t = useT();
32
- return (
33
- <button
34
- onClick={(e) => { e.stopPropagation(); onClick(); }}
35
- disabled={disabled}
36
- title={disabled ? t("openFlowDisabledRunning", undefined, "A flow is running") : undefined}
37
- className="text-[10px] px-1.5 py-0.5 rounded border border-[var(--border-subtle)] text-[var(--text-secondary)] hover:bg-[var(--bg-hover)] disabled:opacity-50 disabled:cursor-not-allowed"
38
- data-testid="flows-open-button"
39
- >
40
- <Icon path={mdiEyeOutline} size={0.4} className="inline mr-0.5" />{t("openFlowButton", undefined, "Open flow…")}
41
- </button>
42
- );
43
- }
44
-
45
- function isAnyFlowRunning(
46
- flowState: FlowState | null | undefined,
47
- flowStates: ReadonlyMap<string, FlowState> | undefined,
48
- ): boolean {
49
- if (flowState?.status === "running") return true;
50
- return flowStates ? Array.from(flowStates.values()).some((s) => s.status === "running") : false;
51
- }
52
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
+ */
53
13
  export function SessionFlowActions({
54
- flows,
55
- editMode,
56
- hasFlowsDelete,
57
- onFlowAction,
58
- onEditFlow,
59
14
  flowState,
60
- flowStates,
61
15
  onAbortFlow,
62
- onOpenFlow,
63
16
  }: {
64
- flows: FlowInfo[];
65
- /** Edit-mode on → show the New / Edit launcher (authoring via the skill). */
66
- editMode: boolean;
67
- hasFlowsDelete?: boolean;
68
- onFlowAction: (action: string, opts?: { flowName?: string; task?: string; description?: string }) => void;
69
- /**
70
- * Launch the manage-flows skill for an existing flow (name) or a new flow
71
- * (undefined), carrying the user's stated intent (description for new, change
72
- * instruction for edit; empty string when none given).
73
- */
74
- onEditFlow: (flowName: string | undefined, instruction: string) => void;
75
- /** 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. */
76
18
  flowState?: FlowState | null;
77
19
  /** Dispatch flow_control abort. Called by the running-flow pill's Abort button. */
78
20
  onAbortFlow?: () => void;
79
- /** All flow states this session — Open is disabled while any is running. */
80
- flowStates?: ReadonlyMap<string, FlowState>;
81
- /** Attach a flow to the session flow slot before it runs. See change:
82
- * attach-flow-before-run (D7). */
83
- onOpenFlow?: (flow: FlowInfo) => void;
84
21
  }) {
85
- const t = useT();
86
- const ConfirmDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.confirmDialog);
87
- const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
88
- const [pickerOpen, setPickerOpen] = useState(false);
89
- const [openPickerOpen, setOpenPickerOpen] = useState(false);
90
- const [editPickerOpen, setEditPickerOpen] = useState(false);
91
- // After picking from the edit launcher, capture intent before launching the skill.
92
- const [authorTarget, setAuthorTarget] = useState<{ mode: "new" | "edit"; flowName?: string } | null>(null);
93
- const [deletePickerOpen, setDeletePickerOpen] = useState(false);
94
- const [deleteFlowName, setDeleteFlowName] = useState<string | null>(null);
95
- const [selectedFlow, setSelectedFlow] = useState<FlowInfo | null>(null);
96
-
97
22
  // Compute running-flow badge inputs from flowState (when present).
98
23
  // See change: fix-flows-plugin-polish (A5 + A6).
99
- const badgeProps = flowState
100
- ? (() => {
101
- const agents = flowState.agents;
102
- const total = agents.size;
103
- const done = Array.from(agents.values()).filter(
104
- (a) => a.status === "complete" || a.status === "error" || a.status === "blocked",
105
- ).length;
106
- return {
107
- flowName: flowState.flowName,
108
- agentsDone: done,
109
- agentsTotal: total,
110
- status: flowState.status,
111
- };
112
- })()
113
- : null;
114
-
115
- if (flows.length === 0 && !editMode && !badgeProps) return null;
116
-
117
- const anyRunning = isAnyFlowRunning(flowState, flowStates);
118
-
119
- const flowOptions: SelectOption[] = flows.map((f) => ({
120
- value: f.name,
121
- label: f.name,
122
- description: f.description,
123
- }));
124
- // Edit launcher options: existing flows + a "new flow" sentinel.
125
- const editOptions: SelectOption[] = [
126
- { value: "__new__", label: t("newFlowOption", undefined, "+ New flow"), description: t("newFlowOptionDesc", undefined, "Author a new flow with the edit-flow skill") },
127
- ...flowOptions,
128
- ];
129
-
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;
130
29
  return (
131
- <>
132
- <div className="flex flex-col gap-1.5">
133
- {badgeProps && (
134
- <FlowActivityBadge
135
- {...badgeProps}
136
- onAbort={badgeProps.status === "running" ? onAbortFlow : undefined}
137
- />
138
- )}
139
- <div className="flex items-center gap-1.5 flex-wrap">
140
- {flows.length > 0 && (
141
- <button
142
- onClick={(e) => { e.stopPropagation(); setPickerOpen(true); }}
143
- className="text-[10px] px-1.5 py-0.5 rounded border border-blue-500/30 text-blue-400 hover:bg-blue-500/10"
144
- >
145
- <Icon path={mdiPlay} size={0.4} className="inline mr-0.5" />{t("runFlowButton", undefined, "Run Flow...")}
146
- </button>
147
- )}
148
- {onOpenFlow && flows.length > 0 && (
149
- <OpenFlowButton disabled={anyRunning} onClick={() => setOpenPickerOpen(true)} />
150
- )}
151
- {editMode && (
152
- <button
153
- onClick={(e) => { e.stopPropagation(); setEditPickerOpen(true); }}
154
- className="text-[10px] px-1.5 py-0.5 rounded border border-purple-500/30 text-purple-400 hover:bg-purple-500/10"
155
- data-testid="flows-new-edit-button"
156
- >
157
- <Icon path={mdiPencil} size={0.4} className="inline mr-0.5" />{t("newEditButton", undefined, "New / Edit…")}
158
- </button>
159
- )}
160
- {hasFlowsDelete && flows.length > 0 && (
161
- <button
162
- onClick={(e) => { e.stopPropagation(); setDeletePickerOpen(true); }}
163
- 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)]"
164
- >
165
- &#215; {t("delete", undefined, "Delete")}
166
- </button>
167
- )}
168
- </div>
169
- </div>
170
-
171
- {/* Run: pick flow → task dialog */}
172
- {pickerOpen && (
173
- <SearchableSelectDialog
174
- title={t("runFlowDialogTitle", undefined, "Run Flow")}
175
- options={flowOptions}
176
- placeholder={t("searchFlows", undefined, "Search flows...")}
177
- emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
178
- onSelect={(value) => {
179
- const flow = flows.find(f => f.name === value);
180
- if (flow) setSelectedFlow(flow);
181
- setPickerOpen(false);
182
- }}
183
- onCancel={() => setPickerOpen(false)}
184
- />
185
- )}
186
-
187
- {selectedFlow && (
188
- <FlowLaunchDialog
189
- flowName={selectedFlow.name}
190
- description={selectedFlow.description}
191
- onSubmit={(task) => {
192
- onFlowAction("run", { flowName: selectedFlow.name, task: task || undefined });
193
- setSelectedFlow(null);
194
- }}
195
- onCancel={() => setSelectedFlow(null)}
196
- />
197
- )}
198
-
199
- {/* Open: pick flow → attach it to the flow slot (not started). */}
200
- {openPickerOpen && onOpenFlow && (
201
- <SearchableSelectDialog
202
- title={t("openFlowDialogTitle", undefined, "Open flow")}
203
- options={flowOptions}
204
- placeholder={t("searchFlows", undefined, "Search flows...")}
205
- emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
206
- onSelect={(value) => {
207
- const flow = flows.find((f) => f.name === value);
208
- if (flow) onOpenFlow(flow);
209
- setOpenPickerOpen(false);
210
- }}
211
- onCancel={() => setOpenPickerOpen(false)}
212
- />
213
- )}
214
-
215
- {/* New / Edit: pick an existing flow or "new" → launch the edit-flow skill */}
216
- {editPickerOpen && (
217
- <SearchableSelectDialog
218
- title={t("newEditFlowTitle", undefined, "New / Edit flow")}
219
- options={editOptions}
220
- placeholder={t("pickFlowToEdit", undefined, "Pick a flow to edit, or + New flow…")}
221
- emptyMessage={t("noFlowsYet", undefined, "No flows yet — pick + New flow")}
222
- onSelect={(value) => {
223
- setAuthorTarget(
224
- value === "__new__" ? { mode: "new" } : { mode: "edit", flowName: value },
225
- );
226
- setEditPickerOpen(false);
227
- }}
228
- onCancel={() => setEditPickerOpen(false)}
229
- />
230
- )}
231
-
232
- {/* New / Edit: capture intent → launch the manage-flows skill */}
233
- {authorTarget && (
234
- <FlowAuthorPromptDialog
235
- mode={authorTarget.mode}
236
- flowName={authorTarget.flowName}
237
- onSubmit={(instruction) => {
238
- onEditFlow(authorTarget.flowName, instruction);
239
- setAuthorTarget(null);
240
- }}
241
- onCancel={() => setAuthorTarget(null)}
242
- />
243
- )}
244
-
245
- {/* Delete: pick flow → confirm dialog */}
246
- {deletePickerOpen && (
247
- <SearchableSelectDialog
248
- title={t("deleteFlowTitle", undefined, "Delete Flow")}
249
- options={flowOptions}
250
- placeholder={t("searchFlows", undefined, "Search flows...")}
251
- emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
252
- onSelect={(value) => {
253
- setDeleteFlowName(value);
254
- setDeletePickerOpen(false);
255
- }}
256
- onCancel={() => setDeletePickerOpen(false)}
257
- />
258
- )}
259
-
260
- {deleteFlowName && (
261
- <ConfirmDialog
262
- message={t("deleteFlowConfirm", { name: deleteFlowName }, `Delete flow "${deleteFlowName}"? This will remove the flow file and any associated agents.`)}
263
- confirmLabel={t("delete", undefined, "Delete")}
264
- onConfirm={() => {
265
- onFlowAction("delete", { flowName: deleteFlowName });
266
- setDeleteFlowName(null);
267
- }}
268
- onCancel={() => setDeleteFlowName(null)}
269
- />
270
- )}
271
- </>
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
+ />
272
37
  );
273
38
  }
274
39
 
275
40
  /**
276
- * Slot-consumer wrapper for the `session-card-action-bar` claim.
277
- * Reads per-session `flows_list` and `commands_list` from the plugin-
278
- * runtime per-session-data store (mirrored by the shell on every
279
- * `flows_list` / `commands_list` browser-protocol message). Dispatches
280
- * via pluginContext.send. See change: pluginize-flows-via-registry.
281
- *
282
- * Returns null when the session has no flows AND no `flows:new`
283
- * command — this matches the shell's previous gate at
284
- * 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.
285
45
  */
286
46
  export function SessionFlowActionsClaim({ session }: { session: DashboardSession }) {
287
- const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
288
- const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
289
- const { flowState, flowStates, lastFlowStartedAt } = useFlowsSessionState(session.id);
290
- const events = useSessionEvents(session.id);
47
+ const { flowState } = useFlowsSessionState(session.id);
291
48
  const send = usePluginSend();
292
- // The edit-mode reconcile effect and the author-prompt handler cannot own the
293
- // send promise — discard it explicitly.
294
- // See change: cleanup-client-plugin-promises.
295
- const dispatch = useMemo(() => makeSafeSend(send), [send]);
296
- const config = usePluginConfig<FlowsPluginConfig>();
297
- const editMode = config.editFlow ?? false;
298
-
299
- const hasFlowsDelete = commands.some((c) => c.name === "flows:delete");
300
-
301
- // Reconcile the GLOBAL edit-mode default down to this session once its flows
302
- // plugin is available (flowsList observed). pi-flows persists it to the
303
- // project .pi/settings.json. Idempotent — re-emits only when the default
304
- // changes. See change: rework-flows-plugin-for-new-pi-flows (D4).
305
- const reconciledRef = useRef<boolean | null>(null);
306
- useEffect(() => {
307
- if (flows.length === 0) return; // wait until flows-plugin is available
308
- if (reconciledRef.current === editMode) return;
309
- reconciledRef.current = editMode;
310
- dispatch({ type: "flow_management", sessionId: session.id, action: "set-edit-mode", enabled: editMode });
311
- }, [flows.length, editMode, session.id, dispatch]);
312
-
313
- // Render when there's a flow active OR action buttons are available.
314
- if (flows.length === 0 && !editMode && !flowState) return null;
315
-
316
49
  return (
317
50
  <SessionFlowActions
318
- flows={flows}
319
- editMode={editMode}
320
- hasFlowsDelete={hasFlowsDelete}
321
51
  flowState={flowState}
322
- flowStates={flowStates}
323
- onOpenFlow={(flow) =>
324
- // Baseline = newest flow_started seen now; null on an empty (not yet
325
- // replayed) stream — the flow slot resolves it from the first batch.
326
- // See change: attach-flow-before-run (D4).
327
- setAttachment(session.id, {
328
- id: newAttachmentId(),
329
- name: flow.name,
330
- source: flow.source,
331
- baselineStartedAt: events.length > 0 ? (lastFlowStartedAt ?? 0) : null,
332
- })
333
- }
334
52
  onAbortFlow={() => send({ type: "flow_control", sessionId: session.id, action: "abort" })}
335
- onEditFlow={(flowName, instruction) => {
336
- const intent = instruction.trim();
337
- // New flow: instruction describes what to build. Edit: flow name is
338
- // token-1 (the skill reads that file), instruction follows on a new line.
339
- const text = flowName
340
- ? intent
341
- ? `/skill:manage-flows ${flowName}\n\n${intent}`
342
- : `/skill:manage-flows ${flowName}`
343
- : `/skill:manage-flows ${intent}`;
344
- dispatch({ type: "send_prompt", sessionId: session.id, text });
345
- }}
346
- onFlowAction={(action, opts) =>
347
- send({
348
- type: "flow_management",
349
- sessionId: session.id,
350
- action,
351
- flowName: opts?.flowName,
352
- task: opts?.task,
353
- description: opts?.description,
354
- })
355
- }
356
53
  />
357
54
  );
358
55
  }
@@ -0,0 +1,258 @@
1
+ import { usePluginConfig, usePluginSend, useSessionData, useSessionEvents, useT, useUiPrimitive } from "@blackbelt-technology/dashboard-plugin-runtime";
2
+ import { ActionList } from "@blackbelt-technology/pi-dashboard-client-utils/ActionList";
3
+ import type { UiSelectOption as SelectOption } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
4
+ import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
5
+ import type {
6
+ CommandInfo,
7
+ DashboardSession,
8
+ FlowInfo,
9
+ FlowState,
10
+ } from "@blackbelt-technology/pi-dashboard-shared/types.js";
11
+ import React, { useEffect, useMemo, useRef, useState } from "react";
12
+ import { FlowAuthorPromptDialog } from "./FlowAuthorPromptDialog.js";
13
+ import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
14
+ import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
15
+ import type { FlowsPluginConfig } from "./FlowsSettings.js";
16
+ import { newAttachmentId, setAttachment } from "./flow-attach-store.js";
17
+ import { hasFlowsCommand } from "./flowsActionsGate.js";
18
+ import { sessionHasFlowEvents } from "./flowsAvailability.js";
19
+ import { makeSafeSend } from "./send-safe.js";
20
+
21
+ function isAnyFlowRunning(
22
+ flowState: FlowState | null | undefined,
23
+ flowStates: ReadonlyMap<string, FlowState> | undefined,
24
+ ): boolean {
25
+ if (flowState?.status === "running") return true;
26
+ return flowStates ? Array.from(flowStates.values()).some((s) => s.status === "running") : false;
27
+ }
28
+
29
+ /**
30
+ * `session-card-action-bar` claim: the flow ACTIONS (Run Flow…, Open flow…,
31
+ * New / Edit…, Delete) rendered as an `ActionList` for the session actions menu,
32
+ * plus the dialogs they open and the edit-mode reconcile. Flow STATUS stays in
33
+ * the FLOWS subcard (`SessionFlowActionsClaim`).
34
+ *
35
+ * The claim stays mounted for the card's lifetime (dialogs portal to body and
36
+ * survive the menu closing; the reconcile runs without the menu being opened).
37
+ * Gated by availability — a `flows` / `flows:*` command (not `flows:new` alone)
38
+ * or any flow event; never by `flowsList` length.
39
+ *
40
+ * See change: add-session-actions-flyout (D7, D12).
41
+ */
42
+ export function SessionFlowMenuClaim({ session }: { session: DashboardSession }) {
43
+ const t = useT();
44
+ const ConfirmDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.confirmDialog);
45
+ const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
46
+ const flows = useSessionData<FlowInfo[]>(session.id, "flowsList") ?? [];
47
+ const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
48
+ const { flowState, flowStates, lastFlowStartedAt } = useFlowsSessionState(session.id);
49
+ const events = useSessionEvents(session.id);
50
+ const send = usePluginSend();
51
+ // The edit-mode reconcile and author-prompt handlers cannot own the send
52
+ // promise — discard it explicitly. See change: cleanup-client-plugin-promises.
53
+ const dispatch = useMemo(() => makeSafeSend(send), [send]);
54
+ const config = usePluginConfig<FlowsPluginConfig>();
55
+ const editMode = config.editFlow ?? false;
56
+
57
+ // commandsList (subscribed above) + the event stream drive re-evaluation; the
58
+ // gate reads the same sources as `flowsActionsAvailable`.
59
+ const available = hasFlowsCommand(commands) || sessionHasFlowEvents(session.id);
60
+ const hasFlowsDelete = commands.some((c) => c.name === "flows:delete");
61
+
62
+ const [pickerOpen, setPickerOpen] = useState(false);
63
+ const [openPickerOpen, setOpenPickerOpen] = useState(false);
64
+ const [editPickerOpen, setEditPickerOpen] = useState(false);
65
+ // After picking from the edit launcher, capture intent before launching the skill.
66
+ const [authorTarget, setAuthorTarget] = useState<{ mode: "new" | "edit"; flowName?: string } | null>(null);
67
+ const [deletePickerOpen, setDeletePickerOpen] = useState(false);
68
+ const [deleteFlowName, setDeleteFlowName] = useState<string | null>(null);
69
+ const [selectedFlow, setSelectedFlow] = useState<FlowInfo | null>(null);
70
+
71
+ // Reconcile the GLOBAL edit-mode default down to this session once flows is
72
+ // available. pi-flows persists it to the project .pi/settings.json. Idempotent
73
+ // — re-emits only when the default changes. See change:
74
+ // rework-flows-plugin-for-new-pi-flows (D4), add-session-actions-flyout (D12).
75
+ const reconciledRef = useRef<boolean | null>(null);
76
+ useEffect(() => {
77
+ if (!available) return; // wait until flows is available
78
+ if (reconciledRef.current === editMode) return;
79
+ reconciledRef.current = editMode;
80
+ dispatch({ type: "flow_management", sessionId: session.id, action: "set-edit-mode", enabled: editMode });
81
+ }, [available, editMode, session.id, dispatch]);
82
+
83
+ if (!available) return null;
84
+
85
+ const anyRunning = isAnyFlowRunning(flowState, flowStates);
86
+ const hasFlows = flows.length > 0;
87
+
88
+ const flowOptions: SelectOption[] = flows.map((f) => ({
89
+ value: f.name,
90
+ label: f.name,
91
+ description: f.description,
92
+ }));
93
+ // Edit launcher options: existing flows + a "new flow" sentinel.
94
+ const editOptions: SelectOption[] = [
95
+ { value: "__new__", label: t("newFlowOption", undefined, "+ New flow"), description: t("newFlowOptionDesc", undefined, "Author a new flow with the edit-flow skill") },
96
+ ...flowOptions,
97
+ ];
98
+
99
+ const actions = [
100
+ ...(hasFlows
101
+ ? [{ label: t("runFlowButton", undefined, "Run Flow..."), icon: "mdiPlay", onClick: () => setPickerOpen(true) }]
102
+ : []),
103
+ ...(hasFlows
104
+ ? [{
105
+ label: t("openFlowButton", undefined, "Open flow…"),
106
+ icon: "mdiEyeOutline",
107
+ disabled: anyRunning,
108
+ tooltip: anyRunning ? t("openFlowDisabledRunning", undefined, "A flow is running") : undefined,
109
+ onClick: () => setOpenPickerOpen(true),
110
+ }]
111
+ : []),
112
+ ...(editMode
113
+ ? [{ label: t("newEditButton", undefined, "New / Edit…"), icon: "mdiPencil", onClick: () => setEditPickerOpen(true) }]
114
+ : []),
115
+ ...(hasFlowsDelete && hasFlows
116
+ ? [{ label: `${t("delete", undefined, "Delete")}…`, icon: "mdiDeleteOutline", onClick: () => setDeletePickerOpen(true) }]
117
+ : []),
118
+ ];
119
+
120
+ const onFlowAction = (action: string, opts?: { flowName?: string; task?: string }) =>
121
+ dispatch({
122
+ type: "flow_management",
123
+ sessionId: session.id,
124
+ action,
125
+ flowName: opts?.flowName,
126
+ task: opts?.task,
127
+ });
128
+
129
+ const onEditFlow = (flowName: string | undefined, instruction: string) => {
130
+ const intent = instruction.trim();
131
+ // New flow: instruction describes what to build. Edit: flow name is
132
+ // token-1 (the skill reads that file), instruction follows on a new line.
133
+ const text = flowName
134
+ ? intent
135
+ ? `/skill:manage-flows ${flowName}\n\n${intent}`
136
+ : `/skill:manage-flows ${flowName}`
137
+ : `/skill:manage-flows ${intent}`;
138
+ dispatch({ type: "send_prompt", sessionId: session.id, text });
139
+ };
140
+
141
+ return (
142
+ <>
143
+ {actions.length > 0 && <ActionList actions={actions} />}
144
+
145
+ {/* Run: pick flow → task dialog */}
146
+ {pickerOpen && (
147
+ <SearchableSelectDialog
148
+ title={t("runFlowDialogTitle", undefined, "Run Flow")}
149
+ options={flowOptions}
150
+ placeholder={t("searchFlows", undefined, "Search flows...")}
151
+ emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
152
+ onSelect={(value) => {
153
+ const flow = flows.find((f) => f.name === value);
154
+ if (flow) setSelectedFlow(flow);
155
+ setPickerOpen(false);
156
+ }}
157
+ onCancel={() => setPickerOpen(false)}
158
+ />
159
+ )}
160
+
161
+ {selectedFlow && (
162
+ <FlowLaunchDialog
163
+ flowName={selectedFlow.name}
164
+ description={selectedFlow.description}
165
+ onSubmit={(task) => {
166
+ onFlowAction("run", { flowName: selectedFlow.name, task: task || undefined });
167
+ setSelectedFlow(null);
168
+ }}
169
+ onCancel={() => setSelectedFlow(null)}
170
+ />
171
+ )}
172
+
173
+ {/* Open: pick flow → attach it to the flow slot (not started). See change:
174
+ attach-flow-before-run (D7). */}
175
+ {openPickerOpen && (
176
+ <SearchableSelectDialog
177
+ title={t("openFlowDialogTitle", undefined, "Open flow")}
178
+ options={flowOptions}
179
+ placeholder={t("searchFlows", undefined, "Search flows...")}
180
+ emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
181
+ onSelect={(value) => {
182
+ const flow = flows.find((f) => f.name === value);
183
+ if (flow) {
184
+ // Baseline = newest flow_started seen now; null on an empty (not yet
185
+ // replayed) stream — the flow slot resolves it from the first batch.
186
+ // See change: attach-flow-before-run (D4).
187
+ setAttachment(session.id, {
188
+ id: newAttachmentId(),
189
+ name: flow.name,
190
+ source: flow.source,
191
+ baselineStartedAt: events.length > 0 ? (lastFlowStartedAt ?? 0) : null,
192
+ });
193
+ }
194
+ setOpenPickerOpen(false);
195
+ }}
196
+ onCancel={() => setOpenPickerOpen(false)}
197
+ />
198
+ )}
199
+
200
+ {/* New / Edit: pick an existing flow or "new" → launch the edit-flow skill */}
201
+ {editPickerOpen && (
202
+ <SearchableSelectDialog
203
+ title={t("newEditFlowTitle", undefined, "New / Edit flow")}
204
+ options={editOptions}
205
+ placeholder={t("pickFlowToEdit", undefined, "Pick a flow to edit, or + New flow…")}
206
+ emptyMessage={t("noFlowsYet", undefined, "No flows yet — pick + New flow")}
207
+ onSelect={(value) => {
208
+ setAuthorTarget(
209
+ value === "__new__" ? { mode: "new" } : { mode: "edit", flowName: value },
210
+ );
211
+ setEditPickerOpen(false);
212
+ }}
213
+ onCancel={() => setEditPickerOpen(false)}
214
+ />
215
+ )}
216
+
217
+ {/* New / Edit: capture intent → launch the manage-flows skill */}
218
+ {authorTarget && (
219
+ <FlowAuthorPromptDialog
220
+ mode={authorTarget.mode}
221
+ flowName={authorTarget.flowName}
222
+ onSubmit={(instruction) => {
223
+ onEditFlow(authorTarget.flowName, instruction);
224
+ setAuthorTarget(null);
225
+ }}
226
+ onCancel={() => setAuthorTarget(null)}
227
+ />
228
+ )}
229
+
230
+ {/* Delete: pick flow → confirm dialog */}
231
+ {deletePickerOpen && (
232
+ <SearchableSelectDialog
233
+ title={t("deleteFlowTitle", undefined, "Delete Flow")}
234
+ options={flowOptions}
235
+ placeholder={t("searchFlows", undefined, "Search flows...")}
236
+ emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
237
+ onSelect={(value) => {
238
+ setDeleteFlowName(value);
239
+ setDeletePickerOpen(false);
240
+ }}
241
+ onCancel={() => setDeletePickerOpen(false)}
242
+ />
243
+ )}
244
+
245
+ {deleteFlowName && (
246
+ <ConfirmDialog
247
+ message={t("deleteFlowConfirm", { name: deleteFlowName }, `Delete flow "${deleteFlowName}"? This will remove the flow file and any associated agents.`)}
248
+ confirmLabel={t("delete", undefined, "Delete")}
249
+ onConfirm={() => {
250
+ onFlowAction("delete", { flowName: deleteFlowName });
251
+ setDeleteFlowName(null);
252
+ }}
253
+ onCancel={() => setDeleteFlowName(null)}
254
+ />
255
+ )}
256
+ </>
257
+ );
258
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Actions gate for flows-plugin's `session-card-action-bar` claim
3
+ * (`SessionFlowMenuClaim`). Distinct from the FLOWS-subcard gate in
4
+ * `shouldRender.ts` (flow events only).
5
+ *
6
+ * Open iff pi-flows is active in the session's cwd — a command named `flows` or
7
+ * starting with `flows:` in `commandsList`, the removed `flows:new` alone NOT
8
+ * counting — OR the session has any flow event (live or replayed). Never gates on
9
+ * `flowsList` length, so an active-but-empty cwd still offers New / Edit….
10
+ * Closed by default: no `commandsList` published yet → closed.
11
+ *
12
+ * Synchronous and side-effect-free; reads `getSessionData` directly like
13
+ * `shouldRender.ts`.
14
+ *
15
+ * See change: add-session-actions-flyout (D12).
16
+ */
17
+ import { getSessionData } from "@blackbelt-technology/dashboard-plugin-runtime";
18
+ import type { CommandInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
19
+ import { sessionHasFlowEvents } from "./flowsAvailability.js";
20
+
21
+ /** True when `commands` carries a `flows` / `flows:*` signal (`flows:new` ignored). */
22
+ export function hasFlowsCommand(commands: readonly CommandInfo[] | null | undefined): boolean {
23
+ if (!Array.isArray(commands)) return false;
24
+ return commands.some(
25
+ (c) => c.name !== "flows:new" && (c.name === "flows" || c.name.startsWith("flows:")),
26
+ );
27
+ }
28
+
29
+ /** Whether the flows actions (menu claim) are available for `sessionId`. */
30
+ export function flowsActionsAvailable(sessionId: string): boolean {
31
+ return (
32
+ hasFlowsCommand(getSessionData<CommandInfo[]>(sessionId, "commandsList")) ||
33
+ sessionHasFlowEvents(sessionId)
34
+ );
35
+ }
@@ -25,26 +25,27 @@ export { FlowAgentsToolRenderer } from "./FlowAgentsToolRenderer.js";
25
25
  // session-card-badge claim was dropped because the badge belongs in the
26
26
  // FLOWS subcard, not WORKSPACE. SessionFlowActions now renders the badge
27
27
  // directly via the FlowActivityBadge component.
28
- export { FlowDashboard, FlowDashboardClaim } from "./FlowDashboard.js";
29
28
  export { computeLayout, FlowGraph, flowStateToGraphSteps } from "./FlowGraph.js";
30
29
  // Input-wiring editor claimed into automation-plugin's `automation-action-editor`
31
30
  // slot for `flows.run`. See change: wire-flow-inputs-in-automation.
32
- export { FlowInputWiring, FlowInputWiringClaim } from "./FlowInputWiring.js";
33
31
  export { FlowLaunchDialog } from "./FlowLaunchDialog.js";
34
32
  export { FlowSummary, FlowSummaryClaim } from "./FlowSummary.js";
35
33
  export type { FlowsPluginConfig } from "./FlowsSettings.js";
36
34
 
37
35
  // Settings section (global edit-mode default) — manifest `settings-section` claim.
38
- export { FlowsSettings } from "./FlowsSettings.js";
39
36
  export { FlowTabBar } from "./FlowTabBar.js";
40
37
  // Authoring tool-renderers (main-session timeline) — referenced by the
41
38
  // manifest's `tool-renderer` claims. See change: rework-flows-plugin-for-new-pi-flows.
42
- export { FlowWriteToolRenderer } from "./FlowWriteToolRenderer.js";
43
- export { FlowYamlPreviewClaim } from "./FlowYamlPreview.js";
44
39
  export { SessionFlowActions, SessionFlowActionsClaim } from "./SessionFlowActions.js";
45
40
 
46
- // Manifest-level shouldRender predicate for the `session-card-flows` claim.
47
- // See change: add-flows-subcard.
41
+ // `session-card-action-bar` claim: flow actions (Run / Open / New-Edit / Delete)
42
+ // in the session actions menu + dialogs + edit-mode reconcile, and its
43
+ // availability gate. See change: add-session-actions-flyout.
44
+ export { flowsActionsAvailable, hasFlowsCommand } from "./flowsActionsGate.js";
45
+ export { SessionFlowMenuClaim } from "./SessionFlowMenuClaim.js";
46
+
47
+ // Manifest-level shouldRender predicate for the `session-card-flows` claim
48
+ // (any flow event). See change: add-flows-subcard, add-session-actions-flyout.
48
49
  export { shouldRenderFlowsSubcard } from "./shouldRender.js";
49
50
 
50
51
  // Flow slash commands (`/flows`, `/flows:new`, `/flows:edit`, `/flows:delete`)
@@ -2,37 +2,22 @@
2
2
  * Manifest-level `shouldRender` callback for flows-plugin's
3
3
  * `session-card-flows` claim (`SessionFlowActionsClaim`).
4
4
  *
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`.
5
+ * The FLOWS subcard carries flow STATUS only, so it renders IFF the session has
6
+ * any flow event (live or replayed). It no longer depends on `flowsList`, edit
7
+ * mode or extension presence — those gate the flow ACTIONS, which live in the
8
+ * `session-card-action-bar` claim (see `flowsActionsGate.ts`).
11
9
  *
12
10
  * 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).
11
+ * contract). Reads the live event stream directly via `sessionHasFlowEvents`.
18
12
  *
19
- * See change: fix-empty-flows-subcard.
13
+ * See change: fix-empty-flows-subcard, add-session-actions-flyout.
20
14
  */
21
- import { getSessionData } from "@blackbelt-technology/dashboard-plugin-runtime";
22
- import { getPluginConfig } from "@blackbelt-technology/dashboard-plugin-runtime/context";
23
15
  import type { DashboardSession } from "@blackbelt-technology/pi-dashboard-shared/types.js";
24
- import type { FlowInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
25
16
  import { sessionHasFlowEvents } from "./flowsAvailability.js";
26
17
 
27
18
  export function shouldRenderFlowsSubcard(
28
19
  session: DashboardSession | null | undefined,
29
20
  ): boolean {
30
21
  if (!session) return false;
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
- );
22
+ return sessionHasFlowEvents(session.id);
38
23
  }
package/src/i18n.ts CHANGED
@@ -25,6 +25,9 @@ export const catalog = {
25
25
  dismiss: "关闭",
26
26
  flowsHeading: "流程",
27
27
  editModeLabel: "编辑模式",
28
+ settingsIntro: "多智能体工作流。这是所有会话的默认设置。",
29
+ editModeHintPre: "允许主会话创建和修改流程与智能体。启用",
30
+ editModeHintPost: "以及 edit-flow 技能。默认关闭。",
28
31
  runFlowTitle: "运行流程:{flowName}",
29
32
  taskPlaceholder: "描述任务(可选)…",
30
33
  summary: "摘要",
@@ -76,6 +79,9 @@ export const catalog = {
76
79
  dismiss: "Bezárás",
77
80
  flowsHeading: "Folyamatok",
78
81
  editModeLabel: "Szerkesztő mód",
82
+ settingsIntro: "Többügynökös munkafolyamatok. Ez az alapértelmezés minden munkamenetre.",
83
+ editModeHintPre: "Lehetővé teszi, hogy a fő munkamenet folyamatokat és ügynököket hozzon létre és módosítson. Bekapcsolja a",
84
+ editModeHintPost: "eszközöket és az edit-flow skillt. Alapértelmezetten kikapcsolva.",
79
85
  runFlowTitle: "Folyamat futtatása: {flowName}",
80
86
  taskPlaceholder: "Írd le a feladatot (opcionális)…",
81
87
  summary: "Összefoglaló",
@@ -13,6 +13,12 @@
13
13
  */
14
14
  import fs from "node:fs";
15
15
  import path from "node:path";
16
+ import type { ServerPluginContext } from "@blackbelt-technology/dashboard-plugin-runtime/server";
17
+ import type { AdmitCwdOptions } from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
18
+ import {
19
+ admitRouteCwdParam,
20
+ sendRouteCwdRefusal,
21
+ } from "@blackbelt-technology/pi-dashboard-shared/plugin-route-cwd.js";
16
22
  import { parse as parseYaml } from "yaml";
17
23
 
18
24
  export type FlowInputType = "string" | "number" | "boolean" | "object" | "array";
@@ -24,10 +30,24 @@ export interface FlowInputField {
24
30
  required: boolean;
25
31
  }
26
32
 
33
+ /** A path segment that would climb or stay put (`.` / `..`) — never a flow namespace or name. */
34
+ const isDotSegment = (s: string): boolean => s === "." || s === "..";
35
+
36
+ /**
37
+ * Whether a flow id could escape the flows dir: exactly `.` / `..`, or any path separator.
38
+ * Only EXACT dot segments count — `team.review`, `a..b`, `...`, `.hidden`, `x.` stay valid.
39
+ * For the `<ns>:<name>` form each segment is checked, since `..:x` would climb.
40
+ * See change: harden-git-terminal-plugin-boundaries (S1r).
41
+ */
42
+ function isTraversalFlowId(flowId: string): boolean {
43
+ if (flowId.includes("/") || flowId.includes("\\")) return true;
44
+ return flowId.split(":").some(isDotSegment);
45
+ }
46
+
27
47
  /** Resolve a `<ns>:<name>` flow id to its `flow.yaml` path under `cwd`. */
28
48
  export function flowYamlPath(cwd: string, flowId: string): string | null {
29
49
  const m = /^([\w.-]+):([\w.-]+)$/.exec(flowId);
30
- if (!m) return null;
50
+ if (!m || isDotSegment(m[1]) || isDotSegment(m[2])) return null;
31
51
  return path.join(cwd, ".pi", "flows", "flows", m[1], m[2], "flow.yaml");
32
52
  }
33
53
 
@@ -56,3 +76,38 @@ export function readFlowInputs(cwd: string, flowId: string): FlowInputField[] {
56
76
  }
57
77
  return out;
58
78
  }
79
+
80
+ export interface FlowInputsRouteDeps {
81
+ /** Live admit set (host known folders), read per request. Fail-closed default: nothing known. */
82
+ knownCwds?: () => string[];
83
+ /** `admitCwd` options (the host's throttled `onIndeterminate` logger; test seams). */
84
+ admitOptions?: AdmitCwdOptions;
85
+ }
86
+
87
+ /**
88
+ * `GET /api/plugins/flows/flow-inputs?cwd=&flow=` — read-only. The cwd is REQUIRED and admitted
89
+ * (400 `invalid_cwd` / `cwd_required`, 403, 503) before any flow file is read — there is no
90
+ * `process.cwd()` fallback — and a traversal-shaped flow id is 400 `invalid_flow_id`.
91
+ * See change: wire-flow-inputs-in-automation; harden-git-terminal-plugin-boundaries (S1r).
92
+ */
93
+ export function mountFlowInputsRoute(fastify: ServerPluginContext["fastify"], deps: FlowInputsRouteDeps = {}): void {
94
+ fastify.get("/api/plugins/flows/flow-inputs", async (req, reply) => {
95
+ const q = (req.query ?? {}) as Record<string, unknown>;
96
+ const adm = await admitRouteCwdParam(q.cwd, {
97
+ required: true,
98
+ ...(deps.knownCwds ? { knownCwds: deps.knownCwds } : {}),
99
+ ...(deps.admitOptions ? { admitOptions: deps.admitOptions } : {}),
100
+ });
101
+ if (!adm.ok) return sendRouteCwdRefusal(reply, adm);
102
+ try {
103
+ const flow = typeof q.flow === "string" ? q.flow : "";
104
+ if (flow && isTraversalFlowId(flow)) {
105
+ reply.code(400);
106
+ return { error: "invalid_flow_id", message: "flow id must not contain path separators or dot segments" };
107
+ }
108
+ return { inputs: flow && adm.cwd ? readFlowInputs(adm.cwd, flow) : [] };
109
+ } finally {
110
+ adm.release();
111
+ }
112
+ });
113
+ }
@@ -8,9 +8,10 @@
8
8
  * See change: adopt-server-driven-intent-rendering.
9
9
  */
10
10
  import type { ServerPluginContext } from "@blackbelt-technology/dashboard-plugin-runtime/server";
11
+ import type { AdmitCwdOptions } from "@blackbelt-technology/pi-dashboard-shared/cwd-guard.js";
11
12
  import { provideFlowsActions } from "./automation-actions.js";
12
- import { readFlowInputs } from "./flow-inputs.js";
13
13
  import { registerFlowFileRoutes } from "./flow-files.js";
14
+ import { mountFlowInputsRoute } from "./flow-inputs.js";
14
15
  import { renderSessionFlowActions } from "./render-actions.js";
15
16
  import { stateStore } from "./state-store.js";
16
17
 
@@ -61,11 +62,15 @@ export async function registerPlugin(ctx: ServerPluginContext): Promise<void> {
61
62
  // Read-only endpoint: a flow's declared `inputs:` schema, for the automation
62
63
  // input-wiring UI. Never writes a flow file. See change:
63
64
  // wire-flow-inputs-in-automation.
64
- ctx.fastify.get("/api/plugins/flows/flow-inputs", async (req) => {
65
- const q = (req.query ?? {}) as Record<string, unknown>;
66
- const cwd = typeof q.cwd === "string" ? q.cwd : process.cwd();
67
- const flow = typeof q.flow === "string" ? q.flow : "";
68
- return { inputs: flow ? readFlowInputs(cwd, flow) : [] };
65
+ // The cwd is required + admitted against the host known folders (no `process.cwd()`
66
+ // fallback); a traversal-shaped flow id is refused. See change:
67
+ // harden-git-terminal-plugin-boundaries (S1r).
68
+ const admitOnIndeterminate = ctx.consume<NonNullable<AdmitCwdOptions["onIndeterminate"]>>(
69
+ "host.cwdAdmissionOnIndeterminate",
70
+ );
71
+ mountFlowInputsRoute(ctx.fastify, {
72
+ knownCwds: ctx.consume<() => string[]>("host.knownFolderCwds") ?? (() => []),
73
+ ...(admitOnIndeterminate ? { admitOptions: { onIndeterminate: admitOnIndeterminate } } : {}),
69
74
  });
70
75
 
71
76
  // Flow YAML / agent / code-handler files reported by this plugin's bridge,