@ftrdotdev/pi-delegates 0.0.0-stage → 0.2.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/CHANGELOG.md +128 -0
- package/LICENSE +21 -0
- package/OPERATIONS.md +130 -0
- package/README.md +456 -2
- package/ROADMAP.md +179 -0
- package/TESTING.md +896 -0
- package/agents.ts +8 -0
- package/examples/README.md +114 -0
- package/examples/gated.ts +28 -0
- package/index.ts +9 -0
- package/package.json +94 -4
- package/skills/pi-delegates/SKILL.md +176 -0
- package/skills/pi-delegates/references/control.md +159 -0
- package/skills/pi-delegates/references/definitions.md +163 -0
- package/skills/pi-delegates/references/gates.md +175 -0
- package/skills/pi-delegates/references/launch.md +184 -0
- package/src/docs-contract.test.ts +106 -0
- package/src/domain/definitions.test.ts +41 -0
- package/src/domain/definitions.ts +163 -0
- package/src/domain/failure.ts +33 -0
- package/src/domain/ids.ts +13 -0
- package/src/domain/model-source.ts +30 -0
- package/src/domain/names.ts +35 -0
- package/src/domain/orchestration/admission.ts +78 -0
- package/src/domain/orchestration/control.test.ts +1332 -0
- package/src/domain/orchestration/control.ts +457 -0
- package/src/domain/orchestration/fanout.test.ts +524 -0
- package/src/domain/orchestration/fanout.ts +372 -0
- package/src/domain/orchestration/gates.test.ts +685 -0
- package/src/domain/orchestration/gates.ts +360 -0
- package/src/domain/orchestration/launch.test.ts +372 -0
- package/src/domain/orchestration/launch.ts +691 -0
- package/src/domain/orchestration/requests.test.ts +695 -0
- package/src/domain/orchestration/requests.ts +782 -0
- package/src/domain/orchestration/review.test.ts +292 -0
- package/src/domain/orchestration/review.ts +168 -0
- package/src/domain/orchestration/run-wait.test.ts +265 -0
- package/src/domain/orchestration/run-wait.ts +256 -0
- package/src/domain/orchestration/workflow-section.test.ts +62 -0
- package/src/domain/orchestration/workflow-section.ts +99 -0
- package/src/domain/orchestration/workflow.test.ts +1566 -0
- package/src/domain/orchestration/workflow.ts +778 -0
- package/src/domain/run-records.test.ts +27 -0
- package/src/domain/run-records.ts +689 -0
- package/src/domain/settlement.test.ts +186 -0
- package/src/domain/settlement.ts +137 -0
- package/src/domain/shapes.test.ts +185 -0
- package/src/domain/skills.test.ts +477 -0
- package/src/domain/skills.ts +114 -0
- package/src/domain/tool-schema.test.ts +46 -0
- package/src/domain/tool-schema.ts +20 -0
- package/src/domain/toolkit.test.ts +215 -0
- package/src/domain/toolkit.ts +374 -0
- package/src/domain/turn-budget.test.ts +37 -0
- package/src/domain/turn-budget.ts +23 -0
- package/src/domain/view.test.ts +803 -0
- package/src/domain/view.ts +491 -0
- package/src/example.test.ts +15 -0
- package/src/extension/commands.test.ts +485 -0
- package/src/extension/commands.ts +230 -0
- package/src/extension/entry.test.ts +1276 -0
- package/src/extension/entry.ts +380 -0
- package/src/extension/gate-alerts.test.ts +237 -0
- package/src/extension/gate-alerts.ts +143 -0
- package/src/extension/guard.test.ts +48 -0
- package/src/extension/guard.ts +31 -0
- package/src/extension/host-signals.test.ts +20 -0
- package/src/extension/host-signals.ts +13 -0
- package/src/extension/inspector-command.test.ts +1343 -0
- package/src/extension/inspector-command.ts +685 -0
- package/src/extension/prompt.test.ts +108 -0
- package/src/extension/prompt.ts +50 -0
- package/src/extension/request-alerts.test.ts +183 -0
- package/src/extension/request-alerts.ts +181 -0
- package/src/extension/retry-observer.test.ts +292 -0
- package/src/extension/retry-observer.ts +150 -0
- package/src/extension/revocation.test.ts +81 -0
- package/src/extension/revocation.ts +84 -0
- package/src/extension/settle-alerts.test.ts +579 -0
- package/src/extension/settle-alerts.ts +175 -0
- package/src/extension/shortcut.test.ts +62 -0
- package/src/extension/shortcut.ts +105 -0
- package/src/extension/tools.test.ts +1294 -0
- package/src/extension/tools.ts +553 -0
- package/src/extension/version.test.ts +115 -0
- package/src/extension/version.ts +97 -0
- package/src/goldens.test.ts +294 -0
- package/src/harness-policy.test.ts +76 -0
- package/src/layers.test.ts +309 -0
- package/src/layers.ts +405 -0
- package/src/package-manifest.test.ts +170 -0
- package/src/presentation/actions.test.ts +221 -0
- package/src/presentation/actions.ts +85 -0
- package/src/presentation/activity.test.ts +386 -0
- package/src/presentation/activity.ts +66 -0
- package/src/presentation/close.test.ts +359 -0
- package/src/presentation/inspector.test.ts +682 -0
- package/src/presentation/inspector.ts +442 -0
- package/src/presentation/overlay.test.ts +553 -0
- package/src/presentation/overlay.ts +229 -0
- package/src/presentation/repaint.test.ts +365 -0
- package/src/presentation/shortcut.ts +2 -0
- package/src/presentation/snapshot.test.ts +535 -0
- package/src/presentation/snapshot.ts +306 -0
- package/src/presentation/status.test.ts +43 -0
- package/src/presentation/status.ts +30 -0
- package/src/presentation/strip.test.ts +203 -0
- package/src/presentation/strip.ts +67 -0
- package/src/presentation/wording.test.ts +388 -0
- package/src/presentation/wording.ts +294 -0
- package/src/runtime/bridge.test.ts +131 -0
- package/src/runtime/bridge.ts +128 -0
- package/src/runtime/clock.test.ts +31 -0
- package/src/runtime/clock.ts +31 -0
- package/src/runtime/config.test.ts +63 -0
- package/src/runtime/config.ts +92 -0
- package/src/runtime/context.test.ts +19 -0
- package/src/runtime/context.ts +9 -0
- package/src/runtime/execution-env.test.ts +33 -0
- package/src/runtime/execution-env.ts +15 -0
- package/src/runtime/extensions.test.ts +86 -0
- package/src/runtime/extensions.ts +152 -0
- package/src/runtime/handle.ts +54 -0
- package/src/runtime/log.test.ts +140 -0
- package/src/runtime/log.ts +91 -0
- package/src/runtime/mcp.test.ts +1450 -0
- package/src/runtime/mcp.ts +1005 -0
- package/src/runtime/models.test.ts +145 -0
- package/src/runtime/models.ts +259 -0
- package/src/runtime/observe.test.ts +50 -0
- package/src/runtime/observe.ts +150 -0
- package/src/runtime/runtime-state.test.ts +25 -0
- package/src/runtime/runtime-state.ts +36 -0
- package/src/runtime/session-tag.ts +11 -0
- package/src/runtime/session.test.ts +352 -0
- package/src/runtime/session.ts +263 -0
- package/src/runtime/storage.ts +29 -0
- package/src/test-hygiene.test.ts +97 -0
|
@@ -0,0 +1,553 @@
|
|
|
1
|
+
import { assert, it } from "@effect/vitest";
|
|
2
|
+
import type { Theme } from "@earendil-works/pi-coding-agent";
|
|
3
|
+
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
4
|
+
import { VimRouter } from "@ftrdotdev/pi-tui";
|
|
5
|
+
import type { GateRow, InspectorRow, InspectorSnapshot, RequestRow } from "./snapshot.ts";
|
|
6
|
+
import { makeDelegatesOverlay, rowsOf } from "./overlay.ts";
|
|
7
|
+
import {
|
|
8
|
+
GATES_HEADER,
|
|
9
|
+
OVERLAY_FOOTER,
|
|
10
|
+
REQUESTS_HEADER,
|
|
11
|
+
REQUEST_DETAIL_WIDTH,
|
|
12
|
+
laneLine,
|
|
13
|
+
} from "./wording.ts";
|
|
14
|
+
|
|
15
|
+
const plainTheme = {
|
|
16
|
+
fg: (_color: string, text: string): string => text,
|
|
17
|
+
bg: (_color: string, text: string): string => text,
|
|
18
|
+
bold: (text: string): string => text,
|
|
19
|
+
style: (text: string): string => text,
|
|
20
|
+
} as unknown as Theme;
|
|
21
|
+
|
|
22
|
+
const vimRouter = (enabled: boolean): VimRouter["Service"] => VimRouter.make(() => enabled);
|
|
23
|
+
|
|
24
|
+
const row = (input: Partial<InspectorRow> & { readonly id: string }): InspectorRow => ({
|
|
25
|
+
runId: input.id,
|
|
26
|
+
parentId: null,
|
|
27
|
+
childCount: 0,
|
|
28
|
+
label: input.id,
|
|
29
|
+
lane: "default",
|
|
30
|
+
status: "running",
|
|
31
|
+
conversationId: null,
|
|
32
|
+
taskId: null,
|
|
33
|
+
gates: [],
|
|
34
|
+
requests: [],
|
|
35
|
+
tool: null,
|
|
36
|
+
slot: null,
|
|
37
|
+
idleMs: null,
|
|
38
|
+
durationMs: null,
|
|
39
|
+
diagnostic: null,
|
|
40
|
+
...input,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const gate = (input: Partial<GateRow> & { readonly gate: string }): GateRow => ({
|
|
44
|
+
id: `gate:run:one:${input.gate}`,
|
|
45
|
+
runId: "run:one",
|
|
46
|
+
lane: "default",
|
|
47
|
+
tool: "bash",
|
|
48
|
+
childRunIds: [],
|
|
49
|
+
idleMs: 40_000,
|
|
50
|
+
...input,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const snapshot = (
|
|
54
|
+
input: Partial<InspectorSnapshot> & { readonly rows: readonly InspectorRow[] },
|
|
55
|
+
): InspectorSnapshot => ({
|
|
56
|
+
revision: 1,
|
|
57
|
+
gates: [],
|
|
58
|
+
requests: [],
|
|
59
|
+
lanes: [],
|
|
60
|
+
counts: { running: 0, queued: 0, waiting: 0, gates: 0, requests: 0 },
|
|
61
|
+
omitted: 0,
|
|
62
|
+
...input,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const make = (
|
|
66
|
+
getSnapshot: () => InspectorSnapshot,
|
|
67
|
+
options: {
|
|
68
|
+
readonly router?: VimRouter["Service"];
|
|
69
|
+
readonly onAction?: (rowId: string, verb: string) => void;
|
|
70
|
+
readonly onClose?: () => void;
|
|
71
|
+
readonly statusLine?: () => string | null;
|
|
72
|
+
} = {},
|
|
73
|
+
) =>
|
|
74
|
+
makeDelegatesOverlay({
|
|
75
|
+
getSnapshot,
|
|
76
|
+
theme: plainTheme,
|
|
77
|
+
requestRender: () => {},
|
|
78
|
+
onClose: options.onClose ?? (() => {}),
|
|
79
|
+
...(options.router === undefined ? {} : { router: options.router }),
|
|
80
|
+
...(options.onAction === undefined ? {} : { onAction: options.onAction as never }),
|
|
81
|
+
...(options.statusLine === undefined ? {} : { statusLine: options.statusLine }),
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("the overlay lists runs newest first under the pinned headers", () => {
|
|
85
|
+
const current = snapshot({
|
|
86
|
+
rows: [
|
|
87
|
+
row({ id: "child:r1", label: "deployer", tool: "bash" }),
|
|
88
|
+
row({ id: "child:r2", label: "scout", idleMs: 72_000 }),
|
|
89
|
+
],
|
|
90
|
+
gates: [gate({ gate: "deploy" })],
|
|
91
|
+
});
|
|
92
|
+
const overlay = make(() => current);
|
|
93
|
+
const lines = overlay.render(80);
|
|
94
|
+
const runs = lines.findIndex((line) => line.includes("Runs"));
|
|
95
|
+
const first = lines.findIndex((line) => line.includes("deployer"));
|
|
96
|
+
const second = lines.findIndex((line) => line.includes("scout"));
|
|
97
|
+
const gates = lines.findIndex((line) => line.includes("Gates"));
|
|
98
|
+
assert.ok(runs >= 0 && runs < first, lines.join("\n"));
|
|
99
|
+
assert.ok(first < second && second < gates, lines.join("\n"));
|
|
100
|
+
assert.ok(lines[first]?.includes("deployer · running · bash"));
|
|
101
|
+
assert.ok(lines[second]?.includes("scout · running · 1m 12s ago"));
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("arrows move the cursor across run and gate rows", () => {
|
|
105
|
+
const current = snapshot({
|
|
106
|
+
rows: [row({ id: "child:r1" }), row({ id: "child:r2" })],
|
|
107
|
+
gates: [gate({ gate: "deploy" })],
|
|
108
|
+
});
|
|
109
|
+
const overlay = make(() => current);
|
|
110
|
+
assert.strictEqual(overlay.selectedId(), "child:r1");
|
|
111
|
+
overlay.handleInput("\x1b[B");
|
|
112
|
+
assert.strictEqual(overlay.selectedId(), "child:r2");
|
|
113
|
+
overlay.handleInput("\x1b[B");
|
|
114
|
+
assert.strictEqual(overlay.selectedId(), "gate:run:one:deploy");
|
|
115
|
+
overlay.handleInput("\x1b[A");
|
|
116
|
+
assert.strictEqual(overlay.selectedId(), "child:r2");
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("a group row hides its children until enter opens it", () => {
|
|
120
|
+
const parent = row({
|
|
121
|
+
id: "run:parent",
|
|
122
|
+
runId: "parent-run",
|
|
123
|
+
label: "fanout",
|
|
124
|
+
status: "waiting",
|
|
125
|
+
childCount: 1,
|
|
126
|
+
gates: ["deploy"],
|
|
127
|
+
});
|
|
128
|
+
const child = row({
|
|
129
|
+
id: "child:c1",
|
|
130
|
+
parentId: "run:parent",
|
|
131
|
+
runId: "child-run",
|
|
132
|
+
label: "scout",
|
|
133
|
+
status: "waiting",
|
|
134
|
+
gates: ["deploy"],
|
|
135
|
+
});
|
|
136
|
+
const overlay = make(() => snapshot({ rows: [parent, child] }));
|
|
137
|
+
|
|
138
|
+
const collapsed = overlay.render(80);
|
|
139
|
+
assert.ok(
|
|
140
|
+
collapsed.some((line) => line.includes("fanout")),
|
|
141
|
+
collapsed.join("\n"),
|
|
142
|
+
);
|
|
143
|
+
assert.ok(!collapsed.some((line) => line.includes("scout")), collapsed.join("\n"));
|
|
144
|
+
|
|
145
|
+
overlay.handleInput("\r");
|
|
146
|
+
const open = overlay.render(80);
|
|
147
|
+
assert.ok(
|
|
148
|
+
open.some((line) => line.includes("scout")),
|
|
149
|
+
open.join("\n"),
|
|
150
|
+
);
|
|
151
|
+
assert.strictEqual(overlay.selectedId(), "run:parent");
|
|
152
|
+
|
|
153
|
+
overlay.handleInput("\x1b[B");
|
|
154
|
+
assert.strictEqual(overlay.selectedId(), "child:c1");
|
|
155
|
+
overlay.handleInput("\r");
|
|
156
|
+
assert.ok(
|
|
157
|
+
overlay.render(80).some((line) => line.includes("definition scout")),
|
|
158
|
+
overlay.render(80).join("\n"),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
overlay.handleInput("\x1b[A");
|
|
162
|
+
overlay.handleInput("\r");
|
|
163
|
+
const closed = overlay.render(80);
|
|
164
|
+
assert.ok(!closed.some((line) => line.includes("scout")), closed.join("\n"));
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("a group row at the bottom opens its children inside the overlay window", () => {
|
|
168
|
+
const rows = Array.from({ length: 12 }, (_, index) =>
|
|
169
|
+
row({ id: `child:${index}`, label: `row ${index}` }),
|
|
170
|
+
);
|
|
171
|
+
rows.push(
|
|
172
|
+
row({ id: "run:parent", runId: "parent", label: "fanout", childCount: 2 }),
|
|
173
|
+
row({ id: "child:c0", parentId: "run:parent", runId: "c0", label: "scout" }),
|
|
174
|
+
row({ id: "child:c1", parentId: "run:parent", runId: "c1", label: "reviewer" }),
|
|
175
|
+
);
|
|
176
|
+
const overlay = make(() => snapshot({ rows }));
|
|
177
|
+
for (let index = 0; index < 12; index += 1) overlay.handleInput("\x1b[B");
|
|
178
|
+
assert.strictEqual(overlay.selectedId(), "run:parent");
|
|
179
|
+
|
|
180
|
+
overlay.handleInput("\r");
|
|
181
|
+
const open = overlay.render(80);
|
|
182
|
+
assert.ok(
|
|
183
|
+
open.some((line) => line.includes("fanout")),
|
|
184
|
+
open.join("\n"),
|
|
185
|
+
);
|
|
186
|
+
assert.ok(
|
|
187
|
+
open.some((line) => line.includes("scout")),
|
|
188
|
+
open.join("\n"),
|
|
189
|
+
);
|
|
190
|
+
assert.ok(
|
|
191
|
+
open.some((line) => line.includes("reviewer")),
|
|
192
|
+
open.join("\n"),
|
|
193
|
+
);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("vim keys move only when the shared toggle is on", () => {
|
|
197
|
+
const current = snapshot({
|
|
198
|
+
rows: [row({ id: "child:r1" }), row({ id: "child:r2" }), row({ id: "child:r3" })],
|
|
199
|
+
});
|
|
200
|
+
const enabled = make(() => current, { router: vimRouter(true) });
|
|
201
|
+
const disabled = make(() => current, { router: vimRouter(false) });
|
|
202
|
+
enabled.handleInput("j");
|
|
203
|
+
disabled.handleInput("j");
|
|
204
|
+
assert.strictEqual(enabled.selectedId(), "child:r2");
|
|
205
|
+
assert.strictEqual(disabled.selectedId(), "child:r1");
|
|
206
|
+
enabled.handleInput("\x1b[B");
|
|
207
|
+
disabled.handleInput("\x1b[B");
|
|
208
|
+
assert.strictEqual(enabled.selectedId(), "child:r3");
|
|
209
|
+
assert.strictEqual(disabled.selectedId(), "child:r2");
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it("a gate row names the children that wait on it", () => {
|
|
213
|
+
const current = snapshot({
|
|
214
|
+
rows: [row({ id: "child:r1" })],
|
|
215
|
+
gates: [gate({ gate: "deploy", childRunIds: ["run:child:0", "run:child:1"] })],
|
|
216
|
+
});
|
|
217
|
+
const overlay = make(() => current);
|
|
218
|
+
assert.ok(
|
|
219
|
+
overlay.render(80).some((line) => line.includes("2 children")),
|
|
220
|
+
overlay.render(80).join("\n"),
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("escape closes once and returns to the chat", () => {
|
|
225
|
+
const current = snapshot({ rows: [row({ id: "child:r1" })] });
|
|
226
|
+
let closes = 0;
|
|
227
|
+
const overlay = make(() => current, { onClose: () => (closes += 1) });
|
|
228
|
+
overlay.handleInput("\x1b");
|
|
229
|
+
overlay.handleInput("\x1b");
|
|
230
|
+
assert.strictEqual(closes, 1);
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
it("selection survives a snapshot replacement", () => {
|
|
234
|
+
let current = snapshot({
|
|
235
|
+
rows: [row({ id: "child:r1" }), row({ id: "child:r2" }), row({ id: "child:r3" })],
|
|
236
|
+
});
|
|
237
|
+
const actions: string[] = [];
|
|
238
|
+
const overlay = make(() => current, { onAction: (id) => actions.push(id) });
|
|
239
|
+
overlay.handleInput("\x1b[B");
|
|
240
|
+
overlay.handleInput("\x1b[B");
|
|
241
|
+
assert.strictEqual(overlay.selectedId(), "child:r3");
|
|
242
|
+
overlay.handleInput("\x1b[A");
|
|
243
|
+
assert.strictEqual(overlay.selectedId(), "child:r2");
|
|
244
|
+
current = snapshot({ rows: [row({ id: "child:r1" }), row({ id: "child:r3" })] });
|
|
245
|
+
overlay.render(60);
|
|
246
|
+
assert.strictEqual(overlay.selectedId(), "child:r3");
|
|
247
|
+
assert.deepStrictEqual(actions, []);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("a snapshot with no rows still renders the lane summary, the footer and no cursor", () => {
|
|
251
|
+
const current = snapshot({
|
|
252
|
+
rows: [],
|
|
253
|
+
lanes: [{ name: "coding", running: 0, queued: 0, answered: 0 }],
|
|
254
|
+
});
|
|
255
|
+
const overlay = make(() => current);
|
|
256
|
+
const lines = overlay.render(80);
|
|
257
|
+
assert.ok(lines.some((line) => line.includes("coding: running 0, queued 0, answered 0")));
|
|
258
|
+
assert.strictEqual(lines.at(-2)?.includes(OVERLAY_FOOTER), true);
|
|
259
|
+
assert.strictEqual(overlay.selectedId(), undefined);
|
|
260
|
+
overlay.handleInput("\r");
|
|
261
|
+
assert.strictEqual(overlay.selectedId(), undefined);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it("the lane summary reuses the house formatter", () => {
|
|
265
|
+
const lanes = [
|
|
266
|
+
{ name: "coding", running: 1, queued: 0, answered: 0 },
|
|
267
|
+
{ name: "review", running: 0, queued: 0, answered: 2 },
|
|
268
|
+
];
|
|
269
|
+
const overlay = make(() => snapshot({ rows: [row({ id: "child:r1" })], lanes }));
|
|
270
|
+
const lines = overlay.render(70);
|
|
271
|
+
for (const lane of lanes) {
|
|
272
|
+
assert.ok(
|
|
273
|
+
lines.some((line) => line.includes(laneLine(lane))),
|
|
274
|
+
laneLine(lane),
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("the omitted line reuses the house sentence", () => {
|
|
280
|
+
const withOmitted = make(() => snapshot({ rows: [row({ id: "child:r1" })], omitted: 5 }));
|
|
281
|
+
assert.ok(withOmitted.render(60).some((line) => line.includes("5 older runs not shown.")));
|
|
282
|
+
|
|
283
|
+
const without = make(() => snapshot({ rows: [row({ id: "child:r1" })], omitted: 0 }));
|
|
284
|
+
assert.ok(!without.render(60).some((line) => line.includes("older runs not shown.")));
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
it("pending gates are listed oldest first", () => {
|
|
288
|
+
const current = snapshot({
|
|
289
|
+
rows: [row({ id: "child:r1" })],
|
|
290
|
+
gates: [
|
|
291
|
+
gate({ gate: "later", idleMs: 1_000 }),
|
|
292
|
+
gate({ gate: "oldest", idleMs: 3_000 }),
|
|
293
|
+
gate({ gate: "middle", idleMs: 2_000 }),
|
|
294
|
+
],
|
|
295
|
+
});
|
|
296
|
+
const overlay = make(() => current);
|
|
297
|
+
const lines = overlay.render(80);
|
|
298
|
+
const order = ["oldest", "middle", "later"].map((name) =>
|
|
299
|
+
lines.findIndex((line) => line.includes(`gate ${name}`)),
|
|
300
|
+
);
|
|
301
|
+
assert.ok(order[0]! >= 0 && order[0]! < order[1]! && order[1]! < order[2]!, lines.join("\n"));
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("the overlay bounds itself and scrolls to the cursor", () => {
|
|
305
|
+
const rows = Array.from({ length: 40 }, (_, index) =>
|
|
306
|
+
row({ id: `row ${index}`, label: `row ${index}` }),
|
|
307
|
+
);
|
|
308
|
+
const overlay = make(() => snapshot({ rows }));
|
|
309
|
+
overlay.handleInput("\x1b[A");
|
|
310
|
+
for (let index = 0; index < 39; index += 1) overlay.handleInput("\x1b[B");
|
|
311
|
+
const lines = overlay.render(80);
|
|
312
|
+
assert.ok(lines.some((line) => line.includes("row 39")));
|
|
313
|
+
assert.ok(!lines.some((line) => line.includes("row 0")), lines.join("\n"));
|
|
314
|
+
assert.strictEqual(lines.filter((line) => line.includes("row ")).length, 12);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("the footer is the pinned key line", () => {
|
|
318
|
+
const overlay = make(() => snapshot({ rows: [row({ id: "child:r1" })] }));
|
|
319
|
+
assert.strictEqual(overlay.render(80).at(-2)?.includes(OVERLAY_FOOTER), true);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("the overlay renders inside the house box with its label", () => {
|
|
323
|
+
const overlay = make(() => snapshot({ rows: [row({ id: "child:r1" })] }));
|
|
324
|
+
const lines = overlay.render(80);
|
|
325
|
+
assert.ok(lines[0]?.includes("Delegates"));
|
|
326
|
+
for (const line of lines) assert.ok(visibleWidth(line) <= 80, `${visibleWidth(line)}: ${line}`);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("the status line renders above the footer when present", () => {
|
|
330
|
+
const overlay = make(() => snapshot({ rows: [row({ id: "child:r1" })] }), {
|
|
331
|
+
statusLine: () => "stopped run run:one",
|
|
332
|
+
});
|
|
333
|
+
const lines = overlay.render(80);
|
|
334
|
+
const status = lines.findIndex((line) => line.includes("stopped run run:one"));
|
|
335
|
+
const footer = lines.findIndex((line) => line.includes(OVERLAY_FOOTER));
|
|
336
|
+
assert.ok(status >= 0 && status < footer, lines.join("\n"));
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
it("i expands the selected row into its detail block", () => {
|
|
340
|
+
const current = snapshot({
|
|
341
|
+
rows: [
|
|
342
|
+
row({
|
|
343
|
+
id: "child:r1",
|
|
344
|
+
label: "deployer",
|
|
345
|
+
lane: "coding",
|
|
346
|
+
status: "waiting",
|
|
347
|
+
conversationId: 7,
|
|
348
|
+
gates: ["deploy"],
|
|
349
|
+
diagnostic: null,
|
|
350
|
+
idleMs: 4_000,
|
|
351
|
+
}),
|
|
352
|
+
],
|
|
353
|
+
});
|
|
354
|
+
const overlay = make(() => current);
|
|
355
|
+
overlay.handleInput("i");
|
|
356
|
+
const rendered = overlay.render(80);
|
|
357
|
+
const lines = rendered.join("\n");
|
|
358
|
+
assert.match(lines, /definition deployer · lane coding · status waiting/);
|
|
359
|
+
assert.match(lines, /conversation 7 · gates deploy/);
|
|
360
|
+
assert.match(lines, /diagnostic none · age 4s/);
|
|
361
|
+
assert.ok(rendered.some((line) => line.includes(" ├ definition deployer")));
|
|
362
|
+
assert.ok(rendered.some((line) => line.includes(" └ diagnostic none")));
|
|
363
|
+
assert.ok(!rendered.some((line) => line.includes("→ definition")));
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("a finished detail block names took instead of an age", () => {
|
|
367
|
+
const current = snapshot({
|
|
368
|
+
rows: [
|
|
369
|
+
row({
|
|
370
|
+
id: "child:r1",
|
|
371
|
+
label: "deployer",
|
|
372
|
+
status: "stopped",
|
|
373
|
+
durationMs: 12_000,
|
|
374
|
+
idleMs: 60_000,
|
|
375
|
+
}),
|
|
376
|
+
],
|
|
377
|
+
});
|
|
378
|
+
const overlay = make(() => current);
|
|
379
|
+
overlay.handleInput("i");
|
|
380
|
+
const lines = overlay.render(80).join("\n");
|
|
381
|
+
assert.match(lines, /took 12s/);
|
|
382
|
+
assert.ok(!lines.includes("age 1m"), lines);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("i again collapses it", () => {
|
|
386
|
+
const current = snapshot({ rows: [row({ id: "child:r1" })] });
|
|
387
|
+
const overlay = make(() => current);
|
|
388
|
+
overlay.handleInput("i");
|
|
389
|
+
assert.match(overlay.render(80).join("\n"), /definition/);
|
|
390
|
+
overlay.handleInput("i");
|
|
391
|
+
assert.ok(!overlay.render(80).join("\n").includes("definition "));
|
|
392
|
+
assert.strictEqual(overlay.selectedId(), "child:r1");
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
it("i expands a gate row with the gate's own fields", () => {
|
|
396
|
+
const current = snapshot({
|
|
397
|
+
rows: [row({ id: "child:r1" })],
|
|
398
|
+
gates: [gate({ gate: "deploy", lane: "coding", tool: "bash", idleMs: 40_000 })],
|
|
399
|
+
});
|
|
400
|
+
const overlay = make(() => current);
|
|
401
|
+
overlay.handleInput("\x1b[B");
|
|
402
|
+
overlay.handleInput("i");
|
|
403
|
+
assert.match(
|
|
404
|
+
overlay.render(80).join("\n"),
|
|
405
|
+
/gate deploy · run run:one · lane coding · bash · 40s/,
|
|
406
|
+
);
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("enter expands the selected run row and dispatches no action", () => {
|
|
410
|
+
const current = snapshot({ rows: [row({ id: "child:r1", label: "deployer" })] });
|
|
411
|
+
const actions: string[] = [];
|
|
412
|
+
const overlay = make(() => current, { onAction: (id, verb) => actions.push(`${id}:${verb}`) });
|
|
413
|
+
overlay.handleInput("\r");
|
|
414
|
+
assert.match(overlay.render(80).join("\n"), /definition deployer/);
|
|
415
|
+
assert.deepStrictEqual(actions, []);
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
it("enter expands a gate row and dispatches no action", () => {
|
|
419
|
+
const current = snapshot({
|
|
420
|
+
rows: [],
|
|
421
|
+
gates: [gate({ gate: "deploy", lane: "coding", tool: "bash", idleMs: 40_000 })],
|
|
422
|
+
});
|
|
423
|
+
const actions: string[] = [];
|
|
424
|
+
const overlay = make(() => current, { onAction: (id, verb) => actions.push(`${id}:${verb}`) });
|
|
425
|
+
overlay.handleInput("\r");
|
|
426
|
+
assert.match(
|
|
427
|
+
overlay.render(80).join("\n"),
|
|
428
|
+
/gate deploy · run run:one · lane coding · bash · 40s/,
|
|
429
|
+
);
|
|
430
|
+
assert.deepStrictEqual(actions, []);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it("a finished row names took with a fixed duration, not an age", () => {
|
|
434
|
+
const current = snapshot({
|
|
435
|
+
rows: [
|
|
436
|
+
row({ id: "child:r1", label: "deployer", status: "stopped", durationMs: 12_000 }),
|
|
437
|
+
row({ id: "child:r2", label: "scout", status: "answered", durationMs: 72_000 }),
|
|
438
|
+
],
|
|
439
|
+
});
|
|
440
|
+
const overlay = make(() => current);
|
|
441
|
+
const lines = overlay.render(80);
|
|
442
|
+
assert.ok(
|
|
443
|
+
lines.some((line) => line.includes("deployer · stopped · took 12s")),
|
|
444
|
+
lines.join("\n"),
|
|
445
|
+
);
|
|
446
|
+
assert.ok(
|
|
447
|
+
lines.some((line) => line.includes("scout · answered · took 1m 12s")),
|
|
448
|
+
lines.join("\n"),
|
|
449
|
+
);
|
|
450
|
+
assert.ok(!lines.some((line) => line.includes("ago")), lines.join("\n"));
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it("s stops, a approves and d denies", () => {
|
|
454
|
+
const current = snapshot({
|
|
455
|
+
rows: [row({ id: "child:r1" })],
|
|
456
|
+
gates: [gate({ gate: "deploy" })],
|
|
457
|
+
});
|
|
458
|
+
const actions: string[] = [];
|
|
459
|
+
const overlay = make(() => current, { onAction: (id, verb) => actions.push(`${id}:${verb}`) });
|
|
460
|
+
overlay.handleInput("s");
|
|
461
|
+
overlay.handleInput("\x1b[B");
|
|
462
|
+
overlay.handleInput("a");
|
|
463
|
+
overlay.handleInput("d");
|
|
464
|
+
assert.deepStrictEqual(actions, [
|
|
465
|
+
"child:r1:stop",
|
|
466
|
+
"gate:run:one:deploy:approve",
|
|
467
|
+
"gate:run:one:deploy:deny",
|
|
468
|
+
]);
|
|
469
|
+
});
|
|
470
|
+
|
|
471
|
+
it("the status line survives the push that settles the row", () => {
|
|
472
|
+
let current = snapshot({ rows: [row({ id: "child:r1", label: "r1", status: "running" })] });
|
|
473
|
+
const overlay = make(() => current, { statusLine: () => "stopped run r1" });
|
|
474
|
+
current = snapshot({ rows: [row({ id: "child:r1", label: "r1", status: "stopped" })] });
|
|
475
|
+
const lines = overlay.render(80).join("\n");
|
|
476
|
+
assert.match(lines, /stopped run r1/);
|
|
477
|
+
assert.match(lines, /r1 · stopped/);
|
|
478
|
+
});
|
|
479
|
+
|
|
480
|
+
it("one row expands at a time", () => {
|
|
481
|
+
let current = snapshot({
|
|
482
|
+
rows: [row({ id: "child:r1", label: "r1" }), row({ id: "child:r2", label: "r2" })],
|
|
483
|
+
});
|
|
484
|
+
const overlay = make(() => current);
|
|
485
|
+
overlay.handleInput("i");
|
|
486
|
+
overlay.handleInput("\x1b[B");
|
|
487
|
+
overlay.handleInput("i");
|
|
488
|
+
const lines = overlay.render(80);
|
|
489
|
+
assert.strictEqual(lines.filter((line) => line.includes("definition ")).length, 1);
|
|
490
|
+
const expanded = lines.findIndex((line) => line.includes("definition "));
|
|
491
|
+
const second = lines.findIndex((line) => line.includes("r2 · running"));
|
|
492
|
+
assert.ok(expanded > second, lines.join("\n"));
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
it("the expansion survives a snapshot replacement", () => {
|
|
496
|
+
let current = snapshot({ rows: [row({ id: "child:r1", label: "r1", tool: "bash" })] });
|
|
497
|
+
const overlay = make(() => current);
|
|
498
|
+
overlay.handleInput("i");
|
|
499
|
+
current = snapshot({
|
|
500
|
+
rows: [row({ id: "child:r1", label: "r1", tool: "read", idleMs: 9_000 })],
|
|
501
|
+
});
|
|
502
|
+
assert.match(overlay.render(80).join("\n"), /r1 · running · read/);
|
|
503
|
+
assert.match(overlay.render(80).join("\n"), /age 9s/);
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it("the expansion closes when its row leaves the snapshot", () => {
|
|
507
|
+
let current = snapshot({
|
|
508
|
+
rows: [row({ id: "child:r1", label: "r1" }), row({ id: "child:r2", label: "r2" })],
|
|
509
|
+
});
|
|
510
|
+
const overlay = make(() => current);
|
|
511
|
+
overlay.handleInput("i");
|
|
512
|
+
current = snapshot({ rows: [row({ id: "child:r2", label: "r2" })] });
|
|
513
|
+
const lines = overlay.render(80);
|
|
514
|
+
assert.ok(!lines.some((line) => line.includes("definition ")), lines.join("\n"));
|
|
515
|
+
assert.strictEqual(overlay.selectedId(), "child:r2");
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
const request = (input: Partial<RequestRow> & { readonly requestId: string }): RequestRow => ({
|
|
519
|
+
id: `request:run:one:${input.requestId}`,
|
|
520
|
+
runId: "run:one",
|
|
521
|
+
prompt: "Which environment?",
|
|
522
|
+
options: ["staging", "production"],
|
|
523
|
+
deadline: 9_000,
|
|
524
|
+
...input,
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
it("the overlay names a request on its run row and in its own section", () => {
|
|
528
|
+
const current = snapshot({
|
|
529
|
+
rows: [row({ id: "run:run:one", requests: ["12:c1"] })],
|
|
530
|
+
requests: [request({ requestId: "12:c1" })],
|
|
531
|
+
});
|
|
532
|
+
const rows = rowsOf(current);
|
|
533
|
+
const run = rows.find((entry) => entry.id === "run:run:one");
|
|
534
|
+
assert.ok(run?.lines[0]?.endsWith("request 12:c1"), run?.lines[0] ?? "");
|
|
535
|
+
assert.strictEqual(rows.filter((entry) => entry.header === GATES_HEADER).length, 0);
|
|
536
|
+
assert.strictEqual(rows.filter((entry) => entry.header === REQUESTS_HEADER).length, 1);
|
|
537
|
+
|
|
538
|
+
const expanded = rowsOf(current, "request:run:one:12:c1");
|
|
539
|
+
const detail = expanded.find((entry) => entry.id === "request:run:one:12:c1")?.lines ?? [];
|
|
540
|
+
assert.ok(
|
|
541
|
+
detail.some((line) => line.includes("Which environment?")),
|
|
542
|
+
detail.join("\n"),
|
|
543
|
+
);
|
|
544
|
+
assert.ok(
|
|
545
|
+
detail.some((line) => line.includes(new Date(9_000).toISOString())),
|
|
546
|
+
detail.join("\n"),
|
|
547
|
+
);
|
|
548
|
+
assert.ok(
|
|
549
|
+
detail.some((line) => line.includes("staging, production")),
|
|
550
|
+
detail.join("\n"),
|
|
551
|
+
);
|
|
552
|
+
for (const line of detail.slice(1)) assert.ok(line.length <= REQUEST_DETAIL_WIDTH, line);
|
|
553
|
+
});
|