pi-sakura-cyberdeck 1.5.4 → 1.5.6
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 +64 -0
- package/README.md +14 -16
- package/README.zh-CN.md +1 -1
- package/extensions/shared/tui-context.ts +21 -0
- package/extensions/zentui/footer-segments.ts +14 -7
- package/extensions/zentui/footer.ts +16 -2
- package/extensions/zentui/format.ts +98 -0
- package/extensions/zentui/gradient.ts +3 -12
- package/extensions/zentui/index.ts +53 -5
- package/extensions/zentui/panel-bg.ts +110 -0
- package/extensions/zentui/tool-execution.ts +38 -14
- package/extensions/zentui/user-message.ts +39 -16
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,70 @@
|
|
|
3
3
|
All notable changes to pi-sakura-cyberdeck. Pi >= 1.5.0 shows new package entries
|
|
4
4
|
once after updating; run `/sakura-changelog` on any supported Pi to read this file.
|
|
5
5
|
|
|
6
|
+
## [1.5.6] - 2026-12-06
|
|
7
|
+
|
|
8
|
+
### Highlights
|
|
9
|
+
|
|
10
|
+
- **Transparent card interiors across all Pi themes**: framed user messages and tool cards now stay
|
|
11
|
+
transparent on Pi's `system`, `dark`, `light` and custom themes instead of painting a solid
|
|
12
|
+
panel fill inside Sakura borders.
|
|
13
|
+
- **Compaction-aware footer context budget**: when Pi's `compaction.modelOverrides` or
|
|
14
|
+
`compaction.reserveTokens` is configured and auto-compaction is enabled, the footer context
|
|
15
|
+
gauge, percentage and color tier now track the effective usable budget (`contextWindow - reserveTokens`).
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- **Compaction-aware footer context budget**: Zentui reads explicitly configured Pi compaction
|
|
20
|
+
reserves (`compaction.modelOverrides["provider/modelId"].reserveTokens`, falling back to
|
|
21
|
+
top-level `compaction.reserveTokens`) via `pi.getSettings()` when `compaction.enabled` is not
|
|
22
|
+
`false`, subtracting the reserve from the model's context window and recalculating the footer
|
|
23
|
+
percentage, gauge fill and warning/error tiers against the effective budget (including live
|
|
24
|
+
streaming usage, post-compaction `?` states and routed virtual models). Unconfigured setups and
|
|
25
|
+
`compaction.enabled: false` keep the raw model window unchanged; toggling auto-compaction or
|
|
26
|
+
switching models invalidates the footer frame cache immediately.
|
|
27
|
+
|
|
28
|
+
### Fixed
|
|
29
|
+
|
|
30
|
+
- **Solid panel backgrounds inside framed cards**: Pi's `UserMessageComponent` and
|
|
31
|
+
`ToolExecutionComponent` wrap rendered rows with `userMessageBg`, `toolPendingBg`,
|
|
32
|
+
`toolSuccessBg` or `toolErrorBg`, which painted colored rectangles inside Zentui's borders
|
|
33
|
+
whenever Pi used a theme with non-transparent panel fills (such as Pi's default `system`,
|
|
34
|
+
`dark` or `light` themes). Zentui now strips only the active theme's matching outer panel
|
|
35
|
+
wrapper (`extensions/zentui/panel-bg.ts`) while preserving foreground styles, OSC 133 prompt
|
|
36
|
+
markers, terminal image rows and tool output's own ANSI backgrounds, and invalidates card caches
|
|
37
|
+
on live theme switches.
|
|
38
|
+
|
|
39
|
+
## [1.5.5] - 2026-12-03
|
|
40
|
+
|
|
41
|
+
### Highlights
|
|
42
|
+
|
|
43
|
+
- **Linear sakura→sky frame gradients**: sent messages, tool cards and selector borders now flow
|
|
44
|
+
linearly from sakura pink (`#F2A7C6`) on the left to sky blue (`#9FD3F2`) on the right, with
|
|
45
|
+
sky-blue right tool rails (`│`) matching `╮` and `╯`.
|
|
46
|
+
- **Fullscreen `auto` scrollbar border clearance**: tool cards and user message hairlines reserve
|
|
47
|
+
1 right-edge column under Pi's default fullscreen `auto` scrollbar so the scrollbar no longer
|
|
48
|
+
overwrites card right borders.
|
|
49
|
+
|
|
50
|
+
### Fixed
|
|
51
|
+
|
|
52
|
+
- **Linear sakura→sky frame gradients**: `renderSakuraFrameGradient` now delegates directly to the
|
|
53
|
+
linear sakura→sky gradient (matching the editor and header) instead of curving pink → sky → pink.
|
|
54
|
+
Tool card right vertical rails (`│`) now use sky blue (`#9FD3F2`) so `╮`, `│` and `╯` connect
|
|
55
|
+
seamlessly.
|
|
56
|
+
- **Fullscreen `auto` scrollbar border clearance**: in Pi's fullscreen mode under the default
|
|
57
|
+
`fullscreenScrollbar: "auto"` setting, `ScrollView` passes full width `W` to transcript children
|
|
58
|
+
and overlays the transient scrollbar onto column `W - 1`, overwriting tool card right borders.
|
|
59
|
+
Tool cards and user message hairlines now reserve 1 right-edge column in fullscreen `"auto"` mode
|
|
60
|
+
(leaving `"always"`, `"hidden"` and `regular` mode untouched) so frames stay closed, aligned and
|
|
61
|
+
jitter-free while scrolling, with mouse hit-testing and render caches updated across live mode and
|
|
62
|
+
setting switches.
|
|
63
|
+
|
|
64
|
+
### Docs
|
|
65
|
+
|
|
66
|
+
- Updated README and social preview screenshots (`docs/screenshots/session.png` and
|
|
67
|
+
`docs/screenshots/social-preview.png`) to match the linear sakura→sky borders and sky-blue right
|
|
68
|
+
tool rails.
|
|
69
|
+
|
|
6
70
|
## [1.5.4] - 2026-12-03
|
|
7
71
|
|
|
8
72
|
### Highlights
|
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Then pick the theme in `/settings` → **sakura-macaron** and restart Pi once. D
|
|
|
18
18
|
<sub>Real Pi 1.5.2 session rendered by this pack (scripted demo model; GohuFont uni14 Nerd Font Mono).</sub>
|
|
19
19
|
</p>
|
|
20
20
|
|
|
21
|
-
**v1.5.
|
|
21
|
+
**v1.5.6** — transparent user message and tool card interiors across all Pi themes, plus compaction-aware footer context budgets honoring Pi's `compaction.reserveTokens` and `modelOverrides`. See [what changed](#156).
|
|
22
22
|
|
|
23
23
|
## What’s inside
|
|
24
24
|
|
|
@@ -147,9 +147,9 @@ Restart Pi after updating. Pi **>= 1.5.0** shows what changed under **Extension
|
|
|
147
147
|
Pi does not push package updates automatically. Users who pinned a version, tag or commit must explicitly select the new version:
|
|
148
148
|
|
|
149
149
|
```bash
|
|
150
|
-
pi install npm:pi-sakura-cyberdeck@1.5.
|
|
150
|
+
pi install npm:pi-sakura-cyberdeck@1.5.6
|
|
151
151
|
# or
|
|
152
|
-
pi install git:github.com/beautifulrem/pi-sakura-cyberdeck@v1.5.
|
|
152
|
+
pi install git:github.com/beautifulrem/pi-sakura-cyberdeck@v1.5.6
|
|
153
153
|
```
|
|
154
154
|
|
|
155
155
|
Notes for 1.2.0:
|
|
@@ -175,7 +175,7 @@ Or start with `pi --tui-mode fullscreen`. Pack styling (editor chrome, footer, s
|
|
|
175
175
|
|
|
176
176
|
### Load only some pieces
|
|
177
177
|
|
|
178
|
-
Pi can filter a package's resources. Replace the plain source string in `~/.pi/agent/settings.json` with an object. Keep `source` exactly as it is in your settings (a Git source, or an npm version pin such as `npm:pi-sakura-cyberdeck@1.5.
|
|
178
|
+
Pi can filter a package's resources. Replace the plain source string in `~/.pi/agent/settings.json` with an object. Keep `source` exactly as it is in your settings (a Git source, or an npm version pin such as `npm:pi-sakura-cyberdeck@1.5.6`); changing it installs a different package rather than filtering the one you have.
|
|
179
179
|
|
|
180
180
|
```jsonc
|
|
181
181
|
{
|
|
@@ -239,22 +239,20 @@ Avoid stacking with `pi-zentui`, `pi-powerline-footer`, stock `pi-claude-shimmer
|
|
|
239
239
|
|
|
240
240
|
Full history: [CHANGELOG.md](CHANGELOG.md) (also available in Pi via `/sakura-changelog`).
|
|
241
241
|
|
|
242
|
-
### 1.5.
|
|
242
|
+
### 1.5.6
|
|
243
243
|
|
|
244
|
-
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
BiDi/SGR sanitization for extension statuses, `.unref()` across all timers, and standalone
|
|
253
|
-
extension hardening across `claude-shimmer`, `matrix`, `header` and `changelog`.
|
|
244
|
+
- Transparent card interiors on every Pi theme: framed user messages and tool cards now strip Pi's
|
|
245
|
+
outer theme panel background fill (`userMessageBg`, `toolPendingBg`, `toolSuccessBg`,
|
|
246
|
+
`toolErrorBg`) so borders stay transparent on `system`, `dark`, `light` and custom themes while
|
|
247
|
+
preserving foreground styling, OSC 133 markers, image rows and tool output's own ANSI backgrounds.
|
|
248
|
+
- Compaction-aware footer context budget: when Pi's `compaction.modelOverrides` or
|
|
249
|
+
`compaction.reserveTokens` is configured and auto-compaction is enabled, the footer context
|
|
250
|
+
window, percentage, Macaron gauge and threshold color tier reflect `contextWindow - reserveTokens`
|
|
251
|
+
and update live across settings toggles and model switches.
|
|
254
252
|
|
|
255
253
|
### Earlier versions
|
|
256
254
|
|
|
257
|
-
See [CHANGELOG.md](CHANGELOG.md) for 1.0.0 – 1.5.
|
|
255
|
+
See [CHANGELOG.md](CHANGELOG.md) for 1.0.0 – 1.5.5.
|
|
258
256
|
|
|
259
257
|
## Development
|
|
260
258
|
|
package/README.zh-CN.md
CHANGED
|
@@ -50,7 +50,7 @@ pi install npm:pi-sakura-cyberdeck
|
|
|
50
50
|
|
|
51
51
|
## 只加载部分组件
|
|
52
52
|
|
|
53
|
-
在 `~/.pi/agent/settings.json` 里把包来源写成对象,可以按需过滤。`source` 保持你设置里原来的写法(比如 Git 来源,或者 `npm:pi-sakura-cyberdeck@1.5.
|
|
53
|
+
在 `~/.pi/agent/settings.json` 里把包来源写成对象,可以按需过滤。`source` 保持你设置里原来的写法(比如 Git 来源,或者 `npm:pi-sakura-cyberdeck@1.5.6` 这样锁定版本的写法);改了它就等于装了另一个包,而不是过滤现有的这个。
|
|
54
54
|
|
|
55
55
|
```jsonc
|
|
56
56
|
{
|
|
@@ -26,6 +26,27 @@ export function normalizeWidth(width: number): number {
|
|
|
26
26
|
return Number.isFinite(width) && width > 0 ? Math.floor(width) : 0;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Resolve an optional right-edge inset (e.g. fullscreen overlay scrollbar clearance) to a
|
|
31
|
+
* non-negative integer, clamping to 0 if applying it would push width below `minWidth`.
|
|
32
|
+
*/
|
|
33
|
+
export function resolveRightInset(
|
|
34
|
+
getRightInset: (() => number) | undefined,
|
|
35
|
+
width: number,
|
|
36
|
+
minWidth: number,
|
|
37
|
+
): number {
|
|
38
|
+
if (!getRightInset) return 0;
|
|
39
|
+
let raw: unknown;
|
|
40
|
+
try {
|
|
41
|
+
raw = getRightInset();
|
|
42
|
+
} catch {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
if (typeof raw !== "number" || !Number.isFinite(raw) || raw <= 0) return 0;
|
|
46
|
+
const inset = Math.floor(raw);
|
|
47
|
+
return width - inset >= minWidth ? inset : 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
29
50
|
/**
|
|
30
51
|
* Compare two rendered line arrays, taking an O(1) identity fast path when Pi's
|
|
31
52
|
* Container/Component render cache returns the exact same array reference.
|
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
formatUsernameHostLabel,
|
|
20
20
|
getCachedContextUsage,
|
|
21
21
|
getUsageTotals,
|
|
22
|
+
resolveContextPercent,
|
|
23
|
+
resolveEffectiveContextWindow,
|
|
22
24
|
type UsageTotals,
|
|
23
25
|
} from "./format";
|
|
24
26
|
import { renderSakuraGradient } from "./gradient";
|
|
@@ -44,6 +46,8 @@ export type FooterRenderInput = {
|
|
|
44
46
|
/** Pre-fetched memoized context usage from cache-key check (avoids double lookup on miss). */
|
|
45
47
|
contextUsage?: ReturnType<ExtensionContext["getContextUsage"]>;
|
|
46
48
|
hasContextUsage?: boolean;
|
|
49
|
+
/** Explicitly configured Pi compaction reserveTokens for the active model, if enabled. */
|
|
50
|
+
compactionReserveTokens?: number;
|
|
47
51
|
/** Pre-fetched memoized usage totals from cache-key check (avoids double lookup on miss). */
|
|
48
52
|
usageTotals?: UsageTotals;
|
|
49
53
|
phase: number;
|
|
@@ -175,13 +179,16 @@ function buildContextSegment(input: FooterRenderInput): string {
|
|
|
175
179
|
const asciiGauge = config.icons.mode === "ascii";
|
|
176
180
|
const contextUsage = input.hasContextUsage ? input.contextUsage : getCachedContextUsage(ctx);
|
|
177
181
|
// Pi sizes context by the routed physical model; a virtual (routed) model itself
|
|
178
|
-
// reports contextWindow 0, which `??` would keep. Prefer Pi's figure, then a real window
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
const contextPercent =
|
|
183
|
-
|
|
184
|
-
:
|
|
182
|
+
// reports contextWindow 0, which `??` would keep. Prefer Pi's figure, then a real window,
|
|
183
|
+
// and apply any explicit compaction reserveTokens cap so the gauge tracks the real budget.
|
|
184
|
+
const rawWindow = resolveContextWindow(contextUsage, ctx.model?.contextWindow);
|
|
185
|
+
const contextWindow = resolveEffectiveContextWindow(rawWindow, input.compactionReserveTokens);
|
|
186
|
+
const contextPercent = resolveContextPercent({
|
|
187
|
+
rawWindow,
|
|
188
|
+
effectiveWindow: contextWindow,
|
|
189
|
+
contextUsage,
|
|
190
|
+
liveTokens: liveContext?.tokens,
|
|
191
|
+
});
|
|
185
192
|
const tier = contextColorTier(contextPercent, config.contextThresholds);
|
|
186
193
|
const label = buildContextDisplayLabel({
|
|
187
194
|
percent: contextPercent,
|
|
@@ -204,6 +204,8 @@ export type FooterHooks = {
|
|
|
204
204
|
scheduleProjectRefresh: () => void;
|
|
205
205
|
setExtensionStatusesGetter?: (fn: (() => ReadonlyMap<string, string>) | undefined) => void;
|
|
206
206
|
getLiveContext?: () => LiveContextOverride | undefined;
|
|
207
|
+
/** Explicit Pi compaction reserveTokens for the active model when auto-compaction is enabled. */
|
|
208
|
+
getCompactionReserveTokens?: (model: ExtensionContext["model"]) => number | undefined;
|
|
207
209
|
/** True between agent_start and agent_end. */
|
|
208
210
|
isAgentWorking: () => boolean;
|
|
209
211
|
/** Receives a callback that re-evaluates the pulse timer (config change / agent state). */
|
|
@@ -424,8 +426,9 @@ function serializeContextInputs(
|
|
|
424
426
|
contextUsage: ReturnType<ExtensionContext["getContextUsage"]>,
|
|
425
427
|
liveContext: LiveContextOverride | undefined,
|
|
426
428
|
modelContextWindow: number | undefined,
|
|
429
|
+
compactionReserveTokens: number | undefined,
|
|
427
430
|
): string {
|
|
428
|
-
return `${str(contextUsage?.tokens)},${str(contextUsage?.contextWindow)},${str(contextUsage?.percent)},${str(liveContext?.tokens)},${str(modelContextWindow)}`;
|
|
431
|
+
return `${str(contextUsage?.tokens)},${str(contextUsage?.contextWindow)},${str(contextUsage?.percent)},${str(liveContext?.tokens)},${str(modelContextWindow)},${str(compactionReserveTokens)}`;
|
|
429
432
|
}
|
|
430
433
|
|
|
431
434
|
function computeTimeBucketKey(
|
|
@@ -589,6 +592,7 @@ function buildStaticFrameKey(
|
|
|
589
592
|
contextUsage: ReturnType<ExtensionContext["getContextUsage"]>,
|
|
590
593
|
liveContext: LiveContextOverride | undefined,
|
|
591
594
|
modelContextWindow: number | undefined,
|
|
595
|
+
compactionReserveTokens: number | undefined,
|
|
592
596
|
nowMs: number,
|
|
593
597
|
): string {
|
|
594
598
|
return [
|
|
@@ -598,7 +602,9 @@ function buildStaticFrameKey(
|
|
|
598
602
|
serializeFooterState(state),
|
|
599
603
|
extStatusConfigKey,
|
|
600
604
|
usageTotals ? serializeUsageTotals(usageTotals) : "",
|
|
601
|
-
vis.needsContext
|
|
605
|
+
vis.needsContext
|
|
606
|
+
? serializeContextInputs(contextUsage, liveContext, modelContextWindow, compactionReserveTokens)
|
|
607
|
+
: "",
|
|
602
608
|
computeTimeBucketKey(vis, state.sessionStartEpoch, nowMs),
|
|
603
609
|
].join("\0");
|
|
604
610
|
}
|
|
@@ -673,6 +679,7 @@ export function installFooter(
|
|
|
673
679
|
liveContext: LiveContextOverride | undefined,
|
|
674
680
|
hasContextUsage: boolean,
|
|
675
681
|
contextUsage: ReturnType<ExtensionContext["getContextUsage"]>,
|
|
682
|
+
compactionReserveTokens: number | undefined,
|
|
676
683
|
usageTotals: UsageTotals | undefined,
|
|
677
684
|
rawStatuses: ReadonlyMap<string, string>,
|
|
678
685
|
extStatusConfigKey: string,
|
|
@@ -696,6 +703,7 @@ export function installFooter(
|
|
|
696
703
|
liveContext,
|
|
697
704
|
contextUsage,
|
|
698
705
|
hasContextUsage,
|
|
706
|
+
compactionReserveTokens,
|
|
699
707
|
usageTotals,
|
|
700
708
|
phase,
|
|
701
709
|
separator,
|
|
@@ -749,6 +757,9 @@ export function installFooter(
|
|
|
749
757
|
const vis = getFooterVisibility(config);
|
|
750
758
|
const nowMs = vis.needsTime || vis.needsDuration ? Date.now() : 0;
|
|
751
759
|
const liveContext = vis.needsContext ? hooks.getLiveContext?.() : undefined;
|
|
760
|
+
const compactionReserveTokens = vis.needsContext
|
|
761
|
+
? hooks.getCompactionReserveTokens?.(ctx.model)
|
|
762
|
+
: undefined;
|
|
752
763
|
|
|
753
764
|
if (pulseTimer !== undefined) {
|
|
754
765
|
frameCache = undefined;
|
|
@@ -762,6 +773,7 @@ export function installFooter(
|
|
|
762
773
|
liveContext,
|
|
763
774
|
false,
|
|
764
775
|
undefined,
|
|
776
|
+
compactionReserveTokens,
|
|
765
777
|
undefined,
|
|
766
778
|
rawStatuses,
|
|
767
779
|
extStatusConfigKey,
|
|
@@ -784,6 +796,7 @@ export function installFooter(
|
|
|
784
796
|
contextUsage,
|
|
785
797
|
liveContext,
|
|
786
798
|
ctx.model?.contextWindow,
|
|
799
|
+
compactionReserveTokens,
|
|
787
800
|
nowMs,
|
|
788
801
|
);
|
|
789
802
|
|
|
@@ -801,6 +814,7 @@ export function installFooter(
|
|
|
801
814
|
liveContext,
|
|
802
815
|
vis.needsContext,
|
|
803
816
|
contextUsage,
|
|
817
|
+
compactionReserveTokens,
|
|
804
818
|
usageTotals,
|
|
805
819
|
rawStatuses,
|
|
806
820
|
extStatusConfigKey,
|
|
@@ -280,6 +280,104 @@ export function buildSessionDurationLabel(startEpoch: number, now = Date.now()):
|
|
|
280
280
|
return `${seconds}s`;
|
|
281
281
|
}
|
|
282
282
|
|
|
283
|
+
type ModelIdentityLike = {
|
|
284
|
+
readonly provider?: unknown;
|
|
285
|
+
readonly id?: unknown;
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
function isPlainRecord(value: unknown): value is Record<string, unknown> {
|
|
289
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function parseNonNegativeSafeInt(value: unknown): number | undefined {
|
|
293
|
+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0
|
|
294
|
+
? value
|
|
295
|
+
: undefined;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
function readModelOverrideReserve(
|
|
299
|
+
modelOverrides: unknown,
|
|
300
|
+
modelKey: string,
|
|
301
|
+
): { matched: true; value: number | undefined } | { matched: false } {
|
|
302
|
+
if (!isPlainRecord(modelOverrides)) return { matched: true, value: undefined };
|
|
303
|
+
if (!Object.hasOwn(modelOverrides, modelKey)) return { matched: false };
|
|
304
|
+
const entry = modelOverrides[modelKey];
|
|
305
|
+
if (!isPlainRecord(entry)) return { matched: true, value: undefined };
|
|
306
|
+
if (entry.reserveTokens === undefined) return { matched: false };
|
|
307
|
+
return { matched: true, value: parseNonNegativeSafeInt(entry.reserveTokens) };
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Resolve an explicitly configured Pi compaction `reserveTokens` value from `pi.getSettings()`.
|
|
312
|
+
*
|
|
313
|
+
* Follows Pi's `SettingsManager.getCompactionSettings(model)` precedence:
|
|
314
|
+
* - `compaction.enabled === false` disables automatic compaction, so no reserve is subtracted.
|
|
315
|
+
* - `compaction.modelOverrides["provider/modelId"].reserveTokens` wins over top-level
|
|
316
|
+
* `compaction.reserveTokens` (including an explicit `0`).
|
|
317
|
+
* - Omitting both leaves Pi's built-in 16,384 default unapplied so the raw model window stays
|
|
318
|
+
* unchanged for unconfigured setups; malformed entries fail safe to `undefined`.
|
|
319
|
+
*/
|
|
320
|
+
export function resolveConfiguredCompactionReserveTokens(
|
|
321
|
+
settings: unknown,
|
|
322
|
+
model: ModelIdentityLike | undefined,
|
|
323
|
+
): number | undefined {
|
|
324
|
+
if (!isPlainRecord(settings)) return undefined;
|
|
325
|
+
const compaction = settings.compaction;
|
|
326
|
+
if (!isPlainRecord(compaction) || compaction.enabled === false) return undefined;
|
|
327
|
+
|
|
328
|
+
const provider = typeof model?.provider === "string" ? model.provider : "";
|
|
329
|
+
const id = typeof model?.id === "string" ? model.id : "";
|
|
330
|
+
const modelKey = provider && id ? `${provider}/${id}` : undefined;
|
|
331
|
+
if (modelKey !== undefined && compaction.modelOverrides !== undefined) {
|
|
332
|
+
const override = readModelOverrideReserve(compaction.modelOverrides, modelKey);
|
|
333
|
+
if (override.matched) return override.value;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
if (compaction.reserveTokens === undefined) return undefined;
|
|
337
|
+
return parseNonNegativeSafeInt(compaction.reserveTokens);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Compute the effective usable context window after subtracting an explicit compaction reserve.
|
|
342
|
+
* Falls back to `rawWindow` when no positive reserve applies or when `reserve >= rawWindow`.
|
|
343
|
+
*/
|
|
344
|
+
export function resolveEffectiveContextWindow(
|
|
345
|
+
rawWindow: number | undefined,
|
|
346
|
+
compactionReserveTokens: number | undefined,
|
|
347
|
+
): number | undefined {
|
|
348
|
+
if (rawWindow === undefined || !Number.isFinite(rawWindow) || rawWindow <= 0) return rawWindow;
|
|
349
|
+
if (
|
|
350
|
+
compactionReserveTokens === undefined ||
|
|
351
|
+
!Number.isFinite(compactionReserveTokens) ||
|
|
352
|
+
compactionReserveTokens <= 0
|
|
353
|
+
) {
|
|
354
|
+
return rawWindow;
|
|
355
|
+
}
|
|
356
|
+
const effective = rawWindow - compactionReserveTokens;
|
|
357
|
+
return effective > 0 ? effective : rawWindow;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
export function resolveContextPercent(options: {
|
|
361
|
+
rawWindow: number | undefined;
|
|
362
|
+
effectiveWindow: number | undefined;
|
|
363
|
+
contextUsage: ReturnType<ExtensionContext["getContextUsage"]>;
|
|
364
|
+
liveTokens: number | undefined;
|
|
365
|
+
}): number | null | undefined {
|
|
366
|
+
const { rawWindow, effectiveWindow, contextUsage, liveTokens } = options;
|
|
367
|
+
const hasValidWindow =
|
|
368
|
+
effectiveWindow !== undefined && Number.isFinite(effectiveWindow) && effectiveWindow > 0;
|
|
369
|
+
if (liveTokens !== undefined && hasValidWindow) {
|
|
370
|
+
return (liveTokens / effectiveWindow) * 100;
|
|
371
|
+
}
|
|
372
|
+
if (effectiveWindow !== rawWindow && hasValidWindow) {
|
|
373
|
+
const tokens = contextUsage?.tokens;
|
|
374
|
+
return tokens !== null && tokens !== undefined
|
|
375
|
+
? (tokens / effectiveWindow) * 100
|
|
376
|
+
: contextUsage?.percent;
|
|
377
|
+
}
|
|
378
|
+
return contextUsage?.percent;
|
|
379
|
+
}
|
|
380
|
+
|
|
283
381
|
export function contextColorTier(
|
|
284
382
|
percent: number | null | undefined,
|
|
285
383
|
thresholds: ContextThresholds = { warning: 70, error: 90 },
|
|
@@ -153,20 +153,11 @@ export function renderSakuraGradient(text: string, phase = 0): string {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
/**
|
|
156
|
-
* Box-frame gradient: sakura
|
|
157
|
-
*
|
|
156
|
+
* Box-frame gradient: linear sakura pink (#F2A7C6) on the left → sky blue (#9FD3F2) on the right,
|
|
157
|
+
* matching the editor and header gradients.
|
|
158
158
|
*/
|
|
159
159
|
export function renderSakuraFrameGradient(text: string): string {
|
|
160
|
-
|
|
161
|
-
const cacheKey = `\0frame\0${text}`;
|
|
162
|
-
const cached = cacheGet(cacheKey);
|
|
163
|
-
if (cached !== undefined) return cached;
|
|
164
|
-
// 0 → 1 → 0 so left/right corners share sakura pink.
|
|
165
|
-
const rendered = paintPositions(text, (pos) =>
|
|
166
|
-
sampleSakuraGradient(pos <= 0.5 ? pos * 2 : (1 - pos) * 2),
|
|
167
|
-
);
|
|
168
|
-
cacheSet(cacheKey, rendered);
|
|
169
|
-
return rendered;
|
|
160
|
+
return renderSakuraGradient(text);
|
|
170
161
|
}
|
|
171
162
|
|
|
172
163
|
/** Context fill palettes — stay macaron, shift with severity. */
|
|
@@ -37,7 +37,10 @@ import {
|
|
|
37
37
|
type UiFeaturesConfig,
|
|
38
38
|
} from "./config";
|
|
39
39
|
import { installFooter } from "./footer";
|
|
40
|
-
import {
|
|
40
|
+
import {
|
|
41
|
+
invalidateSessionCaches,
|
|
42
|
+
resolveConfiguredCompactionReserveTokens,
|
|
43
|
+
} from "./format";
|
|
41
44
|
import { emptyGitStatus, readGitStatus } from "./git";
|
|
42
45
|
import { LiveContextController } from "./live-context";
|
|
43
46
|
import { readPackageVersionResult } from "./package-version";
|
|
@@ -110,6 +113,49 @@ function sameProjectProbes(a: ProjectProbePlan, b: ProjectProbePlan): boolean {
|
|
|
110
113
|
);
|
|
111
114
|
}
|
|
112
115
|
|
|
116
|
+
type ActiveTuiLike = Pick<TUI, "invalidate" | "requestRender"> & { readonly mode?: unknown };
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Pi's fullscreen `ScrollView` subtracts 1 column only when `fullscreenScrollbar` is `"always"`.
|
|
120
|
+
* Under the default `"auto"` mode, transcript children receive the full width `W` and the
|
|
121
|
+
* transient scrollbar overlays column `W - 1`, overwriting the right border of framed cards.
|
|
122
|
+
* Reserving 1 column ourselves in fullscreen `"auto"` keeps card frames closed and aligned with
|
|
123
|
+
* `"always"` without width jitter as the scrollbar appears and fades.
|
|
124
|
+
*/
|
|
125
|
+
function transcriptRightInset(pi: ExtensionAPI, tui: ActiveTuiLike | undefined): number {
|
|
126
|
+
const liveMode = typeof tui?.mode === "string" ? tui.mode : undefined;
|
|
127
|
+
if (liveMode === "regular") return 0;
|
|
128
|
+
|
|
129
|
+
let settings: { tuiMode?: unknown; fullscreenScrollbar?: unknown } | undefined;
|
|
130
|
+
if (typeof (pi as { getSettings?: unknown }).getSettings === "function") {
|
|
131
|
+
try {
|
|
132
|
+
const raw = pi.getSettings();
|
|
133
|
+
if (raw && typeof raw === "object") settings = raw;
|
|
134
|
+
} catch {
|
|
135
|
+
// Older or restricted host: fall back to live TUI mode below.
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const tuiMode =
|
|
140
|
+
liveMode ?? (settings ? (settings.tuiMode === "regular" ? "regular" : "fullscreen") : undefined);
|
|
141
|
+
if (tuiMode !== "fullscreen") return 0;
|
|
142
|
+
|
|
143
|
+
const scrollbar = settings?.fullscreenScrollbar;
|
|
144
|
+
return scrollbar === "always" || scrollbar === "hidden" ? 0 : 1;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function configuredCompactionReserveTokens(
|
|
148
|
+
pi: ExtensionAPI,
|
|
149
|
+
model: ExtensionContext["model"],
|
|
150
|
+
): number | undefined {
|
|
151
|
+
if (typeof (pi as { getSettings?: unknown }).getSettings !== "function") return undefined;
|
|
152
|
+
try {
|
|
153
|
+
return resolveConfiguredCompactionReserveTokens(pi.getSettings(), model);
|
|
154
|
+
} catch {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
113
159
|
export default function (pi: ExtensionAPI) {
|
|
114
160
|
const state: FooterState = createInitialState(emptyGitStatus());
|
|
115
161
|
const sessionLifecycle = new SessionLifecycle();
|
|
@@ -120,8 +166,8 @@ export default function (pi: ExtensionAPI) {
|
|
|
120
166
|
let probePlan: { version: number; plan: ProjectProbePlan } | undefined;
|
|
121
167
|
let activeCtx: ExtensionContext | undefined;
|
|
122
168
|
let activeTheme: Theme | undefined;
|
|
123
|
-
/** Pi's TUI, as seen by our footer or editor factory; needed to drop cached renders. */
|
|
124
|
-
let activeTui:
|
|
169
|
+
/** Pi's TUI, as seen by our footer or editor factory; needed to drop cached renders and inspect mode. */
|
|
170
|
+
let activeTui: ActiveTuiLike | undefined;
|
|
125
171
|
let requestFooterRender: (() => void) | undefined;
|
|
126
172
|
let syncFooterAnimation: (() => void) | undefined;
|
|
127
173
|
let getActiveExtensionStatuses: () => ReadonlyMap<string, string> = () => new Map();
|
|
@@ -335,9 +381,10 @@ export default function (pi: ExtensionAPI) {
|
|
|
335
381
|
// Host prototype method missing or changed: keep remaining surfaces & session startup intact.
|
|
336
382
|
}
|
|
337
383
|
};
|
|
384
|
+
const getTranscriptRightInset = () => transcriptRightInset(pi, activeTui);
|
|
338
385
|
tryInstall(() => installSelectorBorderStyle(getActiveTheme, getCurrentConfig));
|
|
339
|
-
tryInstall(() => installUserMessageStyle(getActiveTheme, getCurrentConfig));
|
|
340
|
-
tryInstall(() => installToolExecutionStyle(getActiveTheme));
|
|
386
|
+
tryInstall(() => installUserMessageStyle(getActiveTheme, getCurrentConfig, getTranscriptRightInset));
|
|
387
|
+
tryInstall(() => installToolExecutionStyle(getActiveTheme, getTranscriptRightInset));
|
|
341
388
|
cleanupPrototypePatches = () => {
|
|
342
389
|
for (let i = disposers.length - 1; i >= 0; i -= 1) {
|
|
343
390
|
try {
|
|
@@ -474,6 +521,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
474
521
|
getActiveExtensionStatuses = fn ?? (() => new Map());
|
|
475
522
|
},
|
|
476
523
|
getLiveContext: () => liveContext.get(),
|
|
524
|
+
getCompactionReserveTokens: (model) => configuredCompactionReserveTokens(pi, model),
|
|
477
525
|
onMount: (tui) => {
|
|
478
526
|
activeTui = tui;
|
|
479
527
|
},
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import type { Theme, ThemeBg } from "@earendil-works/pi-coding-agent";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Outer panel-background wrapper produced by Pi's `theme.bg(token, line)` around framed
|
|
5
|
+
* transcript cards (`UserMessageComponent` and `ToolExecutionComponent`).
|
|
6
|
+
*
|
|
7
|
+
* When Zentui draws its own Sakura frame around those cards, keeping Pi's solid theme panel fill
|
|
8
|
+
* (e.g. from Pi's default `system`, `dark`, or `light` themes) paints a colored rectangle inside
|
|
9
|
+
* the transparent border. Stripping only the active theme's matching outer panel wrapper leaves
|
|
10
|
+
* card interiors transparent while keeping foreground styles, semantic colors, and any ANSI
|
|
11
|
+
* background emitted by tool output itself untouched.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export type PanelBgWrapper = {
|
|
15
|
+
readonly open: string;
|
|
16
|
+
readonly close: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const EMPTY_PANEL_BG_WRAPPERS: readonly PanelBgWrapper[] = Object.freeze([]);
|
|
20
|
+
export const USER_MESSAGE_BG_TOKENS: readonly ThemeBg[] = Object.freeze(["userMessageBg"]);
|
|
21
|
+
export const TOOL_PANEL_BG_TOKENS: readonly ThemeBg[] = Object.freeze([
|
|
22
|
+
"toolPendingBg",
|
|
23
|
+
"toolSuccessBg",
|
|
24
|
+
"toolErrorBg",
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const SENTINEL = "\u0000";
|
|
28
|
+
const PI_THEME_KEY = Symbol.for("@earendil-works/pi-coding-agent:theme");
|
|
29
|
+
const PI_THEME_KEY_OLD = Symbol.for("@mariozechner/pi-coding-agent:theme");
|
|
30
|
+
|
|
31
|
+
function isTransparentBgSequence(open: string): boolean {
|
|
32
|
+
return open === "" || open === "\x1b[49m" || open === "\x1b[0m";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function getGlobalPiTheme(): Theme | undefined {
|
|
36
|
+
const g = globalThis as Record<symbol, unknown>;
|
|
37
|
+
const candidate = g[PI_THEME_KEY] ?? g[PI_THEME_KEY_OLD];
|
|
38
|
+
return candidate && typeof (candidate as { bg?: unknown }).bg === "function"
|
|
39
|
+
? (candidate as Theme)
|
|
40
|
+
: undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function readThemeBgWrapper(theme: Theme | undefined, token: ThemeBg): PanelBgWrapper | undefined {
|
|
44
|
+
if (!theme || typeof theme.bg !== "function") return undefined;
|
|
45
|
+
try {
|
|
46
|
+
const wrapped = theme.bg(token, SENTINEL);
|
|
47
|
+
if (typeof wrapped !== "string") return undefined;
|
|
48
|
+
const idx = wrapped.indexOf(SENTINEL);
|
|
49
|
+
if (idx < 0) return undefined;
|
|
50
|
+
const open = wrapped.slice(0, idx);
|
|
51
|
+
if (isTransparentBgSequence(open)) return undefined;
|
|
52
|
+
const close = wrapped.slice(idx + SENTINEL.length);
|
|
53
|
+
return { open, close };
|
|
54
|
+
} catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function collectPanelBgWrappers(
|
|
60
|
+
tokens: readonly ThemeBg[],
|
|
61
|
+
activeTheme?: Theme,
|
|
62
|
+
): readonly PanelBgWrapper[] {
|
|
63
|
+
const globalTheme = getGlobalPiTheme();
|
|
64
|
+
const themes =
|
|
65
|
+
globalTheme && activeTheme && globalTheme !== activeTheme
|
|
66
|
+
? [globalTheme, activeTheme]
|
|
67
|
+
: globalTheme
|
|
68
|
+
? [globalTheme]
|
|
69
|
+
: activeTheme
|
|
70
|
+
? [activeTheme]
|
|
71
|
+
: [];
|
|
72
|
+
if (themes.length === 0) return EMPTY_PANEL_BG_WRAPPERS;
|
|
73
|
+
const out: PanelBgWrapper[] = [];
|
|
74
|
+
for (const theme of themes) {
|
|
75
|
+
for (const token of tokens) {
|
|
76
|
+
const wrapper = readThemeBgWrapper(theme, token);
|
|
77
|
+
if (!wrapper) continue;
|
|
78
|
+
if (!out.some((existing) => existing.open === wrapper.open && existing.close === wrapper.close)) {
|
|
79
|
+
out.push(wrapper);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return out.length > 0 ? out : EMPTY_PANEL_BG_WRAPPERS;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function panelBgSignature(wrappers: readonly PanelBgWrapper[]): string {
|
|
87
|
+
if (wrappers.length === 0) return "";
|
|
88
|
+
let sig = "";
|
|
89
|
+
for (let i = 0; i < wrappers.length; i += 1) {
|
|
90
|
+
const w = wrappers[i]!;
|
|
91
|
+
sig += i === 0 ? `${w.open}\u0001${w.close}` : `\u0002${w.open}\u0001${w.close}`;
|
|
92
|
+
}
|
|
93
|
+
return sig;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Strip a matching outer Pi panel background wrapper from a single rendered row.
|
|
98
|
+
* Never strips arbitrary inner ANSI backgrounds from tool output.
|
|
99
|
+
*/
|
|
100
|
+
export function stripPanelBg(line: string, wrappers: readonly PanelBgWrapper[]): string {
|
|
101
|
+
if (wrappers.length === 0 || line.length === 0) return line;
|
|
102
|
+
for (const { open, close } of wrappers) {
|
|
103
|
+
if (!line.startsWith(open)) continue;
|
|
104
|
+
if (close.length === 0) return line.slice(open.length);
|
|
105
|
+
if (line.endsWith(close) && line.length >= open.length + close.length) {
|
|
106
|
+
return line.slice(open.length, line.length - close.length);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return line;
|
|
110
|
+
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import { type Theme, ToolExecutionComponent } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
import { type ColorMode, getColorMode, paintFg, type RGB } from "../shared/color";
|
|
4
|
-
import { normalizeWidth, sameLines } from "../shared/tui-context";
|
|
4
|
+
import { normalizeWidth, resolveRightInset, sameLines } from "../shared/tui-context";
|
|
5
5
|
import { renderSakuraFrameGradient, splitGraphemes } from "./gradient";
|
|
6
|
+
import {
|
|
7
|
+
collectPanelBgWrappers,
|
|
8
|
+
type PanelBgWrapper,
|
|
9
|
+
panelBgSignature,
|
|
10
|
+
stripPanelBg,
|
|
11
|
+
TOOL_PANEL_BG_TOKENS,
|
|
12
|
+
} from "./panel-bg";
|
|
6
13
|
import { installPrototypePatch } from "./prototype-patch-registry";
|
|
7
14
|
import { safeThemeFg } from "./style";
|
|
8
15
|
|
|
9
16
|
/**
|
|
10
17
|
* Tool card chrome: sakura gradient title frame + status rail around Pi's own tool rendering.
|
|
11
18
|
*
|
|
12
|
-
* Body lines are Pi's render output at `width - 3` columns,
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
19
|
+
* Body lines are Pi's render output at `width - 3` columns, with only Pi's outer panel background
|
|
20
|
+
* fill (`toolPendingBg` / `toolSuccessBg` / `toolErrorBg`) stripped so the framed card stays
|
|
21
|
+
* transparent on any theme; foreground styles, semantic colors, and any ANSI background emitted
|
|
22
|
+
* by tool output itself stay untouched. Only hidden cards stay stock; `renderShell: "self"` tools
|
|
23
|
+
* such as `edit` and results with images (e.g. `read` of a PNG on a vision model, browser
|
|
24
|
+
* screenshots) are framed like any other. Terminal image rows are passed through untouched apart
|
|
25
|
+
* from the left rail (see `railLine`).
|
|
17
26
|
*
|
|
18
27
|
* Why a component hook instead of `pi.registerToolRenderer()`: that API selects a tool's own
|
|
19
28
|
* `renderShell`/`renderCall`/`renderResult`, which draws the *inside* of the tool row. This card
|
|
@@ -45,6 +54,7 @@ type CardRender = {
|
|
|
45
54
|
name: string;
|
|
46
55
|
colorMode: string;
|
|
47
56
|
statusStyle: string;
|
|
57
|
+
bgSignature: string;
|
|
48
58
|
added: number;
|
|
49
59
|
removed: number;
|
|
50
60
|
/** Number of leading inner lines kept outside the frame (Pi's spacer row). */
|
|
@@ -59,7 +69,8 @@ const STATUS_RGB: Record<ToolStatus, RGB> = {
|
|
|
59
69
|
ok: [174, 229, 197],
|
|
60
70
|
error: [255, 143, 163],
|
|
61
71
|
};
|
|
62
|
-
|
|
72
|
+
// Right vertical rail matches the sky-blue (#9FD3F2) right end of the linear frame gradient.
|
|
73
|
+
const FRAME_RGB: RGB = [159, 211, 242];
|
|
63
74
|
const LEFT_RAIL = "┃ ";
|
|
64
75
|
const RIGHT_RAIL = "│";
|
|
65
76
|
const LEFT_COLUMNS = 2; // visible width of LEFT_RAIL
|
|
@@ -117,15 +128,17 @@ function railLine(
|
|
|
117
128
|
left: string,
|
|
118
129
|
right: string,
|
|
119
130
|
colorMode: ColorMode,
|
|
131
|
+
bgWrappers: readonly PanelBgWrapper[],
|
|
120
132
|
): string {
|
|
121
133
|
if (isTerminalImageLine(line)) return `${left}${line}`;
|
|
134
|
+
const clean = stripPanelBg(line, bgWrappers);
|
|
122
135
|
// A self-rendered tool may return rows wider than the width it was given; clip them so the
|
|
123
136
|
// right rail stays inside the card instead of being cut off by the terminal.
|
|
124
|
-
const lineWidth = visibleWidth(
|
|
125
|
-
let body =
|
|
137
|
+
const lineWidth = visibleWidth(clean);
|
|
138
|
+
let body = clean;
|
|
126
139
|
let bodyWidth = lineWidth;
|
|
127
140
|
if (lineWidth > innerWidth) {
|
|
128
|
-
body = truncateToWidth(
|
|
141
|
+
body = truncateToWidth(clean, innerWidth, "");
|
|
129
142
|
bodyWidth = visibleWidth(body);
|
|
130
143
|
}
|
|
131
144
|
const pad = innerWidth - bodyWidth;
|
|
@@ -232,6 +245,7 @@ function buildCard(
|
|
|
232
245
|
stats: DiffStats | undefined,
|
|
233
246
|
theme: Theme | undefined,
|
|
234
247
|
colorMode: ColorMode,
|
|
248
|
+
bgWrappers: readonly PanelBgWrapper[],
|
|
235
249
|
): { lines: string[]; prefix: number } {
|
|
236
250
|
const prefix = inner[0] === "" ? 1 : 0; // Pi's Spacer(1) row stays above the frame
|
|
237
251
|
const role = status === "error" ? "error" : status === "ok" ? "success" : "toolTitle";
|
|
@@ -242,7 +256,7 @@ function buildCard(
|
|
|
242
256
|
lines.push(renderSakuraFrameGradient(frameTop(statusText(status, name, stats), width)));
|
|
243
257
|
const innerWidth = width - RAIL_COLUMNS;
|
|
244
258
|
for (let i = prefix; i < inner.length; i++) {
|
|
245
|
-
lines.push(railLine(inner[i]!, innerWidth, left, right, colorMode));
|
|
259
|
+
lines.push(railLine(inner[i]!, innerWidth, left, right, colorMode, bgWrappers));
|
|
246
260
|
}
|
|
247
261
|
lines.push(renderSakuraFrameGradient(frameBottom(width)));
|
|
248
262
|
return { lines, prefix };
|
|
@@ -278,7 +292,10 @@ export function mapCardMouseEvent<T extends MouseEventLike>(
|
|
|
278
292
|
return { ...event, y, x, width: card.innerWidth, height: inner.length };
|
|
279
293
|
}
|
|
280
294
|
|
|
281
|
-
export function installToolExecutionStyle(
|
|
295
|
+
export function installToolExecutionStyle(
|
|
296
|
+
getTheme?: () => Theme | undefined,
|
|
297
|
+
getRightInset?: () => number,
|
|
298
|
+
): Cleanup {
|
|
282
299
|
const cards = new WeakMap<object, CardRender>();
|
|
283
300
|
const captures = new WeakMap<object, CardMouseCapture>();
|
|
284
301
|
|
|
@@ -304,7 +321,9 @@ export function installToolExecutionStyle(getTheme?: () => Theme | undefined): C
|
|
|
304
321
|
return Reflect.apply(predecessor, receiver, width === rawWidth ? args : [width, ...args.slice(1)]);
|
|
305
322
|
}
|
|
306
323
|
|
|
307
|
-
const
|
|
324
|
+
const rightInset = resolveRightInset(getRightInset, width, MIN_WIDTH);
|
|
325
|
+
const cardWidth = width - rightInset;
|
|
326
|
+
const innerWidth = cardWidth - RAIL_COLUMNS;
|
|
308
327
|
const inner = Reflect.apply(predecessor, receiver, [innerWidth, ...args.slice(1)]);
|
|
309
328
|
if (!Array.isArray(inner) || inner.length === 0) {
|
|
310
329
|
cards.delete(receiver as object);
|
|
@@ -318,16 +337,20 @@ export function installToolExecutionStyle(getTheme?: () => Theme | undefined): C
|
|
|
318
337
|
const colorMode = getColorMode();
|
|
319
338
|
const role = status === "error" ? "error" : status === "ok" ? "success" : "toolTitle";
|
|
320
339
|
const statusStyle = theme ? safeThemeFg(theme, role, "x") : "";
|
|
340
|
+
const bgWrappers = collectPanelBgWrappers(TOOL_PANEL_BG_TOKENS, theme);
|
|
341
|
+
const bgSignature = panelBgSignature(bgWrappers);
|
|
321
342
|
const stats = statsForResult(runtime.result);
|
|
322
343
|
const cached = cards.get(receiver as object);
|
|
323
344
|
if (
|
|
324
345
|
cached &&
|
|
325
346
|
cached.width === width &&
|
|
347
|
+
cached.innerWidth === innerWidth &&
|
|
326
348
|
cached.status === status &&
|
|
327
349
|
cached.expanded === expanded &&
|
|
328
350
|
cached.name === name &&
|
|
329
351
|
cached.colorMode === colorMode &&
|
|
330
352
|
cached.statusStyle === statusStyle &&
|
|
353
|
+
cached.bgSignature === bgSignature &&
|
|
331
354
|
cached.added === (stats?.added ?? 0) &&
|
|
332
355
|
cached.removed === (stats?.removed ?? 0) &&
|
|
333
356
|
sameLines(cached.inner, lines)
|
|
@@ -335,7 +358,7 @@ export function installToolExecutionStyle(getTheme?: () => Theme | undefined): C
|
|
|
335
358
|
return cached.lines;
|
|
336
359
|
}
|
|
337
360
|
|
|
338
|
-
const card = buildCard(lines,
|
|
361
|
+
const card = buildCard(lines, cardWidth, status, name, stats, theme, colorMode, bgWrappers);
|
|
339
362
|
cards.set(receiver as object, {
|
|
340
363
|
width,
|
|
341
364
|
innerWidth,
|
|
@@ -344,6 +367,7 @@ export function installToolExecutionStyle(getTheme?: () => Theme | undefined): C
|
|
|
344
367
|
name,
|
|
345
368
|
colorMode,
|
|
346
369
|
statusStyle,
|
|
370
|
+
bgSignature,
|
|
347
371
|
added: stats?.added ?? 0,
|
|
348
372
|
removed: stats?.removed ?? 0,
|
|
349
373
|
prefix: card.prefix,
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { type Theme, UserMessageComponent } from "@earendil-works/pi-coding-agent";
|
|
2
2
|
import { visibleWidth } from "@earendil-works/pi-tui";
|
|
3
3
|
import { getColorMode, paintFg, type RGB } from "../shared/color";
|
|
4
|
-
import { normalizeWidth, sameLines } from "../shared/tui-context";
|
|
4
|
+
import { normalizeWidth, resolveRightInset, sameLines } from "../shared/tui-context";
|
|
5
5
|
import type { PolishedTuiConfig } from "./config";
|
|
6
6
|
import { renderSakuraFrameGradient } from "./gradient";
|
|
7
|
+
import {
|
|
8
|
+
collectPanelBgWrappers,
|
|
9
|
+
EMPTY_PANEL_BG_WRAPPERS,
|
|
10
|
+
type PanelBgWrapper,
|
|
11
|
+
panelBgSignature,
|
|
12
|
+
stripPanelBg,
|
|
13
|
+
USER_MESSAGE_BG_TOKENS,
|
|
14
|
+
} from "./panel-bg";
|
|
7
15
|
import { installPrototypePatch } from "./prototype-patch-registry";
|
|
8
16
|
import { safeThemeFg } from "./style";
|
|
9
17
|
|
|
@@ -11,9 +19,10 @@ import { safeThemeFg } from "./style";
|
|
|
11
19
|
* User prompt chrome: gradient hairlines above/below plus a sakura rail on the left.
|
|
12
20
|
*
|
|
13
21
|
* The message body is Pi's own UserMessageComponent render (markdown options, extension
|
|
14
|
-
* markdown transformers, outputPad, OSC 133 prompt markers) at the reduced width,
|
|
15
|
-
*
|
|
16
|
-
*
|
|
22
|
+
* markdown transformers, outputPad, OSC 133 prompt markers) at the reduced width, with only Pi's
|
|
23
|
+
* outer `userMessageBg` panel fill stripped so the framed card stays transparent on any theme
|
|
24
|
+
* while leading OSC 133 markers remain in front of the rail (see `railLine`). Copy-friendly mode
|
|
25
|
+
* drops the rail so copied text has no extra glyphs.
|
|
17
26
|
*/
|
|
18
27
|
|
|
19
28
|
type Cleanup = () => void;
|
|
@@ -44,12 +53,17 @@ function railFor(config: PolishedTuiConfig | undefined): { text: string; columns
|
|
|
44
53
|
*/
|
|
45
54
|
const OSC133_ZONE_PREFIX = /^(?:\x1b\]133;[ABC](?:\x07|\x1b\\))+/;
|
|
46
55
|
|
|
47
|
-
function railLine(
|
|
48
|
-
|
|
56
|
+
function railLine(
|
|
57
|
+
line: string,
|
|
58
|
+
rail: string,
|
|
59
|
+
bgWrappers: readonly PanelBgWrapper[],
|
|
60
|
+
): string {
|
|
61
|
+
if (!rail && bgWrappers.length === 0) return line;
|
|
49
62
|
// Keep Pi's markers in front of the rail: behind it they would leak to the terminal (a false
|
|
50
63
|
// shell-prompt mark that also ends OSC 7501 program status) and prompt navigation would miss them.
|
|
51
64
|
const markers = OSC133_ZONE_PREFIX.exec(line)?.[0] ?? "";
|
|
52
|
-
|
|
65
|
+
const body = stripPanelBg(line.slice(markers.length), bgWrappers);
|
|
66
|
+
return `${markers}${rail}${body}`;
|
|
53
67
|
}
|
|
54
68
|
|
|
55
69
|
export function renderUserMessageCard(
|
|
@@ -57,9 +71,10 @@ export function renderUserMessageCard(
|
|
|
57
71
|
width: number,
|
|
58
72
|
rail: string,
|
|
59
73
|
border = renderSakuraFrameGradient("─".repeat(normalizeWidth(width))),
|
|
74
|
+
bgWrappers: readonly PanelBgWrapper[] = EMPTY_PANEL_BG_WRAPPERS,
|
|
60
75
|
): string[] {
|
|
61
76
|
const lines: string[] = [border];
|
|
62
|
-
for (const line of inner) lines.push(railLine(line, rail));
|
|
77
|
+
for (const line of inner) lines.push(railLine(line, rail, bgWrappers));
|
|
63
78
|
lines.push(border);
|
|
64
79
|
return lines;
|
|
65
80
|
}
|
|
@@ -67,6 +82,7 @@ export function renderUserMessageCard(
|
|
|
67
82
|
export function installUserMessageStyle(
|
|
68
83
|
getTheme?: () => Theme | undefined,
|
|
69
84
|
getConfig?: () => PolishedTuiConfig,
|
|
85
|
+
getRightInset?: () => number,
|
|
70
86
|
): Cleanup {
|
|
71
87
|
const cards = new WeakMap<object, UserMessageCard>();
|
|
72
88
|
return installPrototypePatch(
|
|
@@ -87,21 +103,28 @@ export function installUserMessageStyle(
|
|
|
87
103
|
cards.delete(receiver as object);
|
|
88
104
|
return Reflect.apply(predecessor, receiver, width === rawWidth ? args : [width, ...args.slice(1)]);
|
|
89
105
|
}
|
|
106
|
+
const rightInset = resolveRightInset(getRightInset, width, MIN_WIDTH);
|
|
107
|
+
const cardWidth = width - rightInset;
|
|
90
108
|
const config = getConfig?.();
|
|
91
109
|
const rail = railFor(config);
|
|
92
|
-
const inner = Reflect.apply(predecessor, receiver, [
|
|
93
|
-
if (!Array.isArray(inner) || inner.length === 0)
|
|
110
|
+
const inner = Reflect.apply(predecessor, receiver, [cardWidth - rail.columns, ...args.slice(1)]);
|
|
111
|
+
if (!Array.isArray(inner) || inner.length === 0) {
|
|
112
|
+
cards.delete(receiver as object);
|
|
113
|
+
return inner;
|
|
114
|
+
}
|
|
94
115
|
|
|
95
116
|
const lines = inner as string[];
|
|
96
|
-
const
|
|
117
|
+
const activeTheme = getTheme?.();
|
|
118
|
+
const railTheme = config?.colorSources?.userMessages === "theme" ? activeTheme : undefined;
|
|
119
|
+
const bgWrappers = collectPanelBgWrappers(USER_MESSAGE_BG_TOKENS, activeTheme);
|
|
97
120
|
// The brand frame stays gradient; colorSources.userMessages controls the rail only.
|
|
98
|
-
const border = renderSakuraFrameGradient("─".repeat(
|
|
121
|
+
const border = renderSakuraFrameGradient("─".repeat(cardWidth));
|
|
99
122
|
const paintedRail = rail.text
|
|
100
|
-
?
|
|
101
|
-
? safeThemeFg(
|
|
123
|
+
? railTheme
|
|
124
|
+
? safeThemeFg(railTheme, "accent", rail.text)
|
|
102
125
|
: paintFg(RAIL_RGB, rail.text)
|
|
103
126
|
: "";
|
|
104
|
-
const chromeKey = `${paintedRail}\0${border}\0${getColorMode()}`;
|
|
127
|
+
const chromeKey = `${cardWidth}\0${paintedRail}\0${border}\0${getColorMode()}\0${panelBgSignature(bgWrappers)}`;
|
|
105
128
|
const cached = cards.get(receiver as object);
|
|
106
129
|
if (
|
|
107
130
|
cached &&
|
|
@@ -111,7 +134,7 @@ export function installUserMessageStyle(
|
|
|
111
134
|
) {
|
|
112
135
|
return cached.lines;
|
|
113
136
|
}
|
|
114
|
-
const card = renderUserMessageCard(lines,
|
|
137
|
+
const card = renderUserMessageCard(lines, cardWidth, paintedRail, border, bgWrappers);
|
|
115
138
|
cards.set(receiver as object, { width, chromeKey, inner: lines, lines: card });
|
|
116
139
|
return card;
|
|
117
140
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-sakura-cyberdeck",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.6",
|
|
4
4
|
"description": "Lightweight Sakura Macaron visual pack for Pi: theme, cyberdeck header, macaron Zentui chrome, Claude-style shimmer, optional matrix rain.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|