@narumitw/pi-btw 0.63.0 → 0.63.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.
- package/README.md +1 -1
- package/dist/index.ts +77 -64
- package/dist/index.ts.map +2 -2
- package/docs/core-alignment.md +10 -2
- package/package.json +5 -5
- package/src/fullscreen-ui.ts +83 -63
package/README.md
CHANGED
|
@@ -191,7 +191,7 @@ The file is read for every `/btw` invocation, so edits apply without `/reload`.
|
|
|
191
191
|
- Resume state is memory-only and lasts only for the current extension instance.
|
|
192
192
|
- Main-conversation context is a limited text snapshot, not the complete session; see [context scope](./docs/workflows.md#choose-context-and-resume-threads).
|
|
193
193
|
- Clipboard access depends on Pi's host helper, the operating system, and the terminal.
|
|
194
|
-
- The live workspace
|
|
194
|
+
- The live workspace uses a separate TUI instance and BTW-owned private host-layout access because Pi has no public workspace-composition API; see the [core-alignment handoff](./docs/core-alignment.md) for tested safeguards, exact limits, and proposed APIs. This intentionally deviates from Pi's advice against a second terminal renderer: only one renderer owns the terminal at a time, without an official support guarantee. The [shared fullscreen handoff record](https://github.com/narumiruna/pi-extensions/blob/main/packages/pi-tui-kit/docs/fullscreen-handoff.md) records the Kit physical-lifecycle contract, two-consumer proof, release guards, and physical-terminal limits; layouts, input, and domain state stay in BTW.
|
|
195
195
|
- Pi does not expose all effective renderer options or a public clipboard-read callback. BTW uses native automatic wheel behavior but does not inherit private host wheel overrides or right-click clipboard paste.
|
|
196
196
|
- Conversation appearance follows native defaults, not custom host editor/footer extensions or private padding settings. BTW uses one-cell message padding and zero-cell editor padding; see the [appearance reference and before/after frames](./docs/native-appearance.md).
|
|
197
197
|
- Malformed, unsupported, or oversized Mermaid diagrams remain readable as fenced source; partial parses also show a warning.
|
package/dist/index.ts
CHANGED
|
@@ -1940,6 +1940,10 @@ var FullscreenUiDisposedError = class extends Error {
|
|
|
1940
1940
|
}
|
|
1941
1941
|
};
|
|
1942
1942
|
async function runBtwFullscreen(ctx, run, options = {}, dependencies = {}) {
|
|
1943
|
+
const { createFullscreenHandoff } = await import("@narumitw/pi-tui-kit/fullscreen-handoff");
|
|
1944
|
+
if (ctx.signal?.aborted || options.signal?.aborted || options.canRestoreParent?.() === false) {
|
|
1945
|
+
throw new FullscreenUiDisposedError();
|
|
1946
|
+
}
|
|
1943
1947
|
const createTui = dependencies.createTui ?? ((parent, theme, keybindings, fullscreenOptions) => createBtwFullscreenTui(
|
|
1944
1948
|
parent,
|
|
1945
1949
|
theme,
|
|
@@ -1973,7 +1977,8 @@ async function runBtwFullscreen(ctx, run, options = {}, dependencies = {}) {
|
|
|
1973
1977
|
done(value);
|
|
1974
1978
|
},
|
|
1975
1979
|
createTui,
|
|
1976
|
-
options
|
|
1980
|
+
options,
|
|
1981
|
+
createFullscreenHandoff
|
|
1977
1982
|
);
|
|
1978
1983
|
return host;
|
|
1979
1984
|
},
|
|
@@ -1992,7 +1997,7 @@ async function runBtwFullscreen(ctx, run, options = {}, dependencies = {}) {
|
|
|
1992
1997
|
return outcome.value;
|
|
1993
1998
|
}
|
|
1994
1999
|
var BtwFullscreenHost = class {
|
|
1995
|
-
constructor(parent, theme, keybindings, ctx, run, done, createTui, options) {
|
|
2000
|
+
constructor(parent, theme, keybindings, ctx, run, done, createTui, options, createHandoff) {
|
|
1996
2001
|
this.parent = parent;
|
|
1997
2002
|
this.theme = theme;
|
|
1998
2003
|
this.keybindings = keybindings;
|
|
@@ -2010,6 +2015,10 @@ var BtwFullscreenHost = class {
|
|
|
2010
2015
|
},
|
|
2011
2016
|
() => this.fullscreen?.requestRender()
|
|
2012
2017
|
);
|
|
2018
|
+
this.handoff = createHandoff(parent, {
|
|
2019
|
+
isCurrent: () => !this.disposed && !this.finished && !this.lifetimeController.signal.aborted && this.options.canRestoreParent?.() !== false,
|
|
2020
|
+
canRestoreParent: () => this.options.canRestoreParent?.() !== false
|
|
2021
|
+
});
|
|
2013
2022
|
this.sidePaneRatio = options.sidePaneRatio;
|
|
2014
2023
|
queueMicrotask(() => void this.start());
|
|
2015
2024
|
}
|
|
@@ -2022,7 +2031,7 @@ var BtwFullscreenHost = class {
|
|
|
2022
2031
|
createTui;
|
|
2023
2032
|
options;
|
|
2024
2033
|
fullscreen;
|
|
2025
|
-
|
|
2034
|
+
handoff;
|
|
2026
2035
|
cancelActiveCustom;
|
|
2027
2036
|
hardCancelActiveCustom;
|
|
2028
2037
|
removeHardCancelListener;
|
|
@@ -2030,13 +2039,8 @@ var BtwFullscreenHost = class {
|
|
|
2030
2039
|
started = false;
|
|
2031
2040
|
disposed = false;
|
|
2032
2041
|
finished = false;
|
|
2033
|
-
parentStopped = false;
|
|
2034
|
-
parentRestoreAttempted = false;
|
|
2035
|
-
fullscreenCreated = false;
|
|
2036
|
-
fullscreenStopped = false;
|
|
2037
|
-
parentRestoreQueued = false;
|
|
2038
2042
|
parentRestorePromise;
|
|
2039
|
-
|
|
2043
|
+
cleanupErrors = [];
|
|
2040
2044
|
removeMainThreadUpdateListener;
|
|
2041
2045
|
mainThreadRefreshTimer;
|
|
2042
2046
|
mainThreadInput;
|
|
@@ -2046,7 +2050,7 @@ var BtwFullscreenHost = class {
|
|
|
2046
2050
|
sidePaneWriteGeneration = 0;
|
|
2047
2051
|
confirmedSidePaneWriteGeneration = 0;
|
|
2048
2052
|
setParentOverlay(overlay) {
|
|
2049
|
-
this.
|
|
2053
|
+
this.handoff.setOverlayHandle(overlay);
|
|
2050
2054
|
}
|
|
2051
2055
|
render(width) {
|
|
2052
2056
|
return [truncateToWidth3(this.theme.fg("muted", "Opening btw side thread\u2026"), width)];
|
|
@@ -2074,12 +2078,12 @@ var BtwFullscreenHost = class {
|
|
|
2074
2078
|
getParentFullscreenLayout(this.parent);
|
|
2075
2079
|
getParentFullscreenScrollView(this.parent);
|
|
2076
2080
|
}
|
|
2077
|
-
this.
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
this.fullscreen
|
|
2081
|
-
|
|
2082
|
-
|
|
2081
|
+
this.fullscreen = await this.handoff.enter(
|
|
2082
|
+
() => this.createTui(this.parent, this.theme, this.keybindings, this.options)
|
|
2083
|
+
);
|
|
2084
|
+
if (!this.fullscreen || this.disposed || this.finished || this.options.canRestoreParent?.() === false) {
|
|
2085
|
+
throw new FullscreenUiDisposedError();
|
|
2086
|
+
}
|
|
2083
2087
|
this.watchMainThreadUpdates();
|
|
2084
2088
|
const shortcuts = resolveBtwShortcuts(
|
|
2085
2089
|
this.options.keybindings,
|
|
@@ -2128,11 +2132,19 @@ var BtwFullscreenHost = class {
|
|
|
2128
2132
|
try {
|
|
2129
2133
|
this.cancelActiveCustom?.();
|
|
2130
2134
|
} catch (error) {
|
|
2131
|
-
this.
|
|
2135
|
+
this.cleanupErrors.push(error);
|
|
2136
|
+
}
|
|
2137
|
+
this.queueParentRestore();
|
|
2138
|
+
await this.parentRestorePromise;
|
|
2139
|
+
if (this.cleanupErrors.length) {
|
|
2140
|
+
outcome = {
|
|
2141
|
+
kind: "failed",
|
|
2142
|
+
error: combineErrors(
|
|
2143
|
+
outcome.kind === "failed" ? [outcome.error, ...this.cleanupErrors] : this.cleanupErrors,
|
|
2144
|
+
"Pi BTW flow and terminal cleanup failed"
|
|
2145
|
+
)
|
|
2146
|
+
};
|
|
2132
2147
|
}
|
|
2133
|
-
if (this.parentRestorePromise) await this.parentRestorePromise;
|
|
2134
|
-
else this.restoreParent();
|
|
2135
|
-
if (this.cleanupError !== void 0) outcome = { kind: "failed", error: this.cleanupError };
|
|
2136
2148
|
this.finished = true;
|
|
2137
2149
|
this.done(outcome);
|
|
2138
2150
|
}
|
|
@@ -2168,16 +2180,13 @@ var BtwFullscreenHost = class {
|
|
|
2168
2180
|
if (signal.aborted) onAbort();
|
|
2169
2181
|
}
|
|
2170
2182
|
queueParentRestore() {
|
|
2171
|
-
if (this.
|
|
2172
|
-
this.
|
|
2183
|
+
if (this.parentRestorePromise) return;
|
|
2184
|
+
const restoration = this.handoff.restore().catch((error) => {
|
|
2185
|
+
this.cleanupErrors.push(error);
|
|
2186
|
+
});
|
|
2173
2187
|
this.parentRestorePromise = Promise.resolve().then(async () => {
|
|
2174
|
-
try {
|
|
2175
|
-
await this.fullscreen?.terminal.drainInput?.();
|
|
2176
|
-
} catch (error) {
|
|
2177
|
-
this.cleanupError ??= error;
|
|
2178
|
-
}
|
|
2179
|
-
this.parentRestoreQueued = false;
|
|
2180
2188
|
this.restoreParent();
|
|
2189
|
+
await restoration;
|
|
2181
2190
|
});
|
|
2182
2191
|
}
|
|
2183
2192
|
watchMainThreadUpdates() {
|
|
@@ -2202,50 +2211,26 @@ var BtwFullscreenHost = class {
|
|
|
2202
2211
|
try {
|
|
2203
2212
|
removeMainThreadUpdateListener?.();
|
|
2204
2213
|
} catch (error) {
|
|
2205
|
-
this.
|
|
2214
|
+
this.cleanupErrors.push(error);
|
|
2206
2215
|
}
|
|
2207
2216
|
try {
|
|
2208
2217
|
this.mainThreadInput.dispose();
|
|
2209
2218
|
} catch (error) {
|
|
2210
|
-
this.
|
|
2219
|
+
this.cleanupErrors.push(error);
|
|
2211
2220
|
}
|
|
2212
2221
|
const removeUpstreamAbortListener = this.removeUpstreamAbortListener;
|
|
2213
2222
|
this.removeUpstreamAbortListener = void 0;
|
|
2214
2223
|
try {
|
|
2215
2224
|
removeUpstreamAbortListener?.();
|
|
2216
2225
|
} catch (error) {
|
|
2217
|
-
this.
|
|
2226
|
+
this.cleanupErrors.push(error);
|
|
2218
2227
|
}
|
|
2219
2228
|
const removeHardCancelListener = this.removeHardCancelListener;
|
|
2220
2229
|
this.removeHardCancelListener = void 0;
|
|
2221
2230
|
try {
|
|
2222
2231
|
removeHardCancelListener?.();
|
|
2223
2232
|
} catch (error) {
|
|
2224
|
-
this.
|
|
2225
|
-
}
|
|
2226
|
-
if (this.fullscreenCreated && !this.fullscreenStopped) {
|
|
2227
|
-
this.fullscreenStopped = true;
|
|
2228
|
-
try {
|
|
2229
|
-
this.fullscreen?.stop({ preserveScreen: true });
|
|
2230
|
-
} catch (error) {
|
|
2231
|
-
this.cleanupError ??= error;
|
|
2232
|
-
}
|
|
2233
|
-
}
|
|
2234
|
-
if (!this.parentStopped || this.parentRestoreAttempted) return;
|
|
2235
|
-
const parentOverlay = this.parentOverlay;
|
|
2236
|
-
this.parentOverlay = void 0;
|
|
2237
|
-
try {
|
|
2238
|
-
parentOverlay?.setHidden(true);
|
|
2239
|
-
} catch (error) {
|
|
2240
|
-
this.cleanupError ??= error;
|
|
2241
|
-
}
|
|
2242
|
-
try {
|
|
2243
|
-
this.parentRestoreAttempted = true;
|
|
2244
|
-
if (this.options.canRestoreParent?.() === false) return;
|
|
2245
|
-
this.parent.start();
|
|
2246
|
-
this.parent.renderNow(false);
|
|
2247
|
-
} catch (error) {
|
|
2248
|
-
this.cleanupError ??= error;
|
|
2233
|
+
this.cleanupErrors.push(error);
|
|
2249
2234
|
}
|
|
2250
2235
|
}
|
|
2251
2236
|
createContext() {
|
|
@@ -2306,22 +2291,23 @@ var BtwFullscreenHost = class {
|
|
|
2306
2291
|
componentDisposed = true;
|
|
2307
2292
|
try {
|
|
2308
2293
|
component.dispose?.();
|
|
2309
|
-
} catch {
|
|
2294
|
+
} catch (error) {
|
|
2295
|
+
this.cleanupErrors.push(error);
|
|
2310
2296
|
}
|
|
2311
2297
|
};
|
|
2312
2298
|
const unmount = () => {
|
|
2313
|
-
|
|
2299
|
+
const cleanupErrors = [];
|
|
2314
2300
|
const removeFocusListener = removePaneFocusListener;
|
|
2315
2301
|
removePaneFocusListener = void 0;
|
|
2316
2302
|
try {
|
|
2317
2303
|
removeFocusListener?.();
|
|
2318
2304
|
} catch (error) {
|
|
2319
|
-
|
|
2305
|
+
cleanupErrors.push(error);
|
|
2320
2306
|
}
|
|
2321
2307
|
try {
|
|
2322
2308
|
splitPane?.dispose();
|
|
2323
2309
|
} catch (error) {
|
|
2324
|
-
|
|
2310
|
+
cleanupErrors.push(error);
|
|
2325
2311
|
}
|
|
2326
2312
|
splitPane = void 0;
|
|
2327
2313
|
try {
|
|
@@ -2329,18 +2315,18 @@ var BtwFullscreenHost = class {
|
|
|
2329
2315
|
else if (mounted && layoutMounted) fullscreen.setLayoutRoot(void 0);
|
|
2330
2316
|
else if (mounted && component) fullscreen.removeChild(component);
|
|
2331
2317
|
} catch (error) {
|
|
2332
|
-
|
|
2318
|
+
cleanupErrors.push(error);
|
|
2333
2319
|
}
|
|
2334
2320
|
if (overlay || mounted) {
|
|
2335
2321
|
try {
|
|
2336
2322
|
fullscreen.setFocus(null);
|
|
2337
2323
|
fullscreen.requestRender();
|
|
2338
2324
|
} catch (error) {
|
|
2339
|
-
|
|
2325
|
+
cleanupErrors.push(error);
|
|
2340
2326
|
}
|
|
2341
2327
|
}
|
|
2342
2328
|
disposeComponent();
|
|
2343
|
-
if (
|
|
2329
|
+
if (cleanupErrors.length) throw combineErrors(cleanupErrors, "Pi BTW custom UI cleanup failed");
|
|
2344
2330
|
};
|
|
2345
2331
|
const complete = () => {
|
|
2346
2332
|
if (promiseSettled || !hasPendingValue) return;
|
|
@@ -2375,7 +2361,7 @@ var BtwFullscreenHost = class {
|
|
|
2375
2361
|
unmount();
|
|
2376
2362
|
reject(error);
|
|
2377
2363
|
} catch (cleanupError) {
|
|
2378
|
-
reject(cleanupError);
|
|
2364
|
+
reject(combineErrors([error, cleanupError], "Pi BTW custom UI and cleanup failed"));
|
|
2379
2365
|
}
|
|
2380
2366
|
};
|
|
2381
2367
|
this.cancelActiveCustom = () => {
|
|
@@ -2512,6 +2498,33 @@ var BtwFullscreenHost = class {
|
|
|
2512
2498
|
}
|
|
2513
2499
|
}
|
|
2514
2500
|
};
|
|
2501
|
+
function combineErrors(errors, message) {
|
|
2502
|
+
const causes = [];
|
|
2503
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2504
|
+
const remember = (error) => {
|
|
2505
|
+
if (seen.has(error)) return;
|
|
2506
|
+
seen.add(error);
|
|
2507
|
+
if (error instanceof AggregateError) error.errors.forEach(remember);
|
|
2508
|
+
};
|
|
2509
|
+
const overlaps = (error, visited = /* @__PURE__ */ new Set()) => {
|
|
2510
|
+
if (seen.has(error)) return true;
|
|
2511
|
+
if (visited.has(error)) return false;
|
|
2512
|
+
visited.add(error);
|
|
2513
|
+
return error instanceof AggregateError && error.errors.some((cause) => overlaps(cause, visited));
|
|
2514
|
+
};
|
|
2515
|
+
const append = (error) => {
|
|
2516
|
+
if (seen.has(error)) return;
|
|
2517
|
+
if (error instanceof AggregateError && overlaps(error)) {
|
|
2518
|
+
seen.add(error);
|
|
2519
|
+
error.errors.forEach(append);
|
|
2520
|
+
return;
|
|
2521
|
+
}
|
|
2522
|
+
causes.push(error);
|
|
2523
|
+
remember(error);
|
|
2524
|
+
};
|
|
2525
|
+
errors.forEach(append);
|
|
2526
|
+
return causes.length === 1 ? causes[0] : new AggregateError(causes, message);
|
|
2527
|
+
}
|
|
2515
2528
|
function formatError3(error) {
|
|
2516
2529
|
return error instanceof Error ? error.message : String(error);
|
|
2517
2530
|
}
|