@blackbelt-technology/pi-dashboard-flows-plugin 0.7.0 → 0.9.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 +18 -7
- package/src/bridge/flow-files-reporter.ts +113 -0
- package/src/bridge/index.ts +5 -1
- package/src/client/FlowAgentCard.tsx +82 -213
- package/src/client/FlowAgentDetail.tsx +1 -1
- package/src/client/FlowDashboard.tsx +428 -66
- package/src/client/FlowInputWiring.tsx +2 -2
- package/src/client/FlowSummary.tsx +22 -16
- package/src/client/FlowYamlPopoverButton.tsx +27 -92
- package/src/client/FlowsCommandRoutes.tsx +13 -5
- package/src/client/FlowsSessionStateContext.tsx +40 -4
- package/src/client/FlowsSettings.tsx +4 -4
- package/src/client/SessionFlowActions.tsx +80 -6
- package/src/client/flow-attach-store.ts +140 -0
- package/src/client/flow-card-grid.ts +36 -0
- package/src/client/flow-files.ts +152 -0
- package/src/client/flow-idle-state.ts +230 -0
- package/src/client/format-cost.ts +21 -0
- package/src/client/send-safe.ts +19 -0
- package/src/flow-files-contract.ts +21 -0
- package/src/flow-reducer.ts +4 -0
- package/src/i18n.ts +28 -0
- package/src/server/automation-actions.ts +3 -0
- package/src/server/flow-files.ts +264 -0
- package/src/server/index.ts +15 -0
- package/src/AGENTS.md +0 -8
- package/src/__tests__/FlowGraph.test.ts +0 -305
- package/src/__tests__/FlowInputWiring.test.tsx +0 -97
- package/src/__tests__/FlowSummary.test.tsx +0 -331
- package/src/__tests__/FlowYamlPreview.test.tsx +0 -75
- package/src/__tests__/FlowsSessionStateContext.test.tsx +0 -223
- package/src/__tests__/FlowsUiStateContext.test.tsx +0 -140
- package/src/__tests__/authoring-renderers.test.tsx +0 -190
- package/src/__tests__/automation-actions.test.ts +0 -117
- package/src/__tests__/flow-agent-card-code-source.test.tsx +0 -190
- package/src/__tests__/flow-agent-cost.test.tsx +0 -160
- package/src/__tests__/flow-agent-error.test.ts +0 -60
- package/src/__tests__/flow-collapse-storage.test.ts +0 -90
- package/src/__tests__/flow-edges.test.ts +0 -195
- package/src/__tests__/flow-inputs.test.ts +0 -69
- package/src/__tests__/flow-reducer-bridge-contract.test.ts +0 -108
- package/src/__tests__/flow-reducer-seed-on-start.test.ts +0 -61
- package/src/__tests__/flow-yaml-parse.test.ts +0 -124
- package/src/__tests__/flows-for-cwd.test.ts +0 -51
- package/src/__tests__/flowsAvailability.test.ts +0 -79
- package/src/__tests__/manifest-discoverability.test.ts +0 -97
- package/src/__tests__/node-kind-reducer.test.ts +0 -135
- package/src/__tests__/plugin-action-handler.test.ts +0 -54
- package/src/__tests__/reducer-parity.test.ts +0 -106
- package/src/__tests__/render-actions.test.ts +0 -63
- package/src/__tests__/session-flow-actions-edit.test.tsx +0 -98
- package/src/bridge/AGENTS.md +0 -8
- package/src/client/AGENTS.md +0 -32
- package/src/server/AGENTS.md +0 -10
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
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.
|
|
7
|
-
*/
|
|
8
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
9
|
-
import {
|
|
10
|
-
__resetSessionDataStoreForTests,
|
|
11
|
-
clearSessionEvents,
|
|
12
|
-
publishSessionData,
|
|
13
|
-
publishSessionEvent,
|
|
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";
|
|
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", () => {
|
|
23
|
-
beforeEach(() => {
|
|
24
|
-
__resetFlowsAvailabilityForTests();
|
|
25
|
-
__resetSessionDataStoreForTests();
|
|
26
|
-
setEditMode(false);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
__resetFlowsAvailabilityForTests();
|
|
31
|
-
__resetSessionDataStoreForTests();
|
|
32
|
-
setEditMode(false);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it("returns false for null/undefined session", () => {
|
|
36
|
-
expect(shouldRenderFlowsSubcard(null)).toBe(false);
|
|
37
|
-
expect(shouldRenderFlowsSubcard(undefined)).toBe(false);
|
|
38
|
-
});
|
|
39
|
-
|
|
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);
|
|
46
|
-
});
|
|
47
|
-
|
|
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);
|
|
52
|
-
});
|
|
53
|
-
|
|
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);
|
|
59
|
-
});
|
|
60
|
-
|
|
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);
|
|
68
|
-
});
|
|
69
|
-
|
|
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);
|
|
78
|
-
});
|
|
79
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Discoverability test — flows-plugin manifest.
|
|
3
|
-
*
|
|
4
|
-
* Verifies the flows-plugin's `pi-dashboard-plugin` manifest (read from its
|
|
5
|
-
* own package.json) validates against the dashboard's manifest schema and
|
|
6
|
-
* encodes the contract this plugin promises to the shell.
|
|
7
|
-
*
|
|
8
|
-
* Specifically asserts:
|
|
9
|
-
* - manifest is present and schema-valid
|
|
10
|
-
* - plugin id is `flows`
|
|
11
|
-
* - `SessionFlowActionsClaim` lives in the `session-card-flows` slot
|
|
12
|
-
* (not `session-card-action-bar` — see change: add-flows-subcard)
|
|
13
|
-
* - the `session-card-flows` claim declares the `shouldRenderFlowsSubcard`
|
|
14
|
-
* gate so the FLOWS subcard hides cleanly when no flows are available
|
|
15
|
-
* - `shouldRenderFlowsSubcard` is exported from the client entry so the
|
|
16
|
-
* vite plugin's name-resolver can wire it
|
|
17
|
-
*/
|
|
18
|
-
import { describe, it, expect } from "vitest";
|
|
19
|
-
import { readFileSync } from "node:fs";
|
|
20
|
-
import { dirname, resolve } from "node:path";
|
|
21
|
-
import { fileURLToPath } from "node:url";
|
|
22
|
-
import { validateManifest } from "@blackbelt-technology/dashboard-plugin-runtime/manifest-validator";
|
|
23
|
-
import * as flowsClientEntry from "../client/index.js";
|
|
24
|
-
|
|
25
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
26
|
-
const __dirname = dirname(__filename);
|
|
27
|
-
const PACKAGE_JSON = resolve(__dirname, "../../package.json");
|
|
28
|
-
|
|
29
|
-
describe("flows-plugin manifest discoverability", () => {
|
|
30
|
-
const pkg = JSON.parse(readFileSync(PACKAGE_JSON, "utf-8")) as {
|
|
31
|
-
name: string;
|
|
32
|
-
"pi-dashboard-plugin"?: unknown;
|
|
33
|
-
};
|
|
34
|
-
const manifest = pkg["pi-dashboard-plugin"];
|
|
35
|
-
|
|
36
|
-
it("declares a `pi-dashboard-plugin` manifest field", () => {
|
|
37
|
-
expect(manifest).toBeDefined();
|
|
38
|
-
expect(typeof manifest).toBe("object");
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("validates against the dashboard's manifest schema", () => {
|
|
42
|
-
expect(() => validateManifest(manifest, pkg.name)).not.toThrow();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("declares plugin id `flows`", () => {
|
|
46
|
-
const validated = validateManifest(manifest, pkg.name);
|
|
47
|
-
expect(validated.id).toBe("flows");
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("routes SessionFlowActions through `session-card-flows` slot", () => {
|
|
51
|
-
// Post add-flows-subcard: SessionFlowActionsClaim moved from
|
|
52
|
-
// `session-card-action-bar` to its own `session-card-flows` slot so the
|
|
53
|
-
// shell can host it inside a dedicated FLOWS subcard.
|
|
54
|
-
const validated = validateManifest(manifest, pkg.name);
|
|
55
|
-
const flowsSubcardClaims = validated.claims.filter(
|
|
56
|
-
(c) => c.slot === "session-card-flows",
|
|
57
|
-
);
|
|
58
|
-
const components = new Set(flowsSubcardClaims.map((c) => c.component));
|
|
59
|
-
expect(components.has("SessionFlowActionsClaim")).toBe(true);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("no claim occupies the deprecated `session-card-action-bar` mapping", () => {
|
|
63
|
-
// Defensive: ensure the legacy slot mapping is gone (would silently
|
|
64
|
-
// double-render the actions outside the FLOWS subcard otherwise).
|
|
65
|
-
const validated = validateManifest(manifest, pkg.name);
|
|
66
|
-
const actionBarClaims = validated.claims.filter(
|
|
67
|
-
(c) =>
|
|
68
|
-
c.slot === "session-card-action-bar" &&
|
|
69
|
-
c.component === "SessionFlowActionsClaim",
|
|
70
|
-
);
|
|
71
|
-
expect(actionBarClaims).toHaveLength(0);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("every `session-card-flows` claim declares the shouldRenderFlowsSubcard gate", () => {
|
|
75
|
-
const validated = validateManifest(manifest, pkg.name);
|
|
76
|
-
const flowsClaims = validated.claims.filter(
|
|
77
|
-
(c) => c.slot === "session-card-flows",
|
|
78
|
-
);
|
|
79
|
-
expect(flowsClaims.length).toBeGreaterThan(0);
|
|
80
|
-
for (const c of flowsClaims) {
|
|
81
|
-
expect((c as { shouldRender?: string }).shouldRender).toBe(
|
|
82
|
-
"shouldRenderFlowsSubcard",
|
|
83
|
-
);
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("client entry exports `shouldRenderFlowsSubcard`", () => {
|
|
88
|
-
// The vite plugin's plugin-registry generator resolves the
|
|
89
|
-
// `shouldRender` string against this module's named exports. If the
|
|
90
|
-
// export is missing, the build fails — this test catches the
|
|
91
|
-
// contract break before the build.
|
|
92
|
-
expect(
|
|
93
|
-
(flowsClientEntry as { shouldRenderFlowsSubcard?: unknown })
|
|
94
|
-
.shouldRenderFlowsSubcard,
|
|
95
|
-
).toBeTypeOf("function");
|
|
96
|
-
});
|
|
97
|
-
});
|
|
@@ -1,135 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,54 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parity test pinning the moved reducer's behavior post-extraction.
|
|
3
|
-
*
|
|
4
|
-
* The reducer logic was moved from `packages/client/src/lib/flow-reducer.ts`
|
|
5
|
-
* to `packages/flows-plugin/src/flow-reducer.ts` by the OpenSpec change
|
|
6
|
-
* `extract-flows-as-plugin`. The contract — `(state, event) → newState` —
|
|
7
|
-
* is unchanged. This test dispatches a representative `flow_started →
|
|
8
|
-
* flow_agent_started → flow_complete` sequence and snapshots the resulting
|
|
9
|
-
* `FlowState` so a future contract drift fails loudly here.
|
|
10
|
-
*/
|
|
11
|
-
import { describe, it, expect } from "vitest";
|
|
12
|
-
import { isFlowEvent, reduceFlowEvent } from "../reducer.js";
|
|
13
|
-
import type { DashboardEvent, FlowState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
14
|
-
|
|
15
|
-
function ev(type: string, data: Record<string, unknown>): DashboardEvent {
|
|
16
|
-
return {
|
|
17
|
-
seq: 1,
|
|
18
|
-
timestamp: 0,
|
|
19
|
-
sessionId: "s1",
|
|
20
|
-
eventType: type,
|
|
21
|
-
data,
|
|
22
|
-
} as unknown as DashboardEvent;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
describe("flow-reducer parity (post-extract-flows-as-plugin)", () => {
|
|
26
|
-
it("recognizes every flow_* event type via isFlowEvent", () => {
|
|
27
|
-
expect(isFlowEvent("flow_started")).toBe(true);
|
|
28
|
-
expect(isFlowEvent("flow_agent_started")).toBe(true);
|
|
29
|
-
expect(isFlowEvent("flow_agent_complete")).toBe(true);
|
|
30
|
-
expect(isFlowEvent("flow_tool_call")).toBe(true);
|
|
31
|
-
expect(isFlowEvent("flow_tool_result")).toBe(true);
|
|
32
|
-
expect(isFlowEvent("flow_assistant_text")).toBe(true);
|
|
33
|
-
expect(isFlowEvent("flow_thinking_text")).toBe(true);
|
|
34
|
-
expect(isFlowEvent("flow_loop_iteration")).toBe(true);
|
|
35
|
-
expect(isFlowEvent("flow_complete")).toBe(true);
|
|
36
|
-
expect(isFlowEvent("flow_summary_dismissed")).toBe(true);
|
|
37
|
-
// negative
|
|
38
|
-
expect(isFlowEvent("message_start")).toBe(false);
|
|
39
|
-
expect(isFlowEvent("turn_end")).toBe(false);
|
|
40
|
-
expect(isFlowEvent("architect_started")).toBe(false);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it("reduces flow_started → creates FlowState with pending agents", () => {
|
|
44
|
-
const state: FlowState | null = null;
|
|
45
|
-
const next = reduceFlowEvent(
|
|
46
|
-
state,
|
|
47
|
-
ev("flow_started", {
|
|
48
|
-
flowName: "research",
|
|
49
|
-
task: "Find bugs",
|
|
50
|
-
steps: [
|
|
51
|
-
{ id: "r", agent: "researcher", blockedBy: [] },
|
|
52
|
-
{ id: "d", agent: "developer", blockedBy: ["r"] },
|
|
53
|
-
],
|
|
54
|
-
}),
|
|
55
|
-
);
|
|
56
|
-
expect(next).not.toBeNull();
|
|
57
|
-
expect(next!.flowName).toBe("research");
|
|
58
|
-
expect(next!.task).toBe("Find bugs");
|
|
59
|
-
expect(next!.status).toBe("running");
|
|
60
|
-
expect(next!.agents.size).toBe(2);
|
|
61
|
-
const r = next!.agents.get("r")!;
|
|
62
|
-
const d = next!.agents.get("d")!;
|
|
63
|
-
expect(r.agentName).toBe("researcher");
|
|
64
|
-
expect(r.status).toBe("pending");
|
|
65
|
-
expect(d.blockedBy).toEqual(["r"]);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it("reduces flow_agent_started → agent transitions to running", () => {
|
|
69
|
-
let s = reduceFlowEvent(
|
|
70
|
-
null,
|
|
71
|
-
ev("flow_started", {
|
|
72
|
-
flowName: "f",
|
|
73
|
-
task: "t",
|
|
74
|
-
steps: [{ id: "r", agent: "researcher", blockedBy: [] }],
|
|
75
|
-
}),
|
|
76
|
-
);
|
|
77
|
-
s = reduceFlowEvent(
|
|
78
|
-
s,
|
|
79
|
-
ev("flow_agent_started", {
|
|
80
|
-
agentName: "researcher",
|
|
81
|
-
config: { model: "@research", card: { label: "Research" } },
|
|
82
|
-
}),
|
|
83
|
-
);
|
|
84
|
-
const r = s!.agents.get("r")!;
|
|
85
|
-
expect(r.status).toBe("running");
|
|
86
|
-
expect(r.label).toBe("Research");
|
|
87
|
-
expect(r.model).toBe("@research");
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
it("reduces flow_complete → status updates and flowResult stored", () => {
|
|
91
|
-
let s = reduceFlowEvent(
|
|
92
|
-
null,
|
|
93
|
-
ev("flow_started", { flowName: "f", task: "t", steps: [{ id: "r", agent: "r", blockedBy: [] }] }),
|
|
94
|
-
);
|
|
95
|
-
s = reduceFlowEvent(
|
|
96
|
-
s,
|
|
97
|
-
ev("flow_complete", {
|
|
98
|
-
status: "success",
|
|
99
|
-
flowName: "f",
|
|
100
|
-
results: { totalAgents: 1, successCount: 1 },
|
|
101
|
-
}),
|
|
102
|
-
);
|
|
103
|
-
expect(s!.status).toBe("success");
|
|
104
|
-
expect(s!.flowResult).toBeDefined();
|
|
105
|
-
});
|
|
106
|
-
});
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect } from "vitest";
|
|
2
|
-
import { renderSessionFlowActions } from "../server/render-actions.js";
|
|
3
|
-
import type { FlowInfo, CommandInfo } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
4
|
-
|
|
5
|
-
const cmd = (name: string): CommandInfo => ({ name }) as CommandInfo;
|
|
6
|
-
const flow = (name: string, description = ""): FlowInfo =>
|
|
7
|
-
({ name, description }) as FlowInfo;
|
|
8
|
-
|
|
9
|
-
describe("renderSessionFlowActions", () => {
|
|
10
|
-
it("returns null when no flows and no /flows:new command", () => {
|
|
11
|
-
const result = renderSessionFlowActions({ flows: [], commands: [] });
|
|
12
|
-
expect(result).toBeNull();
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it("renders flows as action items with dataAction descriptors", () => {
|
|
16
|
-
const result = renderSessionFlowActions({
|
|
17
|
-
flows: [flow("alpha", "desc-a"), flow("beta", "desc-b")],
|
|
18
|
-
commands: [],
|
|
19
|
-
});
|
|
20
|
-
expect(result).not.toBeNull();
|
|
21
|
-
expect(result!.primitive).toBe("ui:action-list");
|
|
22
|
-
const actions = (result!.props as { actions: any[] }).actions;
|
|
23
|
-
expect(actions).toHaveLength(2);
|
|
24
|
-
expect(actions[0].label).toBe("alpha");
|
|
25
|
-
expect(actions[0].tooltip).toBe("desc-a");
|
|
26
|
-
expect(actions[0].dataAction).toEqual({
|
|
27
|
-
pluginId: "flows",
|
|
28
|
-
action: "flow.run",
|
|
29
|
-
payload: { flow: "alpha" },
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it("appends + New Flow item when flows:new command is available", () => {
|
|
34
|
-
const result = renderSessionFlowActions({
|
|
35
|
-
flows: [flow("alpha")],
|
|
36
|
-
commands: [cmd("flows:new")],
|
|
37
|
-
});
|
|
38
|
-
const actions = (result!.props as { actions: any[] }).actions;
|
|
39
|
-
expect(actions).toHaveLength(2);
|
|
40
|
-
expect(actions[1].label).toBe("+ New Flow");
|
|
41
|
-
expect(actions[1].dataAction.action).toBe("flow.new");
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it("renders ONLY + New Flow when no flows but command available", () => {
|
|
45
|
-
const result = renderSessionFlowActions({
|
|
46
|
-
flows: [],
|
|
47
|
-
commands: [cmd("flows:new")],
|
|
48
|
-
});
|
|
49
|
-
const actions = (result!.props as { actions: any[] }).actions;
|
|
50
|
-
expect(actions).toHaveLength(1);
|
|
51
|
-
expect(actions[0].label).toBe("+ New Flow");
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it("returns null intent is JSON-serializable when not null", () => {
|
|
55
|
-
const result = renderSessionFlowActions({
|
|
56
|
-
flows: [flow("alpha")],
|
|
57
|
-
commands: [cmd("flows:new")],
|
|
58
|
-
});
|
|
59
|
-
expect(() => JSON.stringify(result)).not.toThrow();
|
|
60
|
-
const roundtrip = JSON.parse(JSON.stringify(result));
|
|
61
|
-
expect(roundtrip.primitive).toBe("ui:action-list");
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
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
|
-
});
|
package/src/bridge/AGENTS.md
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
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. |
|