@notrico/pi-fold 3.0.5 → 3.1.1

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +1 -1
  3. package/docs/compatibility-testing.md +17 -0
  4. package/docs/implementation.md +1 -1
  5. package/docs/renderer-reference.md +1 -1
  6. package/index.ts +37 -23
  7. package/package.json +3 -2
  8. package/scripts/compatibility-check.mjs +40 -0
  9. package/scripts/compatibility-cli-smoke.mjs +41 -0
  10. package/scripts/preview-scroll.mjs +9 -0
  11. package/scripts/preview-work-strip.mjs +15 -1
  12. package/scripts/test.mjs +2 -2
  13. package/src/action-intent.ts +5 -1
  14. package/src/display-card.ts +2 -1
  15. package/src/fold-command.ts +7 -3
  16. package/src/fullscreen-overlays.ts +13 -11
  17. package/src/inspection.ts +19 -12
  18. package/src/modern-native-tools.ts +13 -7
  19. package/src/modern-prompts-adapter.ts +9 -7
  20. package/src/modern-skill-prompts.ts +17 -10
  21. package/src/modern-subagent-messages.ts +16 -7
  22. package/src/modern-subagent-spacing.ts +8 -6
  23. package/src/modern-thinking-adapter.ts +13 -9
  24. package/src/modern-thinking.ts +1 -1
  25. package/src/modern-tool-images.ts +8 -6
  26. package/src/modern-tools.ts +74 -30
  27. package/src/modern-workflows.ts +12 -7
  28. package/src/permission-presentation.ts +2 -1
  29. package/src/runtime-compatibility.ts +53 -14
  30. package/src/work-strip.ts +11 -9
  31. package/tests/action-intent.test.mjs +2 -0
  32. package/tests/codemode-wheel.test.mjs +111 -0
  33. package/tests/codemode.test.mjs +1 -1
  34. package/tests/compatibility-fallbacks.test.mjs +99 -0
  35. package/tests/display-cache-lifecycle.test.mjs +3 -3
  36. package/tests/fold-command.test.mjs +4 -4
  37. package/tests/fullscreen-overlays.test.mjs +4 -2
  38. package/tests/inspection.test.mjs +1 -1
  39. package/tests/modern-prompts.test.mjs +2 -2
  40. package/tests/modern-subagent-messages.test.mjs +2 -2
  41. package/tests/modern-thinking.test.mjs +2 -2
  42. package/tests/modern-tools.test.mjs +17 -8
  43. package/tests/modern-workflows.test.mjs +2 -2
  44. package/tests/ordinary-prompts.test.mjs +0 -1
  45. package/tests/preview-example.test.mjs +2 -2
  46. package/tests/runtime-compatibility.test.mjs +48 -21
  47. package/tests/subagent-spacing.test.mjs +1 -1
  48. package/tests/work-strip-hierarchy.test.mjs +0 -1
  49. package/tests/work-strip.test.mjs +13 -0
@@ -1,31 +1,38 @@
1
- import { supportsPiVersion } from './runtime-compatibility.ts';
2
1
  import type { DisplayMode } from './display-mode.ts';
3
- import { InteractiveMode, SkillInvocationMessageComponent, UserMessageComponent, VERSION, type ExtensionAPI } from '@earendil-works/pi-coding-agent';
4
- import { Container, Markdown, MouseRegion, Spacer, Text, matchesKey, stripTerminalSequences, visibleWidth } from '@earendil-works/pi-tui';
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 { fillBackground } from './display-card.ts';
6
6
  import { chainNativeMethod } from './native-method-chain.ts';
7
7
  import { projectedChildren } from './work-strip-view.ts';
8
8
 
