@blackbelt-technology/pi-dashboard-flows-plugin 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/package.json +25 -16
  2. package/src/AGENTS.md +8 -0
  3. package/src/__tests__/FlowGraph.test.ts +151 -5
  4. package/src/__tests__/FlowInputWiring.test.tsx +97 -0
  5. package/src/__tests__/FlowSummary.test.tsx +331 -0
  6. package/src/__tests__/FlowYamlPreview.test.tsx +75 -0
  7. package/src/__tests__/FlowsSessionStateContext.test.tsx +2 -39
  8. package/src/__tests__/authoring-renderers.test.tsx +190 -0
  9. package/src/__tests__/automation-actions.test.ts +117 -0
  10. package/src/__tests__/flow-agent-card-code-source.test.tsx +154 -0
  11. package/src/__tests__/flow-agent-cost.test.tsx +160 -0
  12. package/src/__tests__/flow-agent-error.test.ts +60 -0
  13. package/src/__tests__/flow-collapse-storage.test.ts +90 -0
  14. package/src/__tests__/flow-edges.test.ts +195 -0
  15. package/src/__tests__/flow-inputs.test.ts +69 -0
  16. package/src/__tests__/flow-reducer-bridge-contract.test.ts +108 -0
  17. package/src/__tests__/flow-reducer-seed-on-start.test.ts +61 -0
  18. package/src/__tests__/flow-yaml-parse.test.ts +124 -0
  19. package/src/__tests__/flows-for-cwd.test.ts +51 -0
  20. package/src/__tests__/flowsAvailability.test.ts +51 -64
  21. package/src/__tests__/node-kind-reducer.test.ts +135 -0
  22. package/src/__tests__/plugin-action-handler.test.ts +54 -0
  23. package/src/__tests__/session-flow-actions-edit.test.tsx +98 -0
  24. package/src/bridge/AGENTS.md +8 -0
  25. package/src/client/AGENTS.md +32 -0
  26. package/src/client/FlowActivityBadge.tsx +8 -5
  27. package/src/client/FlowAgentCard.tsx +231 -110
  28. package/src/client/FlowAgentDetail.tsx +20 -12
  29. package/src/client/FlowAgentsToolRenderer.tsx +228 -0
  30. package/src/client/FlowAuthorPromptDialog.tsx +92 -0
  31. package/src/client/FlowDashboard.tsx +88 -23
  32. package/src/client/FlowGraph.tsx +420 -275
  33. package/src/client/FlowInputWiring.tsx +243 -0
  34. package/src/client/FlowLaunchDialog.tsx +48 -54
  35. package/src/client/FlowQuestionCard.tsx +6 -3
  36. package/src/client/FlowSummary.tsx +252 -69
  37. package/src/client/FlowWriteToolRenderer.tsx +127 -0
  38. package/src/client/FlowYamlPopoverButton.tsx +26 -25
  39. package/src/client/FlowYamlPreview.tsx +9 -7
  40. package/src/client/FlowsSessionStateContext.tsx +14 -33
  41. package/src/client/FlowsSettings.tsx +68 -0
  42. package/src/client/SessionFlowActions.tsx +92 -76
  43. package/src/client/flow-collapse-storage.ts +79 -0
  44. package/src/client/flow-edges.ts +173 -0
  45. package/src/client/flow-yaml-parse.ts +140 -0
  46. package/src/client/flowsAvailability.ts +28 -87
  47. package/src/client/index.tsx +27 -32
  48. package/src/client/shouldRender.ts +24 -12
  49. package/src/configSchema.json +14 -0
  50. package/src/flow-reducer.ts +94 -13
  51. package/src/i18n.ts +90 -0
  52. package/src/reducer.ts +5 -5
  53. package/src/server/AGENTS.md +10 -0
  54. package/src/server/automation-actions.ts +162 -0
  55. package/src/server/flow-inputs.ts +58 -0
  56. package/src/server/index.ts +93 -9
  57. package/src/server/state-store.ts +3 -14
  58. package/src/__tests__/ArchitectInputPrompt.test.tsx +0 -81
  59. package/src/__tests__/architect-reducer.test.ts +0 -307
  60. package/src/architect-reducer.ts +0 -386
  61. package/src/client/FlowAgentPopoutClaim.tsx +0 -66
  62. package/src/client/FlowAgentPopoutPage.tsx +0 -177
  63. package/src/client/FlowArchitect.tsx +0 -699
  64. package/src/client/FlowArchitectPopoutClaim.tsx +0 -52
  65. package/src/client/FlowArchitectPopoutPage.tsx +0 -133
  66. package/src/client/popout-url.ts +0 -59
