@notrico/pi-fold 3.0.3 → 3.0.4

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 CHANGED
@@ -1,5 +1,10 @@
1
1
  # Release notes
2
2
 
3
+ ## 3.0.4 — Fullscreen overlays
4
+
5
+ - Temporarily hide inline Kitty images while an overlay is visible in Pi 1.3.0 fullscreen mode. This keeps panel borders and text readable. Restore the images when the last overlay closes or hides, including with folding off.
6
+ - Remove padded shell prompt markers from fullscreen display output so they cannot erase overlay rows. Preserve the original transcript and prompt-navigation metadata.
7
+
3
8
  ## 3.0.3 — Approval layout
4
9
 
5
10
  - Match approval dialogs to the quieter prompt layout: add spacing around the content and choices, mute keyboard hints, and fill only the selected choice. Keep approval decisions and Details controls unchanged.
package/README.md CHANGED
@@ -15,7 +15,7 @@ Replies without tool or subagent activity skip the work strip.
15
15
  Tested with **Pi 1.3.0** and **Node.js 22.19.0 or later**. Other Pi versions are not verified; version-sensitive features fall back to native rendering.
16
16
 
17
17
  ```sh
18
- pi install npm:@notrico/pi-fold@3.0.0
18
+ pi install npm:@notrico/pi-fold@3.0.4
19
19
  ```
20
20
 
21
21
  Restart Pi, or run `/reload` when the session and its background work are idle.
