pi-render-btw 0.6.10 → 0.6.12
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 +16 -0
- package/README.md +18 -1
- package/extensions/btw/peek.test.ts +33 -0
- package/extensions/btw/peek.ts +164 -7
- package/extensions/btw/transcript-store.ts +616 -0
- package/extensions/btw-transcript.test.ts +512 -2
- package/extensions/btw.ts +1050 -118
- package/package.json +2 -1
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import path from "node:path";
|
|
1
4
|
import { describe, expect, it } from "vitest";
|
|
2
5
|
import { BtwOverlayComponent } from "./btw.ts";
|
|
6
|
+
import { BtwTranscriptStore } from "./btw/transcript-store.ts";
|
|
3
7
|
|
|
4
8
|
const theme = {
|
|
5
9
|
bg: (_name: string, text: string) => text,
|
|
@@ -37,7 +41,7 @@ describe("BTW transcript message layout", () => {
|
|
|
37
41
|
{ id: 1, turnId: 1, type: "user-message", text: "Prompt" },
|
|
38
42
|
]);
|
|
39
43
|
|
|
40
|
-
expect(lines.slice(0, 2)).toEqual(["
|
|
44
|
+
expect(lines.slice(0, 2)).toEqual([" USER ", " Prompt"]);
|
|
41
45
|
});
|
|
42
46
|
|
|
43
47
|
it("keeps assistant heading and response on separate lines", () => {
|
|
@@ -45,7 +49,7 @@ describe("BTW transcript message layout", () => {
|
|
|
45
49
|
{ id: 1, turnId: 1, type: "assistant-text", text: "Response", streaming: false },
|
|
46
50
|
]);
|
|
47
51
|
|
|
48
|
-
expect(lines[0]).toBe("
|
|
52
|
+
expect(lines[0]).toBe(" ASSISTANT ");
|
|
49
53
|
expect(lines[1].startsWith(" Response")).toBe(true);
|
|
50
54
|
});
|
|
51
55
|
|
|
@@ -166,6 +170,512 @@ describe("BTW transcript message layout", () => {
|
|
|
166
170
|
expect(component.getDraft()).toBe("draft prompt");
|
|
167
171
|
});
|
|
168
172
|
|
|
173
|
+
it("selects exactly one rendered block on an explicit normalized click", () => {
|
|
174
|
+
const component = new BtwOverlayComponent(
|
|
175
|
+
tui,
|
|
176
|
+
theme,
|
|
177
|
+
keybindings,
|
|
178
|
+
() => [
|
|
179
|
+
{ id: 1, turnId: 1, type: "user-message", text: "Prompt" },
|
|
180
|
+
{ id: 2, turnId: 1, type: "assistant-text", text: "Response", streaming: false },
|
|
181
|
+
] as any,
|
|
182
|
+
() => null,
|
|
183
|
+
() => "contextual",
|
|
184
|
+
() => {},
|
|
185
|
+
() => {},
|
|
186
|
+
() => {},
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
component.handleInput("\x10");
|
|
190
|
+
component.render(80);
|
|
191
|
+
const starts = (component as any).peekBlockStarts as number[];
|
|
192
|
+
const contentTop = (component as any).peekContentTop as number;
|
|
193
|
+
expect(starts).toHaveLength(2);
|
|
194
|
+
const before = (component as any).peekState.selectedIndex;
|
|
195
|
+
component.handleMouse({ action: "move", button: 0, x: 5, y: contentTop + starts[1] } as any);
|
|
196
|
+
expect((component as any).peekHoveredIndex).toBe(1);
|
|
197
|
+
expect((component as any).peekState.selectedIndex).toBe(before);
|
|
198
|
+
component.handleMouse({ action: "press", button: 0, x: 5, y: contentTop + starts[1] } as any);
|
|
199
|
+
component.handleMouse({ action: "release", button: 0, x: 5, y: contentTop + starts[1] } as any);
|
|
200
|
+
component.handleInput(`\x1b[<0;5;${contentTop + starts[1]}M`);
|
|
201
|
+
component.handleInput(`\x1b[<0;5;${contentTop + starts[1]}m`);
|
|
202
|
+
expect((component as any).peekState.selectedIndex).toBe(before);
|
|
203
|
+
component.handleMouse({ action: "click", button: 0, x: 5, y: contentTop + starts[1] } as any);
|
|
204
|
+
expect((component as any).peekState.selectedIndex).toBe(1);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("accepts the host TUI mouse shape and ignores separator clicks", () => {
|
|
208
|
+
const component = new BtwOverlayComponent(
|
|
209
|
+
tui,
|
|
210
|
+
theme,
|
|
211
|
+
keybindings,
|
|
212
|
+
() => [
|
|
213
|
+
{ id: 1, turnId: 1, type: "user-message", text: "Prompt" },
|
|
214
|
+
{ id: 2, turnId: 1, type: "assistant-text", text: "Response", streaming: false },
|
|
215
|
+
] as any,
|
|
216
|
+
() => null,
|
|
217
|
+
() => "contextual",
|
|
218
|
+
() => {},
|
|
219
|
+
() => {},
|
|
220
|
+
() => {},
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
component.handleInput("\x10");
|
|
224
|
+
component.render(80);
|
|
225
|
+
const starts = (component as any).peekBlockStarts as number[];
|
|
226
|
+
const ends = (component as any).peekBlockEnds as number[];
|
|
227
|
+
const contentTop = (component as any).peekContentTop as number;
|
|
228
|
+
component.handleMouse({
|
|
229
|
+
type: "click", button: "left", x: 5, y: contentTop + starts[1] - 1,
|
|
230
|
+
} as any);
|
|
231
|
+
expect((component as any).peekState.selectedIndex).toBe(1);
|
|
232
|
+
|
|
233
|
+
// The blank separator after the second block is not an interactive span.
|
|
234
|
+
const before = (component as any).peekState.selectedIndex;
|
|
235
|
+
component.handleMouse({
|
|
236
|
+
type: "click", button: "left", x: 5, y: contentTop + ends[1] - 1,
|
|
237
|
+
} as any);
|
|
238
|
+
expect((component as any).peekState.selectedIndex).toBe(before);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("handles a chat wheel event even before the first transcript render", () => {
|
|
242
|
+
const component = new BtwOverlayComponent(
|
|
243
|
+
tui,
|
|
244
|
+
theme,
|
|
245
|
+
keybindings,
|
|
246
|
+
() => [{
|
|
247
|
+
id: 1,
|
|
248
|
+
turnId: 1,
|
|
249
|
+
type: "assistant-text",
|
|
250
|
+
text: Array.from({ length: 50 }, (_, index) => `Response ${index}`).join("\n"),
|
|
251
|
+
streaming: false,
|
|
252
|
+
}] as any,
|
|
253
|
+
() => null,
|
|
254
|
+
() => "contextual",
|
|
255
|
+
() => {},
|
|
256
|
+
() => {},
|
|
257
|
+
() => {},
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
component.handleMouse({
|
|
261
|
+
type: "wheel", button: "none", x: 5, y: 4, wheelDelta: -1,
|
|
262
|
+
} as any);
|
|
263
|
+
|
|
264
|
+
expect((component as any).transcriptScrollOffset).toBeGreaterThan(0);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("handles the first wheel event immediately after opening a tool preview", () => {
|
|
268
|
+
const component = new BtwOverlayComponent(
|
|
269
|
+
tui,
|
|
270
|
+
theme,
|
|
271
|
+
keybindings,
|
|
272
|
+
() => [
|
|
273
|
+
{ id: 1, turnId: 1, type: "tool-call", toolCallId: "call-1", toolName: "read", args: "src/index.ts" },
|
|
274
|
+
{ id: 2, turnId: 1, type: "tool-result", toolCallId: "call-1", toolName: "read", content: Array.from({ length: 40 }, (_, index) => `line ${index}`).join("\n"), isError: false, truncated: false, streaming: false },
|
|
275
|
+
] as any,
|
|
276
|
+
() => null,
|
|
277
|
+
() => "contextual",
|
|
278
|
+
() => {},
|
|
279
|
+
() => {},
|
|
280
|
+
() => {},
|
|
281
|
+
);
|
|
282
|
+
|
|
283
|
+
component.handleInput("\x10");
|
|
284
|
+
component.render(80);
|
|
285
|
+
component.handleInput("w");
|
|
286
|
+
component.handleMouse({ action: "wheel", button: 0, x: 5, y: 4, delta: 1 } as any);
|
|
287
|
+
|
|
288
|
+
expect((component as any).peekToolPreviewScrollOffset).toBeGreaterThan(0);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it("updates the single selected target while line scrolling across tool rows", () => {
|
|
292
|
+
const component = new BtwOverlayComponent(
|
|
293
|
+
tui,
|
|
294
|
+
theme,
|
|
295
|
+
keybindings,
|
|
296
|
+
() => [
|
|
297
|
+
{ id: 1, turnId: 1, type: "user-message", text: Array.from({ length: 40 }, (_, index) => `Prompt ${index}`).join("\n") },
|
|
298
|
+
{ id: 2, turnId: 1, type: "tool-call", toolCallId: "call-1", toolName: "read", args: "src/index.ts" },
|
|
299
|
+
{ id: 3, turnId: 1, type: "tool-result", toolCallId: "call-1", toolName: "read", content: "done", isError: false, truncated: false, streaming: false },
|
|
300
|
+
{ id: 4, turnId: 1, type: "assistant-text", text: Array.from({ length: 40 }, (_, index) => `Response ${index}`).join("\n"), streaming: false },
|
|
301
|
+
] as any,
|
|
302
|
+
() => null,
|
|
303
|
+
() => "contextual",
|
|
304
|
+
() => {},
|
|
305
|
+
() => {},
|
|
306
|
+
() => {},
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
component.handleInput("\x10");
|
|
310
|
+
component.render(80);
|
|
311
|
+
const starts = (component as any).peekBlockStarts as number[];
|
|
312
|
+
for (let i = 0; i < starts[1]; i++) component.handleInput("j");
|
|
313
|
+
expect((component as any).peekState.selectedIndex).toBe(1);
|
|
314
|
+
component.handleInput("J");
|
|
315
|
+
expect((component as any).peekState.selectedIndex).toBe(3);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it("opens and closes a bounded read-only tool preview without leaving Peek", () => {
|
|
319
|
+
const component = new BtwOverlayComponent(
|
|
320
|
+
tui,
|
|
321
|
+
theme,
|
|
322
|
+
keybindings,
|
|
323
|
+
() => [
|
|
324
|
+
{ id: 1, turnId: 1, type: "tool-call", toolCallId: "call-1", toolName: "read", args: "src/index.ts" },
|
|
325
|
+
{ id: 2, turnId: 1, type: "tool-result", toolCallId: "call-1", toolName: "read", content: Array.from({ length: 40 }, (_, index) => `line ${index}`).join("\n"), isError: false, truncated: false, streaming: false },
|
|
326
|
+
] as any,
|
|
327
|
+
() => null,
|
|
328
|
+
() => "contextual",
|
|
329
|
+
() => {},
|
|
330
|
+
() => {},
|
|
331
|
+
() => {},
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
component.handleInput("\x10");
|
|
335
|
+
expect(component.render(80).join("\n")).toContain("w:preview");
|
|
336
|
+
component.handleInput("\r");
|
|
337
|
+
expect((component as any).expandedToolId).toBe(0);
|
|
338
|
+
component.render(80);
|
|
339
|
+
const starts = (component as any).peekBlockStarts as number[];
|
|
340
|
+
const contentTop = (component as any).peekContentTop as number;
|
|
341
|
+
component.handleMouse({
|
|
342
|
+
action: "click", button: 0, x: 5, y: contentTop + starts[0], clickCount: 2,
|
|
343
|
+
} as any);
|
|
344
|
+
expect((component as any).expandedToolId).toBeNull();
|
|
345
|
+
component.handleInput("w");
|
|
346
|
+
const preview = component.render(80).join("\n");
|
|
347
|
+
expect(preview).toContain("Input:");
|
|
348
|
+
expect(preview).toContain("Output");
|
|
349
|
+
component.handleInput("g");
|
|
350
|
+
const beforeWheel = (component as any).peekToolPreviewScrollOffset as number;
|
|
351
|
+
component.handleMouse({ action: "wheel", button: 0, x: 5, y: 4, delta: 1 } as any);
|
|
352
|
+
expect((component as any).peekToolPreviewScrollOffset).toBeGreaterThan(beforeWheel);
|
|
353
|
+
component.handleInput("G");
|
|
354
|
+
const previewState = (component as any).peekState;
|
|
355
|
+
const previewOffset = (component as any).peekToolPreviewScrollOffset as number;
|
|
356
|
+
expect(previewOffset).toBeLessThanOrEqual(
|
|
357
|
+
Math.max(0, ((component as any).peekToolPreviewLines as string[]).length - previewState.viewportHeight),
|
|
358
|
+
);
|
|
359
|
+
component.handleInput("j");
|
|
360
|
+
expect((component as any).peekToolPreviewScrollOffset).toBe(previewOffset);
|
|
361
|
+
component.handleInput("g");
|
|
362
|
+
expect((component as any).peekToolPreviewScrollOffset).toBe(0);
|
|
363
|
+
component.handleInput("q");
|
|
364
|
+
expect((component as any).peekState.active).toBe(true);
|
|
365
|
+
expect((component as any).peekToolPreviewIndex).toBeNull();
|
|
366
|
+
component.handleInput("q");
|
|
367
|
+
expect((component as any).peekState.active).toBe(false);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("keeps the rendered overlay within a short terminal height", () => {
|
|
371
|
+
const shortTui = { ...tui, terminal: { write: () => {}, rows: 10 } } as any;
|
|
372
|
+
const component = new BtwOverlayComponent(
|
|
373
|
+
shortTui,
|
|
374
|
+
theme,
|
|
375
|
+
keybindings,
|
|
376
|
+
() => [{ id: 1, turnId: 1, type: "assistant-text", text: "A\nB\nC", streaming: false }] as any,
|
|
377
|
+
() => null,
|
|
378
|
+
() => "contextual",
|
|
379
|
+
() => {},
|
|
380
|
+
() => {},
|
|
381
|
+
() => {},
|
|
382
|
+
);
|
|
383
|
+
|
|
384
|
+
expect(component.render(80)).toHaveLength(10);
|
|
385
|
+
component.handleInput("\x10");
|
|
386
|
+
expect(component.render(80)).toHaveLength(10);
|
|
387
|
+
});
|
|
388
|
+
|
|
389
|
+
it("persists line-delimited snapshots and complete tool artifacts", () => {
|
|
390
|
+
const projectDir = mkdtempSync(path.join(tmpdir(), "pi-btw-store-test-"));
|
|
391
|
+
try {
|
|
392
|
+
const store = new BtwTranscriptStore(projectDir, "session-1");
|
|
393
|
+
const snapshot = store.appendSnapshot({
|
|
394
|
+
mode: "contextual",
|
|
395
|
+
entries: [
|
|
396
|
+
{ id: 1, turnId: 1, type: "turn-boundary", phase: "start" },
|
|
397
|
+
{ id: 2, turnId: 1, type: "tool-call", toolCallId: "call-1", toolName: "write", args: "{\"path\":\"a\"}" },
|
|
398
|
+
{ id: 3, turnId: 1, type: "tool-result", toolCallId: "call-1", toolName: "write", content: "ok", fullContent: "ok", truncated: false, isError: false, streaming: false },
|
|
399
|
+
],
|
|
400
|
+
nextEntryId: 4,
|
|
401
|
+
nextTurnId: 2,
|
|
402
|
+
currentTurnId: null,
|
|
403
|
+
lastTurnId: 1,
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
expect(readFileSync(store.transcriptPath, "utf8").trim().split(/\r?\n/)).toHaveLength(1);
|
|
407
|
+
expect(store.readSnapshot(snapshot.recordId)?.snapshot.entries).toHaveLength(3);
|
|
408
|
+
|
|
409
|
+
store.writeToolArtifact({
|
|
410
|
+
toolCallId: "call-1",
|
|
411
|
+
toolName: "write",
|
|
412
|
+
phase: "start",
|
|
413
|
+
input: { path: "a" },
|
|
414
|
+
});
|
|
415
|
+
store.writeToolArtifact({
|
|
416
|
+
toolCallId: "call-1",
|
|
417
|
+
toolName: "write",
|
|
418
|
+
phase: "end",
|
|
419
|
+
output: { content: [{ type: "text", text: "ok" }], details: { durationMs: 3, diff: "@@ -1 +1 @@" } },
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
const artifact = store.readToolArtifact("call-1");
|
|
423
|
+
expect(artifact?.input).toEqual({ path: "a" });
|
|
424
|
+
expect(artifact?.details).toEqual({ durationMs: 3, diff: "@@ -1 +1 @@" });
|
|
425
|
+
expect(artifact?.diff).toBe("@@ -1 +1 @@\n");
|
|
426
|
+
} finally {
|
|
427
|
+
rmSync(projectDir, { recursive: true, force: true });
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
|
|
431
|
+
it("recovers a valid record appended after an unterminated EOF", () => {
|
|
432
|
+
const projectDir = mkdtempSync(path.join(tmpdir(), "pi-btw-store-eof-test-"));
|
|
433
|
+
try {
|
|
434
|
+
const store = new BtwTranscriptStore(projectDir, "session-eof");
|
|
435
|
+
const base = {
|
|
436
|
+
mode: "contextual" as const,
|
|
437
|
+
entries: [],
|
|
438
|
+
nextEntryId: 1,
|
|
439
|
+
nextTurnId: 1,
|
|
440
|
+
currentTurnId: null,
|
|
441
|
+
lastTurnId: null,
|
|
442
|
+
};
|
|
443
|
+
store.appendSnapshot(base);
|
|
444
|
+
writeFileSync(store.transcriptPath, readFileSync(store.transcriptPath, "utf8").replace(/\n$/, ""));
|
|
445
|
+
|
|
446
|
+
const next = store.appendSnapshot(base);
|
|
447
|
+
const lines = readFileSync(store.transcriptPath, "utf8").trim().split(/\r?\n/);
|
|
448
|
+
expect(lines).toHaveLength(2);
|
|
449
|
+
expect(store.readSnapshot(next.recordId)?.snapshot.recordId).toBe(next.recordId);
|
|
450
|
+
} finally {
|
|
451
|
+
rmSync(projectDir, { recursive: true, force: true });
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
it("coalesces queued snapshots and tool updates until an explicit flush", async () => {
|
|
456
|
+
const projectDir = mkdtempSync(path.join(tmpdir(), "pi-btw-store-queue-test-"));
|
|
457
|
+
try {
|
|
458
|
+
const store = new BtwTranscriptStore(projectDir, "session-queue");
|
|
459
|
+
const first = store.enqueueSnapshot({
|
|
460
|
+
mode: "contextual",
|
|
461
|
+
entries: [],
|
|
462
|
+
nextEntryId: 1,
|
|
463
|
+
nextTurnId: 1,
|
|
464
|
+
currentTurnId: null,
|
|
465
|
+
lastTurnId: null,
|
|
466
|
+
});
|
|
467
|
+
const second = store.enqueueSnapshot({
|
|
468
|
+
mode: "tangent",
|
|
469
|
+
entries: [{ id: 1, turnId: 1, type: "turn-boundary", phase: "start" }],
|
|
470
|
+
nextEntryId: 2,
|
|
471
|
+
nextTurnId: 2,
|
|
472
|
+
currentTurnId: 1,
|
|
473
|
+
lastTurnId: 1,
|
|
474
|
+
});
|
|
475
|
+
store.enqueueToolArtifact({
|
|
476
|
+
toolCallId: "call-queue",
|
|
477
|
+
toolName: "read",
|
|
478
|
+
phase: "start",
|
|
479
|
+
input: { path: "a.txt" },
|
|
480
|
+
});
|
|
481
|
+
store.enqueueToolArtifact({
|
|
482
|
+
toolCallId: "call-queue",
|
|
483
|
+
toolName: "read",
|
|
484
|
+
phase: "update",
|
|
485
|
+
output: { content: [{ type: "text", text: "partial" }] },
|
|
486
|
+
});
|
|
487
|
+
store.enqueueToolArtifact({
|
|
488
|
+
toolCallId: "call-queue",
|
|
489
|
+
toolName: "read",
|
|
490
|
+
phase: "end",
|
|
491
|
+
output: { content: [{ type: "text", text: "complete" }] },
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
expect(existsSync(store.transcriptPath)).toBe(false);
|
|
495
|
+
await store.flush();
|
|
496
|
+
|
|
497
|
+
expect(store.readSnapshot(first.recordId)).toBeNull();
|
|
498
|
+
expect(store.readSnapshot(second.recordId)?.snapshot.mode).toBe("tangent");
|
|
499
|
+
expect(store.readToolArtifact("call-queue")?.input).toEqual({ path: "a.txt" });
|
|
500
|
+
expect(store.readToolArtifact("call-queue")?.output).toEqual({ content: [{ type: "text", text: "complete" }] });
|
|
501
|
+
} finally {
|
|
502
|
+
rmSync(projectDir, { recursive: true, force: true });
|
|
503
|
+
}
|
|
504
|
+
});
|
|
505
|
+
|
|
506
|
+
it("focuses and expands a live tool, scrolls locally, and opens Ctrl+O output", () => {
|
|
507
|
+
const entries = [
|
|
508
|
+
{ id: 1, turnId: 1, type: "tool-call", toolCallId: "call-1", toolName: "write", args: "compact input" },
|
|
509
|
+
{ id: 2, turnId: 1, type: "tool-result", toolCallId: "call-1", toolName: "write", content: "compact output", fullContent: Array.from({ length: 40 }, (_, index) => `line ${index}`).join("\n"), truncated: true, isError: false, streaming: false },
|
|
510
|
+
] as any;
|
|
511
|
+
const artifact = {
|
|
512
|
+
toolCallId: "call-1",
|
|
513
|
+
toolName: "write",
|
|
514
|
+
phase: "end" as const,
|
|
515
|
+
isError: false,
|
|
516
|
+
input: { path: "full.txt" },
|
|
517
|
+
output: { content: [{ type: "text", text: "full output" }] },
|
|
518
|
+
details: { durationMs: 3 },
|
|
519
|
+
diff: "@@ -1 +1 @@\n",
|
|
520
|
+
};
|
|
521
|
+
let dismissed = 0;
|
|
522
|
+
const component = new BtwOverlayComponent(
|
|
523
|
+
tui,
|
|
524
|
+
theme,
|
|
525
|
+
keybindings,
|
|
526
|
+
() => entries,
|
|
527
|
+
() => null,
|
|
528
|
+
() => "contextual",
|
|
529
|
+
() => {},
|
|
530
|
+
() => { dismissed++; },
|
|
531
|
+
() => {},
|
|
532
|
+
undefined,
|
|
533
|
+
undefined,
|
|
534
|
+
() => artifact,
|
|
535
|
+
);
|
|
536
|
+
|
|
537
|
+
component.render(80);
|
|
538
|
+
const contentTop = (component as any).transcriptContentTop as number;
|
|
539
|
+
const hostToolRow = contentTop - 1;
|
|
540
|
+
component.handleMouse({ type: "press", button: "left", x: 5, y: hostToolRow } as any);
|
|
541
|
+
component.handleMouse({ type: "release", button: "left", x: 5, y: hostToolRow } as any);
|
|
542
|
+
expect((component as any).liveFocusedToolCallId).toBeNull();
|
|
543
|
+
|
|
544
|
+
component.handleMouse({ type: "move", button: "none", x: 5, y: hostToolRow } as any);
|
|
545
|
+
expect((component as any).liveHoveredEntryId).toBe(1);
|
|
546
|
+
component.handleMouse({ type: "click", button: "left", x: 5, y: hostToolRow } as any);
|
|
547
|
+
expect((component as any).liveFocusedToolCallId).toBe("call-1");
|
|
548
|
+
expect((component as any).liveExpandedToolCallId).toBe("call-1");
|
|
549
|
+
(component as any).followTranscript = false;
|
|
550
|
+
(component as any).transcriptScrollOffset = 0;
|
|
551
|
+
expect(component.render(80).join("\n")).toContain("line 0");
|
|
552
|
+
|
|
553
|
+
component.handleMouse({ type: "wheel", button: "none", x: 5, y: hostToolRow, wheelDelta: 1 } as any);
|
|
554
|
+
expect((component as any).transcriptScrollOffset).toBeGreaterThan(0);
|
|
555
|
+
|
|
556
|
+
component.handleInput("\x0f");
|
|
557
|
+
const output = component.render(80).join("\n");
|
|
558
|
+
expect(output).toContain("BTW Tool Output");
|
|
559
|
+
expect(output).toContain("full.txt");
|
|
560
|
+
expect(output).toContain("durationMs");
|
|
561
|
+
expect(output).toContain("Diff:");
|
|
562
|
+
component.handleInput("\x1b");
|
|
563
|
+
expect((component as any).toolPreviewParent).toBeNull();
|
|
564
|
+
expect(dismissed).toBe(0);
|
|
565
|
+
|
|
566
|
+
component.handleMouse({ type: "click", button: "left", x: 5, y: hostToolRow } as any);
|
|
567
|
+
component.handleMouse({ type: "click", button: "left", clickCount: 2, x: 5, y: hostToolRow } as any);
|
|
568
|
+
expect((component as any).liveExpandedToolCallId).toBeNull();
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
it("shows live partial tool output as STREAMING and updates it in place", () => {
|
|
572
|
+
let entries: any[] = [
|
|
573
|
+
{ id: 1, turnId: 1, type: "tool-call", toolCallId: "call-live", toolName: "bash", args: "{\"command\":\"echo hi\"}" },
|
|
574
|
+
{ id: 2, turnId: 1, type: "tool-result", toolCallId: "call-live", toolName: "bash", content: "partial output", fullContent: "partial output", truncated: false, isError: false, streaming: true },
|
|
575
|
+
];
|
|
576
|
+
const component = new BtwOverlayComponent(
|
|
577
|
+
tui,
|
|
578
|
+
theme,
|
|
579
|
+
keybindings,
|
|
580
|
+
() => entries,
|
|
581
|
+
() => null,
|
|
582
|
+
() => "contextual",
|
|
583
|
+
() => {},
|
|
584
|
+
() => {},
|
|
585
|
+
() => {},
|
|
586
|
+
);
|
|
587
|
+
|
|
588
|
+
component.render(80);
|
|
589
|
+
const contentTop = (component as any).transcriptContentTop as number;
|
|
590
|
+
component.handleMouse({ type: "click", button: "left", x: 5, y: contentTop - 1 } as any);
|
|
591
|
+
component.handleInput("\x0f");
|
|
592
|
+
let output = component.render(80).join("\n");
|
|
593
|
+
expect(output).toContain("STREAMING");
|
|
594
|
+
expect(output).toContain("partial output");
|
|
595
|
+
expect(output).toContain("echo hi");
|
|
596
|
+
|
|
597
|
+
entries = [
|
|
598
|
+
entries[0],
|
|
599
|
+
{ ...entries[1], content: "final output", fullContent: "final output", streaming: false },
|
|
600
|
+
];
|
|
601
|
+
output = component.render(80).join("\n");
|
|
602
|
+
expect(output).toContain("final output");
|
|
603
|
+
expect(output).not.toContain("STREAMING");
|
|
604
|
+
|
|
605
|
+
component.handleInput("\x1b");
|
|
606
|
+
expect((component as any).toolPreviewParent).toBeNull();
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
it("consumes Ctrl+O without a focused tool", () => {
|
|
610
|
+
const component = new BtwOverlayComponent(
|
|
611
|
+
tui,
|
|
612
|
+
theme,
|
|
613
|
+
keybindings,
|
|
614
|
+
() => [],
|
|
615
|
+
() => null,
|
|
616
|
+
() => "contextual",
|
|
617
|
+
() => {},
|
|
618
|
+
() => {},
|
|
619
|
+
() => {},
|
|
620
|
+
);
|
|
621
|
+
component.setDraft("keep this draft");
|
|
622
|
+
component.handleInput("\x0f");
|
|
623
|
+
|
|
624
|
+
expect((component as any).toolPreviewParent).toBeNull();
|
|
625
|
+
expect((component as any).input.getText()).toBe("keep this draft");
|
|
626
|
+
});
|
|
627
|
+
|
|
628
|
+
it("marks a focused tool with no result as streaming without inventing output", () => {
|
|
629
|
+
const entries = [
|
|
630
|
+
{ id: 1, turnId: 1, type: "tool-call", toolCallId: "call-pending", toolName: "read", args: "{\"path\":\"pending.txt\"}" },
|
|
631
|
+
];
|
|
632
|
+
const component = new BtwOverlayComponent(
|
|
633
|
+
tui,
|
|
634
|
+
theme,
|
|
635
|
+
keybindings,
|
|
636
|
+
() => entries as any,
|
|
637
|
+
() => null,
|
|
638
|
+
() => "contextual",
|
|
639
|
+
() => {},
|
|
640
|
+
() => {},
|
|
641
|
+
() => {},
|
|
642
|
+
);
|
|
643
|
+
component.render(80);
|
|
644
|
+
const contentTop = (component as any).transcriptContentTop as number;
|
|
645
|
+
component.handleMouse({ type: "click", button: "left", x: 5, y: contentTop - 1 } as any);
|
|
646
|
+
component.handleInput("\x0f");
|
|
647
|
+
|
|
648
|
+
const output = component.render(80).join("\n");
|
|
649
|
+
expect(output).toContain("STREAMING");
|
|
650
|
+
expect(output).toContain("(no output)");
|
|
651
|
+
});
|
|
652
|
+
|
|
653
|
+
it("keeps Enter and Escape composer behavior outside Peek", () => {
|
|
654
|
+
let submitted = "";
|
|
655
|
+
let dismissed = 0;
|
|
656
|
+
const composerKeybindings = {
|
|
657
|
+
matches: (data: string, action: string) => action === "app.interrupt" && data === "\x1b",
|
|
658
|
+
} as any;
|
|
659
|
+
const component = new BtwOverlayComponent(
|
|
660
|
+
tui,
|
|
661
|
+
theme,
|
|
662
|
+
composerKeybindings,
|
|
663
|
+
() => [],
|
|
664
|
+
() => null,
|
|
665
|
+
() => "contextual",
|
|
666
|
+
(value) => { submitted = value; },
|
|
667
|
+
() => { dismissed++; },
|
|
668
|
+
() => {},
|
|
669
|
+
);
|
|
670
|
+
|
|
671
|
+
component.focused = true;
|
|
672
|
+
component.setDraft("submit me");
|
|
673
|
+
component.handleInput("\r");
|
|
674
|
+
expect(submitted).toBe("submit me");
|
|
675
|
+
component.handleInput("\x1b");
|
|
676
|
+
expect(dismissed).toBe(1);
|
|
677
|
+
});
|
|
678
|
+
|
|
169
679
|
it("configures fd-backed completion for @ path suggestions", () => {
|
|
170
680
|
const component = new BtwOverlayComponent(
|
|
171
681
|
tui,
|