@blackbelt-technology/pi-dashboard-flows-plugin 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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
|
@@ -2,14 +2,12 @@
|
|
|
2
2
|
* Per-session flow state holder on the server.
|
|
3
3
|
*
|
|
4
4
|
* Holds Map<sessionId, FlowsSessionServerState>. Subscribes (TODO 17.3)
|
|
5
|
-
* to event broadcasts and applies the pure
|
|
6
|
-
* and architect-reducer.ts.
|
|
5
|
+
* to event broadcasts and applies the pure reducer from flow-reducer.ts.
|
|
7
6
|
*
|
|
8
7
|
* See change: adopt-server-driven-intent-rendering.
|
|
9
8
|
*/
|
|
10
|
-
import type { FlowState,
|
|
9
|
+
import type { FlowState, FlowInfo, CommandInfo, DashboardEvent } from "@blackbelt-technology/pi-dashboard-shared/types.js";
|
|
11
10
|
import { isFlowEvent, reduceFlowEvent } from "../flow-reducer.js";
|
|
12
|
-
import { isArchitectEvent, reduceArchitectEvent } from "../architect-reducer.js";
|
|
13
11
|
|
|
14
12
|
export interface FlowsSessionServerState {
|
|
15
13
|
/** Available flows for this session (from pi-flows extension). */
|
|
@@ -18,8 +16,6 @@ export interface FlowsSessionServerState {
|
|
|
18
16
|
commands: CommandInfo[];
|
|
19
17
|
/** Current flow state derived from event stream. Null when no flow active. */
|
|
20
18
|
flowState?: FlowState | null;
|
|
21
|
-
/** Architect state derived from event stream. */
|
|
22
|
-
architectState?: ArchitectState | null;
|
|
23
19
|
}
|
|
24
20
|
|
|
25
21
|
class StateStore {
|
|
@@ -39,7 +35,7 @@ class StateStore {
|
|
|
39
35
|
return this.map.get(sessionId);
|
|
40
36
|
}
|
|
41
37
|
|
|
42
|
-
/** Apply an event from pi (flow_*,
|
|
38
|
+
/** Apply an event from pi (flow_*, etc.) to the session's state. */
|
|
43
39
|
applyEvent(sessionId: string, event: DashboardEvent): boolean {
|
|
44
40
|
const s = this.ensure(sessionId);
|
|
45
41
|
let changed = false;
|
|
@@ -50,13 +46,6 @@ class StateStore {
|
|
|
50
46
|
changed = true;
|
|
51
47
|
}
|
|
52
48
|
}
|
|
53
|
-
if (isArchitectEvent(event.eventType)) {
|
|
54
|
-
const next = reduceArchitectEvent(s.architectState ?? null, event);
|
|
55
|
-
if (next !== s.architectState) {
|
|
56
|
-
s.architectState = next;
|
|
57
|
-
changed = true;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
49
|
return changed;
|
|
61
50
|
}
|
|
62
51
|
|
|
@@ -1,81 +0,0 @@
|
|
|
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
|
-
});
|
|
@@ -1,307 +0,0 @@
|
|
|
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
|
-
});
|