@@ -66,7 +66,7 @@ Run `npm test`, `npm run preview:work`, or `npm run benchmark`. See the [rendere
66
66
  ## Uninstall
67
67
 
68
68
  ```sh
69
- pi remove npm:@notrico/pi-fold@3.0.0
69
+ pi remove npm:@notrico/pi-fold@3.0.4
70
70
  ```
71
71
 
72
72
  [MIT license](LICENSE) · [Report an issue](https://github.com/rrrrrrrrrricoxi/pi-fold/issues)
@@ -109,4 +109,8 @@ The renderer respects Pi's show-images setting and terminal capability detection
109
109
 
110
110
  Compact mode off preserves native image display and sizing. The image adapter is gated to Pi 1.3.0 and restores the native component's options after each compact paint. It does not alter image data, terminal settings, tmux settings, or saved transcripts.
111
111
 
112
+ In Pi 1.3.0 fullscreen mode, visible overlays temporarily hide inline Kitty images. This works around native image placements covering overlay text and breaking borders. Images return from the native cache when the last overlay closes or hides. The compatibility fix also runs with `/fold off`; it preserves image row heights and does not change image settings or overlay packages such as BTW. Other runtimes and image protocols retain native behavior.
113
+
114
+ The fullscreen adapter also removes shell prompt-zone markers (`OSC 133 A/B/C`) from display rows after layout padding. Pi's native cleanup misses these padded markers, which can make the terminal hide overlay text and border rows. Source rows and prompt-navigation metadata retain their markers. Regular terminal mode and other Pi versions keep native behavior.
115
+
112
116
  To inspect mixed bash/codemode groups in the isolated fixture, run `node scripts/preview-actions.mjs`. The final work section includes both bash-led and codemode-led groups and a separate nested-error card. No tools or model run.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@notrico/pi-fold",
3
- "version": "3.0.3",
3
+ "version": "3.0.4",
4
4
  "type": "module",
5
5
  "description": "Pi Fold: readable agent transcripts with collapsible work, inspectable details, and clear final replies",
6
6
  "license": "MIT",
package/scripts/test.mjs CHANGED
@@ -13,6 +13,7 @@ required.push('display-cache-lifecycle.test.mjs');
13
13
  required.push('fold-command.test.mjs', 'fold-shortcut.test.mjs');
14
14
  required.push('mixed-thinking.test.mjs', 'work-strip.test.mjs', 'work-strip-subagents.test.mjs', 'work-strip-preview.test.mjs', 'work-strip-spacing.test.mjs');
15
15
  required.push('mixed-action-groups.test.mjs', 'action-group-preview.test.mjs');
16
+ required.push('fullscreen-overlays.test.mjs');
16
17
  for (const name of required) {
17
18
  if (!fs.existsSync(path.join(directory, name))) throw new Error(`Missing required regression suite: ${name}`);
18
19
  const result = spawnSync(process.execPath, [path.join(directory, name)], { cwd: directory, env: process.env, stdio: 'inherit' });
@@ -0,0 +1,29 @@
1
+ import { VERSION } from '@earendil-works/pi-coding-agent';
2
+ import { TuiAltScreen } from '@earendil-works/pi-tui';
3
+ import { chainNativeMethod } from './native-method-chain.ts';
4
+
5
+ const promptZones = /\x1b\]133;[ABC](?:\x07|\x1b\\)/g;
6
+
7
+ /** Pi 1.3 fullscreen output retains prompt markers after layout padding and
8
+ * skips overlay composition on image anchors. Strip display-only zone markers;
9
+ * suppress Kitty anchors while an overlay is visible so native placement cleanup
10
+ * and restoration work. Keep source rows, layout metadata, and settings intact.
11
+ */
12
+ export function installFullscreenOverlayGuard(tui: any, version = VERSION): () => void {
13
+ if (version !== '1.3.0' || !['regular', 'fullscreen'].includes(tui?.mode) || typeof tui.compositeOverlays !== 'function'
14
+ || typeof tui.hasOverlay !== 'function') return () => {};
15
+ if (tui.mode === 'fullscreen' && typeof tui.prepareKittyScreen !== 'function') return () => {};
16
+ // Extension UI handles are proxies with unstable method identities. Their
17
+ // prototype is native; chain there and limit this guard to the captured terminal.
18
+ // A regular-mode session can switch renderers without recreating its widgets.
19
+ const proto = tui.mode === 'regular' ? TuiAltScreen.prototype as any : Object.getPrototypeOf(tui), terminal = tui.terminal;
20
+ if (!terminal || typeof proto?.compositeOverlays !== 'function' || typeof proto.prepareKittyScreen !== 'function') return () => {};
21
+ const detach = chainNativeMethod(proto, 'compositeOverlays', function(this: any, native, lines: string[], ...args: any[]) {
22
+ if (this.terminal !== terminal || this.mode !== 'fullscreen') return native.call(this, lines, ...args);
23
+ // ponytail: Pi 1.3 fullscreen only; remove when native composition is fixed.
24
+ const hideImages = this.imageProtocol === 'kitty' && this.hasOverlay();
25
+ const base = lines.map(line => hideImages && line.includes('\x1b_G') ? '' : line.replace(promptZones, ''));
26
+ return native.call(this, base, ...args);
27
+ });
28
+ return () => { detach(); tui.requestRender?.(); };
29
+ }
package/src/inspection.ts CHANGED
@@ -2,6 +2,7 @@ import type { DisplayMode } from './display-mode.ts';
2
2
  import { VERSION, type ExtensionAPI } from '@earendil-works/pi-coding-agent';
3
3
  import { Container, ScrollView, isViewportTUI, type Component } from '@earendil-works/pi-tui';
4
4
  import { projectedChildren } from './work-strip-view.ts';
5
+ import { installFullscreenOverlayGuard } from './fullscreen-overlays.ts';
5
6
 
6
7
  type Choice = { id: string; kind: string; label: string; focus(): void };
7
8
  type Target = (component: Component) => boolean;
@@ -46,14 +47,18 @@ export function revealInspection(tui: any, target: Target, version = VERSION): b
46
47
  /** Native picker plus visible focus status. No model tools, transcript or editor mutation. */
47
48
  export function registerInspection(pi: ExtensionAPI, mode: DisplayMode): () => void {
48
49
  let ui: any, tui: any, disposed = false;
50
+ let restoreFullscreenOverlays: (() => void) | undefined;
49
51
  let revealTimer: ReturnType<typeof setTimeout> | undefined;
50
52
  const clearStatus = () => { if (revealTimer) clearTimeout(revealTimer); revealTimer = undefined; ui?.setStatus?.('compact-inspection', undefined); };
51
- const clear = () => { clearStatus(); ui?.setWidget?.('compact-inspection-host', undefined); ui = undefined; tui = undefined; };
53
+ const clear = () => { clearStatus(); restoreFullscreenOverlays?.(); restoreFullscreenOverlays = undefined; ui?.setWidget?.('compact-inspection-host', undefined); ui = undefined; tui = undefined; };
52
54
  const subscriptions = [
53
55
  pi.on('session_start', (_event, ctx) => {
54
56
  clear(); if (disposed || !ctx.hasUI) return; ui = ctx.ui;
55
57
  // This zero-row widget only obtains the supported TUI handle. It owns no root.
56
- ui.setWidget?.('compact-inspection-host', (host: any) => { tui = host; return { render: () => [], invalidate() {} }; });
58
+ ui.setWidget?.('compact-inspection-host', (host: any) => {
59
+ tui = host; restoreFullscreenOverlays?.(); restoreFullscreenOverlays = installFullscreenOverlayGuard(host);
60
+ return { render: () => [], invalidate() {} };
61
+ });
57
62
  }),
58
63
  pi.on('session_before_switch', clear), pi.on('session_shutdown', clear),
59
64
  pi.on('ui_prompt_start', clearStatus), pi.on('session_tree', clearStatus), pi.on('session_compact', clearStatus), mode.onChange(clearStatus),
@@ -0,0 +1,168 @@
1
+ import assert from 'node:assert/strict';
2
+ import path from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { loadAgent, loadSource, tui, tuiRoot } from './test-runtime.mjs';
5
+
6
+ const { installFullscreenOverlayGuard } = await loadSource('fullscreen-overlays.ts');
7
+ const { encodeKitty, registerKittyImageMetadata, isImageLine } = await import(
8
+ pathToFileURL(path.join(tuiRoot, 'dist/terminal-image.js')).href
9
+ );
10
+ const deletion = '\x1b_Ga=d,d=a,q=2\x1b\\';
11
+ const { createInteractiveTuiReference } = await loadAgent('modes/interactive/tui-renderer.js');
12
+ let nextImageId = 742;
13
+
14
+ function fixture() {
15
+ const output = [];
16
+ const terminal = { columns: 40, rows: 12, write: text => output.push(text), hideCursor() {} };
17
+ const screen = new tui.TuiAltScreen(terminal, false);
18
+ screen.requestRender = () => {};
19
+ screen.altScreenActive = true;
20
+ screen.imageProtocol = 'kitty';
21
+ const imageId = nextImageId++;
22
+ registerKittyImageMetadata({ imageId, columns: 28, rows: 6, widthPx: 280, heightPx: 120 });
23
+ const image = encodeKitty('c3ludGhldGlj', { columns: 28, rows: 6, imageId, moveCursor: false });
24
+ const lines = ['first row', 'second row', image, '', '', '', '', '', 'last row', '', '', ''];
25
+ screen.addChild({ render: () => lines, invalidate() {} });
26
+ const paint = () => { output.length = 0; screen.doRender(); return output.join(''); };
27
+ const open = () => screen.showOverlay({
28
+ render: () => Array.from({ length: 6 }, () => `│${' '.repeat(18)}│`), invalidate() {},
29
+ }, { width: 20, row: 2, col: 5 });
30
+ return { screen, lines, paint, open };
31
+ }
32
+
33
+ // Reproduce the native failure: the anchor row bypasses text compositing, and
34
+ // the unchanged Kitty placement remains over subsequent overlay rows.
35
+ const stock = fixture();
36
+ stock.paint(); stock.open();
37
+ assert.ok(!stock.paint().includes(deletion), 'stock does not remove the unchanged image placement');
38
+ assert.ok(isImageLine(stock.screen.getScreenLines()[2]), 'stock retains the image anchor inside the overlay');
39
+ assert.ok(!stock.screen.getScreenLines()[2].includes('│'), 'stock loses the anchor-row border');
40
+
41
+ const guarded = fixture();
42
+ guarded.paint();
43
+ const original = guarded.screen.compositeOverlays;
44
+ const initialFrame = guarded.screen.getScreenLines();
45
+ const recordedLines = guarded.lines.slice();
46
+ const cleanup = installFullscreenOverlayGuard(guarded.screen);
47
+ assert.equal(typeof cleanup, 'function', 'the supported native runtime installs a disposable guard');
48
+ try {
49
+ assert.ok(!guarded.paint().includes(deletion), 'no visible overlay leaves image placements intact');
50
+ assert.deepEqual(guarded.screen.getScreenLines(), initialFrame, 'no overlay preserves the native frame');
51
+ const unrelated = fixture(); unrelated.open(); unrelated.paint();
52
+ assert.ok(isImageLine(unrelated.screen.getScreenLines()[2]), 'another terminal keeps its native image behavior');
53
+ const overlay = guarded.open();
54
+ const opened = guarded.paint();
55
+ assert.ok(opened.includes(deletion), 'opening an overlay deletes existing Kitty placements');
56
+ assert.ok(!guarded.screen.getScreenLines().some(isImageLine), 'overlay frame contains no underlying image anchors');
57
+ for (const line of guarded.screen.getScreenLines().slice(2, 8)) {
58
+ assert.equal((line.match(/│/g) || []).length, 2, 'both borders survive on every covered row');
59
+ }
60
+ assert.deepEqual(guarded.lines, recordedLines, 'suppression does not mutate the underlying image rows');
61
+
62
+ overlay.setHidden(true);
63
+ const hidden = guarded.paint();
64
+ assert.match(hidden, /\x1b_Ga=p,q=2,/, 'hiding the last overlay restores the cached image placement');
65
+ assert.doesNotMatch(hidden, /\x1b_Ga=T,/, 'restoring a hidden overlay does not upload the image again');
66
+ assert.ok(guarded.screen.getScreenLines().some(isImageLine));
67
+ overlay.setHidden(false);
68
+ assert.ok(guarded.paint().includes(deletion), 'showing the overlay removes its underlying image again');
69
+ overlay.hide();
70
+ const closed = guarded.paint();
71
+ assert.match(closed, /\x1b_Ga=p,q=2,/, 'closing the last overlay restores the cached image placement');
72
+ assert.doesNotMatch(closed, /\x1b_Ga=T,/, 'closing does not upload image data again');
73
+ assert.deepEqual(guarded.screen.getScreenLines(), initialFrame, 'closing restores the original native frame');
74
+
75
+ cleanup(); cleanup();
76
+ assert.equal(guarded.screen.compositeOverlays, original, 'cleanup restores native compositing');
77
+ guarded.open(); guarded.paint();
78
+ assert.ok(isImageLine(guarded.screen.getScreenLines()[2]), 'cleanup returns image handling to native behavior');
79
+ } finally { cleanup(); }
80
+
81
+ // Widget factories receive the stable native Proxy rather than the renderer.
82
+ // Its method reads return fresh forwarding functions, which must not prevent cleanup.
83
+ const proxied = fixture();
84
+ proxied.paint();
85
+ const proxyOriginal = proxied.screen.compositeOverlays;
86
+ const proxyCleanup = installFullscreenOverlayGuard(createInteractiveTuiReference(() => proxied.screen));
87
+ try {
88
+ proxied.open();
89
+ assert.ok(proxied.paint().includes(deletion), 'the real native forwarding Proxy installs the guard on its renderer');
90
+ assert.ok(!proxied.screen.getScreenLines().some(isImageLine));
91
+ } finally { proxyCleanup(); }
92
+ assert.equal(proxied.screen.compositeOverlays, proxyOriginal, 'Proxy cleanup restores the actual renderer method');
93
+ proxied.paint();
94
+ assert.ok(proxied.screen.getScreenLines().some(isImageLine), 'Proxy cleanup restores native image handling');
95
+
96
+ for (const protocol of [null, 'iterm2']) {
97
+ const fallback = fixture();
98
+ fallback.screen.imageProtocol = protocol;
99
+ const dispose = installFullscreenOverlayGuard(fallback.screen);
100
+ try {
101
+ fallback.open(); fallback.paint();
102
+ assert.ok(isImageLine(fallback.screen.getScreenLines()[2]), 'other protocols preserve native compositing');
103
+ } finally { dispose?.(); }
104
+ }
105
+ for (const overrides of [
106
+ { mode: 'unknown' },
107
+ { prepareKittyScreen: undefined }, { hasOverlay: undefined }, { compositeOverlays: undefined },
108
+ ]) {
109
+ const { screen } = fixture();
110
+ Object.assign(screen, overrides);
111
+ const before = screen.compositeOverlays;
112
+ const dispose = installFullscreenOverlayGuard(screen);
113
+ assert.equal(screen.compositeOverlays, before, 'unsupported native seams are unchanged');
114
+ dispose?.();
115
+ }
116
+ const future = fixture().screen;
117
+ const futureOriginal = future.compositeOverlays;
118
+ installFullscreenOverlayGuard(future, 'future')?.();
119
+ assert.equal(future.compositeOverlays, futureOriginal, 'an unknown native version remains unchanged');
120
+
121
+ const switched = fixture();
122
+ const regular = new tui.TuiMainScreen(switched.screen.terminal, false);
123
+ regular.requestRender = () => {};
124
+ let active = regular;
125
+ const switchProxy = createInteractiveTuiReference(() => active);
126
+ const regularOriginal = regular.compositeOverlays;
127
+ const switchedOriginal = switched.screen.compositeOverlays;
128
+ const cleanupSwitch = installFullscreenOverlayGuard(switchProxy);
129
+ try {
130
+ const row = [' \x1b]133;A\x07retained source'];
131
+ assert.equal(regular.compositeOverlays, regularOriginal, 'regular-mode native rendering is unchanged');
132
+ assert.match(switchProxy.compositeOverlays(row, 40, 12)[0], /\x1b\]133;/);
133
+ active = switched.screen;
134
+ assert.doesNotMatch(switchProxy.compositeOverlays(row, 40, 12)[0], /\x1b\]133;/, 'switching to fullscreen activates the guard without a widget rebuild');
135
+ active = regular;
136
+ assert.match(switchProxy.compositeOverlays(row, 40, 12)[0], /\x1b\]133;/, 'switching back retains regular-mode prompt markers');
137
+ } finally { cleanupSwitch(); }
138
+ assert.equal(switched.screen.compositeOverlays, switchedOriginal, 'cleanup detaches even after switching back to regular mode');
139
+
140
+ // Fullscreen Pi strips zone markers only at column zero. Layout padding leaves
141
+ // A/B/C in actual terminal writes, where they can erase complete overlay rows.
142
+ const zones = fixture();
143
+ zones.screen.imageProtocol = null;
144
+ const zoneRows = [
145
+ ' \x1b]133;A\x07',
146
+ ' \x1b[32m\x1b]133;B\x07\x1b]133;C\x07answer\x1b[0m',
147
+ ' \x1b]133;A\x1b\\padding',
148
+ ' before\x1b]133;B\x1b\\\x1b]133;C\x1b\\after',
149
+ ];
150
+ zones.lines.splice(2, 4, ...zoneRows);
151
+ const zonesOverlay = zones.open();
152
+ const stockZones = zones.paint();
153
+ assert.match(stockZones, /\x1b\]133;[ABC]/, 'padded zone markers survive stock fullscreen output');
154
+ const beforeZones = zones.lines.slice();
155
+ const clearZones = installFullscreenOverlayGuard(zones.screen);
156
+ try {
157
+ assert.doesNotMatch(zones.paint(), /\x1b\]133;[ABC]/, 'terminal writes contain no padded prompt markers');
158
+ assert.ok(zones.screen.getScreenLines().slice(2, 6).every(line => (line.match(/│/g) || []).length === 2), 'marker rows retain both overlay borders');
159
+ assert.deepEqual(zones.lines, beforeZones, 'source rows and native prompt-navigation markers remain intact');
160
+ zonesOverlay.hide();
161
+ assert.doesNotMatch(zones.paint(), /\x1b\]133;[ABC]/, 'fullscreen output also removes markers with no overlay');
162
+ const source = [' \x1b]133;A\x07\x1b]8;;https://example.com\x07label\x1b]8;;\x07\x1b]133;D;0\x07'];
163
+ const nativeRow = zones.screen.compositeOverlays(source, 40, 12)[0];
164
+ assert.match(nativeRow, /\x1b\]8;;https:\/\/example.com\x07label/, 'hyperlink controls remain intact');
165
+ assert.match(nativeRow, /\x1b\]133;D;0\x07/, 'only the native fullscreen A/B/C marker family is removed');
166
+ } finally { clearZones(); }
167
+ assert.match(zones.paint(), /\x1b\]133;[ABC]/, 'cleanup restores native marker handling');
168
+ console.log('Fullscreen overlays: image lifecycle, prompt zones, native Proxy cleanup and fallback passed');