@blackbelt-technology/pi-dashboard-flows-plugin 0.0.0-test-darwin-x64.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/README.md +18 -0
- package/package.json +62 -0
- package/src/__tests__/ArchitectInputPrompt.test.tsx +81 -0
- package/src/__tests__/FlowGraph.test.ts +159 -0
- package/src/__tests__/architect-reducer.test.ts +307 -0
- package/src/__tests__/reducer-parity.test.ts +106 -0
- package/src/architect-reducer.ts +386 -0
- package/src/client/FlowActivityBadge.tsx +41 -0
- package/src/client/FlowAgentCard.tsx +133 -0
- package/src/client/FlowAgentDetail.tsx +173 -0
- package/src/client/FlowArchitect.tsx +622 -0
- package/src/client/FlowDashboard.tsx +230 -0
- package/src/client/FlowGraph.tsx +563 -0
- package/src/client/FlowLaunchDialog.tsx +87 -0
- package/src/client/FlowSummary.tsx +137 -0
- package/src/client/FlowTabBar.tsx +52 -0
- package/src/client/SessionFlowActions.tsx +178 -0
- package/src/client/index.tsx +29 -0
- package/src/flow-reducer.ts +323 -0
- package/src/reducer.ts +10 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @blackbelt-technology/pi-dashboard-flows-plugin
|
|
2
|
+
|
|
3
|
+
Flow rendering plugin for pi-dashboard. Owns the React components and reducer slices that react to `flow_*` events emitted by the external `pi-flows` pi extension.
|
|
4
|
+
|
|
5
|
+
## Status
|
|
6
|
+
|
|
7
|
+
This package was extracted from `packages/client/` by the OpenSpec change `extract-flows-as-plugin`. The current shape is:
|
|
8
|
+
|
|
9
|
+
- **Reducer code** lives here (`src/flow-reducer.ts`, `src/architect-reducer.ts`, re-exported via `./reducer`).
|
|
10
|
+
- **React components** live here (`src/client/*.tsx`, re-exported via `./client`).
|
|
11
|
+
- **Shell wiring** still imports components directly from this package and mounts them in `App.tsx` / `SessionCard.tsx` JSX. Slot-consumer-based mounting is tracked as the follow-up change `migrate-flows-jsx-to-slots`.
|
|
12
|
+
|
|
13
|
+
The manifest (`pi-dashboard-plugin` field in `package.json`) declares the eventual slot claims. `session-card-badge` and `session-card-action-bar` are already wired through the slot consumers; richer slots (`content-header-sticky`, `content-view`, `content-inline-footer`) wait on either an extended slot prop contract or a self-deriving component refactor.
|
|
14
|
+
|
|
15
|
+
## Imports
|
|
16
|
+
|
|
17
|
+
- Reducer: `import { isFlowEvent, reduceFlowEvent, isArchitectEvent, reduceArchitectEvent } from "@blackbelt-technology/pi-dashboard-flows-plugin/reducer"`
|
|
18
|
+
- Components: `import { FlowDashboard, FlowAgentDetail, FlowArchitect, FlowSummary, FlowActivityBadge, SessionFlowActions, FlowLaunchDialog } from "@blackbelt-technology/pi-dashboard-flows-plugin/client"`
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blackbelt-technology/pi-dashboard-flows-plugin",
|
|
3
|
+
"version": "0.0.0-test-darwin-x64.1",
|
|
4
|
+
"description": "Flow rendering plugin for pi-dashboard — pi-flows event reaction (FlowDashboard, FlowAgentCard, FlowArchitect, etc.)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/BlackBeltTechnology/pi-agent-dashboard",
|
|
13
|
+
"directory": "packages/flows-plugin"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./src/client/index.tsx",
|
|
18
|
+
"default": "./src/client/index.tsx"
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"types": "./src/client/index.tsx",
|
|
22
|
+
"default": "./src/client/index.tsx"
|
|
23
|
+
},
|
|
24
|
+
"./reducer": {
|
|
25
|
+
"types": "./src/reducer.ts",
|
|
26
|
+
"default": "./src/reducer.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"src/"
|
|
31
|
+
],
|
|
32
|
+
"pi-dashboard-plugin": {
|
|
33
|
+
"id": "flows",
|
|
34
|
+
"displayName": "Flows",
|
|
35
|
+
"priority": 100,
|
|
36
|
+
"client": "./src/client/index.tsx",
|
|
37
|
+
"claims": [
|
|
38
|
+
{
|
|
39
|
+
"slot": "session-card-badge",
|
|
40
|
+
"component": "FlowActivityBadge",
|
|
41
|
+
"predicate": "hasActiveFlow"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"slot": "session-card-action-bar",
|
|
45
|
+
"component": "SessionFlowActions"
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": ">=18.0.0",
|
|
51
|
+
"react-dom": ">=18.0.0"
|
|
52
|
+
},
|
|
53
|
+
"dependencies": {
|
|
54
|
+
"@blackbelt-technology/pi-dashboard-shared": "^0.0.0-test-darwin-x64.1"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/react": "^19.0.0",
|
|
58
|
+
"@types/react-dom": "^19.0.0",
|
|
59
|
+
"react": "^19.0.0",
|
|
60
|
+
"react-dom": "^19.0.0"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
2
|
+
import { render, screen, fireEvent, cleanup } from "@testing-library/react";
|
|
3
|
+
import React from "react";
|
|
4
|
+
import { ArchitectInputPrompt } from "../client/FlowArchitect.js";
|
|
5
|
+
|
|
6
|
+
afterEach(cleanup);
|
|
7
|
+
|
|
8
|
+
const basePrompt = {
|
|
9
|
+
id: "prompt-1",
|
|
10
|
+
type: "input" as const,
|
|
11
|
+
question: "What should be changed?",
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
describe("ArchitectInputPrompt", () => {
|
|
15
|
+
it("renders question and input field", () => {
|
|
16
|
+
render(
|
|
17
|
+
<ArchitectInputPrompt prompt={basePrompt} onRespond={vi.fn()} />,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
expect(screen.getByText("What should be changed?")).toBeTruthy();
|
|
21
|
+
expect(screen.getByRole("textbox")).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("submits empty string via Enter key", () => {
|
|
25
|
+
const onRespond = vi.fn();
|
|
26
|
+
render(
|
|
27
|
+
<ArchitectInputPrompt prompt={basePrompt} onRespond={onRespond} />,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
fireEvent.keyDown(screen.getByRole("textbox"), { key: "Enter" });
|
|
31
|
+
|
|
32
|
+
expect(onRespond).toHaveBeenCalledWith("");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("submits empty string via button click", () => {
|
|
36
|
+
const onRespond = vi.fn();
|
|
37
|
+
render(
|
|
38
|
+
<ArchitectInputPrompt prompt={basePrompt} onRespond={onRespond} />,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
fireEvent.click(screen.getByText("Submit"));
|
|
42
|
+
|
|
43
|
+
expect(onRespond).toHaveBeenCalledWith("");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("submits entered text via Enter key", () => {
|
|
47
|
+
const onRespond = vi.fn();
|
|
48
|
+
render(
|
|
49
|
+
<ArchitectInputPrompt prompt={basePrompt} onRespond={onRespond} />,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
fireEvent.change(screen.getByRole("textbox"), { target: { value: "Fix the bug" } });
|
|
53
|
+
fireEvent.keyDown(screen.getByRole("textbox"), { key: "Enter" });
|
|
54
|
+
|
|
55
|
+
expect(onRespond).toHaveBeenCalledWith("Fix the bug");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("trims whitespace from submitted text", () => {
|
|
59
|
+
const onRespond = vi.fn();
|
|
60
|
+
render(
|
|
61
|
+
<ArchitectInputPrompt prompt={basePrompt} onRespond={onRespond} />,
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
fireEvent.change(screen.getByRole("textbox"), { target: { value: " hello " } });
|
|
65
|
+
fireEvent.click(screen.getByText("Submit"));
|
|
66
|
+
|
|
67
|
+
expect(onRespond).toHaveBeenCalledWith("hello");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("uses defaultValue from prompt", () => {
|
|
71
|
+
const onRespond = vi.fn();
|
|
72
|
+
render(
|
|
73
|
+
<ArchitectInputPrompt
|
|
74
|
+
prompt={{ ...basePrompt, defaultValue: "prefilled" }}
|
|
75
|
+
onRespond={onRespond}
|
|
76
|
+
/>,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
expect(screen.getByRole("textbox")).toHaveProperty("value", "prefilled");
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { computeLayout, type FlowGraphStep } from "../client/FlowGraph.js";
|
|
3
|
+
|
|
4
|
+
describe("computeLayout", () => {
|
|
5
|
+
it("lays out a linear flow A→B→C left-to-right", () => {
|
|
6
|
+
const steps: FlowGraphStep[] = [
|
|
7
|
+
{ id: "a", label: "step-a", status: "complete", blockedBy: [] },
|
|
8
|
+
{ id: "b", label: "step-b", status: "running", blockedBy: ["a"] },
|
|
9
|
+
{ id: "c", label: "step-c", status: "pending", blockedBy: ["b"] },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
const result = computeLayout(steps);
|
|
13
|
+
|
|
14
|
+
expect(result.nodes).toHaveLength(3);
|
|
15
|
+
expect(result.edges).toHaveLength(2);
|
|
16
|
+
|
|
17
|
+
// Nodes should be left-to-right: a.x < b.x < c.x
|
|
18
|
+
const nodeA = result.nodes.find(n => n.id === "a")!;
|
|
19
|
+
const nodeB = result.nodes.find(n => n.id === "b")!;
|
|
20
|
+
const nodeC = result.nodes.find(n => n.id === "c")!;
|
|
21
|
+
expect(nodeA.x).toBeLessThan(nodeB.x);
|
|
22
|
+
expect(nodeB.x).toBeLessThan(nodeC.x);
|
|
23
|
+
|
|
24
|
+
// All nodes at same y (linear flow, same rank)
|
|
25
|
+
expect(nodeA.y).toBe(nodeB.y);
|
|
26
|
+
expect(nodeB.y).toBe(nodeC.y);
|
|
27
|
+
|
|
28
|
+
// Edges should have points
|
|
29
|
+
for (const edge of result.edges) {
|
|
30
|
+
expect(edge.points.length).toBeGreaterThanOrEqual(2);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Width and height should be positive
|
|
34
|
+
expect(result.width).toBeGreaterThan(0);
|
|
35
|
+
expect(result.height).toBeGreaterThan(0);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("lays out a branching flow A→B, A→C, B→D, C→D with vertical stacking", () => {
|
|
39
|
+
const steps: FlowGraphStep[] = [
|
|
40
|
+
{ id: "a", label: "start", status: "complete", blockedBy: [] },
|
|
41
|
+
{ id: "b", label: "branch-1", status: "running", blockedBy: ["a"] },
|
|
42
|
+
{ id: "c", label: "branch-2", status: "running", blockedBy: ["a"] },
|
|
43
|
+
{ id: "d", label: "merge", status: "pending", blockedBy: ["b", "c"] },
|
|
44
|
+
];
|
|
45
|
+
|
|
46
|
+
const result = computeLayout(steps);
|
|
47
|
+
|
|
48
|
+
expect(result.nodes).toHaveLength(4);
|
|
49
|
+
expect(result.edges).toHaveLength(4); // a→b, a→c, b→d, c→d
|
|
50
|
+
|
|
51
|
+
const nodeA = result.nodes.find(n => n.id === "a")!;
|
|
52
|
+
const nodeB = result.nodes.find(n => n.id === "b")!;
|
|
53
|
+
const nodeC = result.nodes.find(n => n.id === "c")!;
|
|
54
|
+
const nodeD = result.nodes.find(n => n.id === "d")!;
|
|
55
|
+
|
|
56
|
+
// A and D should be at different x positions (different ranks)
|
|
57
|
+
expect(nodeA.x).toBeLessThan(nodeB.x);
|
|
58
|
+
expect(nodeB.x).toBeLessThan(nodeD.x);
|
|
59
|
+
|
|
60
|
+
// B and C should be at the same x (same rank) but different y (stacked)
|
|
61
|
+
expect(nodeB.x).toBe(nodeC.x);
|
|
62
|
+
expect(nodeB.y).not.toBe(nodeC.y);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("handles single-step flow", () => {
|
|
66
|
+
const steps: FlowGraphStep[] = [
|
|
67
|
+
{ id: "solo", label: "solo-step", status: "running", blockedBy: [] },
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const result = computeLayout(steps);
|
|
71
|
+
expect(result.nodes).toHaveLength(1);
|
|
72
|
+
expect(result.edges).toHaveLength(0);
|
|
73
|
+
expect(result.width).toBeGreaterThan(0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("handles empty steps array", () => {
|
|
77
|
+
const result = computeLayout([]);
|
|
78
|
+
// Should return empty layout without throwing
|
|
79
|
+
expect(result.nodes).toHaveLength(0);
|
|
80
|
+
expect(result.edges).toHaveLength(0);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("uses consistent node dimensions", () => {
|
|
84
|
+
const steps: FlowGraphStep[] = [
|
|
85
|
+
{ id: "a", label: "step-a", status: "pending", blockedBy: [] },
|
|
86
|
+
{ id: "b", label: "step-b", status: "pending", blockedBy: ["a"] },
|
|
87
|
+
];
|
|
88
|
+
|
|
89
|
+
const result = computeLayout(steps);
|
|
90
|
+
// All nodes should have same width and height
|
|
91
|
+
expect(result.nodes[0].width).toBe(result.nodes[1].width);
|
|
92
|
+
expect(result.nodes[0].height).toBe(result.nodes[1].height);
|
|
93
|
+
expect(result.nodes[0].width).toBeGreaterThan(0);
|
|
94
|
+
expect(result.nodes[0].height).toBeGreaterThan(0);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("preserves status on positioned nodes", () => {
|
|
98
|
+
const steps: FlowGraphStep[] = [
|
|
99
|
+
{ id: "a", label: "step-a", status: "complete", blockedBy: [] },
|
|
100
|
+
{ id: "b", label: "step-b", status: "error", blockedBy: ["a"] },
|
|
101
|
+
];
|
|
102
|
+
|
|
103
|
+
const result = computeLayout(steps);
|
|
104
|
+
expect(result.nodes.find(n => n.id === "a")!.status).toBe("complete");
|
|
105
|
+
expect(result.nodes.find(n => n.id === "b")!.status).toBe("error");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("edges carry source/target status for styling", () => {
|
|
109
|
+
const steps: FlowGraphStep[] = [
|
|
110
|
+
{ id: "a", label: "step-a", status: "complete", blockedBy: [] },
|
|
111
|
+
{ id: "b", label: "step-b", status: "running", blockedBy: ["a"] },
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
const result = computeLayout(steps);
|
|
115
|
+
expect(result.edges).toHaveLength(1);
|
|
116
|
+
expect(result.edges[0].sourceStatus).toBe("complete");
|
|
117
|
+
expect(result.edges[0].targetStatus).toBe("running");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("layout dimensions are consistent regardless of step count", () => {
|
|
121
|
+
// Single node
|
|
122
|
+
const single = computeLayout([
|
|
123
|
+
{ id: "a", label: "step-a", status: "pending", blockedBy: [] },
|
|
124
|
+
]);
|
|
125
|
+
// Many nodes
|
|
126
|
+
const many = computeLayout([
|
|
127
|
+
{ id: "a", label: "step-a", status: "pending", blockedBy: [] },
|
|
128
|
+
{ id: "b", label: "step-b", status: "pending", blockedBy: ["a"] },
|
|
129
|
+
{ id: "c", label: "step-c", status: "pending", blockedBy: ["b"] },
|
|
130
|
+
{ id: "d", label: "step-d", status: "pending", blockedBy: ["c"] },
|
|
131
|
+
]);
|
|
132
|
+
// Nodes should have identical dimensions in both layouts (fixed-scale)
|
|
133
|
+
expect(single.nodes[0].width).toBe(many.nodes[0].width);
|
|
134
|
+
expect(single.nodes[0].height).toBe(many.nodes[0].height);
|
|
135
|
+
// Multi-node layout should be wider
|
|
136
|
+
expect(many.width).toBeGreaterThan(single.width);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("ignores blockedBy references to non-existent steps", () => {
|
|
140
|
+
const steps: FlowGraphStep[] = [
|
|
141
|
+
{ id: "a", label: "step-a", status: "pending", blockedBy: ["nonexistent"] },
|
|
142
|
+
];
|
|
143
|
+
|
|
144
|
+
const result = computeLayout(steps);
|
|
145
|
+
expect(result.nodes).toHaveLength(1);
|
|
146
|
+
expect(result.edges).toHaveLength(0); // no edge for missing dep
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("preserves type field on positioned nodes for flow-ref steps", () => {
|
|
150
|
+
const steps: FlowGraphStep[] = [
|
|
151
|
+
{ id: "a", label: "agent-step", status: "pending", blockedBy: [], type: "agent" },
|
|
152
|
+
{ id: "b", label: "subflow-step", status: "pending", blockedBy: ["a"], type: "flow-ref" },
|
|
153
|
+
];
|
|
154
|
+
|
|
155
|
+
const result = computeLayout(steps);
|
|
156
|
+
expect(result.nodes.find(n => n.id === "a")!.type).toBe("agent");
|
|
157
|
+
expect(result.nodes.find(n => n.id === "b")!.type).toBe("flow-ref");
|
|
158
|
+
});
|
|
159
|
+
});
|
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { describe, it, expect } from "vitest";
|
|
2
|
+
import { isArchitectEvent, reduceArchitectEvent } from "../architect-reducer.js";
|
|
3
|
+
import type { DashboardEvent, ArchitectState } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
4
|
+
|
|
5
|
+
function makeEvent(eventType: string, data: Record<string, unknown> = {}): DashboardEvent {
|
|
6
|
+
return { eventType, timestamp: Date.now(), data };
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
describe("isArchitectEvent", () => {
|
|
10
|
+
it("returns true for architect_ prefixed events", () => {
|
|
11
|
+
expect(isArchitectEvent("architect_started")).toBe(true);
|
|
12
|
+
expect(isArchitectEvent("architect_tool_call")).toBe(true);
|
|
13
|
+
expect(isArchitectEvent("architect_complete")).toBe(true);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("returns false for non-architect events", () => {
|
|
17
|
+
expect(isArchitectEvent("flow_started")).toBe(false);
|
|
18
|
+
expect(isArchitectEvent("agent_start")).toBe(false);
|
|
19
|
+
expect(isArchitectEvent("tool_execution_start")).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe("architect-reducer state transitions", () => {
|
|
24
|
+
it("full lifecycle: context → designing → preview → complete", () => {
|
|
25
|
+
// Context generating
|
|
26
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_context_generating", { mode: "new" }));
|
|
27
|
+
expect(state).not.toBeNull();
|
|
28
|
+
expect(state!.phase).toBe("context");
|
|
29
|
+
expect(state!.architectMode).toBe("new");
|
|
30
|
+
|
|
31
|
+
// Architect started
|
|
32
|
+
state = reduceArchitectEvent(state, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
33
|
+
expect(state!.phase).toBe("designing");
|
|
34
|
+
expect(state!.iteration).toBe(1);
|
|
35
|
+
|
|
36
|
+
// Tool call: agent_catalog
|
|
37
|
+
state = reduceArchitectEvent(state, makeEvent("architect_tool_call", {
|
|
38
|
+
toolName: "agent_catalog",
|
|
39
|
+
input: {},
|
|
40
|
+
}));
|
|
41
|
+
expect(state!.lastToolCall).toEqual({ toolName: "agent_catalog", inputPreview: "{}" });
|
|
42
|
+
expect(state!.catalogSummary).toBe("Reading catalog…");
|
|
43
|
+
expect(state!.recentTools).toHaveLength(1);
|
|
44
|
+
expect(state!.detailHistory).toHaveLength(1);
|
|
45
|
+
expect(state!.detailHistory[0].kind).toBe("tool");
|
|
46
|
+
|
|
47
|
+
// Tool result: agent_catalog
|
|
48
|
+
state = reduceArchitectEvent(state, makeEvent("architect_tool_result", {
|
|
49
|
+
toolName: "agent_catalog",
|
|
50
|
+
output: JSON.stringify([{ name: "a1" }, { name: "a2" }]),
|
|
51
|
+
isError: false,
|
|
52
|
+
}));
|
|
53
|
+
expect(state!.catalogSummary).toBe("Catalog: 2 agents");
|
|
54
|
+
// Detail history entry should have output filled in
|
|
55
|
+
expect((state!.detailHistory[0] as any).output).toBeDefined();
|
|
56
|
+
|
|
57
|
+
// Tool call: agent_write
|
|
58
|
+
state = reduceArchitectEvent(state, makeEvent("architect_tool_call", {
|
|
59
|
+
toolName: "agent_write",
|
|
60
|
+
input: { path: "/tmp/agents/reviewer.md", content: "name: reviewer\n" },
|
|
61
|
+
}));
|
|
62
|
+
expect(state!.agents).toHaveLength(1);
|
|
63
|
+
expect(state!.agents[0].name).toBe("reviewer");
|
|
64
|
+
expect(state!.agents[0].status).toBe("creating");
|
|
65
|
+
expect(state!.agents[0].type).toBe("custom");
|
|
66
|
+
|
|
67
|
+
// Tool result: agent_write
|
|
68
|
+
state = reduceArchitectEvent(state, makeEvent("architect_tool_result", {
|
|
69
|
+
toolName: "agent_write",
|
|
70
|
+
output: "ok",
|
|
71
|
+
isError: false,
|
|
72
|
+
}));
|
|
73
|
+
expect(state!.agents[0].status).toBe("done");
|
|
74
|
+
|
|
75
|
+
// Tool call: flow_write
|
|
76
|
+
state = reduceArchitectEvent(state, makeEvent("architect_tool_call", {
|
|
77
|
+
toolName: "flow_write",
|
|
78
|
+
input: {
|
|
79
|
+
path: "/tmp/flows/test.yaml",
|
|
80
|
+
content: "name: test-flow\nsteps:\n - id: analyze\n agent: analyzer\n - id: report\n agent: reviewer\n blockedBy: [analyze]\n",
|
|
81
|
+
},
|
|
82
|
+
}));
|
|
83
|
+
expect(state!.flowName).toBe("test-flow");
|
|
84
|
+
expect(state!.dagSteps.length).toBeGreaterThanOrEqual(2);
|
|
85
|
+
expect(state!.dagSteps[0].id).toBe("analyze");
|
|
86
|
+
|
|
87
|
+
// Preview
|
|
88
|
+
state = reduceArchitectEvent(state, makeEvent("architect_preview", {
|
|
89
|
+
parsedFlows: [{
|
|
90
|
+
name: "test-flow",
|
|
91
|
+
description: "A test",
|
|
92
|
+
maxConcurrent: 2,
|
|
93
|
+
steps: [
|
|
94
|
+
{ id: "analyze", agentName: "analyzer", blockedBy: [] },
|
|
95
|
+
{ id: "report", agentName: "reviewer", blockedBy: ["analyze"] },
|
|
96
|
+
],
|
|
97
|
+
}],
|
|
98
|
+
flowPath: "/tmp/flows/test.yaml",
|
|
99
|
+
createdFiles: ["/tmp/flows/test.yaml"],
|
|
100
|
+
}));
|
|
101
|
+
expect(state!.phase).toBe("preview");
|
|
102
|
+
expect(state!.parsedFlows).toHaveLength(1);
|
|
103
|
+
expect(state!.parsedFlows[0].steps).toHaveLength(2);
|
|
104
|
+
|
|
105
|
+
// Complete
|
|
106
|
+
state = reduceArchitectEvent(state, makeEvent("architect_complete", { choice: "save" }));
|
|
107
|
+
expect(state).toBeNull();
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("extracts blockedBy from camelCase YAML (pi-flows format)", () => {
|
|
111
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_context_generating", { mode: "new" }));
|
|
112
|
+
state = reduceArchitectEvent(state, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
113
|
+
state = reduceArchitectEvent(state, makeEvent("architect_tool_call", {
|
|
114
|
+
toolName: "flow_write",
|
|
115
|
+
input: {
|
|
116
|
+
path: "/tmp/flows/pipeline.yaml",
|
|
117
|
+
content: "name: pipeline\nsteps:\n - id: researcher\n agent: test-researcher\n - id: summarizer\n agent: test-summarizer\n blockedBy: [researcher]\n",
|
|
118
|
+
},
|
|
119
|
+
}));
|
|
120
|
+
expect(state!.dagSteps).toHaveLength(2);
|
|
121
|
+
expect(state!.dagSteps[0].blockedBy).toEqual([]);
|
|
122
|
+
expect(state!.dagSteps[1].blockedBy).toEqual(["researcher"]);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("architect_started captures resolvedModel and modelAlias", () => {
|
|
126
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_context_generating", { mode: "new" }));
|
|
127
|
+
state = reduceArchitectEvent(state, makeEvent("architect_started", {
|
|
128
|
+
mode: "new",
|
|
129
|
+
iteration: 1,
|
|
130
|
+
resolvedModel: "anthropic/claude-opus-4-6",
|
|
131
|
+
modelAlias: "@planning",
|
|
132
|
+
}));
|
|
133
|
+
expect(state!.resolvedModel).toBe("anthropic/claude-opus-4-6");
|
|
134
|
+
expect(state!.modelAlias).toBe("@planning");
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("architect_started without model fields leaves them undefined", () => {
|
|
138
|
+
const state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
139
|
+
expect(state!.resolvedModel).toBeUndefined();
|
|
140
|
+
expect(state!.modelAlias).toBeUndefined();
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("architect_started without prior context_generating creates fresh state", () => {
|
|
144
|
+
const state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "edit", iteration: 1 }));
|
|
145
|
+
expect(state).not.toBeNull();
|
|
146
|
+
expect(state!.phase).toBe("designing");
|
|
147
|
+
expect(state!.architectMode).toBe("edit");
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it("architect_cancelled clears state", () => {
|
|
151
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
152
|
+
state = reduceArchitectEvent(state, makeEvent("architect_cancelled", {}));
|
|
153
|
+
expect(state).toBeNull();
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("architect_error stores error message", () => {
|
|
157
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
158
|
+
state = reduceArchitectEvent(state, makeEvent("architect_error", { summary: "Something broke" }));
|
|
159
|
+
expect(state!.error).toBe("Something broke");
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("architect_run_handoff clears state", () => {
|
|
163
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
164
|
+
state = reduceArchitectEvent(state, makeEvent("architect_run_handoff", { flowName: "test" }));
|
|
165
|
+
expect(state).toBeNull();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe("architect-reducer replan loop", () => {
|
|
170
|
+
it("replan resets state with incremented iteration", () => {
|
|
171
|
+
// Start
|
|
172
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
173
|
+
expect(state!.iteration).toBe(1);
|
|
174
|
+
|
|
175
|
+
// Add some agents
|
|
176
|
+
state = reduceArchitectEvent(state, makeEvent("architect_tool_call", {
|
|
177
|
+
toolName: "agent_write",
|
|
178
|
+
input: { path: "/tmp/agents/a.md" },
|
|
179
|
+
}));
|
|
180
|
+
expect(state!.agents).toHaveLength(1);
|
|
181
|
+
|
|
182
|
+
// Replan
|
|
183
|
+
state = reduceArchitectEvent(state, makeEvent("architect_replan", { iteration: 2, notes: "change X" }));
|
|
184
|
+
expect(state!.phase).toBe("designing");
|
|
185
|
+
expect(state!.iteration).toBe(2);
|
|
186
|
+
expect(state!.agents).toHaveLength(0); // reset
|
|
187
|
+
expect(state!.dagSteps).toHaveLength(0); // reset
|
|
188
|
+
expect(state!.lastToolCall).toBeNull(); // reset
|
|
189
|
+
expect(state!.recentTools).toHaveLength(0); // reset
|
|
190
|
+
expect(state!.detailHistory).toHaveLength(0); // reset
|
|
191
|
+
|
|
192
|
+
// Second iteration: new agents
|
|
193
|
+
state = reduceArchitectEvent(state, makeEvent("architect_tool_call", {
|
|
194
|
+
toolName: "agent_write",
|
|
195
|
+
input: { path: "/tmp/agents/b.md" },
|
|
196
|
+
}));
|
|
197
|
+
expect(state!.agents).toHaveLength(1);
|
|
198
|
+
expect(state!.agents[0].name).toBe("b");
|
|
199
|
+
|
|
200
|
+
// Complete
|
|
201
|
+
state = reduceArchitectEvent(state, makeEvent("architect_complete", { choice: "save" }));
|
|
202
|
+
expect(state).toBeNull();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("multiple replans increment correctly", () => {
|
|
206
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "edit", iteration: 1 }));
|
|
207
|
+
state = reduceArchitectEvent(state, makeEvent("architect_replan", { iteration: 2 }));
|
|
208
|
+
expect(state!.iteration).toBe(2);
|
|
209
|
+
state = reduceArchitectEvent(state, makeEvent("architect_replan", { iteration: 3 }));
|
|
210
|
+
expect(state!.iteration).toBe(3);
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
describe("architect-reducer prompt handling", () => {
|
|
215
|
+
it("architect_prompt_request sets pendingPrompt", () => {
|
|
216
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
217
|
+
expect(state!.pendingPrompt).toBeNull();
|
|
218
|
+
|
|
219
|
+
state = reduceArchitectEvent(state, makeEvent("architect_prompt_request", {
|
|
220
|
+
id: "prompt-1",
|
|
221
|
+
promptType: "select",
|
|
222
|
+
question: "What would you like to do?",
|
|
223
|
+
options: ["Save", "Replan", "Cancel"],
|
|
224
|
+
}));
|
|
225
|
+
expect(state!.pendingPrompt).not.toBeNull();
|
|
226
|
+
expect(state!.pendingPrompt!.id).toBe("prompt-1");
|
|
227
|
+
expect(state!.pendingPrompt!.type).toBe("select");
|
|
228
|
+
expect(state!.pendingPrompt!.question).toBe("What would you like to do?");
|
|
229
|
+
expect(state!.pendingPrompt!.options).toEqual(["Save", "Replan", "Cancel"]);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
it("architect_prompt_request with input type and defaultValue", () => {
|
|
233
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "edit", iteration: 1 }));
|
|
234
|
+
state = reduceArchitectEvent(state, makeEvent("architect_prompt_request", {
|
|
235
|
+
id: "prompt-2",
|
|
236
|
+
promptType: "input",
|
|
237
|
+
question: "Name this flow:",
|
|
238
|
+
defaultValue: "my-flow",
|
|
239
|
+
}));
|
|
240
|
+
expect(state!.pendingPrompt!.type).toBe("input");
|
|
241
|
+
expect(state!.pendingPrompt!.defaultValue).toBe("my-flow");
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
it("architect_prompt_request without state returns null", () => {
|
|
245
|
+
const state = reduceArchitectEvent(null, makeEvent("architect_prompt_request", {
|
|
246
|
+
id: "prompt-3",
|
|
247
|
+
promptType: "select",
|
|
248
|
+
question: "test?",
|
|
249
|
+
}));
|
|
250
|
+
expect(state).toBeNull();
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
it("pendingPrompt is cleared on architect_complete", () => {
|
|
254
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
255
|
+
state = reduceArchitectEvent(state, makeEvent("architect_prompt_request", {
|
|
256
|
+
id: "prompt-4", promptType: "select", question: "Save?", options: ["Save", "Cancel"],
|
|
257
|
+
}));
|
|
258
|
+
expect(state!.pendingPrompt).not.toBeNull();
|
|
259
|
+
state = reduceArchitectEvent(state, makeEvent("architect_complete", {}));
|
|
260
|
+
expect(state).toBeNull(); // entire state cleared
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it("pendingPrompt is cleared on architect_cancelled", () => {
|
|
264
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
265
|
+
state = reduceArchitectEvent(state, makeEvent("architect_prompt_request", {
|
|
266
|
+
id: "prompt-5", promptType: "select", question: "Save?", options: ["Save", "Cancel"],
|
|
267
|
+
}));
|
|
268
|
+
state = reduceArchitectEvent(state, makeEvent("architect_cancelled", {}));
|
|
269
|
+
expect(state).toBeNull();
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it("pendingPrompt is cleared on architect_replan", () => {
|
|
273
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
274
|
+
state = reduceArchitectEvent(state, makeEvent("architect_prompt_request", {
|
|
275
|
+
id: "prompt-6", promptType: "select", question: "Save?", options: ["Save", "Cancel"],
|
|
276
|
+
}));
|
|
277
|
+
expect(state!.pendingPrompt).not.toBeNull();
|
|
278
|
+
state = reduceArchitectEvent(state, makeEvent("architect_replan", { iteration: 2 }));
|
|
279
|
+
expect(state!.pendingPrompt).toBeNull();
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("architect_preview stores flowYamlContent", () => {
|
|
283
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
284
|
+
state = reduceArchitectEvent(state, makeEvent("architect_preview", {
|
|
285
|
+
flows: [{ name: "test.yaml", content: "name: test-flow\nsteps:\n - id: a\n agent: analyzer" }],
|
|
286
|
+
parsedFlows: [{ name: "test-flow", steps: [{ id: "a", agentName: "analyzer", blockedBy: [] }] }],
|
|
287
|
+
}));
|
|
288
|
+
expect(state!.flowYamlContent).toBe("name: test-flow\nsteps:\n - id: a\n agent: analyzer");
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("architect_preview without flows has no flowYamlContent", () => {
|
|
292
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
293
|
+
state = reduceArchitectEvent(state, makeEvent("architect_preview", {
|
|
294
|
+
parsedFlows: [{ name: "test-flow", steps: [] }],
|
|
295
|
+
}));
|
|
296
|
+
expect(state!.flowYamlContent).toBeUndefined();
|
|
297
|
+
});
|
|
298
|
+
|
|
299
|
+
it("pendingPrompt is cleared on architect_started (new iteration)", () => {
|
|
300
|
+
let state = reduceArchitectEvent(null, makeEvent("architect_started", { mode: "new", iteration: 1 }));
|
|
301
|
+
state = reduceArchitectEvent(state, makeEvent("architect_prompt_request", {
|
|
302
|
+
id: "prompt-7", promptType: "select", question: "Save?", options: ["Save"],
|
|
303
|
+
}));
|
|
304
|
+
state = reduceArchitectEvent(state, makeEvent("architect_started", { mode: "new", iteration: 2 }));
|
|
305
|
+
expect(state!.pendingPrompt).toBeNull();
|
|
306
|
+
});
|
|
307
|
+
});
|