@@ -1,16 +1,16 @@
1
1
  /**
2
- * Plugin-internal per-session flow/architect state.
2
+ * Plugin-internal per-session flow state.
3
3
  *
4
4
  * Replaces what `packages/client/src/lib/event-reducer.ts` does today
5
- * for `flowState`, `flowStates`, and `architectState` — but lives
6
- * inside flows-plugin so the dashboard shell carries no flow knowledge.
5
+ * for `flowState` and `flowStates` — but lives inside flows-plugin so
6
+ * the dashboard shell carries no flow knowledge.
7
7
  *
8
8
  * Wiring:
9
9
  * - `useSessionEvents(sessionId)` (from dashboard-plugin-runtime) is
10
10
  * the only read into shell state. It returns the raw event stream
11
11
  * for the session.
12
- * - `useMemo` runs `reduceFlowEvent` and `reduceArchitectEvent` over
13
- * the events, producing `{ flowState, flowStates, architectState }`.
12
+ * - `useMemo` runs `reduceFlowEvent` over the events, producing
13
+ * `{ flowState, flowStates }`.
14
14
  * - The hook `useFlowsSessionState(sessionId)` returns the derived
15
15
  * state. Components self-gate on null returns.
16
16
  *
@@ -26,17 +26,11 @@
26
26
  */
27
27
  import { useMemo } from "react";
28
28
  import type {
29
- ArchitectState,
30
29
  FlowState,
31
30
  DashboardEvent,
32
31
  } from "@blackbelt-technology/pi-dashboard-shared/types.js";
33
32
  import { useSessionEvents } from "@blackbelt-technology/dashboard-plugin-runtime";
34
- import {
35
- isFlowEvent,
36
- reduceFlowEvent,
37
- isArchitectEvent,
38
- reduceArchitectEvent,
39
- } from "../reducer.js";
33
+ import { isFlowEvent, reduceFlowEvent } from "../reducer.js";
40
34
 
41
35
  /** Shape exposed to flows-plugin components for a single session. */