9
- type Card = { skill: any; user?: any; gap?: any; detachGap?: () => void; headerEnd?: number; userStart?: number; userHeight?: number; body?: Markdown; bodyKey?: string; bodyTheme?: any };
9
+ const { InteractiveMode, SkillInvocationMessageComponent, UserMessageComponent, VERSION } = Pi;
10
+ const { Container, Markdown, MouseRegion, Spacer, Text, matchesKey, stripTerminalSequences, visibleWidth } = Tui;
11
+
12
+ type Card = { skill: any; user?: any; gap?: any; detachGap?: () => void; headerEnd?: number; userStart?: number; userHeight?: number; body?: InstanceType<typeof Markdown>; bodyKey?: string; bodyTheme?: any };
10
13
  const startZone = '\x1b]133;A\x07', endZone = '\x1b]133;B\x07\x1b]133;C\x07';
11
14
 
12
15
  /** Pi 1.3 creates a native skill and optional user row from one user envelope.
13
16
  * Keep those identities and inputs; combine only their rendered presentation. */
14
- export function registerModernSkillPrompts(pi: ExtensionAPI, mode: DisplayMode, version = VERSION): () => void {
17
+ export function registerModernSkillPrompts(pi: ExtensionAPI, mode: DisplayMode, _version = VERSION): () => void {
15
18
  const owner = Symbol.for('compact-renderer:skill-prompts:v1'), shared = globalThis as any;
16
19
  shared[owner]?.();
17
- const proto = InteractiveMode.prototype as any;
18
- if (!supportsPiVersion(version) || typeof proto.addMessageToChat !== 'function' || typeof SkillInvocationMessageComponent.prototype.setExpanded !== 'function') return () => {};
20
+ const proto = InteractiveMode?.prototype as any;
21
+ if (![Container, Markdown, MouseRegion, Spacer, Text, matchesKey, stripTerminalSequences, visibleWidth].every(value => typeof value === 'function') ||
22
+ !proto || typeof proto.addMessageToChat !== 'function' ||
23
+ !['setExpanded', 'render'].every(key => typeof SkillInvocationMessageComponent?.prototype?.[key] === 'function') ||
24
+ typeof UserMessageComponent?.prototype?.render !== 'function' || typeof pi.on !== 'function' ||
25
+ typeof pi.events?.on !== 'function' || typeof pi.events?.emit !== 'function') return () => {};
19
26
  const cards = new Map<any, Card>(), users = new WeakMap<any, Card>();
20
27
  let active = false, disposed = false, ctx: any, host: any, input: (() => void) | undefined, selected: Card | undefined, rendering: Card | undefined;
21
28
  const redraw = () => host?.ui?.requestRender?.();
22
29
  const release = () => { selected = undefined; };
23
30
  const compatible = (card: Card) => cards.get(card.skill) === card &&
24
31
  typeof card.skill.skillBlock?.name === 'string' && typeof card.skill.skillBlock?.content === 'string' &&
25
- card.skill.children.length === 1 && card.skill.children[0] instanceof MouseRegion && card.skill.children[0].child instanceof Container &&
32
+ Array.isArray(card.skill.children) && card.skill.children.length === 1 && card.skill.children[0] instanceof MouseRegion && card.skill.children[0].child instanceof Container && Array.isArray(card.skill.children[0].child.children) &&
26
33
  (card.skill.expanded ? card.skill.children[0].child.children.length === 2 && card.skill.children[0].child.children[0] instanceof Text && card.skill.children[0].child.children[1] instanceof Markdown :
27
34
  card.skill.children[0].child.children.length === 1 && card.skill.children[0].child.children[0] instanceof Text) &&
28
- (!card.user || card.user.children.length === 1 && card.user.children[0] instanceof Markdown && card.user.children[0].paddingY === 1 && card.user.text === card.skill.skillBlock.userMessage);
35
+ (!card.user || Array.isArray(card.user.children) && card.user.children.length === 1 && card.user.children[0] instanceof Markdown && card.user.children[0].paddingY === 1 && card.user.text === card.skill.skillBlock.userMessage);
29
36
  const enabled = (card: Card) => !disposed && active && mode.isEnabled() &&
30
37
  typeof ctx?.ui?.theme?.fg === 'function' && typeof ctx?.ui?.theme?.bg === 'function' && compatible(card);
31
38
  const publish = (card: Card) => {
@@ -106,7 +113,7 @@ export function registerModernSkillPrompts(pi: ExtensionAPI, mode: DisplayMode,
106
113
  return { handled: true, render: true };
107
114
  }
108
115
  if (card.user && card.userStart !== undefined && event.y >= card.userStart && event.y < card.userStart + card.userHeight! - 2) {
109
- return card.user.handleMouse({ ...event, y: event.y - card.userStart + 1, height: card.userHeight });
116
+ return card.user.handleMouse?.({ ...event, y: event.y - card.userStart + 1, height: card.userHeight });
110
117
  }
111
118
  });
112
119
  const prune = () => {
@@ -1,7 +1,7 @@
1
- import { supportsPiVersion } from './runtime-compatibility.ts';
2
1
  import type { DisplayMode } from './display-mode.ts';
3
- import { ExtensionRunner, VERSION, type ExtensionAPI } from '@earendil-works/pi-coding-agent';
4
- import { matchesKey, truncateToWidth } from '@earendil-works/pi-tui';
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 { ToolPane, type PaneContent } from './modern-tool-pane.ts';
6
6
  import { recordedPaneHeight } from './modern-recorded-pane.ts';
7
7
  import { acquireSubagentProjection, hiddenSubagent } from './modern-subagent-groups.ts';
@@ -9,6 +9,9 @@ import { installSubagentSpacingAdapter } from './modern-subagent-spacing.ts';
9
9
  import { recordedValues } from './modern-tool-content.ts';
10
10
  import { activityHeading } from './display-card.ts';
11
11
 
12
+ const { ExtensionRunner, VERSION } = Pi;
13
+ const { matchesKey, truncateToWidth } = Tui;
14
+
12
15
  type Summary = { title: string; tone: string };
13
16
  const record = (value: any) => value && typeof value === 'object' && !Array.isArray(value);
14
17
  const text = (value: unknown) => typeof value === 'string' ? truncateToWidth(value.slice(0, 512).replace(/[\p{Cc}\p{Cf}]/gu, ' '), 90, '…') : '';
@@ -55,9 +58,9 @@ export function subagentMessageSummary(source: any, entry = false): Summary | un
55
58
 
56
59
  /** Pi 1.3 resolver seam. Keep each extension's original renderer as the fallback.
57
60
  * Registering another message renderer cannot delegate through Pi's first-match registry. */
58
- export function installSubagentMessageAdapter(wrap: (native: any, entry: boolean) => any, version = VERSION): (() => void) | undefined {
59
- const proto = ExtensionRunner.prototype as any;
60
- if (!supportsPiVersion(version) || !['getMessageRenderer', 'getEntryRenderer'].every(k => typeof proto[k] === 'function')) return;
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;
61
64
  const owner = Symbol.for('compact-renderer:subagent-message-adapter:v1');
62
65
  proto[owner]?.();
63
66
  const message = proto.getMessageRenderer, entry = proto.getEntryRenderer;
@@ -85,7 +88,13 @@ function* content(source: any, entry: boolean): Generator<PaneContent> {
85
88
  export function registerModernSubagentMessages(pi: ExtensionAPI, mode: DisplayMode): () => void {
86
89
  const owner = Symbol.for('compact-renderer:subagent-message-registration:v1'), shared = globalThis as any;
87
90
  shared[owner]?.();
88
- const subagents = acquireSubagentProjection(pi), spacing = installSubagentSpacingAdapter();
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);
89
98
  let cards = new Map<any, Card>(), selected: Card | undefined, focused = false, active = false, disposed = false;
90
99
  let input: (() => void) | undefined, redraw: (() => void) | undefined;
91
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,6 +1,8 @@
1
- import { supportsPiVersion } from './runtime-compatibility.ts';
2
- import { CustomMessageComponent, VERSION } from '@earendil-works/pi-coding-agent';
3
- import { Container } from '@earendil-works/pi-tui';
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(version = VERSION): (() => void) | undefined {
12
- const proto = Container.prototype as any;
13
- if (!supportsPiVersion(version) || typeof proto.render !== 'function') return;
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 { supportsPiVersion } from './runtime-compatibility.ts';
2
- import { AssistantMessageComponent, VERSION } from "@earendil-works/pi-coding-agent";
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
- }, version = VERSION): (() => void) | undefined {
52
- const proto = AssistantMessageComponent.prototype as any;
53
- if (!supportsPiVersion(version) || !["updateContent", "render", "setHideThinkingBlock"].every(key => typeof proto[key] === "function")) return;
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.call(region, event);
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
  }
@@ -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 { supportsPiVersion } from './runtime-compatibility.ts';
2
- import { ToolExecutionComponent, VERSION } from "@earendil-works/pi-coding-agent";
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(version = VERSION): (() => void) | undefined {
13
- const proto = ToolExecutionComponent.prototype as any;
14
- if (!supportsPiVersion(version) || typeof proto.render !== "function" || typeof proto.updateDisplay !== "function") return;
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;
@@ -1,6 +1,8 @@
1
1
  import type { DisplayMode } from './display-mode.ts';
2
- import { Text, truncateToWidth, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui";
3
- import { getLanguageFromPath, type ExtensionAPI, type ToolRenderers } from "@earendil-works/pi-coding-agent";
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";
@@ -8,8 +10,11 @@ import { CodePane } from "./modern-code-pane.ts";
8
10
  import { cardContentWidth, activityRow, activityHeading } from "./display-card.ts";
9
11
  import { acquireSubagentProjection, hiddenSubagent } from "./modern-subagent-groups.ts";
10
12
  import { compactSubagent, subagentDecision, subagentTitle } from "./modern-subagents.ts";
11
- import { groupIntent } from "./action-intent.ts";
12
13
  import { compactToolImages, installModernToolImages, type ToolImageView } from "./modern-tool-images.ts";
14
+ import { groupIntent } from "./action-intent.ts";
15
+
16
+ const { Text, truncateToWidth } = Tui;
17
+ const getLanguageFromPath = typeof Pi.getLanguageFromPath === "function" ? Pi.getLanguageFromPath : () => undefined;
13
18
 
14
19
  type Context = Parameters<NonNullable<ToolRenderers["renderCall"]>>[2];
15
20
  type Status = "pending" | "running" | "success" | "failed" | "cancelled" | "unavailable" | "unanswered" | "answered" | "notice";
@@ -198,13 +203,34 @@ function knownFailure(node: Node): { code: string; label: string } | undefined {
198
203
  return { code, label: categories[code] };
199
204
  }
200
205
  }
201
- function failureReason(node: Node): string {
202
- if (node.status !== "failed") return "";
206
+ // Count outer calls only. A codemode call owns its nested actions.
207
+ function groupCounts(nodes: Node[]): string {
208
+ const counts = new Map<string, number>();
209
+ for (const { name } of nodes) {
210
+ const label = clean(shortName(name)) || "tool";
211
+ counts.set(label, (counts.get(label) ?? 0) + 1);
212
+ }
213
+ const entries = [...counts].slice(0, 4);
214
+ const labels = entries.map(([name, count]) => `${name} ×${count}`);
215
+ const more = counts.size - entries.length;
216
+ if (more) labels.push(`+${more} tool type${more === 1 ? "" : "s"}`);
217
+ return labels.join(" · ");
218
+ }
219
+
220
+ function failureLabel(node: Node): string {
203
221
  const known = knownFailure(node);
204
- if (known) return known.label;
205
222
  const details = node.result?.details;
206
- if (typeof details?.exitCode === "number") return `Command failed (exit ${details.exitCode})`;
207
- return ["bash", "powershell"].includes(shortName(node.name)) ? "Command failed" : "Tool failed";
223
+ // Only compact structured identifiers belong in a heading. Keep free text in Details.
224
+ const identifier = [details?.failureReason, details?.code].find(value =>
225
+ typeof value === "string" && value.length <= 64 && /^[a-z][a-z0-9]*(?:_[a-z0-9]+)+$/i.test(value));
226
+ const reason = known?.label ?? identifier?.replaceAll("_", " ").toLowerCase();
227
+ const parts = reason ? [reason] : [];
228
+ if (details?.status === "unknown") parts.push(details.code === "commit_receipt_missing" ? "commit unconfirmed" : "outcome unknown");
229
+ if (parts.length) {
230
+ const label = parts.join(" · ");
231
+ return label[0].toUpperCase() + label.slice(1);
232
+ }
233
+ return typeof details?.exitCode === "number" ? `Exit code ${details.exitCode}` : "Failed";
208
234
  }
209
235
  function questionState(node: Node): string {
210
236
  const statuses: Record<string, string> = { pending: "Pending", running: "Pending", failed: "Failed", answered: "Answered", cancelled: "Cancelled", unavailable: "Unavailable", unanswered: "Unanswered" };
@@ -224,9 +250,10 @@ class DynamicComponent {
224
250
  }
225
251
 
226
252
  /** 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) return () => {};
229
- const subagents = acquireSubagentProjection(pi);
253
+ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode, options: { images?: boolean; subagents?: boolean } = {}): () => void {
254
+ if (!nativeToolsSupported || typeof pi.registerToolRenderer !== 'function' || typeof pi.on !== 'function' ||
255
+ typeof pi.events?.on !== 'function' || typeof pi.events?.emit !== 'function' || typeof truncateToWidth !== 'function') return () => {};
256
+ const subagents = options.subagents !== false ? acquireSubagentProjection(pi) : undefined;
230
257
  let disposed = false;
231
258
  let epoch = 0;
232
259
  let nodes = new Map<string, Node>();
@@ -239,15 +266,17 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
239
266
  const rowGenerations = new WeakMap<object, number>();
240
267
  let rebuilding = false;
241
268
  const subscriptions: (() => void)[] = [];
242
- const imageAdapterOff = installModernToolImages();
269
+ const imageAdapterOff = options.images !== false ? installModernToolImages() : undefined;
270
+ const images = !!imageAdapterOff;
271
+ const nativeImages = (node: Node) => !images && node.images > 0;
243
272
  if (imageAdapterOff) subscriptions.push(imageAdapterOff);
244
273
  const redraw = () => {
245
274
  // Snapshot before native synchronous invalidate -> updateDisplay -> renderer registration.
246
275
  for (const invalidate of [...new Set([...nodes.values()].map(node => node.invalidate).filter(Boolean))]) invalidate!();
247
276
  };
248
277
  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] : []);
278
+ const subagentView = (node: Node) => { if (!subagents) return; subagents.sync(); return compactSubagent(node.name) ? subagents.projection.viewTool(node.id) : undefined; };
279
+ 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
280
  const focusPane = (pane: ToolPane | CodePane) => {
252
281
  if (disposed || !mode.isEnabled() || !panes().includes(pane)) return;
253
282
  release(); focused = pane; pane.focused = true; pane.open = true; redraw();
@@ -270,12 +299,17 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
270
299
  const signature = run.map(node => `${node.id}@${node.revision}`).join("|");
271
300
  let group = groups.get(id);
272
301
  if (!group) group = { members: [], signature: "", pane: new ToolPane([], "", height) };
273
- if (group.signature !== signature) { group.pane.actions = run.map(action); group.pane.selected = Math.min(group.pane.selected, run.length - 1); group.pane.reset(); group.signature = signature; }
302
+ if (group.signature !== signature) {
303
+ group.pane.actions = run.map(action);
304
+ group.pane.selected = Math.min(group.pane.selected, run.length - 1);
305
+ group.pane.reset();
306
+ group.signature = signature;
307
+ group.pane.title = run.length === 1 ? toolLabel(run[0].name, run[0].args) : `${run.length} actions · ${groupIntent(run, "brief")} · ${groupCounts(run)}`;
308
+ if (run.some(node => node.result?.details?.truncation?.truncated || node.result?.details?.truncated)) group.pane.title += " · output truncated";
309
+ if (run.some(node => node.result?.details?.fullOutputPath)) group.pane.title += " · full output saved";
310
+ if (run.some(node => node.result?.details?.warning || node.result?.details?.warnings?.length)) group.pane.title += " · warning recorded";
311
+ }
274
312
  group.members = run;
275
- group.pane.title = run.length === 1 ? toolLabel(run[0].name, run[0].args) : `${run.length} actions · ${groupIntent(run)}`;
276
- if (run.some(node => node.result?.details?.truncation?.truncated || node.result?.details?.truncated)) group.pane.title += " · output truncated";
277
- if (run.some(node => node.result?.details?.fullOutputPath)) group.pane.title += " · full output saved";
278
- if (run.some(node => node.result?.details?.warning || node.result?.details?.warnings?.length)) group.pane.title += " · warning recorded";
279
313
  for (const [index, node] of run.entries()) {
280
314
  node.group = group;
281
315
  if (node.code?.open) {
@@ -439,10 +473,15 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
439
473
  }
440
474
  node.pane ||= new ToolPane([action(node)], "", height);
441
475
  node.pane.expandedTitle = question(name) ? `Question · ${questionState(node)}` : undefined;
442
- const status = node.note || node.status[0].toUpperCase() + node.status.slice(1);
443
- node.pane.title = compactSubagent(name) ? subagentTitle(name, node.args, node.result, node.status) + indicators(node) : question(name) ? questionTitle(node) : `${toolLabel(name, node.args)}${node.images ? ` · ${node.images} image${node.images === 1 ? "" : "s"}` : ""}${node.status === "success" ? "" : ` · ${node.status === "failed" ? "✗ Failed" : `… ${status}`}`}${indicators(node)}`;
444
- const reason = compactSubagent(name) ? "" : failureReason(node);
445
- if (reason) node.pane.title += ` · ${reason}`;
476
+ if (compactSubagent(name)) node.pane.title = subagentTitle(name, node.args, node.result, node.status) + indicators(node);
477
+ else if (question(name)) node.pane.title = questionTitle(node);
478
+ else {
479
+ const parts = [toolLabel(name, node.args)];
480
+ if (node.images) parts.push(`${node.images} image${node.images === 1 ? "" : "s"}`);
481
+ if (node.status === "failed") parts.push(`✗ ${failureLabel(node)}`);
482
+ else if (node.status !== "success") parts.push(`… ${node.note || node.status[0].toUpperCase() + node.status.slice(1)}`);
483
+ node.pane.title = parts.join(" · ") + indicators(node);
484
+ }
446
485
  if (theme) {
447
486
  node.pane.theme = theme;
448
487
  node.pane.styleHeader = text => activityHeading(text, theme, node.status === "failed" ? "error" : question(name) || subagentDecision(name, node.args) ? "accent" : compactSubagent(name) && node.status === "notice" ? "warning" : "mdLink");
@@ -489,7 +528,7 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
489
528
  return {
490
529
  renderShell: "self",
491
530
  [compactToolImages](component: any, width: number): ToolImageView | undefined {
492
- if (disposed || !mode.isEnabled() || rowGenerations.get(component.rendererState) !== generation) return;
531
+ if (!images || disposed || !mode.isEnabled() || rowGenerations.get(component.rendererState) !== generation) return;
493
532
  const node = nodes.get(component.toolCallId);
494
533
  if (!node || !node.images || node.code && !node.code.content.supported || subagentView(node)?.hidden) return;
495
534
  const pane = node.code || individual(node);
@@ -502,23 +541,28 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
502
541
  renderCall(args, theme, context) {
503
542
  if (disposed || !nativeToolContextSupported(context) || stale(context)) return stock?.renderCall?.(args, theme, { ...context, executionStarted: false, state: {}, lastComponent: undefined }) ?? new Text(json(args), 0, 0);
504
543
  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); }
544
+ 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
545
  if (node.code) {
507
546
  if (!codePane(node, theme, context)) node.native.renderCall(args, theme, context);
508
547
  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);
548
+ 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
549
  }
511
550
  node.native.suspend(); syncExpansion(node, context.expanded);
512
551
  return new DynamicComponent(width => {
552
+ if (nativeImages(node)) return node.native.renderCurrent(width);
513
553
  if (subagentView(node)?.hidden || node.group) return [];
514
554
  if (singleCard(node)) return individual(node, theme).render(width);
515
555
  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);
556
+ }, event => nativeImages(node) ? undefined : mouse(!subagentView(node)?.hidden && !node.group && singleCard(node) ? individual(node, theme) : undefined, event), node);
517
557
  },
518
558
  renderResult(result, options, theme, context) {
519
559
  if (disposed || !nativeToolContextSupported(context) || stale(context)) return stock?.renderResult?.(result, options, theme, { ...context, executionStarted: false, state: {}, lastComponent: undefined }) ?? nativeTextFallback(result, theme);
520
560
  const node = get(context.args, context); record(node, result, options.isPartial, context.isError);
521
- if (disposed || !mode.isEnabled()) { node.code?.suspend(); if (node.code) node.native.adoptClock(node.code.clock); return node.native.renderResult(result, options, theme, context); }
561
+ if (disposed || !mode.isEnabled() || nativeImages(node)) {
562
+ node.code?.suspend(); if (node.code) node.native.adoptClock(node.code.clock);
563
+ if (nativeImages(node)) node.native.renderCall(node.args, theme, context);
564
+ return node.native.renderResult(result, options, theme, context);
565
+ }
522
566
  if (node.code) {
523
567
  if (!codePane(node, theme, context)) { node.native.renderCall(node.args, theme, context); node.native.renderResult(result, options, theme, context); }
524
568
  syncExpansion(node, context.expanded);
@@ -530,9 +574,9 @@ export function registerModernTools(pi: ExtensionAPI, mode: DisplayMode): () =>
530
574
  if (node.group) return groupPane(node, theme)?.render(width) ?? [];
531
575
  if (singleCard(node)) return [];
532
576
  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);
577
+ }, 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
578
  },
535
579
  };
536
580
  });
537
- return () => { if (disposed) return; disposed = true; clear(); subagents.release(); for (const off of subscriptions.splice(0)) off(); };
581
+ return () => { if (disposed) return; disposed = true; clear(); subagents?.release(); for (const off of subscriptions.splice(0)) off(); };
538
582
  }
@@ -1,12 +1,15 @@
1
- import { supportsPiVersion } from './runtime-compatibility.ts';
2
1
  import type { DisplayMode } from './display-mode.ts';
3
- import { AssistantMessageComponent, VERSION, type ExtensionAPI } from '@earendil-works/pi-coding-agent';
4
- import { Container, Markdown, MouseRegion, Spacer, Text, matchesKey, truncateToWidth } from '@earendil-works/pi-tui';
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, version = VERSION): () => void {
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.prototype as any;
111
- if (!supportsPiVersion(version) || typeof proto.render !== 'function' || typeof proto.updateContent !== 'function') return () => {};
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
- for (const event of ['session_switch', 'session_tree', 'session_compact', 'session_shutdown']) pi.on?.(event, cancelAll);
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 { VERSION, type ExtensionAPI } from '@earendil-works/pi-coding-agent';
1
+ import * as core from '@earendil-works/pi-coding-agent';
2
+ import * as tui from '@earendil-works/pi-tui';
2
3
 
3
- // Exact versions verified by the native rendering suites. Shape checks still
4
- // protect each private adapter; a new core version needs its own verification.
5
- export const supportedPiVersions = ['1.3.0', '1.4.0'] as const;
6
- export const supportsPiVersion = (version: string) => supportedPiVersions.some(supported => supported === version);
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
- export function registerUnsupportedRuntime(pi: ExtensionAPI, version = VERSION): boolean {
9
- if (supportsPiVersion(version)) return false;
10
- const message = `Pi Fold is unavailable on Pi ${version}. Supported versions: ${supportedPiVersions.join(', ')}. Native display remains active. Update Pi Fold for support.`;
11
- pi.registerCommand('fold', {
12
- description: 'Show Pi Fold compatibility status',
13
- async handler(_args, ctx) { ctx.ui.notify(message, 'warning'); },
14
- });
15
- pi.on('session_start', (_event, ctx) => { if (ctx.hasUI) ctx.ui.notify(message, 'warning'); });
16
- return true;
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>;