@blackbelt-technology/pi-dashboard-flows-plugin 0.5.4 → 0.6.1
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 +25 -16
- package/src/AGENTS.md +8 -0
- package/src/__tests__/FlowGraph.test.ts +151 -5
- package/src/__tests__/FlowInputWiring.test.tsx +97 -0
- package/src/__tests__/FlowSummary.test.tsx +331 -0
- package/src/__tests__/FlowYamlPreview.test.tsx +75 -0
- package/src/__tests__/FlowsSessionStateContext.test.tsx +2 -39
- package/src/__tests__/authoring-renderers.test.tsx +190 -0
- package/src/__tests__/automation-actions.test.ts +117 -0
- package/src/__tests__/flow-agent-card-code-source.test.tsx +154 -0
- package/src/__tests__/flow-agent-cost.test.tsx +160 -0
- package/src/__tests__/flow-agent-error.test.ts +60 -0
- package/src/__tests__/flow-collapse-storage.test.ts +90 -0
- package/src/__tests__/flow-edges.test.ts +195 -0
- package/src/__tests__/flow-inputs.test.ts +69 -0
- package/src/__tests__/flow-reducer-bridge-contract.test.ts +108 -0
- package/src/__tests__/flow-reducer-seed-on-start.test.ts +61 -0
- package/src/__tests__/flow-yaml-parse.test.ts +124 -0
- package/src/__tests__/flows-for-cwd.test.ts +51 -0
- package/src/__tests__/flowsAvailability.test.ts +51 -64
- package/src/__tests__/node-kind-reducer.test.ts +135 -0
- package/src/__tests__/plugin-action-handler.test.ts +54 -0
- package/src/__tests__/session-flow-actions-edit.test.tsx +98 -0
- package/src/bridge/AGENTS.md +8 -0
- package/src/client/AGENTS.md +32 -0
- package/src/client/FlowActivityBadge.tsx +8 -5
- package/src/client/FlowAgentCard.tsx +231 -110
- package/src/client/FlowAgentDetail.tsx +20 -12
- package/src/client/FlowAgentsToolRenderer.tsx +228 -0
- package/src/client/FlowAuthorPromptDialog.tsx +92 -0
- package/src/client/FlowDashboard.tsx +88 -23
- package/src/client/FlowGraph.tsx +420 -275
- package/src/client/FlowInputWiring.tsx +243 -0
- package/src/client/FlowLaunchDialog.tsx +48 -54
- package/src/client/FlowQuestionCard.tsx +6 -3
- package/src/client/FlowSummary.tsx +252 -69
- package/src/client/FlowWriteToolRenderer.tsx +127 -0
- package/src/client/FlowYamlPopoverButton.tsx +26 -25
- package/src/client/FlowYamlPreview.tsx +9 -7
- package/src/client/FlowsSessionStateContext.tsx +14 -33
- package/src/client/FlowsSettings.tsx +68 -0
- package/src/client/SessionFlowActions.tsx +92 -76
- package/src/client/flow-collapse-storage.ts +79 -0
- package/src/client/flow-edges.ts +173 -0
- package/src/client/flow-yaml-parse.ts +140 -0
- package/src/client/flowsAvailability.ts +28 -87
- package/src/client/index.tsx +27 -32
- package/src/client/shouldRender.ts +24 -12
- package/src/configSchema.json +14 -0
- package/src/flow-reducer.ts +94 -13
- package/src/i18n.ts +90 -0
- package/src/reducer.ts +5 -5
- package/src/server/AGENTS.md +10 -0
- package/src/server/automation-actions.ts +162 -0
- package/src/server/flow-inputs.ts +58 -0
- package/src/server/index.ts +93 -9
- package/src/server/state-store.ts +3 -14
- package/src/__tests__/ArchitectInputPrompt.test.tsx +0 -81
- package/src/__tests__/architect-reducer.test.ts +0 -307
- package/src/architect-reducer.ts +0 -386
- package/src/client/FlowAgentPopoutClaim.tsx +0 -66
- package/src/client/FlowAgentPopoutPage.tsx +0 -177
- package/src/client/FlowArchitect.tsx +0 -699
- package/src/client/FlowArchitectPopoutClaim.tsx +0 -52
- package/src/client/FlowArchitectPopoutPage.tsx +0 -133
- package/src/client/popout-url.ts +0 -59
|
@@ -1,92 +1,79 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Unit tests for the
|
|
3
|
-
* `
|
|
2
|
+
* Unit tests for `shouldRenderFlowsSubcard`, the manifest-level visibility gate
|
|
3
|
+
* for the `session-card-flows` claim. The gate reads live per-session-data
|
|
4
|
+
* (`flowsList`) + plugin config (`editFlow`) + flow events — the same sources
|
|
5
|
+
* `SessionFlowActionsClaim` uses to decide it renders content. See change:
|
|
6
|
+
* fix-empty-flows-subcard.
|
|
4
7
|
*/
|
|
5
|
-
import {
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
6
9
|
import {
|
|
7
|
-
getFlowsAvailabilitySync,
|
|
8
|
-
setFlowsAvailability,
|
|
9
|
-
installFlowsAvailabilitySubscriber,
|
|
10
|
-
__resetFlowsAvailabilityForTests,
|
|
11
|
-
} from "../client/flowsAvailability.js";
|
|
12
|
-
import {
|
|
13
|
-
publishSessionData,
|
|
14
|
-
clearSessionData,
|
|
15
10
|
__resetSessionDataStoreForTests,
|
|
11
|
+
clearSessionEvents,
|
|
12
|
+
publishSessionData,
|
|
13
|
+
publishSessionEvent,
|
|
16
14
|
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
15
|
+
import { initPluginConfigs } from "@blackbelt-technology/dashboard-plugin-runtime/context";
|
|
16
|
+
import { __resetFlowsAvailabilityForTests, sessionHasFlowEvents } from "../client/flowsAvailability.js";
|
|
17
|
+
import { shouldRenderFlowsSubcard } from "../client/shouldRender.js";
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
const session = (id: string) => ({ id }) as never;
|
|
20
|
+
const setEditMode = (on: boolean) => initPluginConfigs({ flows: { editFlow: on } });
|
|
21
|
+
|
|
22
|
+
describe("flows-plugin: shouldRenderFlowsSubcard predicate", () => {
|
|
19
23
|
beforeEach(() => {
|
|
20
24
|
__resetFlowsAvailabilityForTests();
|
|
21
25
|
__resetSessionDataStoreForTests();
|
|
26
|
+
setEditMode(false);
|
|
22
27
|
});
|
|
23
28
|
|
|
24
29
|
afterEach(() => {
|
|
25
30
|
__resetFlowsAvailabilityForTests();
|
|
26
31
|
__resetSessionDataStoreForTests();
|
|
32
|
+
setEditMode(false);
|
|
27
33
|
});
|
|
28
34
|
|
|
29
|
-
it("returns false for
|
|
30
|
-
expect(
|
|
35
|
+
it("returns false for null/undefined session", () => {
|
|
36
|
+
expect(shouldRenderFlowsSubcard(null)).toBe(false);
|
|
37
|
+
expect(shouldRenderFlowsSubcard(undefined)).toBe(false);
|
|
31
38
|
});
|
|
32
39
|
|
|
33
|
-
it("
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
expect(
|
|
40
|
+
it("hidden in the bug state: flowsList empty + edit mode off + no flow events", () => {
|
|
41
|
+
const sid = "bug-state";
|
|
42
|
+
publishSessionData(sid, "flowsList", []);
|
|
43
|
+
// Extension present (a /flows command exists) must NOT open the gate anymore.
|
|
44
|
+
publishSessionData(sid, "commandsList", [{ name: "flows" }]);
|
|
45
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(false);
|
|
39
46
|
});
|
|
40
47
|
|
|
41
|
-
it("
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
expect(
|
|
45
|
-
off1();
|
|
48
|
+
it("visible when flowsList is non-empty", () => {
|
|
49
|
+
const sid = "has-flows";
|
|
50
|
+
publishSessionData(sid, "flowsList", [{ name: "deploy" }]);
|
|
51
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(true);
|
|
46
52
|
});
|
|
47
53
|
|
|
48
|
-
it("
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
{ name: "deploy", description: "Deploy the app" },
|
|
54
|
-
]);
|
|
55
|
-
expect(getFlowsAvailabilitySync("s1")).toBe(true);
|
|
56
|
-
off();
|
|
54
|
+
it("visible when edit mode is on (author-first, zero flows)", () => {
|
|
55
|
+
const sid = "edit-mode";
|
|
56
|
+
publishSessionData(sid, "flowsList", []);
|
|
57
|
+
setEditMode(true);
|
|
58
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(true);
|
|
57
59
|
});
|
|
58
60
|
|
|
59
|
-
it("
|
|
60
|
-
const
|
|
61
|
-
publishSessionData(
|
|
62
|
-
expect(
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
it("subscriber leaves cache `false` when neither flows nor flows:new are available", () => {
|
|
67
|
-
const off = installFlowsAvailabilitySubscriber();
|
|
68
|
-
publishSessionData("s3", "flowsList", []);
|
|
69
|
-
publishSessionData("s3", "commandsList", [{ name: "skill:foo" }]);
|
|
70
|
-
expect(getFlowsAvailabilitySync("s3")).toBe(false);
|
|
71
|
-
off();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("subscriber drops availability to false when session data is cleared", () => {
|
|
75
|
-
const off = installFlowsAvailabilitySubscriber();
|
|
76
|
-
publishSessionData("s4", "flowsList", [{ name: "x" }]);
|
|
77
|
-
expect(getFlowsAvailabilitySync("s4")).toBe(true);
|
|
78
|
-
|
|
79
|
-
clearSessionData("s4");
|
|
80
|
-
expect(getFlowsAvailabilitySync("s4")).toBe(false);
|
|
81
|
-
off();
|
|
61
|
+
it("visible when a flow event exists (running/completed, zero listed flows)", () => {
|
|
62
|
+
const sid = "flow-ran";
|
|
63
|
+
publishSessionData(sid, "flowsList", []);
|
|
64
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(false);
|
|
65
|
+
publishSessionEvent(sid, { eventType: "flow_started", timestamp: 1, data: {} } as never);
|
|
66
|
+
expect(shouldRenderFlowsSubcard(session(sid))).toBe(true);
|
|
67
|
+
clearSessionEvents(sid);
|
|
82
68
|
});
|
|
83
69
|
|
|
84
|
-
it("
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
expect(
|
|
89
|
-
|
|
90
|
-
|
|
70
|
+
it("sessionHasFlowEvents ignores non-flow events, reflects flow events", () => {
|
|
71
|
+
const sid = "flow-evt";
|
|
72
|
+
expect(sessionHasFlowEvents(sid)).toBe(false);
|
|
73
|
+
publishSessionEvent(sid, { eventType: "message_start", timestamp: 1, data: {} } as never);
|
|
74
|
+
expect(sessionHasFlowEvents(sid)).toBe(false);
|
|
75
|
+
publishSessionEvent(sid, { eventType: "flow_started", timestamp: 2, data: {} } as never);
|
|
76
|
+
expect(sessionHasFlowEvents(sid)).toBe(true);
|
|
77
|
+
clearSessionEvents(sid);
|
|
91
78
|
});
|
|
92
79
|
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node-kind / code-node reducer coverage for the rework-flows-plugin-for-new-pi-flows
|
|
3
|
+
* change. Pins: nodeKind decided at started, code target, typed outputs + chosen
|
|
4
|
+
* branch from complete, soft/hard outcome, interrupted downgrade, pre-listed code
|
|
5
|
+
* cards, and replay identity (same fold for live + persisted events).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { DashboardEvent, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
9
|
+
import { describe, expect, it } from "vitest";
|
|
10
|
+
import { reduceFlowEvent } from "../reducer.js";
|
|
11
|
+
|
|
12
|
+
function ev(type: string, data: Record<string, unknown>): DashboardEvent {
|
|
13
|
+
return { seq: 1, timestamp: 0, sessionId: "s1", eventType: type, data } as unknown as DashboardEvent;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Drive a sequence of events through the fold, starting from null. */
|
|
17
|
+
function fold(events: Array<[string, Record<string, unknown>]>): FlowState | null {
|
|
18
|
+
let s: FlowState | null = null;
|
|
19
|
+
for (const [t, d] of events) s = reduceFlowEvent(s, ev(t, d));
|
|
20
|
+
return s;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const startedWithCode: Array<[string, Record<string, unknown>]> = [
|
|
24
|
+
["flow_started", {
|
|
25
|
+
flowName: "invoice", task: "validate",
|
|
26
|
+
steps: [
|
|
27
|
+
{ id: "extract", stepType: "agent", agent: "extractor", blockedBy: [] },
|
|
28
|
+
{ id: "validate-nav", stepType: "code", blockedBy: ["extract"] },
|
|
29
|
+
{ id: "approve", stepType: "code-decision", blockedBy: ["validate-nav"] },
|
|
30
|
+
],
|
|
31
|
+
}],
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
describe("node-kind reducer", () => {
|
|
35
|
+
it("pre-lists code and code-decision steps as pending cards (task 2.6)", () => {
|
|
36
|
+
const s = fold(startedWithCode)!;
|
|
37
|
+
expect(s.agents.get("validate-nav")?.nodeKind).toBe("code");
|
|
38
|
+
expect(s.agents.get("validate-nav")?.status).toBe("pending");
|
|
39
|
+
expect(s.agents.get("approve")?.nodeKind).toBe("code-decision");
|
|
40
|
+
expect(s.agents.get("extract")?.nodeKind).toBe("agent");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("decides nodeKind + code target at started; never changes at complete", () => {
|
|
44
|
+
const s = fold([
|
|
45
|
+
...startedWithCode,
|
|
46
|
+
["flow_agent_started", { agentName: "validate-nav", stepId: "validate-nav", nodeKind: "code", target: "handlers/validate-nav.ts" }],
|
|
47
|
+
["flow_assistant_text", { agentName: "validate-nav", stepId: "validate-nav", text: "checking record against NAV" }],
|
|
48
|
+
["flow_agent_complete", { agentName: "validate-nav", stepId: "validate-nav", result: { success: true, summary: "validated against NAV", typedOutputs: { valid: "true", nav_record: "INV-2231" }, outcome: "success" } }],
|
|
49
|
+
])!;
|
|
50
|
+
const code = s.agents.get("validate-nav")!;
|
|
51
|
+
expect(code.nodeKind).toBe("code");
|
|
52
|
+
expect(code.codeTarget).toBe("handlers/validate-nav.ts");
|
|
53
|
+
expect(code.status).toBe("complete");
|
|
54
|
+
expect(code.summary).toBe("validated against NAV");
|
|
55
|
+
expect(code.typedOutputs).toEqual({ valid: "true", nav_record: "INV-2231" });
|
|
56
|
+
// logger output rode the assistant-text channel → detailHistory text entry (logs by card kind)
|
|
57
|
+
expect(code.detailHistory).toContainEqual({ kind: "text", text: "checking record against NAV" });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("exposes the chosen branch from typedOutputs for code-decision", () => {
|
|
61
|
+
const s = fold([
|
|
62
|
+
...startedWithCode,
|
|
63
|
+
["flow_agent_started", { agentName: "approve", stepId: "approve", nodeKind: "code-decision" }],
|
|
64
|
+
["flow_agent_complete", { agentName: "approve", stepId: "approve", result: { success: true, typedOutputs: { branch: "rework", score: "72" }, outcome: "success" } }],
|
|
65
|
+
["flow_loop_iteration", { loopTarget: "approve", iteration: 2, maxIterations: 3 }],
|
|
66
|
+
])!;
|
|
67
|
+
const dec = s.agents.get("approve")!;
|
|
68
|
+
expect(dec.branch).toBe("rework");
|
|
69
|
+
expect(dec.loopIteration).toBe(2);
|
|
70
|
+
expect(dec.loopMax).toBe(3);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("records soft outcome on a routed failure", () => {
|
|
74
|
+
const s = fold([
|
|
75
|
+
...startedWithCode,
|
|
76
|
+
["flow_agent_started", { agentName: "validate-nav", stepId: "validate-nav", nodeKind: "code" }],
|
|
77
|
+
["flow_agent_complete", { agentName: "validate-nav", stepId: "validate-nav", result: { success: false, outcome: "soft" } }],
|
|
78
|
+
])!;
|
|
79
|
+
expect(s.agents.get("validate-nav")?.outcome).toBe("soft");
|
|
80
|
+
expect(s.agents.get("validate-nav")?.status).toBe("error");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("downgrades in-flight cards to error on a non-success terminal (task 3.6)", () => {
|
|
84
|
+
const s = fold([
|
|
85
|
+
...startedWithCode,
|
|
86
|
+
["flow_agent_started", { agentName: "validate-nav", stepId: "validate-nav", nodeKind: "code" }],
|
|
87
|
+
["flow_complete", { status: "interrupted" }],
|
|
88
|
+
])!;
|
|
89
|
+
expect(s.status).toBe("interrupted");
|
|
90
|
+
// started-but-never-completed code card must not spin forever
|
|
91
|
+
expect(s.agents.get("validate-nav")?.status).toBe("error");
|
|
92
|
+
expect(s.agents.get("validate-nav")?.outcome).toBe("hard");
|
|
93
|
+
// pending sibling also resolved
|
|
94
|
+
expect(s.agents.get("approve")?.status).toBe("error");
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("falls back to an agent card when nodeKind is absent (pre-contract / skew)", () => {
|
|
98
|
+
const s = fold([
|
|
99
|
+
["flow_started", { flowName: "f", task: "t", steps: [{ id: "a", stepType: "agent", agent: "a", blockedBy: [] }] }],
|
|
100
|
+
["flow_agent_started", { agentName: "a", stepId: "a" }], // no nodeKind
|
|
101
|
+
])!;
|
|
102
|
+
expect(s.agents.get("a")?.nodeKind).toBe("agent");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("lands on_complete / on_error onto dagSteps; absent fields stay undefined", () => {
|
|
106
|
+
// See change: fix-flow-ui-graph-zoom-summary — routing fields drive live route edges.
|
|
107
|
+
const s = fold([
|
|
108
|
+
["flow_started", {
|
|
109
|
+
flowName: "invoice", task: "t",
|
|
110
|
+
steps: [
|
|
111
|
+
{ id: "load-state", stepType: "code", blockedBy: [], onComplete: "resume-gate", onError: "hold" },
|
|
112
|
+
{ id: "resume-gate", stepType: "code-decision", blockedBy: [], branches: { new: "intake" } },
|
|
113
|
+
],
|
|
114
|
+
}],
|
|
115
|
+
])!;
|
|
116
|
+
const loadState = s.dagSteps?.find(d => d.id === "load-state");
|
|
117
|
+
expect(loadState?.onComplete).toBe("resume-gate");
|
|
118
|
+
expect(loadState?.onError).toBe("hold");
|
|
119
|
+
const gate = s.dagSteps?.find(d => d.id === "resume-gate");
|
|
120
|
+
expect(gate?.onComplete).toBeUndefined();
|
|
121
|
+
expect(gate?.onError).toBeUndefined();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("replays identically: same fold over persisted events rebuilds the same card", () => {
|
|
125
|
+
const seq: Array<[string, Record<string, unknown>]> = [
|
|
126
|
+
...startedWithCode,
|
|
127
|
+
["flow_agent_started", { agentName: "approve", stepId: "approve", nodeKind: "code-decision" }],
|
|
128
|
+
["flow_agent_complete", { agentName: "approve", stepId: "approve", result: { success: true, typedOutputs: { branch: "rework" }, outcome: "success" } }],
|
|
129
|
+
["flow_loop_iteration", { loopTarget: "approve", iteration: 2, maxIterations: 3 }],
|
|
130
|
+
];
|
|
131
|
+
const live = fold(seq)!;
|
|
132
|
+
const replay = fold(seq)!; // replay re-forwards the identical records
|
|
133
|
+
expect(replay.agents.get("approve")).toEqual(live.agents.get("approve"));
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* flows-plugin plugin_action handler — the production wiring that replaced the
|
|
3
|
+
* v1 logging stub. `flow.run` emits the `flow:run` event pi-flows consumes;
|
|
4
|
+
* `flow.new` launches the manage-flows skill; a missing sessionId is a guarded
|
|
5
|
+
* no-op. See change: fix-plugin-action-fanout-and-handlers.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, expect, it, vi } from "vitest";
|
|
8
|
+
import { registerPlugin } from "../server/index.js";
|
|
9
|
+
|
|
10
|
+
type Handler = (msg: unknown) => void;
|
|
11
|
+
|
|
12
|
+
async function setup() {
|
|
13
|
+
const emitEventToSession = vi.fn(() => true);
|
|
14
|
+
const sendToSession = vi.fn(() => true);
|
|
15
|
+
let handler: Handler | undefined;
|
|
16
|
+
const ctx = {
|
|
17
|
+
logger: { info: vi.fn(), warn: vi.fn(), error: vi.fn() },
|
|
18
|
+
broadcastToSubscribers: vi.fn(),
|
|
19
|
+
emitEventToSession,
|
|
20
|
+
sendToSession,
|
|
21
|
+
provide: vi.fn(),
|
|
22
|
+
consume: vi.fn(),
|
|
23
|
+
sessionManager: { listActive: () => [], listAll: () => [] },
|
|
24
|
+
fastify: { get: vi.fn() },
|
|
25
|
+
registerBrowserHandler: (type: string, h: Handler) => {
|
|
26
|
+
if (type === "plugin_action") handler = h;
|
|
27
|
+
},
|
|
28
|
+
} as unknown as Parameters<typeof registerPlugin>[0];
|
|
29
|
+
|
|
30
|
+
await registerPlugin(ctx);
|
|
31
|
+
if (!handler) throw new Error("plugin_action handler not registered");
|
|
32
|
+
return { handler, emitEventToSession, sendToSession, ctx };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe("flows plugin_action handler", () => {
|
|
36
|
+
it("flow.run emits flow:run into the target session (not a stub)", async () => {
|
|
37
|
+
const { handler, emitEventToSession } = await setup();
|
|
38
|
+
handler({ pluginId: "flows", sessionId: "s1", action: "flow.run", payload: { flow: "ns:build", task: "do it" } });
|
|
39
|
+
expect(emitEventToSession).toHaveBeenCalledWith("s1", "flow:run", { flowName: "ns:build", task: "do it" });
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("flow.new launches the manage-flows skill via sendToSession", async () => {
|
|
43
|
+
const { handler, sendToSession } = await setup();
|
|
44
|
+
handler({ pluginId: "flows", sessionId: "s1", action: "flow.new" });
|
|
45
|
+
expect(sendToSession).toHaveBeenCalledWith("s1", "/skill:manage-flows");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("ignores a mismatched pluginId (defense-in-depth) and guards missing sessionId", async () => {
|
|
49
|
+
const { handler, emitEventToSession } = await setup();
|
|
50
|
+
handler({ pluginId: "goal", sessionId: "s1", action: "flow.run", payload: { flow: "ns:x" } });
|
|
51
|
+
handler({ pluginId: "flows", action: "flow.run", payload: { flow: "ns:x" } });
|
|
52
|
+
expect(emitEventToSession).not.toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionFlowActions edit-mode gating + New/Edit launcher.
|
|
3
|
+
* The New/Edit button shows only when editMode is on. Selecting a flow (or
|
|
4
|
+
* "+ New flow") opens an intent-capture dialog; submitting it invokes
|
|
5
|
+
* onEditFlow(name|undefined, instruction) so the claim can send
|
|
6
|
+
* `/skill:manage-flows ...`. See change: rework-flows-plugin-for-new-pi-flows.
|
|
7
|
+
*/
|
|
8
|
+
import React from "react";
|
|
9
|
+
import { describe, it, expect, afterEach, vi } from "vitest";
|
|
10
|
+
import { render, cleanup, fireEvent } from "@testing-library/react";
|
|
11
|
+
import {
|
|
12
|
+
UiPrimitiveProvider,
|
|
13
|
+
createUiPrimitiveRegistry,
|
|
14
|
+
registerUiPrimitive,
|
|
15
|
+
} from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
16
|
+
import { UI_PRIMITIVE_KEYS } from "@blackbelt-technology/pi-dashboard-shared/dashboard-plugin/ui-primitives.js";
|
|
17
|
+
import type { FlowInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
18
|
+
import { SessionFlowActions } from "../client/SessionFlowActions.js";
|
|
19
|
+
|
|
20
|
+
const registry = createUiPrimitiveRegistry();
|
|
21
|
+
registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.confirmDialog, (() => null) as never);
|
|
22
|
+
// Stub Dialog primitive used by FlowAuthorPromptDialog: render children + Footer/Cancel.
|
|
23
|
+
const Dialog = (({ children }: { children: React.ReactNode }) => <div>{children}</div>) as never;
|
|
24
|
+
(Dialog as unknown as { Footer: React.FC<{ children: React.ReactNode }>; Cancel: React.FC<{ onClick: () => void }> }).Footer =
|
|
25
|
+
({ children }) => <div>{children}</div>;
|
|
26
|
+
(Dialog as unknown as { Footer: React.FC; Cancel: React.FC<{ onClick: () => void }> }).Cancel =
|
|
27
|
+
({ onClick }) => <button onClick={onClick}>Cancel</button>;
|
|
28
|
+
registerUiPrimitive(registry, UI_PRIMITIVE_KEYS.dialog, Dialog);
|
|
29
|
+
// Stub SearchableSelectDialog: render each option as a button that selects it.
|
|
30
|
+
registerUiPrimitive(
|
|
31
|
+
registry,
|
|
32
|
+
UI_PRIMITIVE_KEYS.searchableSelectDialog,
|
|
33
|
+
(({ options, onSelect }: { options: Array<{ value: string; label: string }>; onSelect: (v: string) => void }) => (
|
|
34
|
+
<div data-testid="picker">
|
|
35
|
+
{options.map((o) => (
|
|
36
|
+
<button key={o.value} onClick={() => onSelect(o.value)}>{o.label}</button>
|
|
37
|
+
))}
|
|
38
|
+
</div>
|
|
39
|
+
)) as never,
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
const flows: FlowInfo[] = [{ name: "invoice-research" } as FlowInfo];
|
|
43
|
+
|
|
44
|
+
function renderActions(props: Partial<React.ComponentProps<typeof SessionFlowActions>>) {
|
|
45
|
+
return render(
|
|
46
|
+
<UiPrimitiveProvider value={registry}>
|
|
47
|
+
<SessionFlowActions
|
|
48
|
+
flows={flows}
|
|
49
|
+
editMode={false}
|
|
50
|
+
onFlowAction={() => {}}
|
|
51
|
+
onEditFlow={() => {}}
|
|
52
|
+
{...props}
|
|
53
|
+
/>
|
|
54
|
+
</UiPrimitiveProvider>,
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
afterEach(() => cleanup());
|
|
59
|
+
|
|
60
|
+
describe("SessionFlowActions edit mode", () => {
|
|
61
|
+
it("hides New / Edit when edit mode is off", () => {
|
|
62
|
+
const { queryByTestId } = renderActions({ editMode: false });
|
|
63
|
+
expect(queryByTestId("flows-new-edit-button")).toBeNull();
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("shows New / Edit when edit mode is on", () => {
|
|
67
|
+
const { getByTestId } = renderActions({ editMode: true });
|
|
68
|
+
expect(getByTestId("flows-new-edit-button")).toBeTruthy();
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("editing a flow prompts for an instruction, then calls onEditFlow(name, instruction)", () => {
|
|
72
|
+
const onEditFlow = vi.fn();
|
|
73
|
+
const { getByTestId, getByText } = renderActions({ editMode: true, onEditFlow });
|
|
74
|
+
fireEvent.click(getByTestId("flows-new-edit-button"));
|
|
75
|
+
fireEvent.click(getByText("invoice-research"));
|
|
76
|
+
// Intent dialog appears; edit instruction is optional → submit empty.
|
|
77
|
+
const submit = getByTestId("flow-author-submit");
|
|
78
|
+
expect(submit).toBeTruthy();
|
|
79
|
+
fireEvent.click(submit);
|
|
80
|
+
expect(onEditFlow).toHaveBeenCalledWith("invoice-research", "");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("new flow requires a description before onEditFlow(undefined, text) fires", () => {
|
|
84
|
+
const onEditFlow = vi.fn();
|
|
85
|
+
const { getByTestId, getByText, getByPlaceholderText } = renderActions({ editMode: true, onEditFlow });
|
|
86
|
+
fireEvent.click(getByTestId("flows-new-edit-button"));
|
|
87
|
+
fireEvent.click(getByText("+ New flow"));
|
|
88
|
+
const submit = getByTestId("flow-author-submit") as HTMLButtonElement;
|
|
89
|
+
// Required: disabled until text entered.
|
|
90
|
+
expect(submit.disabled).toBe(true);
|
|
91
|
+
fireEvent.change(getByPlaceholderText(/Research an invoice/), {
|
|
92
|
+
target: { value: "Summarize PRs" },
|
|
93
|
+
});
|
|
94
|
+
expect(submit.disabled).toBe(false);
|
|
95
|
+
fireEvent.click(submit);
|
|
96
|
+
expect(onEditFlow).toHaveBeenCalledWith(undefined, "Summarize PRs");
|
|
97
|
+
});
|
|
98
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# DOX — packages/flows-plugin/src/bridge
|
|
2
|
+
|
|
3
|
+
Files in this directory. One row per source file.
|
|
4
|
+
|
|
5
|
+
| File | Purpose |
|
|
6
|
+
|------|---------|
|
|
7
|
+
| `flow-question-adapter.ts` | PromptBus adapter claiming flow-tagged prompts for upper-slot render. Exports `FlowQuestionAdapter` implementing `PromptAdapter` (`name="flow-question"`, `priority=100`). `onRequest` returns claim with `component.type="flow-question"` + `placement="widget-bar"` only when `prompt.metadata.flowId` present; else null. `onResponse`/`onCancel` no-op. Structurally typed against `packages/extension/src/prompt-bus.ts` shapes. Beats `DashboardDefaultAdapter` (priority 9999). |
|
|
8
|
+
| `index.ts` | flows-plugin bridge entry. Default-export `activate(ctx)` emits `prompt:register-adapter` with fresh `FlowQuestionAdapter` via `pi.events.emit`. Auto-registered at `~/.pi/agent/settings.json#dashboardPluginBridges` (key `dashboard-flows`) by dashboard `registerAllPluginBridges`. Narrow: no other behavior. |
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# DOX — packages/flows-plugin/src/client
|
|
2
|
+
|
|
3
|
+
Files in this directory. One row per source file.
|
|
4
|
+
|
|
5
|
+
| File | Purpose |
|
|
6
|
+
|------|---------|
|
|
7
|
+
| `flow-collapse-storage.ts` | Per-session persisted collapse state for flow panels. Exports `FlowCollapseKind`, `flowCollapseKey`, `usePersistedToggle`, `useFlowCollapsePersisted`, `FLOW_SHOW_ERROR_ROUTES_KEY`. localStorage keyed by session id; failures degrade to in-memory. Mirrors `useSidebarState.ts` try/catch-swallow. |
|
|
8
|
+
| `flow-edges.ts` | Shared flow-edge derivation. Exports `FlowEdgeKind`, `FlowEdgeStep`, `FlowEdge`, `deriveFlowEdges`. One rule for live `FlowGraph` + static `flow_write` Mermaid snapshot. Classes: `sequential`, `branch`, `route`, `implicit`. Tags `on_error` route topology (`returning`/`terminal`) via reachability. |
|
|
9
|
+
| `flow-yaml-parse.ts` | Shallow client YAML→steps parser (`parseFlowYaml`) + Mermaid generator (`flowToMermaid`). Extracts id/type/blockedBy/branches + counts. Node-shape glyphs per kind; forward edges from blockedBy, backward branch edges dashed. Graceful null on parse failure. See change: rework-flows-plugin-for-new-pi-flows. |
|
|
10
|
+
| `FlowActivityBadge.tsx` | Running-flow status pill. Exports `FlowActivityBadge`, `FlowActivityBadgeProps`. Maps `FlowStatus` → icon+color; shows agent count when running; renders inline Abort button when `onAbort` provided. Consumed by `SessionFlowActions`. |
|
|
11
|
+
| `FlowAgentCard.tsx` | Step card. nodeKind badge (⌗ code, ◈ code-decision, ◇ fork). Code Log preview from `flow_assistant_text` detailHistory. Outputs KV chips. Chosen-branch line + ↻ loop pill. Soft (amber)/hard (red) outcome. Handler target line. See change: rework-flows-plugin-for-new-pi-flows. Code/code-decision nodes now render `mdiCodeBraces` button (gated `isCodeKind && agent.codeTarget`) opening `ui:dialog`; fetches handler `.ts` via `GET /api/pi-resource-file?path=<codeTarget>` (codeTarget absolute, passed verbatim); renders content wrapped in fenced ```ts block via `ui:markdown-content` (Prism highlight). Mirrors agent `sourcePath` doc-icon path; `codeSourceOpen`/`codeSourceState` state. Keeps `‹› {codeTarget}` text line. See change: open-code-handler-from-flow-card. Exports `formatCost(n)` (`$` + `n>=1?2dp:4dp`, pi-flows parity); complete-state stats line appends ` · $cost` between tokens and duration when `agent.cost != null && > 0`. See change: surface-flow-agent-cost. |
|
|
12
|
+
| `FlowAgentDetail.tsx` | Thin adapter shim over `MinimalChatView`. Exports `FlowAgentDetail`. Maps `FlowAgentState` → `MinimalChatViewProps` (status, `detailHistory` entries, summary footer). Preserves `agent`/`onBack` API for `FlowAgentCard` detail dialog. Imports `formatCost` from `FlowAgentCard`; passes `meta.cost` (pre-formatted string) when `agent.cost != null && > 0`. See change: surface-flow-agent-cost. |
|
|
13
|
+
| `FlowAgentsToolRenderer.tsx` | `tool-renderer` for `flow_agents`. `list` → catalog names + count. `write` → success/failure from `{written,diagnostics,error}`. Args-backed "View agent file" toggle. See change: rework-flows-plugin-for-new-pi-flows. |
|
|
14
|
+
| `FlowAuthorPromptDialog.tsx` | Intent-capture dialog for `/skill:manage-flows` launcher. Exports `FlowAuthorPromptDialog`. Two-step pattern: asks what flow should do (new, required) or what to change (edit, optional). Forwards instruction to manage-flows prompt. |
|
|
15
|
+
| `FlowDashboard.tsx` | Live running-flow panel. Exports `FlowDashboard`, `FlowDashboardClaim`. Renders header (collapse/AUTO/Abort), `FlowTabBar` multi-flow nav, `BreadcrumbSlot`, `FlowQuestionsSection`, `FlowGraph` + expanded dialog, `FlowAgentCard` grid. Forwards to `FlowSummary` on completion. Claim self-derives state via `useFlowsSessionState`. |
|
|
16
|
+
| `FlowGraph.tsx` | dagre SVG graph. `mapStepType` → canonical set (agent/fork/code/code-decision/flow-ref); legacy conditional/agent-loop-decision/loop REMOVED. `architectStepsToGraphSteps` REMOVED. See change: rework-flows-plugin-for-new-pi-flows. |
|
|
17
|
+
| `FlowLaunchDialog.tsx` | Run-flow task-capture dialog. Exports `FlowLaunchDialog`. Renders `GateSlot` decorator; `aggregateGateState` disables Run button when extension gates flow unavailable. Forwards task to `onSubmit`. |
|
|
18
|
+
| `FlowQuestionCard.tsx` | Pending `flow-question` prompt card rendered in FlowDashboard upper slot. Exports `FlowQuestionCard`, `FlowQuestionCardProps`. Routes by `type` (`confirm`/`select`/`multiselect`/`input`/`editor`) to inline renderers. Dispatches `prompt_response`/`prompt_cancel` via callbacks. Shows queue-depth badge. |
|
|
19
|
+
| `FlowQuestionTranscriptPill.tsx` | Collapsed pill for answered/cancelled flow-question in upper-slot transcript. Exports `FlowQuestionTranscriptPill`, `FlowQuestionTranscriptPillProps`. Renders status icon + question + answer (multiselect JSON array compacted). Pending head rendered by `FlowQuestionCard`. |
|
|
20
|
+
| `flowsAvailability.ts` | Flow-event probe. Exports `sessionHasFlowEvents(id)` (ref-memoized, sticky-true) + `__resetFlowsAvailabilityForTests`. Availability cache/subscriber (`computeAvailability`, `getFlowsAvailabilitySync`, `installFlowsAvailabilitySubscriber`) retired. See change: fix-empty-flows-subcard. |
|
|
21
|
+
| `FlowsCommandRoutes.tsx` | Slash-command route components for `/flows`, `/flows:new`, `/flows:edit`, `/flows:delete`. Exports `FlowsListRoute`, `FlowsNewRoute`, `FlowsEditRoute`, `FlowsDeleteRoute`. Each renders launcher/picker/dialog, dispatches `flow_management` via `usePluginSend`, calls `onClose` on dismissal. Replaces App.tsx flow dialog blocks. |
|
|
22
|
+
| `FlowsSessionStateContext.tsx` | Plugin-internal per-session flow state derivation. Exports `FlowsSessionState`, `reduceFlowsSessionState`, `useFlowsSessionState`. Reduces `useSessionEvents` stream via `reduceFlowEvent` into `{ flowState, flowStates }`. `useMemo`-stable; returns frozen `EMPTY_STATE` when no flow activity. Dev-only diagnostic counter. |
|
|
23
|
+
| `FlowsSettings.tsx` | `settings-section` (tab general, draft page plugins). Global edit-mode default via `usePluginConfig`/`plugin_config_write`/`useSettingsDraftSource`. Config `{ editFlow?: boolean }`, default off. See change: rework-flows-plugin-for-new-pi-flows. |
|
|
24
|
+
| `FlowsUiStateContext.tsx` | Plugin-internal UI selection state, module-level store + `useSyncExternalStore`. Exports `FlowsUiState`, `FlowsUiActions`, `getFlowsUiStateSnapshot`, `useFlowsUiState`, `useFlowsUiActions`, `__resetFlowsUiStateForTests`. Holds `sourceOpenAgent`, `flowYamlPreview`; `dismissAll` unifies cleanup. Snapshot used by manifest predicates. |
|
|
25
|
+
| `FlowSummary.tsx` | Completed-flow summary panel. Exports `FlowSummary`, `FlowSummaryClaim`. Renders status header (panel collapse persisted via `useFlowCollapsePersisted`), `FlowGraph` + expanded dialog, frozen `FlowAgentCard` grid, collapsible `FlowSummaryRow` summaries, next-step button. Claim self-derives state, dispatches `dismiss_summary`. |
|
|
26
|
+
| `FlowTabBar.tsx` | Multi-flow tab navigation bar. Exports `FlowTab`, `FlowTabBar`. Renders one tab per concurrent flow; FOLLOW toggle auto-switches to latest active flow. Returns null for single flow. |
|
|
27
|
+
| `FlowWriteToolRenderer.tsx` | `tool-renderer` for `flow_write`. Renders real result contract `{written,name,namespace,command,path,diagnostics}`. Success: command + counts + Mermaid snapshot (via `ui:markdown-content`) parsed from tool args. Failure: diagnostics verbatim. Args-backed "View flow YAML" toggle. See change: rework-flows-plugin-for-new-pi-flows. |
|
|
28
|
+
| `FlowYamlPopoverButton.tsx` | Paper-icon button opening popover with flow YAML. Exports `FlowYamlPopoverButton`. Fetches `/api/pi-resource-file?path=`, renders via `ui:markdown-content` in `yaml` fence. State machine `idle`/`loading`/`loaded`/`error`. Used by `FlowDashboard` + `FlowSummary`. |
|
|
29
|
+
| `FlowYamlPreview.tsx` | Content-view claim renderer for flow YAML preview, gated by `isFlowYamlPreviewActive` predicate. Exports `FlowYamlPreviewClaim`. Reads `flowYamlPreview` from `FlowsUiStateContext`; back action clears preview + `sourceOpenAgent` + calls `onClose`. Replaces App.tsx `MarkdownPreviewView` call site. |
|
|
30
|
+
| `index.tsx` | Re-export barrel: `FlowDashboard`, `FlowAgentCard`, `FlowAgentDetail`, `FlowSummary`, `FlowGraph`, `FlowActivityBadge`, `FlowLaunchDialog`, `FlowTabBar`, `SessionFlowActions`, `FlowWriteToolRenderer`, `FlowAgentsToolRenderer`, `FlowsSettings`. Architect exports REMOVED. See change: rework-flows-plugin-for-new-pi-flows. |
|
|
31
|
+
| `SessionFlowActions.tsx` | Subcard actions. Run / New-Edit (gated on editMode) / Delete / Abort. New/Edit launcher → `onEditFlow` → claim sends `send_prompt /skill:edit-flow [name]`. Claim reconciles global edit-mode default to session via `flow_management{action:set-edit-mode,enabled}` on availability. Architect/new/edit command deps REMOVED. See change: rework-flows-plugin-for-new-pi-flows. |
|
|
32
|
+
| `shouldRender.ts` | Manifest-level sync predicate `shouldRenderFlowsSubcard(session)` for `session-card-flows` claim. Reads live `getSessionData(flowsList)` + `getPluginConfig(flows).editFlow` + `sessionHasFlowEvents` — matches the claim render condition. See change: fix-empty-flows-subcard. |
|
|
@@ -9,10 +9,12 @@
|
|
|
9
9
|
*
|
|
10
10
|
* See change: fix-flows-plugin-polish (A5).
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import { mdiLoading, mdiCheckCircle, mdiAlertCircle, mdiStopCircle, mdiStop } from "@mdi/js";
|
|
12
|
+
|
|
13
|
+
import { useT } from "@blackbelt-technology/dashboard-plugin-runtime";
|
|
15
14
|
import type { FlowStatus } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
15
|
+
import { mdiAlertCircle, mdiCheckCircle, mdiLoading, mdiStop, mdiStopCircle } from "@mdi/js";
|
|
16
|
+
import { Icon } from "@mdi/react";
|
|
17
|
+
import React, { type ReactNode } from "react";
|
|
16
18
|
|
|
17
19
|
const statusConfig: Record<string, { icon: ReactNode; color: string }> = {
|
|
18
20
|
running: { icon: <Icon path={mdiLoading} size={0.45} className="animate-spin" />, color: "text-blue-400" },
|
|
@@ -37,6 +39,7 @@ export function FlowActivityBadge({
|
|
|
37
39
|
status,
|
|
38
40
|
onAbort,
|
|
39
41
|
}: FlowActivityBadgeProps) {
|
|
42
|
+
const t = useT();
|
|
40
43
|
const { icon, color } = statusConfig[status ?? "running"] ?? statusConfig.running;
|
|
41
44
|
const isRunning = status === "running";
|
|
42
45
|
|
|
@@ -57,10 +60,10 @@ export function FlowActivityBadge({
|
|
|
57
60
|
type="button"
|
|
58
61
|
onClick={(e) => { e.stopPropagation(); onAbort(); }}
|
|
59
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"
|
|
60
|
-
title="Abort running flow"
|
|
63
|
+
title={t("abortRunningFlow", undefined, "Abort running flow")}
|
|
61
64
|
>
|
|
62
65
|
<Icon path={mdiStop} size={0.4} />
|
|
63
|
-
Abort
|
|
66
|
+
{t("abort", undefined, "Abort")}
|
|
64
67
|
</button>
|
|
65
68
|
)}
|
|
66
69
|
</div>
|