@notrico/pi-fold 3.0.0 → 3.0.2
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 +12 -0
- package/docs/renderer-reference.md +4 -2
- package/package.json +1 -1
- package/scripts/preview-actions.mjs +9 -0
- package/scripts/preview-inspection.mjs +9 -0
- package/scripts/preview-work-strip.mjs +39 -1
- package/scripts/preview.mjs +3 -1
- package/scripts/test.mjs +2 -1
- package/src/display-card.ts +2 -0
- package/src/modern-code-content.ts +8 -1
- package/src/modern-code-pane.ts +20 -6
- package/src/modern-thinking.ts +25 -3
- package/src/modern-tool-pane.ts +32 -17
- package/src/modern-tools.ts +35 -6
- package/src/modern-workflows.ts +9 -6
- package/src/work-strip-view.ts +13 -5
- package/tests/action-group-preview.test.mjs +43 -0
- package/tests/codemode.test.mjs +31 -6
- package/tests/fold-shortcut.test.mjs +1 -1
- package/tests/inspection-wheel.test.mjs +75 -0
- package/tests/mixed-action-groups.test.mjs +201 -0
- package/tests/mixed-thinking.test.mjs +63 -11
- package/tests/modern-tools.test.mjs +53 -0
- package/tests/modern-workflows.test.mjs +43 -1
- package/tests/preview-example.test.mjs +1 -1
- package/tests/reload-lifecycle.test.mjs +5 -5
- package/tests/test-runtime.mjs +3 -1
- package/tests/work-strip-final-surface.test.mjs +52 -2
- package/tests/work-strip-preview.test.mjs +1 -1
package/src/modern-tools.ts
CHANGED
|
@@ -254,12 +254,18 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
254
254
|
pi.events.emit("compact-renderer:focus:v1", { owner: "tools", label: pane.title,
|
|
255
255
|
target: (component: any) => component instanceof DynamicComponent && (component.owner && subagentView(component.owner)?.pane || component.owner?.group?.pane || component.owner?.code || component.owner?.pane) === pane });
|
|
256
256
|
};
|
|
257
|
-
const action = (node: Node): PaneAction =>
|
|
257
|
+
const action = (node: Node): PaneAction => node.code ? {
|
|
258
|
+
id: node.id, label: `codemode · ${node.code.content.intent}${node.code.content.calls.length ? ` · ${node.code.content.calls.length} nested call${node.code.content.calls.length === 1 ? "" : "s"}` : ""}` + indicators(node),
|
|
259
|
+
sections: () => [], rows: (width, theme) => node.code!.contentRows(width, theme, true),
|
|
260
|
+
} : ({ id: node.id, label: toolLabel(node.name, node.args) + indicators(node), sections: () => sections(node), ...(question(node.name) ? {} : { details: () => actionDetails(node) }) });
|
|
258
261
|
const refreshGroups = () => {
|
|
259
262
|
let run: Node[] = [];
|
|
263
|
+
let transferredFocus: ToolPane | undefined;
|
|
260
264
|
const next = new Map<string, Group>();
|
|
261
265
|
const finish = () => {
|
|
262
266
|
if (!run.length) return;
|
|
267
|
+
// A lone codemode keeps its native-style CodePane and timing/inspection UI.
|
|
268
|
+
if (run.length === 1 && run[0].code) { run = []; return; }
|
|
263
269
|
const id = run[0].id;
|
|
264
270
|
const signature = run.map(node => `${node.id}@${node.revision}`).join("|");
|
|
265
271
|
let group = groups.get(id);
|
|
@@ -270,16 +276,27 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
270
276
|
if (run.some(node => node.result?.details?.truncation?.truncated || node.result?.details?.truncated)) group.pane.title += " · output truncated";
|
|
271
277
|
if (run.some(node => node.result?.details?.fullOutputPath)) group.pane.title += " · full output saved";
|
|
272
278
|
if (run.some(node => node.result?.details?.warning || node.result?.details?.warnings?.length)) group.pane.title += " · warning recorded";
|
|
273
|
-
for (const node of run)
|
|
279
|
+
for (const [index, node] of run.entries()) {
|
|
280
|
+
node.group = group;
|
|
281
|
+
if (node.code?.open) {
|
|
282
|
+
group.pane.open = true; group.pane.expanded.add(node.id);
|
|
283
|
+
if (focused === node.code) { group.pane.select(index); transferredFocus = group.pane; }
|
|
284
|
+
// The shared pane now owns expansion; collapse-all must not leave a
|
|
285
|
+
// hidden singleton state that can reopen after a later regroup.
|
|
286
|
+
node.code.collapse();
|
|
287
|
+
}
|
|
288
|
+
}
|
|
274
289
|
next.set(id, group); run = [];
|
|
275
290
|
};
|
|
276
291
|
for (const node of nodes.values()) {
|
|
277
292
|
node.group = undefined;
|
|
278
|
-
|
|
293
|
+
const code = node.code?.content;
|
|
294
|
+
if (compactSubagent(node.name) || node.status !== "success" || node.images || code && (!code.supported || !code.clean)) { finish(); continue; }
|
|
279
295
|
if (run.length && node.epoch !== run[0].epoch) finish();
|
|
280
296
|
run.push(node);
|
|
281
297
|
}
|
|
282
298
|
finish(); groups = next;
|
|
299
|
+
if (transferredFocus) focusPane(transferredFocus);
|
|
283
300
|
if (focused && ![...groups.values()].some(group => group.pane === focused) && ![...nodes.values()].some(node => !node.group && (node.code || node.pane) === focused)) release();
|
|
284
301
|
};
|
|
285
302
|
const ensure = (id: string, name: string, args?: any, stock?: ToolRenderers) => {
|
|
@@ -298,6 +315,9 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
298
315
|
if (!changed) return;
|
|
299
316
|
node.images = Array.isArray(result?.content) ? result.content.reduce((count: number, block: any) => count + (block?.type === "image" ? 1 : 0), 0) : 0;
|
|
300
317
|
node.revision++; node.pane?.reset();
|
|
318
|
+
// Running code cannot join a group. Defer its aggregate until the renderer
|
|
319
|
+
// receives the final argument revision, as native streaming may replace args.
|
|
320
|
+
if (!partial) node.code?.content.update(node.args, node.result, node.revision);
|
|
301
321
|
if (!rebuilding) refreshGroups();
|
|
302
322
|
};
|
|
303
323
|
const observeMessage = (message: any) => {
|
|
@@ -447,6 +467,8 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
447
467
|
const codePane = (node: Node, theme: any, context: Context) => {
|
|
448
468
|
const pane = node.code!;
|
|
449
469
|
node.native.suspend(); pane.adoptClock(node.native.clock);
|
|
470
|
+
if (pane.content.update(node.args, node.result, node.revision) && !rebuilding) refreshGroups();
|
|
471
|
+
const duration = pane.duration;
|
|
450
472
|
const supported = pane.update(node.args, node.result, node.revision, context);
|
|
451
473
|
if (!supported) { pane.suspend(); node.native.adoptClock(pane.clock); return false; }
|
|
452
474
|
const calls = pane.content.calls;
|
|
@@ -454,9 +476,16 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
454
476
|
const status = node.status === "failed" ? "✗ Failed" : context.isPartial ? context.executionStarted ? "… Running" : "Preparing" : "";
|
|
455
477
|
pane.heading = `codemode${status ? ` · ${status}` : ""} · ${pane.content.intent}`;
|
|
456
478
|
pane.title = `${pane.heading}${calls.length ? ` · ${calls.length} nested call${calls.length === 1 ? "" : "s"}` : ""}${pane.content.images ? ` · ${pane.content.images} image${pane.content.images === 1 ? "" : "s"}` : ""}${errors ? ` · ${errors} nested error${errors === 1 ? "" : "s"}` : ""}${cancelled ? ` · ${cancelled} nested cancelled` : ""}${unresolved ? ` · ${unresolved} nested unresolved` : ""}${typeof context.durationMs === "number" ? ` · ${(context.durationMs / 1000).toFixed(2)}s` : ""}${indicators(node)}`;
|
|
457
|
-
pane.setTheme(theme)
|
|
479
|
+
if (pane.setTheme(theme) || duration !== pane.duration) node.group?.pane.reset();
|
|
480
|
+
pane.tone = node.status === "failed" ? "error" : errors || cancelled || unresolved && !context.isPartial ? "warning" : "syntaxVariable";
|
|
458
481
|
return true;
|
|
459
482
|
};
|
|
483
|
+
const groupPane = (node: Node, theme: any) => {
|
|
484
|
+
const group = node.group;
|
|
485
|
+
if (!group || group.members[0] !== node) return;
|
|
486
|
+
group.pane.theme = theme; group.pane.styleHeader = text => activityHeading(text, theme);
|
|
487
|
+
return group.pane;
|
|
488
|
+
};
|
|
460
489
|
return {
|
|
461
490
|
renderShell: "self",
|
|
462
491
|
[compactToolImages](component: any, width: number): ToolImageView | undefined {
|
|
@@ -477,7 +506,7 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
477
506
|
if (node.code) {
|
|
478
507
|
if (!codePane(node, theme, context)) node.native.renderCall(args, theme, context);
|
|
479
508
|
syncExpansion(node, context.expanded);
|
|
480
|
-
return new DynamicComponent(width => node.code!.content.supported ? node.code!.render(width) : node.native.renderCurrent(width), event => node.code!.content.supported ?
|
|
509
|
+
return new DynamicComponent(width => node.group ? groupPane(node, theme)?.render(width) ?? [] : node.code!.content.supported ? node.code!.render(width) : node.native.renderCurrent(width), event => mouse(node.group ? groupPane(node, theme) : node.code!.content.supported ? node.code : undefined, event), node);
|
|
481
510
|
}
|
|
482
511
|
node.native.suspend(); syncExpansion(node, context.expanded);
|
|
483
512
|
return new DynamicComponent(width => {
|
|
@@ -498,7 +527,7 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
498
527
|
node.native.suspend(); syncExpansion(node, context.expanded);
|
|
499
528
|
return new DynamicComponent(width => {
|
|
500
529
|
if (subagentView(node)?.hidden) return [];
|
|
501
|
-
if (node.group)
|
|
530
|
+
if (node.group) return groupPane(node, theme)?.render(width) ?? [];
|
|
502
531
|
if (singleCard(node)) return [];
|
|
503
532
|
return individual(node, theme).render(width);
|
|
504
533
|
}, event => mouse(node.group ? node.group.members[0] === node ? node.group.pane : undefined : !singleCard(node) ? individual(node, theme) : undefined, event), node);
|
package/src/modern-workflows.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DisplayMode } from './display-mode.ts';
|
|
2
2
|
import { AssistantMessageComponent, VERSION, type ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
3
3
|
import { Container, Markdown, MouseRegion, Spacer, Text, matchesKey, truncateToWidth } from '@earendil-works/pi-tui';
|
|
4
|
-
import { activityRow, cardContentWidth } from './display-card.ts';
|
|
4
|
+
import { activityRow, cardContentWidth, finalReplyRendering } from './display-card.ts';
|
|
5
5
|
import { richTextRows } from './modern-rich-text.ts';
|
|
6
6
|
import { recordedPaneHeight } from './modern-recorded-pane.ts';
|
|
7
7
|
import { chainNativeMethod } from './native-method-chain.ts';
|
|
@@ -45,7 +45,7 @@ export class WorkflowPane {
|
|
|
45
45
|
open = false; focused = false; offset = 0; paintedRows = 0;
|
|
46
46
|
theme?: any;
|
|
47
47
|
private rows: string[] = []; private iterator?: Iterator<string>; private done = false;
|
|
48
|
-
private width = 0; private themeKey = ''; private lastWidth = 0; private lastHeight = 0;
|
|
48
|
+
private width = 0; private themeKey = ''; private lastWidth = 0; private lastHeight = 0; private lastBodyHeight = 0; private lastMore = false;
|
|
49
49
|
constructor(readonly source: string, readonly summary: string, private release: () => void = () => {}) {}
|
|
50
50
|
collapse() { this.open = false; this.focused = false; this.offset = 0; this.invalidate(); }
|
|
51
51
|
invalidate() { this.rows = []; this.iterator = undefined; this.done = false; this.width = 0; }
|
|
@@ -66,6 +66,7 @@ export class WorkflowPane {
|
|
|
66
66
|
if (this.width !== sourceWidth || themeKey !== this.themeKey) { this.invalidate(); this.width = sourceWidth; this.themeKey = themeKey; this.offset = 0; }
|
|
67
67
|
const label = `${this.open ? '▾' : '▸'} Subagent workflow`;
|
|
68
68
|
const rows = [activityRow(theme ? theme.fg('mdLink', theme.bold(label)) + theme.fg('muted', ` · ${this.summary}`) : `${label} · ${this.summary}`, width, theme, this.focused)];
|
|
69
|
+
this.lastBodyHeight = 0; this.lastMore = false;
|
|
69
70
|
if (this.open) {
|
|
70
71
|
this.iterator ??= richTextRows(this.source, sourceWidth, { format: 'code', language: 'javascript' });
|
|
71
72
|
const height = recordedPaneHeight();
|
|
@@ -78,7 +79,8 @@ export class WorkflowPane {
|
|
|
78
79
|
if (this.done) this.offset = Math.min(this.offset, Math.max(0, this.rows.length - height));
|
|
79
80
|
rows.push(...this.rows.slice(this.offset, this.offset + height).map(row => activityRow(indent + row, width, theme)));
|
|
80
81
|
const more = !this.done || this.offset + height < this.rows.length;
|
|
81
|
-
|
|
82
|
+
this.lastBodyHeight = rows.length - 1; this.lastMore = more;
|
|
83
|
+
const hint = [more ? 'more ↓' : this.offset > 0 ? 'more ↑' : '', this.focused ? 'Enter collapse · ↑/↓ scroll · Home start · Esc release' : ''].filter(Boolean).join(' · ');
|
|
82
84
|
if (hint) rows.push(activityRow(theme ? theme.fg('muted', hint) : hint, width, theme));
|
|
83
85
|
}
|
|
84
86
|
this.lastHeight = rows.length;
|
|
@@ -89,8 +91,9 @@ export class WorkflowPane {
|
|
|
89
91
|
if (event.type === 'wheel' && this.open && Number.isFinite(event.wheelDelta) && event.wheelDelta) {
|
|
90
92
|
this.release(); this.offset = Math.max(0, this.offset + Math.max(-20, Math.min(20, Math.trunc(event.wheelDelta)))); return { handled: true };
|
|
91
93
|
}
|
|
92
|
-
if (event.type === 'click' && event.button === 'left' &&
|
|
93
|
-
this.release(); this.open = !this.open; this.offset = 0; return { handled: true };
|
|
94
|
+
if (event.type === 'click' && event.button === 'left' && !event.ctrl && !event.alt && !event.shift) {
|
|
95
|
+
if (event.y === 0) { this.release(); this.open = !this.open; this.offset = 0; return { handled: true }; }
|
|
96
|
+
if (this.open && (this.lastMore || this.offset > 0) && event.y === this.lastHeight - 1) { this.release(); this.offset = Math.max(0, this.offset + (this.lastMore ? 1 : -1) * Math.max(1, this.lastBodyHeight)); return { handled: true }; }
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
99
|
}
|
|
@@ -113,7 +116,7 @@ export function registerModernWorkflows(pi: ExtensionAPI, mode: DisplayMode, ver
|
|
|
113
116
|
const clear = () => { release(); cards.clear(); input?.(); input = undefined; redraw = undefined; active = false; };
|
|
114
117
|
const supported = (component: any): any[] | undefined => {
|
|
115
118
|
const message = component.lastMessage, container = component.contentContainer;
|
|
116
|
-
if (component.isStreaming !== false || message?.role !== 'assistant' || !Array.isArray(message.content) || !Array.isArray(component.children) || component.children.length !== 1 || component.children[0] !== container || container?.constructor !== Container || !Array.isArray(container.children)) return;
|
|
119
|
+
if (component[finalReplyRendering] || component.isStreaming !== false || message?.role !== 'assistant' || !Array.isArray(message.content) || !Array.isArray(component.children) || component.children.length !== 1 || component.children[0] !== container || container?.constructor !== Container || !Array.isArray(container.children)) return;
|
|
117
120
|
if (!container.children.every((child: any) => child instanceof Markdown || child instanceof Spacer || child instanceof Text || child instanceof MouseRegion && (child.child instanceof Markdown || child.child instanceof Text))) return;
|
|
118
121
|
const text = message.content.filter((block: any) => block.type === 'text' && typeof block.text === 'string' && block.text.trim()).map((block: any) => block.text.trim());
|
|
119
122
|
const markdown = container.children.filter((child: any) => child instanceof Markdown);
|
package/src/work-strip-view.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Box, Markdown, truncateToWidth, visibleWidth } from '@earendil-works/pi-tui';
|
|
2
|
-
import { activityRow, cardContentWidth, fillBackground } from './display-card.ts';
|
|
2
|
+
import { activityRow, cardContentWidth, fillBackground, finalReplyRendering } from './display-card.ts';
|
|
3
3
|
|
|
4
4
|
/** Shared with inspection. Canonical native children stay untouched. */
|
|
5
5
|
export const projectedChildren = Symbol.for('compact-renderer:projected-children:v1');
|
|
@@ -13,17 +13,25 @@ export function renderFinalReply(row: any, width: number, theme: any): string[]
|
|
|
13
13
|
const first = children?.findIndex((child: any) => child instanceof Markdown) ?? -1;
|
|
14
14
|
if (first < 0) return row.render(width);
|
|
15
15
|
const last = children.findLastIndex((child: any) => child instanceof Markdown);
|
|
16
|
-
const padding = { invalidate() {}, render: (contentWidth: number) => [fillBackground('', contentWidth, theme, 'toolPendingBg')] };
|
|
17
16
|
for (const child of children) {
|
|
18
17
|
if (!(child instanceof Markdown)) continue;
|
|
19
18
|
const native = child.render, own = Object.getOwnPropertyDescriptor(child, 'render');
|
|
20
19
|
child.render = function(contentWidth: number) {
|
|
21
|
-
|
|
20
|
+
const lines = native.call(this, contentWidth).map((line: string) => line.includes('\x1b_G') || line.includes('\x1b]1337;File=') ? line : fillBackground(line, Math.max(contentWidth, visibleWidth(line)), theme, 'toolPendingBg'));
|
|
21
|
+
if (child === children[first]) lines.unshift(fillBackground('', contentWidth, theme, 'toolPendingBg'));
|
|
22
|
+
if (child === children[last]) lines.push(fillBackground('', contentWidth, theme, 'toolPendingBg'));
|
|
23
|
+
return lines;
|
|
22
24
|
};
|
|
23
25
|
restore.push(() => { if (own) Object.defineProperty(child, 'render', own); else delete (child as any).render; });
|
|
24
26
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
// Add rows through Markdown rendering, preserving the native child shape
|
|
28
|
+
// used by the thinking adapter throughout this render.
|
|
29
|
+
const marker = Object.getOwnPropertyDescriptor(row, finalReplyRendering);
|
|
30
|
+
row[finalReplyRendering] = true;
|
|
31
|
+
try { return row.render(width); } finally {
|
|
32
|
+
if (marker) Object.defineProperty(row, finalReplyRendering, marker); else delete row[finalReplyRendering];
|
|
33
|
+
restore.forEach(fn => fn());
|
|
34
|
+
}
|
|
27
35
|
}
|
|
28
36
|
/** Native Box owns both rendering and mouse-coordinate translation. */
|
|
29
37
|
export class WorkChild extends Box {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { pathToFileURL } from 'node:url';
|
|
4
|
+
import { createWorkStripPreview } from '../scripts/preview-work-strip.mjs';
|
|
5
|
+
|
|
6
|
+
const preview = await createWorkStripPreview({ actionGroups: true });
|
|
7
|
+
const { core, runtime, manager } = preview;
|
|
8
|
+
const { theme, initTheme } = await import(pathToFileURL(path.join(preview.runtimePath, 'node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js')));
|
|
9
|
+
initTheme('dark', false);
|
|
10
|
+
const plain = value => value.replace(/\x1b\][^\x07]*(?:\x07|\x1b\\)|\x1b\[[0-?]*[ -/]*[@-~]/g, '');
|
|
11
|
+
const errors = [];
|
|
12
|
+
runtime.session.extensionRunner.onError(error => errors.push(error));
|
|
13
|
+
const ui = new core.InteractiveMode(runtime, { tuiMode: 'fullscreen' });
|
|
14
|
+
ui.updateTerminalTitle = () => {};
|
|
15
|
+
Object.defineProperty(ui.ui, 'isFollowingOutput', { get: () => true });
|
|
16
|
+
runtime.session.extensionRunner.setUIContext({ ...ui.createExtensionUIContext(), theme, onTerminalInput() { return () => {}; }, setHiddenThinkingLabel() {}, setStatus() {}, setWidget() {}, notify() {} }, 'tui');
|
|
17
|
+
const paint = () => plain(ui.chatContainer.render(140).join('\n'));
|
|
18
|
+
try {
|
|
19
|
+
ui.renderSessionEntries(manager.getBranch());
|
|
20
|
+
await runtime.session.extensionRunner.emit({ type: 'session_start', reason: 'resume' });
|
|
21
|
+
ui.chatContainer.invalidate();
|
|
22
|
+
assert.match(paint(), /Mixed-action preview:/, 'final reply remains visible while work is folded');
|
|
23
|
+
const projected = ui.chatContainer[Symbol.for('compact-renderer:projected-children:v1')];
|
|
24
|
+
const work = projected.findLast(row => row.constructor.name === 'WorkStripHeader');
|
|
25
|
+
work.render(140);
|
|
26
|
+
work.handleMouse({ type: 'click', button: 'left', x: 4, y: 1, width: 140 });
|
|
27
|
+
const tools = ui.chatContainer.children.filter(row => row instanceof core.ToolExecutionComponent && row.toolCallId?.startsWith('mixed-'));
|
|
28
|
+
assert.equal(tools.length, 7, 'all recorded calls survive replay');
|
|
29
|
+
const rows = tools.map(row => plain(row.render(140).join('\n')));
|
|
30
|
+
assert.match(rows[0], /4 actions/);
|
|
31
|
+
assert.ok(rows.slice(1, 4).every(row => !row.trim()), 'mixed group followers do not duplicate cards');
|
|
32
|
+
assert.match(rows[4], /2 actions/, 'codemode can lead an action group');
|
|
33
|
+
assert.equal(rows[5].trim(), '');
|
|
34
|
+
assert.match(rows[6], /codemode.*1 nested error/, 'handled nested error remains a separate warning card');
|
|
35
|
+
tools[0].setExpanded(true);
|
|
36
|
+
tools[4].setExpanded(true);
|
|
37
|
+
const expanded = paint();
|
|
38
|
+
assert.match(expanded, /codemode/);
|
|
39
|
+
assert.match(expanded, /Mixed-action preview:/);
|
|
40
|
+
assert.deepEqual(runtime.session.getActiveToolNames(), [], 'preview cannot execute tools');
|
|
41
|
+
assert.deepEqual(errors, []);
|
|
42
|
+
console.log('Mixed action groups replay through native Pi, retain warning cards, and preserve work-strip inspection');
|
|
43
|
+
} finally { ui.ui.stop(); await preview.cleanup(); ui.footerDataProvider.dispose(); }
|
package/tests/codemode.test.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { loadSource, loadAgent, themeModule, stripAnsi, tui, backgroundCells } f
|
|
|
4
4
|
const { registerModernTools, toolStatus } = await loadSource('./modern-tools.ts');
|
|
5
5
|
const { createDisplayMode } = await loadSource('./display-mode.ts');
|
|
6
6
|
const { CodePane } = await loadSource('./modern-code-pane.ts');
|
|
7
|
+
const { WorkChild } = await loadSource('./work-strip-view.ts');
|
|
7
8
|
const stylePane = new CodePane(() => 12);
|
|
8
9
|
stylePane.heading = 'codemode · Read files';
|
|
9
10
|
stylePane.title = `${stylePane.heading} · 2 nested calls · 1 nested error`;
|
|
@@ -30,7 +31,9 @@ assert.equal(ToolExecutionComponent.prototype.render,originalToolRender);
|
|
|
30
31
|
const mode = createDisplayMode(), dispose = registerModernTools(pi, mode);
|
|
31
32
|
const ctx = { hasUI: true, sessionManager: { getBranch: () => [] }, ui: { onTerminalInput(fn) { input = fn; return () => { input = undefined; }; } } };
|
|
32
33
|
const event = (name, data = {}) => { for (const fn of hooks.get(name) || []) fn(data, ctx); };
|
|
33
|
-
const create = (name, id, args, native) => {
|
|
34
|
+
const create = (name, id, args, native, adjacent = false) => {
|
|
35
|
+
// These fixtures inspect independent panes. Mixed adjacency has its own assertions below.
|
|
36
|
+
if (!adjacent) event('message_end', { message: { role: 'assistant', content: [{ type: 'text', text: `Fixture ${id}` }] } });
|
|
34
37
|
const component = new ToolExecutionComponent(name, id, args, { showImages: false, outputPad: 0 }, resolver(name, () => native), { requestRender() {} }, '/tmp'); component.setArgsComplete(); return component;
|
|
35
38
|
};
|
|
36
39
|
const result = text => ({ content: [{ type: 'text', text }] });
|
|
@@ -120,8 +123,30 @@ try {
|
|
|
120
123
|
for (const row of rows) assert.ok(tui.visibleWidth(row) <= width);
|
|
121
124
|
}
|
|
122
125
|
assert.match(paint(code), /text\(0\)/);
|
|
126
|
+
// Exercise native container routing, including the work group's horizontal inset.
|
|
127
|
+
const workChild = new WorkChild(code), work = new tui.Container();
|
|
128
|
+
work.addChild(new tui.Text('Work fixture', 0, 0)); work.addChild(workChild);
|
|
129
|
+
const moreRows = work.render(140).map(stripAnsi), moreY = moreRows.findIndex(row => row.includes('more ↓'));
|
|
130
|
+
assert.ok(moreY > 1); const moreX = moreRows[moreY].indexOf('more ↓'); assert.ok(moreX >= 3);
|
|
131
|
+
const beforeMore = pane.offset;
|
|
132
|
+
assert.equal(work.handleMouse({ type: 'click', button: 'left', x: moreX, y: moreY, screenX: moreX, screenY: moreY, width: 140, height: moreRows.length })?.handled, true);
|
|
133
|
+
const afterMore = work.render(140).map(stripAnsi).join('\n');
|
|
134
|
+
assert.ok(pane.offset > beforeMore, 'clicking overflow advances the rendered codemode viewport');
|
|
135
|
+
assert.ok(pane.offset - beforeMore <= 20, 'one click advances at most one bounded viewport');
|
|
136
|
+
assert.doesNotMatch(afterMore, /text\(0\)/); assert.equal(input('\r'), undefined, 'overflow click leaves Enter with the editor');
|
|
137
|
+
const focusedMore = []; pi.events.emit('compact-renderer:inspect:v1', { add: entry => focusedMore.push(entry) });
|
|
138
|
+
focusedMore.find(entry => entry.label.startsWith('codemode')).focus();
|
|
139
|
+
const rows = code.render(140).map(stripAnsi), footerY = rows.findIndex(row => row.includes('more ↓'));
|
|
140
|
+
assert.ok(footerY > 0); mouse(code, 'click', footerY);
|
|
141
|
+
assert.doesNotMatch(paint(code), /focused/); assert.equal(input('\r'), undefined, 'overflow click releases inspection');
|
|
123
142
|
for (let index = 0; index < 120; index++) { mouse(code, 'wheel', 2, 20); code.render(140); }
|
|
124
143
|
assert.match(paint(code), /Recorded script output/, 'bounded viewport can reach full native output');
|
|
144
|
+
assert.doesNotMatch(paint(code), /more ↓/, 'codemode stops offering downward paging at its final rows');
|
|
145
|
+
const endRows = code.render(140).map(stripAnsi), endOffset = pane.offset;
|
|
146
|
+
assert.match(endRows.at(-1), /more ↑/, 'the final footer retains its hit area');
|
|
147
|
+
mouse(code, 'click', endRows.length - 1); code.render(140);
|
|
148
|
+
assert.ok(pane.offset < endOffset, 'the upward footer pages back through the output');
|
|
149
|
+
assert.equal(code.render(140).length, endRows.length, 'paging back keeps the pane height');
|
|
125
150
|
assert.equal(JSON.stringify(final), before);
|
|
126
151
|
const running = create('codemode', 'code-clear', { code: 'text(1);' }, codemodeRenderers); running.markExecutionStarted(); running.updateResult({ ...result(''), details: { calls: [] } }, true);
|
|
127
152
|
assert.equal(intervals.size, 1); event('session_before_switch'); assert.equal(intervals.size, 0, 'session switch clears native owned timer');
|
|
@@ -353,13 +378,13 @@ try {
|
|
|
353
378
|
assert.ok(restoredChoices.length>fallbackChoices.length,'supported result restores compact inspection');
|
|
354
379
|
|
|
355
380
|
const unsupported=create('codemode','bounded-invalid-fallback',{code:42},codemodeRenderers);assert.match(paint(unsupported),/invalid arg/);
|
|
356
|
-
//
|
|
381
|
+
// Adjacent successful code shares the outer action group with ordinary tools.
|
|
357
382
|
const replayFirst = create('read', 'replay-before', { path: '/fixture/replay-before' }, readRenderers); replayFirst.updateResult(result('first'));
|
|
358
383
|
event('message_end', { message: { role: 'assistant', content: [{ type: 'toolCall', id: 'replay-code', name: 'codemode', arguments: { code: 'text(1)' } }] } });
|
|
359
|
-
const replayCode = create('codemode', 'replay-code', { code: 'text(1)' }, codemodeRenderers); replayCode.updateResult(result('done'));
|
|
360
|
-
const last = create('read', 'after-code', { path: '/fixture/after' }, readRenderers); last.updateResult(result('last'));
|
|
361
|
-
assert.
|
|
384
|
+
const replayCode = create('codemode', 'replay-code', { code: 'text(1)' }, codemodeRenderers, true); replayCode.updateResult(result('done'));
|
|
385
|
+
const last = create('read', 'after-code', { path: '/fixture/after' }, readRenderers, true); last.updateResult(result('last'));
|
|
386
|
+
assert.equal(paint(last), '');
|
|
362
387
|
assert.doesNotMatch(paint(replayCode), /successful action/);
|
|
363
|
-
assert.match(paint(replayFirst), /
|
|
388
|
+
assert.match(paint(replayFirst), /3 actions/); assert.equal(paint(replayCode), '');
|
|
364
389
|
console.log('codemode: collapsed summary, bounded details, native images, single image-read headings, nested outcome, timer, inspection/editor and transcript checks passed');
|
|
365
390
|
} finally { dispose(); assert.equal(ToolExecutionComponent.prototype.render,originalToolRender,'disposing restores the native render method'); }
|
|
@@ -8,7 +8,7 @@ import { createWorkStripPreview } from '../scripts/preview-work-strip.mjs';
|
|
|
8
8
|
const preview = await createWorkStripPreview();
|
|
9
9
|
let ui;
|
|
10
10
|
try {
|
|
11
|
-
const { matchesKey, setKittyProtocolActive } = await import(pathToFileURL(
|
|
11
|
+
const { matchesKey, setKittyProtocolActive } = await import(pathToFileURL(preview.tuiPath));
|
|
12
12
|
let receive, kitty = true;
|
|
13
13
|
const terminal = {
|
|
14
14
|
columns: 110,
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { createWorkStripPreview } from '../scripts/preview-work-strip.mjs';
|
|
3
|
+
|
|
4
|
+
const preview = await createWorkStripPreview({ inspection: true });
|
|
5
|
+
const terminal = { columns: 110, rows: 45, kittyProtocolActive: false, start() {}, stop() {}, async drainInput() {} };
|
|
6
|
+
for (const name of ['write', 'moveBy', 'hideCursor', 'showCursor', 'clearLine', 'clearFromCursor', 'clearScreen', 'setTitle', 'setProgress', 'setProgramStatus']) terminal[name] = () => {};
|
|
7
|
+
const plain = rows => rows.join('\n').replace(/\x1b\][^\x07]*(?:\x07|\x1b\\)|\x1b\[[0-?]*[ -/]*[@-~]/g, '');
|
|
8
|
+
let ui;
|
|
9
|
+
try {
|
|
10
|
+
ui = new preview.core.InteractiveMode(preview.runtime, { tuiMode: 'fullscreen', terminal });
|
|
11
|
+
await ui.init();
|
|
12
|
+
const runner = preview.runtime.session.extensionRunner;
|
|
13
|
+
await runner.getCommand('fold').handler('expand', runner.createContext());
|
|
14
|
+
const renderer = ui.renderer;
|
|
15
|
+
renderer.renderNow();
|
|
16
|
+
const screen = () => renderer.getScreenLines().map(row => plain([row]));
|
|
17
|
+
const click = (component, pattern) => {
|
|
18
|
+
const rows = component.render(110), y = rows.findIndex(row => pattern.test(plain([row])));
|
|
19
|
+
assert.ok(y >= 0, String(pattern));
|
|
20
|
+
assert.equal(component.handleMouse({ type: 'click', button: 'left', x: 8, y, width: 110, height: rows.length })?.handled, true);
|
|
21
|
+
renderer.renderNow();
|
|
22
|
+
};
|
|
23
|
+
const wheel = (y, down) => {
|
|
24
|
+
renderer.handleTerminalInput(`\x1b[<${down ? 65 : 64};15;${y + 1}M`);
|
|
25
|
+
renderer.renderNow();
|
|
26
|
+
};
|
|
27
|
+
const choices = [];
|
|
28
|
+
preview.eventBus.emit('compact-renderer:inspect:v1', { add: choice => choices.push(choice) });
|
|
29
|
+
const thinking = choices.find(choice => /Thinking · 3 rounds/.test(choice.label));
|
|
30
|
+
assert.ok(thinking);
|
|
31
|
+
thinking.focus(); renderer.renderNow();
|
|
32
|
+
const component = thinking.target();
|
|
33
|
+
click(component, /1\. Review recorded sample/);
|
|
34
|
+
const beforeThinking = plain(component.render(110));
|
|
35
|
+
click(component, /more ↓/);
|
|
36
|
+
assert.notEqual(plain(component.render(110)), beforeThinking);
|
|
37
|
+
assert.doesNotMatch(plain(component.render(110)), /Thinking\.\.\./);
|
|
38
|
+
|
|
39
|
+
// The recorded read and codemode now share an action pane owned by the read.
|
|
40
|
+
const leader = ui.chatContainer.children.find(row => row.toolCallId === 'inspection-1');
|
|
41
|
+
const wrapper = ui.chatContainer[Symbol.for('compact-renderer:projected-children:v1')].find(row => row.children?.[0] === leader);
|
|
42
|
+
assert.ok(wrapper);
|
|
43
|
+
click(wrapper, /▸ 2 actions/);
|
|
44
|
+
click(wrapper, /2\. codemode/);
|
|
45
|
+
click(wrapper, /more ↓/);
|
|
46
|
+
preview.eventBus.emit('compact-renderer:focus:v1', { owner: 'tools', target: row => row === leader });
|
|
47
|
+
renderer.renderNow();
|
|
48
|
+
const scroll = renderer.getPrimaryScrollView();
|
|
49
|
+
// At the transcript end, auto-clamping can mask a shrinking pane by moving
|
|
50
|
+
// it down under the pointer. Test away from that boundary.
|
|
51
|
+
scroll.scrollTo(scroll.scrollTop - 3, { disableFollow: true }); renderer.renderNow();
|
|
52
|
+
const top = scroll.scrollTop;
|
|
53
|
+
let footerY = -1;
|
|
54
|
+
for (let n = 0; n < 200; n++) {
|
|
55
|
+
const rows = screen(), headerY = rows.findIndex(row => /▾ 2 actions/.test(row));
|
|
56
|
+
assert.ok(headerY >= 0);
|
|
57
|
+
const nextY = rows.findIndex((row, i) => i > headerY && i < headerY + 21 && /more ↓/.test(row));
|
|
58
|
+
if (nextY < 0) break;
|
|
59
|
+
if (footerY >= 0) assert.equal(nextY, footerY, 'footer remains under the pointer');
|
|
60
|
+
footerY = nextY;
|
|
61
|
+
wheel(footerY, true);
|
|
62
|
+
assert.equal(scroll.scrollTop, top, 'downward wheel stays inside the pane');
|
|
63
|
+
}
|
|
64
|
+
const end = screen();
|
|
65
|
+
assert.ok(footerY >= 0);
|
|
66
|
+
assert.match(end[footerY], /more ↑/, 'end of pane retains its footer hit area');
|
|
67
|
+
wheel(footerY, false);
|
|
68
|
+
assert.equal(scroll.scrollTop, top, 'upward wheel at the unchanged footer stays inside the pane');
|
|
69
|
+
assert.notEqual(screen().join('\n'), end.join('\n'), 'upward wheel reveals earlier output');
|
|
70
|
+
assert.equal(renderer.getFocusedComponent(), ui.defaultEditor);
|
|
71
|
+
console.log('Native overflow footer retains wheel routing in both directions');
|
|
72
|
+
} finally {
|
|
73
|
+
ui?.stop();
|
|
74
|
+
await preview.cleanup();
|
|
75
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { loadSource, loadAgent, stripAnsi, tui } from './test-runtime.mjs';
|
|
3
|
+
const { registerModernTools } = await loadSource('./modern-tools.ts');
|
|
4
|
+
const { CodeContent } = await loadSource('./modern-code-content.ts');
|
|
5
|
+
const { ToolExecutionComponent } = await loadAgent('modes/interactive/components/tool-execution.js');
|
|
6
|
+
const { codemodeRenderers } = await loadAgent('extensions/codemode/renderer.js');
|
|
7
|
+
const { createShellRenderers } = await loadAgent('core/tools/renderers/bash.js');
|
|
8
|
+
const { readRenderers } = await loadAgent('core/tools/renderers/read.js');
|
|
9
|
+
const hooks = new Map(), bus = new Map(); let resolver, input;
|
|
10
|
+
const pi = {
|
|
11
|
+
registerToolRenderer(fn) { resolver = fn; },
|
|
12
|
+
on(name, fn) { const set = hooks.get(name) || new Set(); set.add(fn); hooks.set(name, set); return () => set.delete(fn); },
|
|
13
|
+
events: { on(name, fn) { bus.set(name, fn); return () => bus.delete(name); }, emit(name, data) { bus.get(name)?.(data); } },
|
|
14
|
+
};
|
|
15
|
+
const dispose = registerModernTools(pi, { isEnabled: () => true, onChange: () => () => {} });
|
|
16
|
+
let history = [];
|
|
17
|
+
const ctx = { hasUI: true, sessionManager: { getBranch: () => history }, ui: { onTerminalInput(fn) { input = fn; return () => { input = undefined; }; } } };
|
|
18
|
+
const event = (name, data = {}) => { for (const fn of hooks.get(name) || []) fn(data, ctx); };
|
|
19
|
+
const reset = () => { history = []; event('session_start'); };
|
|
20
|
+
const native = new Map([['codemode', codemodeRenderers], ['bash', createShellRenderers('$')], ['read', readRenderers]]);
|
|
21
|
+
const make = (name, id, args = name === 'codemode' ? { code: `text("source-${id}");` } : name === 'bash' ? { command: 'git status' } : { path: `/fixture/${id}` }) => {
|
|
22
|
+
const component = new ToolExecutionComponent(name, id, args, { showImages: false, outputPad: 0 }, resolver(name, () => native.get(name)), { requestRender() {} }, '/tmp');
|
|
23
|
+
component.setArgsComplete(); return component;
|
|
24
|
+
};
|
|
25
|
+
const success = (id, calls = [{ name: 'read', args: `/nested/${id}`, status: 'ok' }], details = {}) => ({ content: [{ type: 'text', text: `output-${id}` }], details: { calls, ...details } });
|
|
26
|
+
const done = (name, id, result = name === 'codemode' ? success(id) : { content: [{ type: 'text', text: `output-${id}` }] }) => {
|
|
27
|
+
const component = make(name, id); component.updateResult(result); return component;
|
|
28
|
+
};
|
|
29
|
+
const owner = component => component.callRendererComponent.owner;
|
|
30
|
+
const paint = (component, width = 140) => stripAnsi(component.render(width).join('\n'));
|
|
31
|
+
const all = components => components.map(component => paint(component)).filter(Boolean).join('\n');
|
|
32
|
+
const choices = () => { const found = []; pi.events.emit('compact-renderer:inspect:v1', { add: entry => found.push(entry) }); return found; };
|
|
33
|
+
const click = (component, y) => component.handleMouse({ type: 'click', button: 'left', x: 2, y, screenX: 2, screenY: y, width: 140, height: component.render(140).length });
|
|
34
|
+
try {
|
|
35
|
+
const accessorDetails = { calls: [] };
|
|
36
|
+
Object.defineProperty(accessorDetails, 'warning', { enumerable: true, get() { throw new Error('recorded warning accessor must not be evaluated'); } });
|
|
37
|
+
const accessorContent = new CodeContent();
|
|
38
|
+
accessorContent.update({ code: 'text(1);' }, { content: [], details: accessorDetails }, 1);
|
|
39
|
+
assert.equal(accessorContent.supported, true); assert.equal(accessorContent.clean, false, 'recorded accessors cannot establish clean grouping eligibility');
|
|
40
|
+
reset();
|
|
41
|
+
const shell = done('bash', 'shell'), codeA = done('codemode', 'code-a'), codeB = done('codemode', 'code-b'), read = done('read', 'read');
|
|
42
|
+
const components = [shell, codeA, codeB, read], group = owner(shell).group;
|
|
43
|
+
assert.deepEqual(group.members.map(node => node.id), ['shell', 'code-a', 'code-b', 'read'], 'each outer call contributes one ordered action');
|
|
44
|
+
assert.match(paint(shell), /4 actions/);
|
|
45
|
+
for (const follower of components.slice(1)) assert.equal(paint(follower), '', 'follower slots contribute no duplicate rows');
|
|
46
|
+
assert.equal(choices().length, 1, 'mixed group has one inspector entry');
|
|
47
|
+
choices()[0].focus();
|
|
48
|
+
assert.match(paint(shell), /2\. codemode · Read files · 1 nested call/);
|
|
49
|
+
input('\x1b[C'); input('\r');
|
|
50
|
+
let visible = paint(shell);
|
|
51
|
+
for (let index = 0; index < 4; index++) { input('\x1b[B'); visible += '\n' + paint(shell); }
|
|
52
|
+
for (const text of ['source-code-a', '✓ read /nested/code-a', 'output-code-a']) assert.ok(visible.includes(text), `group retains code source/calls/output: ${text}`);
|
|
53
|
+
input('\x1b');
|
|
54
|
+
const disclosures = []; pi.events.emit('compact-renderer:disclosures:v1', { add: (...entry) => disclosures.push(entry) });
|
|
55
|
+
assert.equal(disclosures.length, 1); assert.equal(disclosures[0][0](codeA.callRendererComponent), true);
|
|
56
|
+
disclosures[0][2](); assert.equal(group.pane.open, false, 'collapse-all closes mixed group');
|
|
57
|
+
click(shell, 1); assert.equal(group.pane.open, true, 'mouse opens leader group');
|
|
58
|
+
shell.setExpanded(false); shell.setExpanded(true); assert.equal(group.pane.open, true, 'native expansion opens shared group');
|
|
59
|
+
assert.equal(all(components).match(/4 actions/g)?.length, 1);
|
|
60
|
+
// Ordinary Details retain their existing keyboard behavior in mixed groups.
|
|
61
|
+
group.pane.handle('home'); group.pane.handle('\t'); group.pane.handle('\r');
|
|
62
|
+
assert.match(paint(shell), /Arguments/); assert.match(paint(shell), /git status/);
|
|
63
|
+
|
|
64
|
+
reset();
|
|
65
|
+
const firstCode = done('codemode', 'first-code'), nextRead = done('read', 'next-read');
|
|
66
|
+
assert.match(paint(firstCode), /2 actions/); assert.equal(paint(nextRead), '');
|
|
67
|
+
assert.equal(firstCode.resultRendererComponent.render(140).length, 0, 'code-first group stays in its original call slot');
|
|
68
|
+
assert.equal(choices().length, 1);
|
|
69
|
+
choices()[0].focus(); input('\r');
|
|
70
|
+
assert.match(paint(firstCode), /source-first-code/);
|
|
71
|
+
// An unsupported shape must remove membership before native fallback paints.
|
|
72
|
+
firstCode.updateResult({ content: [{ type: 'unknown', text: 'future native shape' }], details: { calls: [] } });
|
|
73
|
+
assert.equal(owner(firstCode).group, undefined); assert.equal(owner(nextRead).group.members.length, 1);
|
|
74
|
+
assert.doesNotMatch(paint(firstCode), /2 actions/); assert.match(paint(nextRead), /next-read/);
|
|
75
|
+
firstCode.updateResult(success('restored'));
|
|
76
|
+
assert.match(paint(firstCode), /2 actions/); assert.equal(paint(nextRead), '', 'supported completion restores code-first ownership');
|
|
77
|
+
|
|
78
|
+
for (const focused of [false, true]) {
|
|
79
|
+
reset();
|
|
80
|
+
const opened = done('codemode', `opened-${focused}`), originalPane = owner(opened).code;
|
|
81
|
+
if (focused) choices()[0].focus(); else click(opened, 1);
|
|
82
|
+
assert.match(paint(opened), /source-opened/);
|
|
83
|
+
done('read', `append-${focused}`);
|
|
84
|
+
const transferred = owner(opened).group.pane;
|
|
85
|
+
assert.equal(transferred.open, true); assert.equal(transferred.expanded.has(`opened-${focused}`), true);
|
|
86
|
+
assert.equal(originalPane.open, false, 'group transfer clears orphan singleton expansion');
|
|
87
|
+
assert.match(paint(opened), /source-opened/, 'appending an action retains the open code content');
|
|
88
|
+
assert.equal(transferred.focused, focused, 'inspection focus follows the transferred content');
|
|
89
|
+
if (focused) { assert.equal(input('\x1b[B').consume, true); assert.match(paint(opened), /focused/); }
|
|
90
|
+
const collapse = []; pi.events.emit('compact-renderer:disclosures:v1', { add: (...entry) => collapse.push(entry) });
|
|
91
|
+
assert.equal(collapse.length, 1); collapse[0][2]();
|
|
92
|
+
assert.equal(transferred.open, false); assert.equal(originalPane.open, false); assert.equal(transferred.expanded.size, 0);
|
|
93
|
+
click(opened, 1);
|
|
94
|
+
assert.match(paint(opened), /1\. codemode/); assert.doesNotMatch(paint(opened), /source-opened/, 'reopening the group starts with closed actions');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
reset();
|
|
98
|
+
const earlier = done('read', 'earlier-large', { content: [{ type: 'text', text: 'earlier-output\n'.repeat(1000) }] });
|
|
99
|
+
done('read', 'earlier-second');
|
|
100
|
+
const earlierGroup = owner(earlier).group.pane;
|
|
101
|
+
choices()[0].focus(); input('\r'); input('\x1b[B'); paint(earlier);
|
|
102
|
+
assert.match(paint(earlier), /earlier-output/);
|
|
103
|
+
const joining = make('codemode', 'anchored-code');
|
|
104
|
+
joining.markExecutionStarted(); joining.updateResult(success('anchored-code', [{ name: 'read', args: '/anchored', status: 'running' }]), true);
|
|
105
|
+
choices().find(choice => choice.label.startsWith('codemode')).focus();
|
|
106
|
+
joining.updateResult(success('anchored-code'));
|
|
107
|
+
assert.equal(owner(earlier).group.pane, earlierGroup, 'completion reuses the prior ordinary group');
|
|
108
|
+
assert.equal(earlierGroup.selected, 2); assert.equal(earlierGroup.offset, 0);
|
|
109
|
+
assert.match(paint(earlier), /source-anchored-code/, 'focus handoff anchors at code beyond a large earlier output');
|
|
110
|
+
assert.doesNotMatch(paint(earlier), /earlier-output/); assert.equal(paint(joining), '');
|
|
111
|
+
|
|
112
|
+
for (const envelope of [true, false]) {
|
|
113
|
+
reset();
|
|
114
|
+
const timed = make('codemode', `timed-${envelope}`, { code: 'text(1);' });
|
|
115
|
+
timed.updateResult({ durationMs: 73250, content: [...(envelope ? [{ type: 'text', text: 'Script completed\nWall time 73.25 seconds\nOutput:\n' }] : []), { type: 'text', text: 'timed output' }], details: { calls: [] } });
|
|
116
|
+
done('read', `after-timed-${envelope}`);
|
|
117
|
+
choices()[0].focus(); input('\r');
|
|
118
|
+
const timing = paint(timed);
|
|
119
|
+
assert.match(timing, envelope ? /Wall time 73\.25 seconds/ : /Took 73\.25s/, 'mixed code retains recorded or context-only duration');
|
|
120
|
+
if (envelope) assert.doesNotMatch(timing, /Took 73\.25s/, 'the recorded envelope does not get duplicate timing');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
reset();
|
|
124
|
+
const before = done('bash', 'before'), live = make('codemode', 'live');
|
|
125
|
+
live.markExecutionStarted(); live.updateResult(success('live', [{ name: 'read', args: '/live', status: 'running' }]), true);
|
|
126
|
+
const after = done('read', 'after');
|
|
127
|
+
assert.equal(owner(live).group, undefined); assert.match(paint(live), /Running/);
|
|
128
|
+
assert.match(paint(before), /bash/); assert.match(paint(after), /after/);
|
|
129
|
+
event('tool_execution_end', { toolCallId: 'live', toolName: 'codemode', result: success('live') });
|
|
130
|
+
live.updateResult(success('live'));
|
|
131
|
+
assert.match(paint(before), /3 actions/); assert.equal(paint(live), ''); assert.equal(paint(after), '');
|
|
132
|
+
const mutable = success('live'); live.updateResult(mutable);
|
|
133
|
+
mutable.details.calls[0].status = 'error'; mutable.details.calls[0].error = 'nested recorded error';
|
|
134
|
+
event('tool_execution_end', { toolCallId: 'live', toolName: 'codemode', result: mutable }); live.updateResult(mutable);
|
|
135
|
+
assert.equal(owner(live).group, undefined, 'in-place final revision removes stale successful membership');
|
|
136
|
+
assert.match(paint(live), /1 nested error/); assert.match(paint(after), /after/); assert.doesNotMatch(paint(before), /3 actions/);
|
|
137
|
+
mutable.details.calls[0].status = 'ok'; delete mutable.details.calls[0].error;
|
|
138
|
+
event('tool_execution_end', { toolCallId: 'live', toolName: 'codemode', result: mutable }); live.updateResult(mutable);
|
|
139
|
+
assert.match(paint(before), /3 actions/); assert.equal(paint(live), '');
|
|
140
|
+
|
|
141
|
+
const blockers = [
|
|
142
|
+
['nested-error', success('bad', [{ name: 'read', args: '', status: 'error', error: 'failed' }])],
|
|
143
|
+
['nested-cancelled', success('bad', [{ name: 'read', args: '', status: 'cancelled' }])],
|
|
144
|
+
['nested-unresolved', success('bad', [{ name: 'read', args: '', status: 'running' }])],
|
|
145
|
+
['unknown-status', success('bad', [{ name: 'read', args: '', status: 'unavailable' }])],
|
|
146
|
+
['recorded-error', success('bad', [{ name: 'read', args: '', status: 'ok', error: 'recorded diagnostic' }])],
|
|
147
|
+
['warning', success('bad', [], { warning: 'inspect this warning' })],
|
|
148
|
+
['warnings', success('bad', [], { warnings: ['inspect this warning'] })],
|
|
149
|
+
['outer-status', success('bad', [], { status: 'cancelled' })],
|
|
150
|
+
['outer-error', { ...success('bad'), isError: true }],
|
|
151
|
+
['image', { content: [{ type: 'image', mimeType: 'image/png', data: '' }], details: { calls: [] } }],
|
|
152
|
+
];
|
|
153
|
+
for (const [id, record] of blockers) {
|
|
154
|
+
reset(); const left = done('read', `left-${id}`), blocked = done('codemode', id, record), right = done('read', `right-${id}`);
|
|
155
|
+
assert.equal(owner(blocked).group, undefined, `${id} remains standalone`);
|
|
156
|
+
assert.equal(owner(left).group.members.length, 1); assert.equal(owner(right).group.members.length, 1);
|
|
157
|
+
assert.ok(paint(blocked), `${id} keeps a visible compact or native row`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Visible commentary, users, questions, and subagents remain boundaries; pure thinking does not.
|
|
161
|
+
for (const [label, message] of [
|
|
162
|
+
['commentary', { role: 'assistant', content: [{ type: 'text', text: 'Visible commentary' }] }],
|
|
163
|
+
['user', { role: 'user', content: [{ type: 'text', text: 'Continue' }] }],
|
|
164
|
+
['question', { role: 'assistant', content: [{ type: 'toolCall', id: 'question', name: 'ask_user_question', arguments: {} }] }],
|
|
165
|
+
['subagent', { role: 'assistant', content: [{ type: 'toolCall', id: 'agent', name: 'subagent', arguments: {} }] }],
|
|
166
|
+
]) {
|
|
167
|
+
reset(); const left = done('codemode', `boundary-${label}`); event('message_end', { message }); const right = done('read', `after-${label}`);
|
|
168
|
+
assert.equal(owner(left).group, undefined, `${label} separates code from ordinary actions`); assert.equal(owner(right).group.members.length, 1);
|
|
169
|
+
}
|
|
170
|
+
reset(); const thinkingCode = done('codemode', 'thinking-code');
|
|
171
|
+
event('message_end', { message: { role: 'assistant', content: [{ type: 'thinking', thinking: 'Private reasoning' }] } });
|
|
172
|
+
const thinkingRead = done('read', 'thinking-read'); assert.match(paint(thinkingCode), /2 actions/); assert.equal(paint(thinkingRead), '');
|
|
173
|
+
|
|
174
|
+
// History derives eligibility before renderers attach, including code-first order.
|
|
175
|
+
for (const names of [['bash', 'codemode', 'codemode', 'read'], ['codemode', 'read']]) {
|
|
176
|
+
reset();
|
|
177
|
+
const calls = names.map((name, index) => ({ type: 'toolCall', id: `replay-${index}`, name, arguments: name === 'codemode' ? { code: `text(${index});` } : name === 'bash' ? { command: 'git status' } : { path: '/fixture/replay' } }));
|
|
178
|
+
history = [{ type: 'message', message: { role: 'assistant', content: calls } }, ...calls.map(call => ({ type: 'message', message: { role: 'toolResult', toolCallId: call.id, toolName: call.name, ...(call.name === 'codemode' ? success(call.id) : { content: [{ type: 'text', text: 'replay output' }] }) } }))];
|
|
179
|
+
event('session_tree');
|
|
180
|
+
const replayed = calls.map(call => { const component = make(call.name, call.id, call.arguments); component.updateResult(call.name === 'codemode' ? success(call.id) : { content: [{ type: 'text', text: 'replay output' }] }); return component; });
|
|
181
|
+
assert.deepEqual(owner(replayed[0]).group.members.map(node => node.id), calls.map(call => call.id));
|
|
182
|
+
assert.equal(all(replayed).match(new RegExp(`${names.length} actions`, 'g'))?.length, 1, 'replay has one owner and no dropped summary');
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
reset();
|
|
186
|
+
const huge = make('codemode', 'huge', { code: 'const longSource = 1;\n'.repeat(500000) });
|
|
187
|
+
const manyCalls = Array.from({ length: 20000 }, (_, index) => ({ name: 'read', args: `/nested/${index}`, status: 'ok' }));
|
|
188
|
+
huge.updateResult(success('huge', manyCalls)); const tail = done('read', 'tail');
|
|
189
|
+
const content = owner(huge).code.content, bounded = owner(huge).group.pane;
|
|
190
|
+
assert.equal(content.aggregateEntries, 20000); assert.equal(content.sourceCharacters, 0); assert.equal(content.paintedCalls, 0);
|
|
191
|
+
choices()[0].focus(); input('\r'); huge.render(100);
|
|
192
|
+
assert.ok(content.sourceCharacters <= 2048, 'group expansion formats one bounded code viewport');
|
|
193
|
+
assert.equal(content.paintedCalls, 0, 'group does not visit nested calls beyond the source viewport');
|
|
194
|
+
const characters = content.sourceCharacters, painted = bounded.paintedRows;
|
|
195
|
+
for (let index = 0; index < 5; index++) { huge.invalidate(); huge.render(100); }
|
|
196
|
+
assert.equal(content.aggregateEntries, 20000, 'unchanged redraws do not rescan nested records');
|
|
197
|
+
assert.equal(content.sourceCharacters, characters); assert.equal(bounded.paintedRows, painted, 'group reuses visited row cache');
|
|
198
|
+
for (const width of [1, 8, 40, 100]) for (const row of huge.render(width)) assert.ok(tui.visibleWidth(row) <= width);
|
|
199
|
+
assert.equal(paint(tail), '');
|
|
200
|
+
console.log('mixed action groups: order, slots, inspection, transitions, exceptions, replay and bounded formatting passed');
|
|
201
|
+
} finally { dispose(); }
|