@notrico/pi-fold 3.0.4 → 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 +13 -0
- package/README.md +3 -3
- package/docs/compatibility-testing.md +17 -0
- package/docs/implementation.md +1 -1
- package/index.ts +37 -21
- package/package.json +3 -2
- package/scripts/compatibility-check.mjs +40 -0
- package/scripts/compatibility-cli-smoke.mjs +41 -0
- package/scripts/preview.mjs +4 -3
- 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 -10
- package/src/inspection.ts +19 -11
- package/src/modern-native-tools.ts +13 -6
- package/src/modern-prompts-adapter.ts +9 -6
- package/src/modern-skill-prompts.ts +17 -9
- package/src/modern-subagent-messages.ts +16 -6
- package/src/modern-subagent-spacing.ts +8 -5
- package/src/modern-thinking-adapter.ts +13 -8
- package/src/modern-thinking.ts +1 -1
- package/src/modern-tool-images.ts +8 -5
- package/src/modern-tools.ts +28 -15
- package/src/modern-workflows.ts +12 -6
- package/src/permission-presentation.ts +2 -1
- package/src/runtime-compatibility.ts +56 -0
- package/src/work-strip.ts +11 -8
- package/tests/action-group-preview.test.mjs +1 -1
- 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/permission-presentation.test.mjs +1 -0
- package/tests/preview-example.test.mjs +2 -2
- package/tests/runtime-compatibility.test.mjs +50 -0
- package/tests/subagent-spacing.test.mjs +1 -1
- package/tests/work-strip-hierarchy.test.mjs +0 -1
- package/tests/work-strip-preview.test.mjs +1 -1
- package/tests/work-strip.test.mjs +13 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DisplayMode } from './display-mode.ts';
|
|
2
|
-
import {
|
|
3
|
-
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';
|
|
4
5
|
import { ToolPane, type PaneContent } from './modern-tool-pane.ts';
|
|
5
6
|
import { recordedPaneHeight } from './modern-recorded-pane.ts';
|
|
6
7
|
import { acquireSubagentProjection, hiddenSubagent } from './modern-subagent-groups.ts';
|
|
@@ -8,6 +9,9 @@ import { installSubagentSpacingAdapter } from './modern-subagent-spacing.ts';
|
|
|
8
9
|
import { recordedValues } from './modern-tool-content.ts';
|
|
9
10
|
import { activityHeading } from './display-card.ts';
|
|
10
11
|
|
|
12
|
+
const { ExtensionRunner, VERSION } = Pi;
|
|
13
|
+
const { matchesKey, truncateToWidth } = Tui;
|
|
14
|
+
|
|
11
15
|
type Summary = { title: string; tone: string };
|
|
12
16
|
const record = (value: any) => value && typeof value === 'object' && !Array.isArray(value);
|
|
13
17
|
const text = (value: unknown) => typeof value === 'string' ? truncateToWidth(value.slice(0, 512).replace(/[\p{Cc}\p{Cf}]/gu, ' '), 90, '…') : '';
|
|
@@ -54,9 +58,9 @@ export function subagentMessageSummary(source: any, entry = false): Summary | un
|
|
|
54
58
|
|
|
55
59
|
/** Pi 1.3 resolver seam. Keep each extension's original renderer as the fallback.
|
|
56
60
|
* Registering another message renderer cannot delegate through Pi's first-match registry. */
|
|
57
|
-
export function installSubagentMessageAdapter(wrap: (native: any, entry: boolean) => any,
|
|
58
|
-
const proto = ExtensionRunner
|
|
59
|
-
if (
|
|
61
|
+
export function installSubagentMessageAdapter(wrap: (native: any, entry: boolean) => any, _version = VERSION): (() => void) | undefined {
|
|
62
|
+
const proto = ExtensionRunner?.prototype as any;
|
|
63
|
+
if (!proto || !['getMessageRenderer', 'getEntryRenderer'].every(k => typeof proto[k] === 'function')) return;
|
|
60
64
|
const owner = Symbol.for('compact-renderer:subagent-message-adapter:v1');
|
|
61
65
|
proto[owner]?.();
|
|
62
66
|
const message = proto.getMessageRenderer, entry = proto.getEntryRenderer;
|
|
@@ -84,7 +88,13 @@ function* content(source: any, entry: boolean): Generator<PaneContent> {
|
|
|
84
88
|
export function registerModernSubagentMessages(pi: ExtensionAPI, mode: DisplayMode): () => void {
|
|
85
89
|
const owner = Symbol.for('compact-renderer:subagent-message-registration:v1'), shared = globalThis as any;
|
|
86
90
|
shared[owner]?.();
|
|
87
|
-
const
|
|
91
|
+
const proto = ExtensionRunner?.prototype as any;
|
|
92
|
+
if (!proto || !['getMessageRenderer', 'getEntryRenderer'].every(key => typeof proto[key] === 'function') ||
|
|
93
|
+
typeof pi.on !== 'function' || typeof pi.events?.on !== 'function' || typeof pi.events?.emit !== 'function' ||
|
|
94
|
+
![matchesKey, truncateToWidth].every(value => typeof value === 'function')) return () => {};
|
|
95
|
+
const spacing = installSubagentSpacingAdapter();
|
|
96
|
+
if (!spacing) return () => {};
|
|
97
|
+
const subagents = acquireSubagentProjection(pi);
|
|
88
98
|
let cards = new Map<any, Card>(), selected: Card | undefined, focused = false, active = false, disposed = false;
|
|
89
99
|
let input: (() => void) | undefined, redraw: (() => void) | undefined;
|
|
90
100
|
const release = (preserveAnchor = false) => { if (focused && selected) { (view(selected.source)?.pane || selected.pane).focused = false; if (!preserveAnchor) (view(selected.source)?.pane || selected.pane).releaseInspection(); } focused = false; };
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
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;
|
|
3
6
|
|
|
4
7
|
const hidden = Symbol.for('compact-renderer:subagent-hidden:v1');
|
|
5
8
|
|
|
@@ -7,9 +10,9 @@ const hidden = Symbol.for('compact-renderer:subagent-hidden:v1');
|
|
|
7
10
|
* our marked grouped followers; an empty unrelated renderer keeps native layout.
|
|
8
11
|
* CustomEntryComponent is not exported by Pi, so this guarded inherited-method
|
|
9
12
|
* seam avoids importing private modules or replacing the transcript container. */
|
|
10
|
-
export function installSubagentSpacingAdapter(
|
|
11
|
-
const proto = Container
|
|
12
|
-
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;
|
|
13
16
|
const owner = Symbol.for('compact-renderer:subagent-spacing:v1');
|
|
14
17
|
proto[owner]?.();
|
|
15
18
|
const original = proto.render;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as Pi from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import * as Tui from '@earendil-works/pi-tui';
|
|
3
3
|
import { chainNativeMethod } from "./native-method-chain.ts";
|
|
4
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
|
+
|
|
5
10
|
/** Private Pi 1.3.0 seam: only pure hidden-thinking assistant containers qualify.
|
|
6
11
|
* Native Ctrl+T/per-run expansion and unknown component shapes always win. */
|
|
7
12
|
export function hiddenThinkingShape(component: any, message: any): boolean {
|
|
8
|
-
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;
|
|
9
14
|
if ([...component.thinkingVisibilityOverrides.values()].some(value => value === false)) return false;
|
|
10
15
|
const children = component.contentContainer?.children;
|
|
11
16
|
let expected = 0, inRun = false, nonempty = false;
|
|
@@ -19,7 +24,7 @@ export function hiddenThinkingShape(component: any, message: any): boolean {
|
|
|
19
24
|
/** One hidden run beside native reply text. Validate the exact native sequence;
|
|
20
25
|
* interleaved runs and unfamiliar/error layouts retain their native rendering. */
|
|
21
26
|
export function mixedThinkingRegion(component: any, message: any): any | undefined {
|
|
22
|
-
if (component.lastMessage !== message || component.hideThinkingBlock !== true || !(component.thinkingVisibilityOverrides instanceof Map)
|
|
27
|
+
if (!thinkingComponentsSupported || component.lastMessage !== message || component.hideThinkingBlock !== true || !(component.thinkingVisibilityOverrides instanceof Map)
|
|
23
28
|
|| [...component.thinkingVisibilityOverrides.values()].some(value => value === false)
|
|
24
29
|
|| ["error", "aborted", "length"].includes(message?.stopReason)) return;
|
|
25
30
|
const expected: string[] = [], visible: string[] = [];
|
|
@@ -47,9 +52,9 @@ export function installModernThinkingAdapter(hooks: {
|
|
|
47
52
|
render(component: any, width: number): string[] | undefined;
|
|
48
53
|
mouse(component: any, event: any): any;
|
|
49
54
|
clear(): void;
|
|
50
|
-
},
|
|
51
|
-
const proto = AssistantMessageComponent
|
|
52
|
-
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;
|
|
53
58
|
const owner = Symbol.for("compact-renderer:thinking-adapter:v1");
|
|
54
59
|
proto[owner]?.();
|
|
55
60
|
let disposed = false;
|
|
@@ -63,7 +68,7 @@ export function installModernThinkingAdapter(hooks: {
|
|
|
63
68
|
if (region) {
|
|
64
69
|
const component = this, render = region.render, mouse = region.handleMouse;
|
|
65
70
|
region.render = (width: number) => hooks.render(component, width)?.slice(1) ?? render.call(region, width);
|
|
66
|
-
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);
|
|
67
72
|
regions.set(this, () => { region.render = render; region.handleMouse = mouse; });
|
|
68
73
|
}
|
|
69
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,16 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import * as Pi from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import * as Tui from '@earendil-works/pi-tui';
|
|
3
3
|
import { chainNativeMethod } from "./native-method-chain.ts";
|
|
4
4
|
import { activityRow, cardContentWidth, cardPadding } from "./display-card.ts";
|
|
5
5
|
|
|
6
|
+
const { ToolExecutionComponent, VERSION } = Pi;
|
|
7
|
+
const { getCapabilities, Image, imageFallback, truncateToWidth } = Tui;
|
|
8
|
+
|
|
6
9
|
export const compactToolImages = Symbol.for("compact-renderer:tool-images:v1");
|
|
7
10
|
export type ToolImageView = { open: boolean; count: number; bodyIndent: number; source?: string; theme?: any };
|
|
8
11
|
|
|
9
12
|
/** Pi 1.3.0 appends images outside renderShell:self. Borrow those same native
|
|
10
13
|
* objects during render only; never change image sources, settings or ownership. */
|
|
11
|
-
export function installModernToolImages(
|
|
12
|
-
const proto = ToolExecutionComponent
|
|
13
|
-
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;
|
|
14
17
|
const owner = Symbol.for("compact-renderer:tool-image-adapter:v1");
|
|
15
18
|
proto[owner]?.();
|
|
16
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,11 +1,15 @@
|
|
|
1
1
|
import type { DisplayMode } from './display-mode.ts';
|
|
2
|
-
import {
|
|
3
|
-
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';
|
|
4
5
|
import { activityRow, cardContentWidth, finalReplyRendering } from './display-card.ts';
|
|
5
6
|
import { richTextRows } from './modern-rich-text.ts';
|
|
6
7
|
import { recordedPaneHeight } from './modern-recorded-pane.ts';
|
|
7
8
|
import { chainNativeMethod } from './native-method-chain.ts';
|
|
8
9
|
|
|
10
|
+
const { AssistantMessageComponent, VERSION } = Pi;
|
|
11
|
+
const { Container, Markdown, MouseRegion, Spacer, Text, matchesKey, truncateToWidth } = Tui;
|
|
12
|
+
|
|
9
13
|
export type WorkflowFence = { start: number; end: number; source: string; summary: string };
|
|
10
14
|
const summaryText = (value: string) => truncateToWidth(value.slice(0, 1024).replace(/[\p{Cc}\p{Cf}]/gu, ' ').replace(/\s+/g, ' ').trim(), 90, '…');
|
|
11
15
|
|
|
@@ -98,16 +102,18 @@ export class WorkflowPane {
|
|
|
98
102
|
}
|
|
99
103
|
}
|
|
100
104
|
|
|
101
|
-
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>> };
|
|
102
106
|
|
|
103
107
|
/** The public Markdown transformer cannot return components or identify a card.
|
|
104
108
|
* This isolated 1.3.0 seam substitutes display children only during native render.
|
|
105
109
|
* Native messages, Markdown sources, updateContent, and execution remain untouched. */
|
|
106
|
-
export function registerModernWorkflows(pi: ExtensionAPI, mode: DisplayMode,
|
|
110
|
+
export function registerModernWorkflows(pi: ExtensionAPI, mode: DisplayMode, _version = VERSION): () => void {
|
|
107
111
|
const owner = Symbol.for('compact-renderer:workflow-registration:v1'), shared = globalThis as any;
|
|
108
112
|
shared[owner]?.();
|
|
109
|
-
const proto = AssistantMessageComponent
|
|
110
|
-
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 () => {};
|
|
111
117
|
const cards = new Map<any, Card>();
|
|
112
118
|
let active = false, disposed = false, selected: WorkflowPane | undefined, uiTheme: any, nextCard = 0;
|
|
113
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
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as core from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import * as tui from '@earendil-works/pi-tui';
|
|
3
|
+
|
|
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';
|
|
26
|
+
|
|
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
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export type RuntimeCompatibility = ReturnType<typeof inspectRuntime>;
|
package/src/work-strip.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { DisplayMode } from './display-mode.ts';
|
|
2
|
-
import { AssistantMessageComponent, CustomMessageComponent, InteractiveMode, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent,
|
|
2
|
+
import { AssistantMessageComponent, CustomMessageComponent, InteractiveMode, SkillInvocationMessageComponent, ToolExecutionComponent, UserMessageComponent, type ExtensionAPI } from '@earendil-works/pi-coding-agent';
|
|
3
3
|
import { Container, Spacer, matchesKey } from '@earendil-works/pi-tui';
|
|
4
4
|
import { chainNativeMethod } from './native-method-chain.ts';
|
|
5
5
|
import { ToolPane } from './modern-tool-pane.ts';
|
|
@@ -65,11 +65,11 @@ export interface WorkStripControls {
|
|
|
65
65
|
|
|
66
66
|
/** Pi 1.3 display seam. The native tree, transcript, execution and Fleet remain
|
|
67
67
|
* authoritative. Only chatContainer's rendered child list is projected. */
|
|
68
|
-
export function registerWorkStrip(pi: ExtensionAPI, mode: DisplayMode, version
|
|
68
|
+
export function registerWorkStrip(pi: ExtensionAPI, mode: DisplayMode, version?: string, unavailable?: (reason: string) => void): WorkStripControls {
|
|
69
69
|
const owner = Symbol.for('compact-renderer:work-registration:v1'), shared = globalThis as any;
|
|
70
70
|
shared[owner]?.();
|
|
71
71
|
const proto = InteractiveMode.prototype as any;
|
|
72
|
-
if (
|
|
72
|
+
if (!['addMessageToChat', 'handleEvent', 'renderSessionItems'].every(k => typeof proto?.[k] === 'function')) return { dispose() {}, setExpanded: () => false, isShortcutEnabled: () => false, setShortcutEnabled() {} };
|
|
73
73
|
let disposed = false, ctx: any, host: any, attached: any, detachChat: (() => void) | undefined;
|
|
74
74
|
let turns = new Map<any, Turn>(), sources = new WeakMap<any, any>(), hooks = new Map<any, ToolPane>();
|
|
75
75
|
let selected: WorkStripHeader | ToolPane | undefined, input: (() => void) | undefined, timer: ReturnType<typeof setTimeout> | undefined;
|
|
@@ -253,23 +253,26 @@ export function registerWorkStrip(pi: ExtensionAPI, mode: DisplayMode, version =
|
|
|
253
253
|
return output;
|
|
254
254
|
};
|
|
255
255
|
const attach = (candidate: any) => {
|
|
256
|
-
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; }
|
|
257
258
|
if (host !== candidate) { detachChat?.(); host = candidate; attached = undefined; }
|
|
258
|
-
if (attached) return;
|
|
259
|
+
if (attached) return true;
|
|
259
260
|
const chat = candidate.chatContainer;
|
|
260
261
|
detachChat = chainNativeMethod(chat, 'render', function(native, width) {
|
|
261
|
-
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); }
|
|
262
263
|
const canonical = this.children;
|
|
263
264
|
this[projectedChildren] = project(canonical);
|
|
264
265
|
this.children = this[projectedChildren];
|
|
265
266
|
try { return native.call(this, width); } finally { this.children = canonical; }
|
|
266
267
|
});
|
|
267
268
|
attached = chat;
|
|
269
|
+
return true;
|
|
268
270
|
};
|
|
269
271
|
const detachAdd = chainNativeMethod(proto, 'addMessageToChat', function(native, message, ...args) {
|
|
270
|
-
attach(this)
|
|
272
|
+
if (!attach(this)) return native.call(this, message, ...args);
|
|
273
|
+
const before = this.chatContainer.children.length;
|
|
271
274
|
const result = native.call(this, message, ...args);
|
|
272
|
-
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);
|
|
273
276
|
if (!replaying && running && message.role === 'user') liveStarts.set(message, Date.now());
|
|
274
277
|
return result;
|
|
275
278
|
});
|
|
@@ -5,7 +5,7 @@ import { createWorkStripPreview } from '../scripts/preview-work-strip.mjs';
|
|
|
5
5
|
|
|
6
6
|
const preview = await createWorkStripPreview({ actionGroups: true });
|
|
7
7
|
const { core, runtime, manager } = preview;
|
|
8
|
-
const { theme, initTheme } = await import(pathToFileURL(path.join(preview.
|
|
8
|
+
const { theme, initTheme } = await import(pathToFileURL(path.join(preview.agentRoot, 'dist/modes/interactive/theme/theme.js')));
|
|
9
9
|
initTheme('dark', false);
|
|
10
10
|
const plain = value => value.replace(/\x1b\][^\x07]*(?:\x07|\x1b\\)|\x1b\[[0-?]*[ -/]*[@-~]/g, '');
|
|
11
11
|
const errors = [];
|
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 {
|