42
36
  export interface FlowsSessionState {
@@ -48,18 +42,15 @@ export interface FlowsSessionState {
48
42
  * (FlowDashboard's multi-flow tab bar).
49
43
  */
50
44
  flowStates: ReadonlyMap<string, FlowState>;
51
- /** Active architect state, or null when no architect is running. */
52
- architectState: ArchitectState | null;
53
45
  }
54
46
 
55
47
  const EMPTY_STATE: FlowsSessionState = Object.freeze({
56
48
  flowState: null,
57
49
  flowStates: new Map() as ReadonlyMap<string, FlowState>,
58
- architectState: null,
59
50
  });
60
51
 
61
52
  /**
62
- * Reduce a session's event stream into flow + architect state. Pure
53
+ * Reduce a session's event stream into flow state. Pure
63
54
  * function — no React, no side effects. Exported for tests and for
64
55
  * future server-side rendering. The reduction matches the shell's
65
56
  * current behavior in `event-reducer.ts` exactly:
@@ -67,7 +58,6 @@ const EMPTY_STATE: FlowsSessionState = Object.freeze({
67
58
  * - flow events → reduceFlowEvent updates flowState; flowStates is
68
59
  * resynced after each flow event so the active flow is also stored
69
60
  * under its name. `flow_summary_dismissed` clears flowStates.
70
- * - architect events → reduceArchitectEvent updates architectState.
71
61
  *
72
62
  * Iterating the full event stream on every render is fine: the event
73
63
  * stream's reference is stable (returned from `useSessionEvents`) and
@@ -78,13 +68,11 @@ export function reduceFlowsSessionState(
78
68
  events: readonly DashboardEvent[],
79
69
  ): FlowsSessionState {
80
70
  let flowState: FlowState | null = null;
81
- let architectState: ArchitectState | null = null;
82
71
  let flowStates: Map<string, FlowState> = new Map();
83
72
  let flowStatesMutated = false;
84
73
 
85
- // Diagnostic counters for C1 — see fix-flows-plugin-polish. Gated to dev.
74
+ // Diagnostic counter for C1 — see fix-flows-plugin-polish. Gated to dev.
86
75
  let flowEventCount = 0;
87
- let architectEventCount = 0;
88
76
 
89
77
  for (const event of events) {
90
78
  if (isFlowEvent(event.eventType)) {
@@ -103,43 +91,36 @@ export function reduceFlowsSessionState(
103
91
  }
104
92
  }
105
93
  }
106
- if (isArchitectEvent(event.eventType)) {
107
- architectEventCount++;
108
- architectState = reduceArchitectEvent(architectState, event);
109
- }
110
94
  }
111
95
 
112
96
  if (typeof import.meta !== "undefined" && (import.meta as { env?: { DEV?: boolean } }).env?.DEV) {
113
- if (flowEventCount > 0 || architectEventCount > 0) {
97
+ if (flowEventCount > 0) {
114
98
  // eslint-disable-next-line no-console
115
99
  console.debug(
116
100
  "[flows] reduceFlowsSessionState",
117
101
  {
118
102
  totalEvents: events.length,
119
103
  flowEvents: flowEventCount,
120
- architectEvents: architectEventCount,
121
104
  resolvedFlowName: flowState?.flowName,
122
105
  resolvedFlowStatus: flowState?.status,
123
106
  flowsCount: flowStates.size,
124
- architectPhase: architectState?.phase,
125
107
  },
126
108
  );
127
109
  }
128
110
  }
129
111
 
130
- if (flowState === null && architectState === null && flowStates.size === 0) {
112
+ if (flowState === null && flowStates.size === 0) {
131
113
  return EMPTY_STATE;
132
114
  }
133
115
 
134
116
  return {
135
117
  flowState,
136
118
  flowStates,
137
- architectState,
138
119
  };
139
120
  }
140
121
 
141
122
  /**
142
- * Hook — derive flow + architect state for a session from its event
123
+ * Hook — derive flow state for a session from its event
143
124
  * stream. Result is `useMemo`-stable across renders that don't bring
144
125
  * a new event for this session.
145
126
  *
@@ -151,9 +132,9 @@ export function reduceFlowsSessionState(
151
132
  * if (!flowState) return null;
152
133
  * ```
153
134
  *
154
- * Returns the frozen `EMPTY_STATE` constant when no flow / architect
155
- * activity has happened for this session, so the same reference is
156
- * shared across many same-state renders.
135
+ * Returns the frozen `EMPTY_STATE` constant when no flow activity has
136
+ * happened for this session, so the same reference is shared across
137
+ * many same-state renders.
157
138
  */
158
139
  export function useFlowsSessionState(sessionId: string): FlowsSessionState {
159
140
  const events = useSessionEvents(sessionId);
@@ -0,0 +1,68 @@
1
+ /**
2
+ * Settings-section for the flows plugin: a global edit-mode default.
3
+ *
4
+ * Edit-mode on → the main session sees the `edit-flow` skill and the
5
+ * `flow_agents` / `flow_write` authoring tools. The global default here is
6
+ * reconciled down to each session (via `flow:set-edit-mode`) when that
7
+ * session's flows plugin becomes available — see SessionFlowActionsClaim.
8
+ *
9
+ * Uses the unified buffered-draft save contract (commits via the host Settings
10
+ * panel's Save). See change: rework-flows-plugin-for-new-pi-flows.
11
+ */
12
+
13
+ import { useSettingsDraftSource, useT } from "@blackbelt-technology/dashboard-plugin-runtime";
14
+ import { usePluginConfig, usePluginSend } from "@blackbelt-technology/dashboard-plugin-runtime/context";
15
+ import type React from "react";
16
+ import { useCallback, useRef, useState } from "react";
17
+
18
+ export interface FlowsPluginConfig {
19
+ /** Global default for pi-flows `flows.editFlow`. Default off. */
20
+ editFlow?: boolean;
21
+ }
22
+
23
+ export function FlowsSettings(): React.ReactElement {
24
+ const t = useT();
25
+ const config = usePluginConfig<FlowsPluginConfig>();
26
+ const send = usePluginSend();
27
+
28
+ const [editFlow, setEditFlow] = useState<boolean>(config.editFlow ?? false);
29
+ const base = config.editFlow ?? false;
30
+ const isDirty = editFlow !== base;
31
+
32
+ const valuesRef = useRef(editFlow);
33
+ valuesRef.current = editFlow;
34
+ const baseRef = useRef(base);
35
+ baseRef.current = base;
36
+
37
+ const commit = useCallback(async () => {
38
+ await send({ type: "plugin_config_write", id: "flows", config: { editFlow: valuesRef.current } });
39
+ }, [send]);
40
+ const reset = useCallback(() => setEditFlow(baseRef.current), []);
41
+ useSettingsDraftSource({ id: "plugin:flows", page: "plugins", isDirty, commit, reset });
42
+
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>
46
+ <p className="text-xs text-[var(--text-tertiary)] mb-3">
47
+ Multi-agent workflow orchestration. Applies globally; sessions inherit this default.
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>
66
+ </section>
67
+ );
68
+ }
@@ -1,51 +1,62 @@
1
- import React, { useState } from "react";
2
- import { Icon } from "@mdi/react";
3
- import { mdiPlay, mdiPlus } from "@mdi/js";
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";
4
10
  import type {
5
11
  CommandInfo,
6
12
  DashboardSession,
7
13
  FlowInfo,
8
14
  FlowState,
9
15
  } from "@blackbelt-technology/pi-dashboard-shared/types.js";
10
- import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
16
+ import { mdiPencil, mdiPlay } from "@mdi/js";
17
+ import { Icon } from "@mdi/react";
18
+ import React, { useEffect, useRef, useState } from "react";
11
19
  import { FlowActivityBadge } from "./FlowActivityBadge.js";
20
+ import { FlowAuthorPromptDialog } from "./FlowAuthorPromptDialog.js";
21
+ import { FlowLaunchDialog } from "./FlowLaunchDialog.js";
12
22
  import { useFlowsSessionState } from "./FlowsSessionStateContext.js";
13
- import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
14
- import type { UiSelectOption as SelectOption } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
15
- import {
16
- useUiPrimitive,
17
- usePluginSend,
18
- useSessionData,
19
- } from "@blackbelt-technology/dashboard-plugin-runtime";
23
+ import type { FlowsPluginConfig } from "./FlowsSettings.js";
20
24
 
21
25
  export function SessionFlowActions({
22
26
  flows,
23
- hasFlowsNew,
24
- hasFlowsEdit,
27
+ editMode,
25
28
  hasFlowsDelete,
26
29
  onFlowAction,
30
+ onEditFlow,
27
31
  flowState,
28
32
  onAbortFlow,
29
33
  }: {
30
34
  flows: FlowInfo[];
31
- hasFlowsNew: boolean;
32
- hasFlowsEdit?: boolean;
35
+ /** Edit-mode on → show the New / Edit launcher (authoring via the skill). */
36
+ editMode: boolean;
33
37
  hasFlowsDelete?: boolean;
34
38
  onFlowAction: (action: string, opts?: { flowName?: string; task?: string; description?: string }) => void;
39
+ /**
40
+ * Launch the manage-flows skill for an existing flow (name) or a new flow
41
+ * (undefined), carrying the user's stated intent (description for new, change
42
+ * instruction for edit; empty string when none given).
43
+ */
44
+ onEditFlow: (flowName: string | undefined, instruction: string) => void;
35
45
  /** Current flow state for this session. Drives the status pill rendered above the action buttons. */
36
46
  flowState?: FlowState | null;
37
47
  /** Dispatch flow_control abort. Called by the running-flow pill's Abort button. */
38
48
  onAbortFlow?: () => void;
39
49
  }) {
50
+ const t = useT();
40
51
  const ConfirmDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.confirmDialog);
41
52
  const SearchableSelectDialog = useUiPrimitive(UI_PRIMITIVE_KEYS.searchableSelectDialog);
42
53
  const [pickerOpen, setPickerOpen] = useState(false);
43
54
  const [editPickerOpen, setEditPickerOpen] = useState(false);
44
- const [editFlowName, setEditFlowName] = useState<string | null>(null);
55
+ // After picking from the edit launcher, capture intent before launching the skill.
56
+ const [authorTarget, setAuthorTarget] = useState<{ mode: "new" | "edit"; flowName?: string } | null>(null);
45
57
  const [deletePickerOpen, setDeletePickerOpen] = useState(false);
46
58
  const [deleteFlowName, setDeleteFlowName] = useState<string | null>(null);
47
59
  const [selectedFlow, setSelectedFlow] = useState<FlowInfo | null>(null);
48
- const [newFlowOpen, setNewFlowOpen] = useState(false);
49
60
 
50
61
  // Compute running-flow badge inputs from flowState (when present).
51
62
  // See change: fix-flows-plugin-polish (A5 + A6).
@@ -65,13 +76,18 @@ export function SessionFlowActions({
65
76
  })()
66
77
  : null;
67
78
 
68
- if (flows.length === 0 && !hasFlowsNew && !badgeProps) return null;
79
+ if (flows.length === 0 && !editMode && !badgeProps) return null;
69
80
 
70
81
  const flowOptions: SelectOption[] = flows.map((f) => ({
71
82
  value: f.name,
72
83
  label: f.name,
73
84
  description: f.description,
74
85
  }));
86
+ // Edit launcher options: existing flows + a "new flow" sentinel.
87
+ const editOptions: SelectOption[] = [
88
+ { value: "__new__", label: t("newFlowOption", undefined, "+ New flow"), description: t("newFlowOptionDesc", undefined, "Author a new flow with the edit-flow skill") },
89
+ ...flowOptions,
90
+ ];
75
91
 
76
92
  return (
77
93
  <>
@@ -88,23 +104,16 @@ export function SessionFlowActions({
88
104
  onClick={(e) => { e.stopPropagation(); setPickerOpen(true); }}
89
105
  className="text-[10px] px-1.5 py-0.5 rounded border border-blue-500/30 text-blue-400 hover:bg-blue-500/10"
90
106
  >
91
- <Icon path={mdiPlay} size={0.4} className="inline mr-0.5" />Run Flow...
107
+ <Icon path={mdiPlay} size={0.4} className="inline mr-0.5" />{t("runFlowButton", undefined, "Run Flow...")}
92
108
  </button>
93
109
  )}
94
- {hasFlowsNew && (
95
- <button
96
- onClick={(e) => { e.stopPropagation(); setNewFlowOpen(true); }}
97
- className="text-[10px] px-1.5 py-0.5 rounded border border-purple-500/30 text-purple-400 hover:bg-purple-500/10"
98
- >
99
- <Icon path={mdiPlus} size={0.4} className="inline mr-0.5" />New Flow
100
- </button>
101
- )}
102
- {hasFlowsEdit && flows.length > 0 && (
110
+ {editMode && (
103
111
  <button
104
112
  onClick={(e) => { e.stopPropagation(); setEditPickerOpen(true); }}
105
- 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)]"
113
+ className="text-[10px] px-1.5 py-0.5 rounded border border-purple-500/30 text-purple-400 hover:bg-purple-500/10"
114
+ data-testid="flows-new-edit-button"
106
115
  >
107
- &#x270E;&#xFE0E; Edit
116
+ <Icon path={mdiPencil} size={0.4} className="inline mr-0.5" />{t("newEditButton", undefined, "New / Edit…")}
108
117
  </button>
109
118
  )}
110
119
  {hasFlowsDelete && flows.length > 0 && (
@@ -112,7 +121,7 @@ export function SessionFlowActions({
112
121
  onClick={(e) => { e.stopPropagation(); setDeletePickerOpen(true); }}
113
122
  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)]"
114
123
  >
115
- &#215; Delete
124
+ &#215; {t("delete", undefined, "Delete")}
116
125
  </button>
117
126
  )}
118
127
  </div>
@@ -121,10 +130,10 @@ export function SessionFlowActions({
121
130
  {/* Run: pick flow → task dialog */}
122
131
  {pickerOpen && (
123
132
  <SearchableSelectDialog
124
- title="Run Flow"
133
+ title={t("runFlowDialogTitle", undefined, "Run Flow")}
125
134
  options={flowOptions}
126
- placeholder="Search flows..."
127
- emptyMessage="No flows available"
135
+ placeholder={t("searchFlows", undefined, "Search flows...")}
136
+ emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
128
137
  onSelect={(value) => {
129
138
  const flow = flows.find(f => f.name === value);
130
139
  if (flow) setSelectedFlow(flow);
@@ -146,42 +155,43 @@ export function SessionFlowActions({
146
155
  />
147
156
  )}
148
157
 
149
- {/* Edit: pick flow → modification input dialog */}
158
+ {/* New / Edit: pick an existing flow or "new" → launch the edit-flow skill */}
150
159
  {editPickerOpen && (
151
160
  <SearchableSelectDialog
152
- title="Edit Flow"
153
- options={flowOptions}
154
- placeholder="Search flows..."
155
- emptyMessage="No flows available"
161
+ title={t("newEditFlowTitle", undefined, "New / Edit flow")}
162
+ options={editOptions}
163
+ placeholder={t("pickFlowToEdit", undefined, "Pick a flow to edit, or + New flow…")}
164
+ emptyMessage={t("noFlowsYet", undefined, "No flows yet — pick + New flow")}
156
165
  onSelect={(value) => {
157
- setEditFlowName(value);
166
+ setAuthorTarget(
167
+ value === "__new__" ? { mode: "new" } : { mode: "edit", flowName: value },
168
+ );
158
169
  setEditPickerOpen(false);
159
170
  }}
160
171
  onCancel={() => setEditPickerOpen(false)}
161
172
  />
162
173
  )}
163
174
 
164
- {editFlowName && (
165
- <FlowLaunchDialog
166
- flowName={editFlowName}
167
- description="Describe how this flow should be updated"
168
- onSubmit={(desc) => {
169
- if (desc.trim()) {
170
- onFlowAction("edit", { flowName: editFlowName, description: desc.trim() });
171
- }
172
- setEditFlowName(null);
175
+ {/* New / Edit: capture intent → launch the manage-flows skill */}
176
+ {authorTarget && (
177
+ <FlowAuthorPromptDialog
178
+ mode={authorTarget.mode}
179
+ flowName={authorTarget.flowName}
180
+ onSubmit={(instruction) => {
181
+ onEditFlow(authorTarget.flowName, instruction);
182
+ setAuthorTarget(null);
173
183
  }}
174
- onCancel={() => setEditFlowName(null)}
184
+ onCancel={() => setAuthorTarget(null)}
175
185
  />
176
186
  )}
177
187
 
178
188
  {/* Delete: pick flow → confirm dialog */}
179
189
  {deletePickerOpen && (
180
190
  <SearchableSelectDialog
181
- title="Delete Flow"
191
+ title={t("deleteFlowTitle", undefined, "Delete Flow")}
182
192
  options={flowOptions}
183
- placeholder="Search flows..."
184
- emptyMessage="No flows available"
193
+ placeholder={t("searchFlows", undefined, "Search flows...")}
194
+ emptyMessage={t("noFlowsAvailable", undefined, "No flows available")}
185
195
  onSelect={(value) => {
186
196
  setDeleteFlowName(value);
187
197
  setDeletePickerOpen(false);
@@ -192,8 +202,8 @@ export function SessionFlowActions({
192
202
 
193
203
  {deleteFlowName && (
194
204
  <ConfirmDialog
195
- message={`Delete flow "${deleteFlowName}"? This will remove the flow file and any associated agents.`}
196
- confirmLabel="Delete"
205
+ message={t("deleteFlowConfirm", { name: deleteFlowName }, `Delete flow "${deleteFlowName}"? This will remove the flow file and any associated agents.`)}
206
+ confirmLabel={t("delete", undefined, "Delete")}
197
207
  onConfirm={() => {
198
208
  onFlowAction("delete", { flowName: deleteFlowName });
199
209
  setDeleteFlowName(null);
@@ -201,21 +211,6 @@ export function SessionFlowActions({
201
211
  onCancel={() => setDeleteFlowName(null)}
202
212
  />
203
213
  )}
204
-
205
- {/* New: description dialog */}
206
- {newFlowOpen && (
207
- <FlowLaunchDialog
208
- flowName="flows:new"
209
- description="Design a new flow with the Flow Architect"
210
- onSubmit={(task) => {
211
- if (task.trim()) {
212
- onFlowAction("new", { description: task.trim() });
213
- }
214
- setNewFlowOpen(false);
215
- }}
216
- onCancel={() => setNewFlowOpen(false)}
217
- />
218
- )}
219
214
  </>
220
215
  );
221
216
  }
@@ -236,23 +231,44 @@ export function SessionFlowActionsClaim({ session }: { session: DashboardSession
236
231
  const commands = useSessionData<CommandInfo[]>(session.id, "commandsList") ?? [];
237
232
  const { flowState } = useFlowsSessionState(session.id);
238
233
  const send = usePluginSend();
234
+ const config = usePluginConfig<FlowsPluginConfig>();
235
+ const editMode = config.editFlow ?? false;
239
236
 
240
- const hasFlowsNew = commands.some((c) => c.name === "flows:new");
241
- const hasFlowsEdit = commands.some((c) => c.name === "flows:edit");
242
237
  const hasFlowsDelete = commands.some((c) => c.name === "flows:delete");
243
238
 
239
+ // Reconcile the GLOBAL edit-mode default down to this session once its flows
240
+ // plugin is available (flowsList observed). pi-flows persists it to the
241
+ // project .pi/settings.json. Idempotent — re-emits only when the default
242
+ // changes. See change: rework-flows-plugin-for-new-pi-flows (D4).
243
+ const reconciledRef = useRef<boolean | null>(null);
244
+ useEffect(() => {
245
+ if (flows.length === 0) return; // wait until flows-plugin is available
246
+ if (reconciledRef.current === editMode) return;
247
+ reconciledRef.current = editMode;
248
+ send({ type: "flow_management", sessionId: session.id, action: "set-edit-mode", enabled: editMode });
249
+ }, [flows.length, editMode, session.id, send]);
250
+
244
251
  // Render when there's a flow active OR action buttons are available.
245
- // See change: fix-flows-plugin-polish (A5).
246
- if (flows.length === 0 && !hasFlowsNew && !flowState) return null;
252
+ if (flows.length === 0 && !editMode && !flowState) return null;
247
253
 
248
254
  return (
249
255
  <SessionFlowActions
250
256
  flows={flows}
251
- hasFlowsNew={hasFlowsNew}
252
- hasFlowsEdit={hasFlowsEdit}
257
+ editMode={editMode}
253
258
  hasFlowsDelete={hasFlowsDelete}
254
259
  flowState={flowState}
255
260
  onAbortFlow={() => send({ type: "flow_control", sessionId: session.id, action: "abort" })}
261
+ onEditFlow={(flowName, instruction) => {
262
+ const intent = instruction.trim();
263
+ // New flow: instruction describes what to build. Edit: flow name is
264
+ // token-1 (the skill reads that file), instruction follows on a new line.
265
+ const text = flowName
266
+ ? intent
267
+ ? `/skill:manage-flows ${flowName}\n\n${intent}`
268
+ : `/skill:manage-flows ${flowName}`
269
+ : `/skill:manage-flows ${intent}`;
270
+ send({ type: "send_prompt", sessionId: session.id, text });
271
+ }}
256
272
  onFlowAction={(action, opts) =>
257
273
  send({
258
274
  type: "flow_management",
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Per-session persistence for the flow socket's collapse state. The whole-panel
3
+ * (`FlowSummary`) and live-dashboard (`FlowDashboard`) collapses are stored in
4
+ * localStorage keyed by session id, so collapsing a session's flow panel sticks
5
+ * across remounts/reloads instead of re-opening every time. Mirrors the
6
+ * try/catch-swallow pattern of `useSidebarState.ts`; a localStorage failure
7
+ * (quota / disabled / private mode) degrades to in-memory state and never throws.
8
+ *
9
+ * Default is expanded (false) for any session never collapsed.
10
+ *
11
+ * See change: fix-flow-ui-graph-zoom-summary.
12
+ */
13
+ import { useCallback, useEffect, useState } from "react";
14
+
15
+ export type FlowCollapseKind = "summary" | "dashboard";
16
+
17
+ /** localStorage key for a (kind, session) pair. */
18
+ export function flowCollapseKey(kind: FlowCollapseKind, sessionId: string): string {
19
+ return `dashboard:flow-${kind}-collapsed:${sessionId}`;
20
+ }
21
+
22
+ function readBoolean(key: string, fallback: boolean): boolean {
23
+ try {
24
+ const raw = localStorage.getItem(key);
25
+ if (raw === null) return fallback;
26
+ return raw === "true";
27
+ } catch {
28
+ return fallback;
29
+ }
30
+ }
31
+
32
+ function writeBoolean(key: string, value: boolean): void {
33
+ try {
34
+ localStorage.setItem(key, String(value));
35
+ } catch {
36
+ /* noop — degrade to in-memory */
37
+ }
38
+ }
39
+
40
+ /**
41
+ * Generic localStorage-backed boolean toggle. Returns `[value, toggle]`.
42
+ * `key === null` → purely in-memory (no persistence). Re-syncs on key change
43
+ * (so a component reused under a new key reads the right value) without
44
+ * clobbering a same-key toggle. localStorage failures degrade to in-memory.
45
+ */
46
+ export function usePersistedToggle(
47
+ key: string | null,
48
+ fallback: boolean,
49
+ ): [boolean, () => void] {
50
+ const [value, setValue] = useState<boolean>(() => (key ? readBoolean(key, fallback) : fallback));
51
+
52
+ useEffect(() => {
53
+ setValue(key ? readBoolean(key, fallback) : fallback);
54
+ }, [key, fallback]);
55
+
56
+ const toggle = useCallback(() => {
57
+ setValue((prev) => {
58
+ const next = !prev;
59
+ if (key) writeBoolean(key, next);
60
+ return next;
61
+ });
62
+ }, [key]);
63
+
64
+ return [value, toggle];
65
+ }
66
+
67
+ /** localStorage key for the global error-route visibility toggle (not session-scoped). */
68
+ export const FLOW_SHOW_ERROR_ROUTES_KEY = "dashboard:flow-show-error-routes";
69
+
70
+ /**
71
+ * Persisted collapse state for one flow panel. Returns `[collapsed, toggle]`.
72
+ * When `sessionId` is undefined the state is purely in-memory (no key to scope by).
73
+ */
74
+ export function useFlowCollapsePersisted(
75
+ sessionId: string | undefined,
76
+ kind: FlowCollapseKind,
77
+ ): [boolean, () => void] {
78
+ return usePersistedToggle(sessionId ? flowCollapseKey(kind, sessionId) : null, false);
79
+ }