@notrico/pi-fold 3.0.5 → 3.1.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 +7 -0
- package/README.md +1 -1
- package/docs/compatibility-testing.md +17 -0
- package/docs/implementation.md +1 -1
- package/index.ts +37 -23
- package/package.json +3 -2
- package/scripts/compatibility-check.mjs +40 -0
- package/scripts/compatibility-cli-smoke.mjs +41 -0
- package/scripts/test.mjs +1 -1
- package/src/display-card.ts +2 -1
- package/src/fold-command.ts +7 -3
- package/src/fullscreen-overlays.ts +13 -11
- package/src/inspection.ts +19 -12
- package/src/modern-native-tools.ts +13 -7
- package/src/modern-prompts-adapter.ts +9 -7
- package/src/modern-skill-prompts.ts +17 -10
- package/src/modern-subagent-messages.ts +16 -7
- package/src/modern-subagent-spacing.ts +8 -6
- package/src/modern-thinking-adapter.ts +13 -9
- package/src/modern-thinking.ts +1 -1
- package/src/modern-tool-images.ts +8 -6
- package/src/modern-tools.ts +28 -15
- package/src/modern-workflows.ts +12 -7
- package/src/permission-presentation.ts +2 -1
- package/src/runtime-compatibility.ts +53 -14
- package/src/work-strip.ts +11 -9
- package/tests/codemode.test.mjs +1 -1
- package/tests/compatibility-fallbacks.test.mjs +99 -0
- package/tests/display-cache-lifecycle.test.mjs +3 -3
- package/tests/fold-command.test.mjs +4 -4
- package/tests/fullscreen-overlays.test.mjs +4 -2
- package/tests/inspection.test.mjs +1 -1
- package/tests/modern-prompts.test.mjs +2 -2
- package/tests/modern-subagent-messages.test.mjs +2 -2
- package/tests/modern-thinking.test.mjs +2 -2
- package/tests/modern-workflows.test.mjs +2 -2
- package/tests/ordinary-prompts.test.mjs +0 -1
- package/tests/runtime-compatibility.test.mjs +48 -21
- package/tests/subagent-spacing.test.mjs +1 -1
- package/tests/work-strip-hierarchy.test.mjs +0 -1
- package/tests/work-strip.test.mjs +13 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
1
|
+
import * as Pi from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import * as Tui from '@earendil-works/pi-tui';
|
|
3
|
+
|
|
4
|
+
const { CustomMessageComponent, VERSION } = Pi;
|
|
5
|
+
const { Container } = Tui;
|
|
4
6
|
|
|
5
7
|
const hidden = Symbol.for('compact-renderer:subagent-hidden:v1');
|
|
6
8
|
|
|
@@ -8,9 +10,9 @@ const hidden = Symbol.for('compact-renderer:subagent-hidden:v1');
|
|
|
8
10
|
* our marked grouped followers; an empty unrelated renderer keeps native layout.
|
|
9
11
|
* CustomEntryComponent is not exported by Pi, so this guarded inherited-method
|
|
10
12
|
* seam avoids importing private modules or replacing the transcript container. */
|
|
11
|
-
export function installSubagentSpacingAdapter(
|
|
12
|
-
const proto = Container
|
|
13
|
-
if (!
|
|
13
|
+
export function installSubagentSpacingAdapter(_version = VERSION): (() => void) | undefined {
|
|
14
|
+
const proto = Container?.prototype as any;
|
|
15
|
+
if (typeof CustomMessageComponent !== 'function' || !proto || typeof proto.render !== 'function') return;
|
|
14
16
|
const owner = Symbol.for('compact-renderer:subagent-spacing:v1');
|
|
15
17
|
proto[owner]?.();
|
|
16
18
|
const original = proto.render;
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { Markdown, MouseRegion, Spacer, Text } from "@earendil-works/pi-tui";
|
|
1
|
+
import * as Pi from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import * as Tui from '@earendil-works/pi-tui';
|
|
4
3
|
import { chainNativeMethod } from "./native-method-chain.ts";
|
|
5
4
|
|
|
5
|
+
const { AssistantMessageComponent, VERSION } = Pi;
|
|
6
|
+
const { Markdown, MouseRegion, Spacer, Text } = Tui;
|
|
7
|
+
|
|
8
|
+
const thinkingComponentsSupported = [Markdown, MouseRegion, Spacer, Text].every(value => typeof value === 'function');
|
|
9
|
+
|
|
6
10
|
/** Private Pi 1.3.0 seam: only pure hidden-thinking assistant containers qualify.
|
|
7
11
|
* Native Ctrl+T/per-run expansion and unknown component shapes always win. */
|
|
8
12
|
export function hiddenThinkingShape(component: any, message: any): boolean {
|
|
9
|
-
if (component.lastMessage !== message || component.hideThinkingBlock !== true || !(component.thinkingVisibilityOverrides instanceof Map)) return false;
|
|
13
|
+
if (!thinkingComponentsSupported || component.lastMessage !== message || component.hideThinkingBlock !== true || !(component.thinkingVisibilityOverrides instanceof Map)) return false;
|
|
10
14
|
if ([...component.thinkingVisibilityOverrides.values()].some(value => value === false)) return false;
|
|
11
15
|
const children = component.contentContainer?.children;
|
|
12
16
|
let expected = 0, inRun = false, nonempty = false;
|
|
@@ -20,7 +24,7 @@ export function hiddenThinkingShape(component: any, message: any): boolean {
|
|
|
20
24
|
/** One hidden run beside native reply text. Validate the exact native sequence;
|
|
21
25
|
* interleaved runs and unfamiliar/error layouts retain their native rendering. */
|
|
22
26
|
export function mixedThinkingRegion(component: any, message: any): any | undefined {
|
|
23
|
-
if (component.lastMessage !== message || component.hideThinkingBlock !== true || !(component.thinkingVisibilityOverrides instanceof Map)
|
|
27
|
+
if (!thinkingComponentsSupported || component.lastMessage !== message || component.hideThinkingBlock !== true || !(component.thinkingVisibilityOverrides instanceof Map)
|
|
24
28
|
|| [...component.thinkingVisibilityOverrides.values()].some(value => value === false)
|
|
25
29
|
|| ["error", "aborted", "length"].includes(message?.stopReason)) return;
|
|
26
30
|
const expected: string[] = [], visible: string[] = [];
|
|
@@ -48,9 +52,9 @@ export function installModernThinkingAdapter(hooks: {
|
|
|
48
52
|
render(component: any, width: number): string[] | undefined;
|
|
49
53
|
mouse(component: any, event: any): any;
|
|
50
54
|
clear(): void;
|
|
51
|
-
},
|
|
52
|
-
const proto = AssistantMessageComponent
|
|
53
|
-
if (!
|
|
55
|
+
}, _version = VERSION): (() => void) | undefined {
|
|
56
|
+
const proto = AssistantMessageComponent?.prototype as any;
|
|
57
|
+
if (!thinkingComponentsSupported || !proto || !["updateContent", "render", "setHideThinkingBlock"].every(key => typeof proto[key] === "function")) return;
|
|
54
58
|
const owner = Symbol.for("compact-renderer:thinking-adapter:v1");
|
|
55
59
|
proto[owner]?.();
|
|
56
60
|
let disposed = false;
|
|
@@ -64,7 +68,7 @@ export function installModernThinkingAdapter(hooks: {
|
|
|
64
68
|
if (region) {
|
|
65
69
|
const component = this, render = region.render, mouse = region.handleMouse;
|
|
66
70
|
region.render = (width: number) => hooks.render(component, width)?.slice(1) ?? render.call(region, width);
|
|
67
|
-
region.handleMouse = (event: any) => hooks.mouse(component, { ...event, y: event.y + 1 }) || mouse
|
|
71
|
+
region.handleMouse = (event: any) => hooks.mouse(component, { ...event, y: event.y + 1 }) || mouse?.call(region, event);
|
|
68
72
|
regions.set(this, () => { region.render = render; region.handleMouse = mouse; });
|
|
69
73
|
}
|
|
70
74
|
}
|
package/src/modern-thinking.ts
CHANGED
|
@@ -224,7 +224,7 @@ export function registerModernThinking(pi: ExtensionAPI, mode: DisplayMode): ()
|
|
|
224
224
|
const rebuild = (_event: unknown, ctx: any) => {
|
|
225
225
|
if (disposed) return;
|
|
226
226
|
stop();
|
|
227
|
-
if (ctx.mode !== "tui" || typeof ctx.ui.setHiddenThinkingLabel !== "function") return;
|
|
227
|
+
if (ctx.mode !== "tui" || typeof ctx.ui.setHiddenThinkingLabel !== "function" || !ctx.sessionManager || (typeof ctx.sessionManager.buildContextEntries !== "function" && typeof ctx.sessionManager.getBranch !== "function")) return;
|
|
228
228
|
const ui = ctx.ui, theme = ui.theme;
|
|
229
229
|
groups = new ModernThinkingGroups(() => mode.isEnabled(), () => theme, inspection => {
|
|
230
230
|
redraw?.();
|
|
@@ -1,17 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import { getCapabilities, Image, imageFallback, truncateToWidth } from "@earendil-works/pi-tui";
|
|
1
|
+
import * as Pi from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import * as Tui from '@earendil-works/pi-tui';
|
|
4
3
|
import { chainNativeMethod } from "./native-method-chain.ts";
|
|
5
4
|
import { activityRow, cardContentWidth, cardPadding } from "./display-card.ts";
|
|
6
5
|
|
|
6
|
+
const { ToolExecutionComponent, VERSION } = Pi;
|
|
7
|
+
const { getCapabilities, Image, imageFallback, truncateToWidth } = Tui;
|
|
8
|
+
|
|
7
9
|
export const compactToolImages = Symbol.for("compact-renderer:tool-images:v1");
|
|
8
10
|
export type ToolImageView = { open: boolean; count: number; bodyIndent: number; source?: string; theme?: any };
|
|
9
11
|
|
|
10
12
|
/** Pi 1.3.0 appends images outside renderShell:self. Borrow those same native
|
|
11
13
|
* objects during render only; never change image sources, settings or ownership. */
|
|
12
|
-
export function installModernToolImages(
|
|
13
|
-
const proto = ToolExecutionComponent
|
|
14
|
-
if (!
|
|
14
|
+
export function installModernToolImages(_version = VERSION): (() => void) | undefined {
|
|
15
|
+
const proto = ToolExecutionComponent?.prototype as any;
|
|
16
|
+
if (![Image, getCapabilities, imageFallback, truncateToWidth].every(value => typeof value === "function") || !proto || typeof proto.render !== "function" || typeof proto.updateDisplay !== "function") return;
|
|
15
17
|
const owner = Symbol.for("compact-renderer:tool-image-adapter:v1");
|
|
16
18
|
proto[owner]?.();
|
|
17
19
|
let disposed = false;
|
package/src/modern-tools.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { DisplayMode } from './display-mode.ts';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
2
|
+
import type { TuiMouseEvent, TuiMouseEventResult } from '@earendil-works/pi-tui';
|
|
3
|
+
import * as Tui from '@earendil-works/pi-tui';
|
|
4
|
+
import type { ExtensionAPI, ToolRenderers } from '@earendil-works/pi-coding-agent';
|
|
5
|
+
import * as Pi from '@earendil-works/pi-coding-agent';
|
|
4
6
|
import { NativeToolOwner, nativeToolsSupported, nativeToolContextSupported, nativeTextFallback } from "./modern-native-tools.ts";
|
|
5
7
|
import { ToolPane, type PaneAction, type PaneContent } from "./modern-tool-pane.ts";
|
|
6
8
|
import { recordedValues } from "./modern-tool-content.ts";
|
|
@@ -11,6 +13,9 @@ import { compactSubagent, subagentDecision, subagentTitle } from "./modern-subag
|
|
|
11
13
|
import { groupIntent } from "./action-intent.ts";
|
|
12
14
|
import { compactToolImages, installModernToolImages, type ToolImageView } from "./modern-tool-images.ts";
|
|
13
15
|
|
|
16
|
+
const { Text, truncateToWidth } = Tui;
|
|
17
|
+
const getLanguageFromPath = typeof Pi.getLanguageFromPath === "function" ? Pi.getLanguageFromPath : () => undefined;
|
|
18
|
+
|
|
14
19
|
type Context = Parameters<NonNullable<ToolRenderers["renderCall"]>>[2];
|
|
15
20
|
type Status = "pending" | "running" | "success" | "failed" | "cancelled" | "unavailable" | "unanswered" | "answered" | "notice";
|
|
16
21
|
type Node = { id: string; name: string; args: any; epoch: number; status: Status; result?: any; images: number; note?: string; pane?: ToolPane; code?: CodePane; group?: Group; native: NativeToolOwner; invalidate?: () => void; nativeExpanded?: boolean; rendererAttached?: boolean; revision: number; lastPartial?: boolean; lastError?: boolean };
|
|
@@ -224,9 +229,10 @@ class DynamicComponent {
|
|
|
224
229
|
}
|
|
225
230
|
|
|
226
231
|
/** Display-only tools: public renderer/event/input APIs; no messages or tool execution are changed. */
|
|
227
|
-
export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () => void {
|
|
228
|
-
if (!nativeToolsSupported
|
|
229
|
-
|
|
232
|
+
export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode, options: { images?: boolean; subagents?: boolean } = {}): () => void {
|
|
233
|
+
if (!nativeToolsSupported || typeof pi.registerToolRenderer !== 'function' || typeof pi.on !== 'function' ||
|
|
234
|
+
typeof pi.events?.on !== 'function' || typeof pi.events?.emit !== 'function' || typeof truncateToWidth !== 'function') return () => {};
|
|
235
|
+
const subagents = options.subagents !== false ? acquireSubagentProjection(pi) : undefined;
|
|
230
236
|
let disposed = false;
|
|
231
237
|
let epoch = 0;
|
|
232
238
|
let nodes = new Map<string, Node>();
|
|
@@ -239,15 +245,17 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
239
245
|
const rowGenerations = new WeakMap<object, number>();
|
|
240
246
|
let rebuilding = false;
|
|
241
247
|
const subscriptions: (() => void)[] = [];
|
|
242
|
-
const imageAdapterOff = installModernToolImages();
|
|
248
|
+
const imageAdapterOff = options.images !== false ? installModernToolImages() : undefined;
|
|
249
|
+
const images = !!imageAdapterOff;
|
|
250
|
+
const nativeImages = (node: Node) => !images && node.images > 0;
|
|
243
251
|
if (imageAdapterOff) subscriptions.push(imageAdapterOff);
|
|
244
252
|
const redraw = () => {
|
|
245
253
|
// Snapshot before native synchronous invalidate -> updateDisplay -> renderer registration.
|
|
246
254
|
for (const invalidate of [...new Set([...nodes.values()].map(node => node.invalidate).filter(Boolean))]) invalidate!();
|
|
247
255
|
};
|
|
248
256
|
const release = (preserveAnchor = false) => { if (focused) { focused.focused = false; if (!preserveAnchor && focused instanceof ToolPane) focused.releaseInspection(); focused = undefined; } };
|
|
249
|
-
const subagentView = (node: Node) => { subagents.sync(); return compactSubagent(node.name) ? subagents.projection.viewTool(node.id) : undefined; };
|
|
250
|
-
const panes = () => [...nodes.values()].flatMap<ToolPane | CodePane>(node => subagentView(node) ? subagentView(node)!.hidden ? [] : [subagentView(node)!.pane] : node.group ? node.group.members[0] === node ? [node.group.pane] : [] : node.code ? node.code.content.supported ? [node.code] : [] : node.pane ? [node.pane] : []);
|
|
257
|
+
const subagentView = (node: Node) => { if (!subagents) return; subagents.sync(); return compactSubagent(node.name) ? subagents.projection.viewTool(node.id) : undefined; };
|
|
258
|
+
const panes = () => [...nodes.values()].flatMap<ToolPane | CodePane>(node => nativeImages(node) ? [] : subagentView(node) ? subagentView(node)!.hidden ? [] : [subagentView(node)!.pane] : node.group ? node.group.members[0] === node ? [node.group.pane] : [] : node.code ? node.code.content.supported ? [node.code] : [] : node.pane ? [node.pane] : []);
|
|
251
259
|
const focusPane = (pane: ToolPane | CodePane) => {
|
|
252
260
|
if (disposed || !mode.isEnabled() || !panes().includes(pane)) return;
|
|
253
261
|
release(); focused = pane; pane.focused = true; pane.open = true; redraw();
|
|
@@ -489,7 +497,7 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
489
497
|
return {
|
|
490
498
|
renderShell: "self",
|
|
491
499
|
[compactToolImages](component: any, width: number): ToolImageView | undefined {
|
|
492
|
-
if (disposed || !mode.isEnabled() || rowGenerations.get(component.rendererState) !== generation) return;
|
|
500
|
+
if (!images || disposed || !mode.isEnabled() || rowGenerations.get(component.rendererState) !== generation) return;
|
|
493
501
|
const node = nodes.get(component.toolCallId);
|
|
494
502
|
if (!node || !node.images || node.code && !node.code.content.supported || subagentView(node)?.hidden) return;
|
|
495
503
|
const pane = node.code || individual(node);
|
|
@@ -502,23 +510,28 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
502
510
|
renderCall(args, theme, context) {
|
|
503
511
|
if (disposed || !nativeToolContextSupported(context) || stale(context)) return stock?.renderCall?.(args, theme, { ...context, executionStarted: false, state: {}, lastComponent: undefined }) ?? new Text(json(args), 0, 0);
|
|
504
512
|
const node = get(args, context);
|
|
505
|
-
if (disposed || !mode.isEnabled()) { node.code?.suspend(); if (node.code) node.native.adoptClock(node.code.clock); return node.native.renderCall(args, theme, context); }
|
|
513
|
+
if (disposed || !mode.isEnabled() || nativeImages(node)) { node.code?.suspend(); if (node.code) node.native.adoptClock(node.code.clock); return node.native.renderCall(args, theme, context); }
|
|
506
514
|
if (node.code) {
|
|
507
515
|
if (!codePane(node, theme, context)) node.native.renderCall(args, theme, context);
|
|
508
516
|
syncExpansion(node, context.expanded);
|
|
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);
|
|
517
|
+
return new DynamicComponent(width => nativeImages(node) ? node.native.renderCurrent(width) : node.group ? groupPane(node, theme)?.render(width) ?? [] : node.code!.content.supported ? node.code!.render(width) : node.native.renderCurrent(width), event => nativeImages(node) ? undefined : mouse(node.group ? groupPane(node, theme) : node.code!.content.supported ? node.code : undefined, event), node);
|
|
510
518
|
}
|
|
511
519
|
node.native.suspend(); syncExpansion(node, context.expanded);
|
|
512
520
|
return new DynamicComponent(width => {
|
|
521
|
+
if (nativeImages(node)) return node.native.renderCurrent(width);
|
|
513
522
|
if (subagentView(node)?.hidden || node.group) return [];
|
|
514
523
|
if (singleCard(node)) return individual(node, theme).render(width);
|
|
515
524
|
return [activityRow(truncateToWidth(activityHeading(`${node.result ? "" : "… "}${toolLabel(name, node.args)}${node.result ? "" : ` · ${context.executionStarted ? "running" : "preparing"}`}`, theme), cardContentWidth(width)), width, theme)];
|
|
516
|
-
}, event => mouse(!subagentView(node)?.hidden && !node.group && singleCard(node) ? individual(node, theme) : undefined, event), node);
|
|
525
|
+
}, event => nativeImages(node) ? undefined : mouse(!subagentView(node)?.hidden && !node.group && singleCard(node) ? individual(node, theme) : undefined, event), node);
|
|
517
526
|
},
|
|
518
527
|
renderResult(result, options, theme, context) {
|
|
519
528
|
if (disposed || !nativeToolContextSupported(context) || stale(context)) return stock?.renderResult?.(result, options, theme, { ...context, executionStarted: false, state: {}, lastComponent: undefined }) ?? nativeTextFallback(result, theme);
|
|
520
529
|
const node = get(context.args, context); record(node, result, options.isPartial, context.isError);
|
|
521
|
-
if (disposed || !mode.isEnabled()
|
|
530
|
+
if (disposed || !mode.isEnabled() || nativeImages(node)) {
|
|
531
|
+
node.code?.suspend(); if (node.code) node.native.adoptClock(node.code.clock);
|
|
532
|
+
if (nativeImages(node)) node.native.renderCall(node.args, theme, context);
|
|
533
|
+
return node.native.renderResult(result, options, theme, context);
|
|
534
|
+
}
|
|
522
535
|
if (node.code) {
|
|
523
536
|
if (!codePane(node, theme, context)) { node.native.renderCall(node.args, theme, context); node.native.renderResult(result, options, theme, context); }
|
|
524
537
|
syncExpansion(node, context.expanded);
|
|
@@ -530,9 +543,9 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
|
|
|
530
543
|
if (node.group) return groupPane(node, theme)?.render(width) ?? [];
|
|
531
544
|
if (singleCard(node)) return [];
|
|
532
545
|
return individual(node, theme).render(width);
|
|
533
|
-
}, event => mouse(node.group ? node.group.members[0] === node ? node.group.pane : undefined : !singleCard(node) ? individual(node, theme) : undefined, event), node);
|
|
546
|
+
}, event => nativeImages(node) ? undefined : mouse(node.group ? node.group.members[0] === node ? node.group.pane : undefined : !singleCard(node) ? individual(node, theme) : undefined, event), node);
|
|
534
547
|
},
|
|
535
548
|
};
|
|
536
549
|
});
|
|
537
|
-
return () => { if (disposed) return; disposed = true; clear(); subagents
|
|
550
|
+
return () => { if (disposed) return; disposed = true; clear(); subagents?.release(); for (const off of subscriptions.splice(0)) off(); };
|
|
538
551
|
}
|
package/src/modern-workflows.ts
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { supportsPiVersion } from './runtime-compatibility.ts';
|
|
2
1
|
import type { DisplayMode } from './display-mode.ts';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
2
|
+
import type { ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
3
|
+
import * as Pi from '@earendil-works/pi-coding-agent';
|
|
4
|
+
import * as Tui from '@earendil-works/pi-tui';
|
|
5
5
|
import { activityRow, cardContentWidth, finalReplyRendering } from './display-card.ts';
|
|
6
6
|
import { richTextRows } from './modern-rich-text.ts';
|
|
7
7
|
import { recordedPaneHeight } from './modern-recorded-pane.ts';
|
|
8
8
|
import { chainNativeMethod } from './native-method-chain.ts';
|
|
9
9
|
|
|
10
|
+
const { AssistantMessageComponent, VERSION } = Pi;
|
|
11
|
+
const { Container, Markdown, MouseRegion, Spacer, Text, matchesKey, truncateToWidth } = Tui;
|
|
12
|
+
|
|
10
13
|
export type WorkflowFence = { start: number; end: number; source: string; summary: string };
|
|
11
14
|
const summaryText = (value: string) => truncateToWidth(value.slice(0, 1024).replace(/[\p{Cc}\p{Cf}]/gu, ' ').replace(/\s+/g, ' ').trim(), 90, '…');
|
|
12
15
|
|
|
@@ -99,16 +102,18 @@ export class WorkflowPane {
|
|
|
99
102
|
}
|
|
100
103
|
}
|
|
101
104
|
|
|
102
|
-
type Card = { id: number; component: any; sources: string[]; fences: WorkflowFence[][]; panes: Map<string, WorkflowPane>; displays: Map<any, Container
|
|
105
|
+
type Card = { id: number; component: any; sources: string[]; fences: WorkflowFence[][]; panes: Map<string, WorkflowPane>; displays: Map<any, InstanceType<typeof Container>> };
|
|
103
106
|
|
|
104
107
|
/** The public Markdown transformer cannot return components or identify a card.
|
|
105
108
|
* This isolated 1.3.0 seam substitutes display children only during native render.
|
|
106
109
|
* Native messages, Markdown sources, updateContent, and execution remain untouched. */
|
|
107
|
-
export function registerModernWorkflows(pi: ExtensionAPI, mode: DisplayMode,
|
|
110
|
+
export function registerModernWorkflows(pi: ExtensionAPI, mode: DisplayMode, _version = VERSION): () => void {
|
|
108
111
|
const owner = Symbol.for('compact-renderer:workflow-registration:v1'), shared = globalThis as any;
|
|
109
112
|
shared[owner]?.();
|
|
110
|
-
const proto = AssistantMessageComponent
|
|
111
|
-
if (!
|
|
113
|
+
const proto = AssistantMessageComponent?.prototype as any;
|
|
114
|
+
if (![Container, Markdown, MouseRegion, Spacer, Text, matchesKey, truncateToWidth].every(value => typeof value === 'function') ||
|
|
115
|
+
!proto || typeof proto.render !== 'function' || typeof proto.updateContent !== 'function' ||
|
|
116
|
+
typeof pi.on !== 'function' || typeof pi.events?.on !== 'function' || typeof pi.events?.emit !== 'function') return () => {};
|
|
112
117
|
const cards = new Map<any, Card>();
|
|
113
118
|
let active = false, disposed = false, selected: WorkflowPane | undefined, uiTheme: any, nextCard = 0;
|
|
114
119
|
let input: (() => void) | undefined, redraw: (() => void) | undefined;
|
|
@@ -275,12 +275,13 @@ export function registerPermissionPresentation(pi: any, mode: DisplayMode): () =
|
|
|
275
275
|
});
|
|
276
276
|
});
|
|
277
277
|
const unsubscribeMode = mode.onChange(() => { if (!mode.isEnabled()) cancelAll(); });
|
|
278
|
-
|
|
278
|
+
const lifecycle = ['session_switch', 'session_tree', 'session_compact', 'session_shutdown'].map(event => pi.on?.(event, cancelAll));
|
|
279
279
|
return () => {
|
|
280
280
|
if (disposed) return;
|
|
281
281
|
disposed = true;
|
|
282
282
|
unsubscribe?.();
|
|
283
283
|
unsubscribeMode();
|
|
284
|
+
lifecycle.forEach(off => { if (typeof off === 'function') off(); });
|
|
284
285
|
cancelAll();
|
|
285
286
|
};
|
|
286
287
|
}
|
|
@@ -1,17 +1,56 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as core from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import * as tui from '@earendil-works/pi-tui';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/** Versions are evidence from CI, never a condition for enabling display features. */
|
|
5
|
+
export const testedPiVersions = ['1.3.0', '1.4.0'] as const;
|
|
6
|
+
const rendering = ['Markdown', 'matchesKey', 'truncateToWidth', 'visibleWidth', 'wrapTextWithAnsi'];
|
|
7
|
+
const richText = ['getMarkdownTheme', 'highlightCode'];
|
|
8
|
+
const panes = [...rendering, 'MouseRegion', 'Spacer', 'Text'];
|
|
9
|
+
const requirements = {
|
|
10
|
+
tools: { api: ['registerToolRenderer', 'events.on', 'events.emit'], core: richText, tui: [...rendering, 'Box', 'Box.prototype.setBgFn', 'Box.prototype.setPaddingX', 'Box.prototype.clear', 'Box.prototype.addChild', 'Box.prototype.render', 'Container', 'Container.prototype.clear', 'Container.prototype.render', 'Text', 'stripTerminalSequences'] },
|
|
11
|
+
images: { core: ['ToolExecutionComponent.prototype.render', 'ToolExecutionComponent.prototype.updateDisplay'], tui: ['Image', 'getCapabilities', 'imageFallback'] },
|
|
12
|
+
thinking: { core: [...richText, 'AssistantMessageComponent.prototype.render', 'AssistantMessageComponent.prototype.updateContent', 'AssistantMessageComponent.prototype.setHideThinkingBlock'], tui: panes },
|
|
13
|
+
prompts: { api: ['registerMarkdownTransformer', 'getCommands'], core: ['UserMessageComponent.prototype.render', 'UserMessageComponent.prototype.rebuild'], tui: ['Markdown', 'matchesKey', 'stripTerminalSequences', 'truncateToWidth'] },
|
|
14
|
+
skills: { core: ['InteractiveMode.prototype.addMessageToChat', 'SkillInvocationMessageComponent.prototype.setExpanded', 'SkillInvocationMessageComponent.prototype.render', 'UserMessageComponent.prototype.render'], tui: [...panes, 'Box', 'Container', 'stripTerminalSequences'] },
|
|
15
|
+
workflows: { core: [...richText, 'AssistantMessageComponent.prototype.render', 'AssistantMessageComponent.prototype.updateContent'], tui: [...panes, 'Container'] },
|
|
16
|
+
subagents: { core: [...richText, 'ExtensionRunner.prototype.getMessageRenderer', 'ExtensionRunner.prototype.getEntryRenderer', 'CustomMessageComponent'], tui: [...rendering, 'Container.prototype.render'] },
|
|
17
|
+
work: { api: ['appendEntry'], core: [...richText, 'InteractiveMode.prototype.addMessageToChat', 'InteractiveMode.prototype.handleEvent', 'InteractiveMode.prototype.renderSessionItems', 'AssistantMessageComponent', 'CustomMessageComponent', 'SkillInvocationMessageComponent', 'ToolExecutionComponent', 'UserMessageComponent'], tui: [...panes, 'Container', 'Box'] },
|
|
18
|
+
inspection: { api: ['events.on', 'events.emit'], tui: ['Box', 'Container', 'Markdown', 'truncateToWidth', 'visibleWidth'] },
|
|
19
|
+
reveal: { tui: ['ScrollView.prototype.scrollTo', 'ScrollView.prototype.getContentWidth', 'isViewportTUI'] },
|
|
20
|
+
overlays: { tui: ['TuiAltScreen.prototype.compositeOverlays', 'TuiAltScreen.prototype.prepareKittyScreen'] },
|
|
21
|
+
permissions: { api: ['events.on'], tui: ['getKeybindings', 'matchesKey', 'truncateToWidth', 'visibleWidth', 'wrapTextWithAnsi'] },
|
|
22
|
+
} as const;
|
|
23
|
+
export type FoldFeature = keyof typeof requirements;
|
|
24
|
+
const labels: Record<FoldFeature, string> = { tools: 'Tool cards', images: 'Tool images', thinking: 'Thinking', prompts: 'Prompt folding', skills: 'Skill prompts', workflows: 'Workflow panes', subagents: 'Subagent groups', work: 'Work sections', inspection: 'Inspection picker', reveal: 'Inspection scrolling', overlays: 'Overlay protection', permissions: 'Permission presentation' };
|
|
25
|
+
const method = (object: any, path: string) => typeof path.split('.').reduce((value, key) => value?.[key], object) === 'function';
|
|
7
26
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
27
|
+
/** Probe once before loading feature modules. Instance guards still protect each native row. */
|
|
28
|
+
export function inspectRuntime(api: any, agent: any = core, terminal: any = tui) {
|
|
29
|
+
const failures = new Map<FoldFeature, string[]>();
|
|
30
|
+
for (const [feature, needs] of Object.entries(requirements)) {
|
|
31
|
+
const missing: string[] = [];
|
|
32
|
+
for (const [source, paths] of Object.entries(needs)) {
|
|
33
|
+
const object = source === 'api' ? api : source === 'core' ? agent : terminal;
|
|
34
|
+
for (const path of paths) if (!method(object, path)) missing.push(`${source}.${path}`);
|
|
35
|
+
}
|
|
36
|
+
for (const path of ['on', 'registerCommand', 'events.on', 'events.emit']) if (!method(api, path)) missing.push(`api.${path}`);
|
|
37
|
+
failures.set(feature as FoldFeature, missing);
|
|
38
|
+
}
|
|
39
|
+
const dependencies: Partial<Record<FoldFeature, FoldFeature>> = { images: 'tools', reveal: 'inspection', overlays: 'inspection' };
|
|
40
|
+
const available = (feature: FoldFeature): boolean => !failures.get(feature)?.length && (!dependencies[feature] || available(dependencies[feature]!));
|
|
41
|
+
return {
|
|
42
|
+
version: typeof agent.VERSION === 'string' ? agent.VERSION : 'unknown',
|
|
43
|
+
available,
|
|
44
|
+
disable(feature: FoldFeature, reason: string) { const reasons = failures.get(feature)!; if (!reasons.includes(reason)) reasons.push(reason); },
|
|
45
|
+
get state(): 'full' | 'partial' | 'unavailable' {
|
|
46
|
+
const features = Object.keys(requirements) as FoldFeature[];
|
|
47
|
+
const count = features.filter(available).length;
|
|
48
|
+
return count === features.length ? 'full' : count ? 'partial' : 'unavailable';
|
|
49
|
+
},
|
|
50
|
+
describe() {
|
|
51
|
+
const disabled = (Object.keys(requirements) as FoldFeature[]).filter(feature => !available(feature));
|
|
52
|
+
return `Compatibility: ${this.state} (Pi ${this.version})` + disabled.map(feature => `\n${labels[feature]} unavailable: ${failures.get(feature)?.join(', ') || `${labels[dependencies[feature]!]} unavailable`}`).join('');
|
|
53
|
+
},
|
|
54
|
+
};
|
|
17
55
|
}
|
|
56
|
+
export type RuntimeCompatibility = ReturnType<typeof inspectRuntime>;
|
package/src/work-strip.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { supportsPiVersion } from './runtime-compatibility.ts';
|
|
2
1
|
import type { DisplayMode } from './display-mode.ts';
|
|
3
|
-
import { AssistantMessageComponent, CustomMessageComponent, InteractiveMode, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent,
|
|
2
|
+
import { AssistantMessageComponent, CustomMessageComponent, InteractiveMode, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent, type ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
4
3
|
import { Container, Spacer, matchesKey } from '@earendil-works/pi-tui';
|
|
5
4
|
import { chainNativeMethod } from './native-method-chain.ts';
|
|
6
5
|
import { ToolPane } from './modern-tool-pane.ts';
|
|
@@ -66,11 +65,11 @@ export interface WorkStripControls {
|
|
|
66
65
|
|
|
67
66
|
/** Pi 1.3 display seam. The native tree, transcript, execution and Fleet remain
|
|
68
67
|
* authoritative. Only chatContainer's rendered child list is projected. */
|
|
69
|
-
export function registerWorkStrip(pi: ExtensionAPI, mode: DisplayMode, version
|
|
68
|
+
export function registerWorkStrip(pi: ExtensionAPI, mode: DisplayMode, version?: string, unavailable?: (reason: string) => void): WorkStripControls {
|
|
70
69
|
const owner = Symbol.for('compact-renderer:work-registration:v1'), shared = globalThis as any;
|
|
71
70
|
shared[owner]?.();
|
|
72
71
|
const proto = InteractiveMode.prototype as any;
|
|
73
|
-
if (!
|
|
72
|
+
if (!['addMessageToChat', 'handleEvent', 'renderSessionItems'].every(k => typeof proto?.[k] === 'function')) return { dispose() {}, setExpanded: () => false, isShortcutEnabled: () => false, setShortcutEnabled() {} };
|
|
74
73
|
let disposed = false, ctx: any, host: any, attached: any, detachChat: (() => void) | undefined;
|
|
75
74
|
let turns = new Map<any, Turn>(), sources = new WeakMap<any, any>(), hooks = new Map<any, ToolPane>();
|
|
76
75
|
let selected: WorkStripHeader | ToolPane | undefined, input: (() => void) | undefined, timer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -254,23 +253,26 @@ export function registerWorkStrip(pi: ExtensionAPI, mode: DisplayMode, version =
|
|
|
254
253
|
return output;
|
|
255
254
|
};
|
|
256
255
|
const attach = (candidate: any) => {
|
|
257
|
-
if (disposed
|
|
256
|
+
if (disposed) return false;
|
|
257
|
+
if (!(candidate?.chatContainer instanceof Container) || !Array.isArray(candidate.chatContainer.children) || typeof candidate.chatContainer.render !== 'function' || !candidate.ui) { unavailable?.('native chat container changed'); return false; }
|
|
258
258
|
if (host !== candidate) { detachChat?.(); host = candidate; attached = undefined; }
|
|
259
|
-
if (attached) return;
|
|
259
|
+
if (attached) return true;
|
|
260
260
|
const chat = candidate.chatContainer;
|
|
261
261
|
detachChat = chainNativeMethod(chat, 'render', function(native, width) {
|
|
262
|
-
if (disposed || !ctx || !mode.isEnabled()) { delete this[projectedChildren]; return native.call(this, width); }
|
|
262
|
+
if (disposed || !ctx || !mode.isEnabled() || !Array.isArray(this.children)) { delete this[projectedChildren]; return native.call(this, width); }
|
|
263
263
|
const canonical = this.children;
|
|
264
264
|
this[projectedChildren] = project(canonical);
|
|
265
265
|
this.children = this[projectedChildren];
|
|
266
266
|
try { return native.call(this, width); } finally { this.children = canonical; }
|
|
267
267
|
});
|
|
268
268
|
attached = chat;
|
|
269
|
+
return true;
|
|
269
270
|
};
|
|
270
271
|
const detachAdd = chainNativeMethod(proto, 'addMessageToChat', function(native, message, ...args) {
|
|
271
|
-
attach(this)
|
|
272
|
+
if (!attach(this)) return native.call(this, message, ...args);
|
|
273
|
+
const before = this.chatContainer.children.length;
|
|
272
274
|
const result = native.call(this, message, ...args);
|
|
273
|
-
for (const row of this.chatContainer?.children.slice(before)
|
|
275
|
+
for (const row of (Array.isArray(this.chatContainer?.children) ? this.chatContainer.children.slice(before) : [])) if (!(row instanceof Spacer)) sources.set(row, message);
|
|
274
276
|
if (!replaying && running && message.role === 'user') liveStarts.set(message, Date.now());
|
|
275
277
|
return result;
|
|
276
278
|
});
|
package/tests/codemode.test.mjs
CHANGED
|
@@ -26,7 +26,7 @@ const pi = {
|
|
|
26
26
|
events: { on(name, fn) { bus.set(name, fn); return () => bus.delete(name); }, emit(name, data) { bus.get(name)?.(data); } },
|
|
27
27
|
};
|
|
28
28
|
const originalToolRender=ToolExecutionComponent.prototype.render;
|
|
29
|
-
|
|
29
|
+
{ const cleanup = installModernToolImages('1.5.0'); assert.equal(typeof cleanup, 'function'); cleanup(); }
|
|
30
30
|
assert.equal(ToolExecutionComponent.prototype.render,originalToolRender);
|
|
31
31
|
const mode = createDisplayMode(), dispose = registerModernTools(pi, mode);
|
|
32
32
|
const ctx = { hasUI: true, sessionManager: { getBranch: () => [] }, ui: { onTerminalInput(fn) { input = fn; return () => { input = undefined; }; } } };
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { core, tui, loadSource, loadAgent, stripAnsi } from './test-runtime.mjs';
|
|
3
|
+
|
|
4
|
+
const { inspectRuntime } = await loadSource('runtime-compatibility.ts');
|
|
5
|
+
const { registerModernTools } = await loadSource('modern-tools.ts');
|
|
6
|
+
const { SubagentProjection } = await loadSource('modern-subagent-groups.ts');
|
|
7
|
+
const { ToolExecutionComponent } = await loadAgent('modes/interactive/components/tool-execution.js');
|
|
8
|
+
const plain = component => stripAnsi(component.render(100).join('\n'));
|
|
9
|
+
|
|
10
|
+
function fixture(entries = []) {
|
|
11
|
+
const hooks = new Map(), events = new Map();
|
|
12
|
+
let resolver;
|
|
13
|
+
const on = (map, name, callback) => {
|
|
14
|
+
const list = map.get(name) || [];
|
|
15
|
+
map.set(name, [...list, callback]);
|
|
16
|
+
return () => map.set(name, (map.get(name) || []).filter(item => item !== callback));
|
|
17
|
+
};
|
|
18
|
+
const pi = {
|
|
19
|
+
on: (name, callback) => on(hooks, name, callback),
|
|
20
|
+
registerCommand() {}, registerMarkdownTransformer() {}, getCommands: () => [], appendEntry() {},
|
|
21
|
+
registerToolRenderer(callback) { resolver = callback; },
|
|
22
|
+
events: {
|
|
23
|
+
on: (name, callback) => on(events, name, callback),
|
|
24
|
+
emit(name, value) { for (const callback of events.get(name) || []) callback(value); },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
const context = { hasUI: true, sessionManager: { getBranch: () => entries }, ui: { onTerminalInput: () => () => {} } };
|
|
28
|
+
return {
|
|
29
|
+
pi, hooks,
|
|
30
|
+
mode: { isEnabled: () => true, onChange: () => () => {} },
|
|
31
|
+
start() { for (const callback of hooks.get('session_start') || []) callback({}, context); },
|
|
32
|
+
create(name, id, args, stock) {
|
|
33
|
+
const component = new ToolExecutionComponent(name, id, args, { showImages: false, outputPad: 0 }, resolver(name, () => stock), { requestRender() {} }, '/synthetic');
|
|
34
|
+
component.setArgsComplete();
|
|
35
|
+
return component;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// This sequence would hide the tool behind a custom-message group leader.
|
|
41
|
+
// A missing resolver must leave that tool available in its own card.
|
|
42
|
+
{
|
|
43
|
+
const receipt = { role: 'toolResult', toolCallId: 'status-1', toolName: 'subagent', content: [{ type: 'text', text: 'Exact visible status receipt' }], details: { agent: 'worker' }, timestamp: 3 };
|
|
44
|
+
const entries = [
|
|
45
|
+
{ type: 'custom_message', id: 'notice-1', customType: 'subagent-notify', content: 'Exact native completion notice', details: { runs: [{ agent: 'worker', status: 'completed' }] }, display: true, timestamp: 1 },
|
|
46
|
+
{ type: 'message', id: 'call-1', message: { role: 'assistant', content: [{ type: 'toolCall', id: receipt.toolCallId, name: 'subagent', arguments: { agent: 'worker', action: 'status' } }], timestamp: 2 } },
|
|
47
|
+
{ type: 'message', id: 'result-1', message: receipt },
|
|
48
|
+
];
|
|
49
|
+
const projection = new SubagentProjection();
|
|
50
|
+
projection.rebuild(entries);
|
|
51
|
+
assert.equal(projection.viewTool(receipt.toolCallId).hidden, true, 'fixture exercises a hidden tool follower');
|
|
52
|
+
const f = fixture(entries);
|
|
53
|
+
const report = inspectRuntime(f.pi, { ...core, ExtensionRunner: undefined }, tui);
|
|
54
|
+
assert.equal(report.available('subagents'), false);
|
|
55
|
+
assert.equal(report.available('tools'), true);
|
|
56
|
+
const dispose = registerModernTools(f.pi, f.mode, { images: report.available('images'), subagents: report.available('subagents') });
|
|
57
|
+
try {
|
|
58
|
+
f.start();
|
|
59
|
+
const component = f.create('subagent', receipt.toolCallId, { agent: 'worker', action: 'status' }, {
|
|
60
|
+
renderCall: () => new tui.Text('Native status call', 0, 0),
|
|
61
|
+
renderResult: () => new tui.Text('Native status result', 0, 0),
|
|
62
|
+
});
|
|
63
|
+
component.updateResult(receipt);
|
|
64
|
+
component.setExpanded(true);
|
|
65
|
+
assert.match(plain(component), /Exact visible status receipt/);
|
|
66
|
+
assert.equal(f.hooks.get('message_update')?.length, undefined, 'disabled grouping acquires no shared projection listener');
|
|
67
|
+
const choices = [];
|
|
68
|
+
f.pi.events.emit('compact-renderer:inspect:v1', { add: choice => choices.push(choice) });
|
|
69
|
+
assert.equal(choices.length, 1, 'standalone subagent tool remains inspectable');
|
|
70
|
+
} finally { dispose(); }
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// The result can introduce an image after the compact call component exists.
|
|
74
|
+
// Both native renderer shell contracts must retain their complete output.
|
|
75
|
+
for (const self of [false, true]) {
|
|
76
|
+
const f = fixture();
|
|
77
|
+
const nativeRender = ToolExecutionComponent.prototype.render;
|
|
78
|
+
const dispose = registerModernTools(f.pi, f.mode, { images: false, subagents: false });
|
|
79
|
+
try {
|
|
80
|
+
assert.equal(ToolExecutionComponent.prototype.render, nativeRender, 'disabled images install no prototype hook');
|
|
81
|
+
f.start();
|
|
82
|
+
const component = f.create('read', `image-fallback-${self}`, { path: '/synthetic/image.png' }, {
|
|
83
|
+
...(self ? { renderShell: 'self' } : {}),
|
|
84
|
+
renderCall: () => new tui.Text('STOCK CALL', 0, 0),
|
|
85
|
+
renderResult: () => new tui.Text('STOCK IMAGE RESULT', 0, 0),
|
|
86
|
+
});
|
|
87
|
+
component.render(100);
|
|
88
|
+
component.updateResult({ content: [{ type: 'image', data: 'synthetic', mimeType: 'image/png' }], details: {} });
|
|
89
|
+
const output = plain(component);
|
|
90
|
+
assert.match(output, /STOCK CALL/);
|
|
91
|
+
assert.match(output, /STOCK IMAGE RESULT/);
|
|
92
|
+
assert.doesNotMatch(output, /▸ read/);
|
|
93
|
+
const choices = [];
|
|
94
|
+
f.pi.events.emit('compact-renderer:inspect:v1', { add: choice => choices.push(choice) });
|
|
95
|
+
assert.equal(choices.length, 0, 'native image fallback is absent from Pi Fold inspection');
|
|
96
|
+
} finally { dispose(); }
|
|
97
|
+
assert.equal(ToolExecutionComponent.prototype.render, nativeRender);
|
|
98
|
+
}
|
|
99
|
+
console.log('compatibility fallbacks: missing subagent resolver preserves tool output; disabled images preserve native shells and cleanup');
|
|
@@ -30,13 +30,13 @@ const pi = {
|
|
|
30
30
|
for (const fn of [...bus.get(event) || []]) fn(data);
|
|
31
31
|
} },
|
|
32
32
|
registerToolRenderer() {}, registerMarkdownTransformer() {}, registerCommand() {},
|
|
33
|
-
registerShortcut() {}, getCommands: () => [], getAllTools: () => [],
|
|
33
|
+
registerShortcut() {}, appendEntry() {}, getCommands: () => [], getAllTools: () => [],
|
|
34
34
|
};
|
|
35
35
|
const ctx = { mode: 'none', hasUI: false, ui: {}, sessionManager: { getBranch: () => [], buildContextEntries: () => [] } };
|
|
36
36
|
const emit = event => { for (const fn of [...hooks.get(event) || []]) fn({}, ctx); };
|
|
37
37
|
try {
|
|
38
38
|
expectCold();
|
|
39
|
-
register(pi);
|
|
39
|
+
await register(pi);
|
|
40
40
|
expectCold(); // Registration also removes text retained by a previous load.
|
|
41
41
|
for (const event of ['session_start', 'session_tree', 'session_compact', 'session_before_switch', 'session_shutdown']) {
|
|
42
42
|
emit(event); expectCold();
|
|
@@ -46,7 +46,7 @@ try {
|
|
|
46
46
|
probe();
|
|
47
47
|
assert.equal(formats, before, 'disposed root callbacks do not clear a later cache');
|
|
48
48
|
// A registration failure before any feature starts must still release shared text.
|
|
49
|
-
assert.
|
|
49
|
+
await assert.rejects(() => register({ ...pi, on() { probe(); throw new Error('registration fixture'); } }), /registration fixture/);
|
|
50
50
|
expectCold();
|
|
51
51
|
console.log('Shared display cache lifecycle: registration, session transitions, shutdown, stale callbacks and failed startup passed');
|
|
52
52
|
} finally {
|
|
@@ -131,16 +131,16 @@ function fixture(hasUI = true) {
|
|
|
131
131
|
on: (event, fn) => subscribe(hooks, event, fn),
|
|
132
132
|
events: { on: (event, fn) => subscribe(bus, event, fn), emit(event, data) { for (const fn of [...bus.get(event) || []]) fn(data); } },
|
|
133
133
|
registerCommand(name, command) { assert.ok(!commands.has(name), `no duplicate /${name}`); commands.set(name, command); },
|
|
134
|
-
registerToolRenderer() {}, registerMarkdownTransformer() {}, registerShortcut() {}, getCommands: () => [], getAllTools: () => [],
|
|
134
|
+
registerToolRenderer() {}, registerMarkdownTransformer() {}, registerShortcut() {}, appendEntry() {}, getCommands: () => [], getAllTools: () => [],
|
|
135
135
|
};
|
|
136
136
|
const ctx = { mode: 'none', hasUI: false, ui: { notify: message => notices.push(message) }, sessionManager: { getBranch: () => [], buildContextEntries: () => [] } };
|
|
137
137
|
const emit = event => { for (const fn of [...hooks.get(event) || []]) fn({}, ctx); };
|
|
138
138
|
try {
|
|
139
|
-
register(pi); emit('session_start');
|
|
139
|
+
await register(pi); emit('session_start');
|
|
140
140
|
assert.ok(commands.has('fold'));
|
|
141
141
|
assert.ok(!commands.has('work')); assert.ok(!commands.has('compact-rendering'), 'old aliases are absent from actual root registration');
|
|
142
|
-
await commands.get('fold').handler('off', ctx); assert.
|
|
143
|
-
await commands.get('fold').handler('on', ctx); assert.
|
|
142
|
+
await commands.get('fold').handler('off', ctx); assert.match(notices.at(-1), /^Pi Fold off\nCompatibility: full/);
|
|
143
|
+
await commands.get('fold').handler('on', ctx); assert.match(notices.at(-1), /^Pi Fold on\nCompatibility: full/);
|
|
144
144
|
emit('session_shutdown'); const count = notices.length;
|
|
145
145
|
await commands.get('fold').handler('toggle', ctx);
|
|
146
146
|
assert.equal(notices.length, count, 'root disposal disables stale command callbacks');
|
|
@@ -115,8 +115,10 @@ for (const overrides of [
|
|
|
115
115
|
}
|
|
116
116
|
const future = fixture().screen;
|
|
117
117
|
const futureOriginal = future.compositeOverlays;
|
|
118
|
-
installFullscreenOverlayGuard(future, 'future')
|
|
119
|
-
assert.
|
|
118
|
+
const futureCleanup = installFullscreenOverlayGuard(future, 'future');
|
|
119
|
+
assert.notEqual(future.compositeOverlays, futureOriginal, 'compatible future runtimes use the same seam');
|
|
120
|
+
futureCleanup();
|
|
121
|
+
assert.equal(future.compositeOverlays, futureOriginal);
|
|
120
122
|
|
|
121
123
|
const switched = fixture();
|
|
122
124
|
const regular = new tui.TuiMainScreen(switched.screen.terminal, false);
|
|
@@ -20,7 +20,7 @@ assert.equal(scroll.scrollTop, before.render(80).length, 'selected opaque native
|
|
|
20
20
|
assert.equal(scroll.isFollowingEnd, false);
|
|
21
21
|
const frame = renderLayoutFrame(root, 80, 24, () => {});
|
|
22
22
|
assert.ok(frame.lines.map(stripAnsi).join('\n').includes('Selected block'));
|
|
23
|
-
assert.equal(revealInspection(host, component => component === inner, '9.0.0'),
|
|
23
|
+
assert.equal(revealInspection(host, component => component === inner, '9.0.0'), true);
|
|
24
24
|
assert.equal(revealInspection({}, () => true), false);
|
|
25
25
|
const previous = scroll.scrollTop;
|
|
26
26
|
assert.equal(revealInspection(host, () => false), false); assert.equal(scroll.scrollTop, previous);
|