pi-sakura-cyberdeck 1.5.5 → 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 +33 -0
- package/README.md +14 -13
- package/README.zh-CN.md +1 -1
- 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/index.ts +17 -1
- package/extensions/zentui/panel-bg.ts +110 -0
- package/extensions/zentui/tool-execution.ts +27 -10
- package/extensions/zentui/user-message.ts +29 -12
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,39 @@
|
|
|
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
|
+
|
|
6
39
|
## [1.5.5] - 2026-12-03
|
|
7
40
|
|
|
8
41
|
### 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,19 +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
|
-
|
|
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.
|
|
251
252
|
|
|
252
253
|
### Earlier versions
|
|
253
254
|
|
|
254
|
-
See [CHANGELOG.md](CHANGELOG.md) for 1.0.0 – 1.5.
|
|
255
|
+
See [CHANGELOG.md](CHANGELOG.md) for 1.0.0 – 1.5.5.
|
|
255
256
|
|
|
256
257
|
## Development
|
|
257
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
|
{
|
|
@@ -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 },
|
|
@@ -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";
|
|
@@ -141,6 +144,18 @@ function transcriptRightInset(pi: ExtensionAPI, tui: ActiveTuiLike | undefined):
|
|
|
141
144
|
return scrollbar === "always" || scrollbar === "hidden" ? 0 : 1;
|
|
142
145
|
}
|
|
143
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
|
+
|
|
144
159
|
export default function (pi: ExtensionAPI) {
|
|
145
160
|
const state: FooterState = createInitialState(emptyGitStatus());
|
|
146
161
|
const sessionLifecycle = new SessionLifecycle();
|
|
@@ -506,6 +521,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
506
521
|
getActiveExtensionStatuses = fn ?? (() => new Map());
|
|
507
522
|
},
|
|
508
523
|
getLiveContext: () => liveContext.get(),
|
|
524
|
+
getCompactionReserveTokens: (model) => configuredCompactionReserveTokens(pi, model),
|
|
509
525
|
onMount: (tui) => {
|
|
510
526
|
activeTui = tui;
|
|
511
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
|
+
}
|
|
@@ -3,17 +3,26 @@ import { truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
|
|
|
3
3
|
import { type ColorMode, getColorMode, paintFg, type RGB } from "../shared/color";
|
|
4
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). */
|
|
@@ -118,15 +128,17 @@ function railLine(
|
|
|
118
128
|
left: string,
|
|
119
129
|
right: string,
|
|
120
130
|
colorMode: ColorMode,
|
|
131
|
+
bgWrappers: readonly PanelBgWrapper[],
|
|
121
132
|
): string {
|
|
122
133
|
if (isTerminalImageLine(line)) return `${left}${line}`;
|
|
134
|
+
const clean = stripPanelBg(line, bgWrappers);
|
|
123
135
|
// A self-rendered tool may return rows wider than the width it was given; clip them so the
|
|
124
136
|
// right rail stays inside the card instead of being cut off by the terminal.
|
|
125
|
-
const lineWidth = visibleWidth(
|
|
126
|
-
let body =
|
|
137
|
+
const lineWidth = visibleWidth(clean);
|
|
138
|
+
let body = clean;
|
|
127
139
|
let bodyWidth = lineWidth;
|
|
128
140
|
if (lineWidth > innerWidth) {
|
|
129
|
-
body = truncateToWidth(
|
|
141
|
+
body = truncateToWidth(clean, innerWidth, "");
|
|
130
142
|
bodyWidth = visibleWidth(body);
|
|
131
143
|
}
|
|
132
144
|
const pad = innerWidth - bodyWidth;
|
|
@@ -233,6 +245,7 @@ function buildCard(
|
|
|
233
245
|
stats: DiffStats | undefined,
|
|
234
246
|
theme: Theme | undefined,
|
|
235
247
|
colorMode: ColorMode,
|
|
248
|
+
bgWrappers: readonly PanelBgWrapper[],
|
|
236
249
|
): { lines: string[]; prefix: number } {
|
|
237
250
|
const prefix = inner[0] === "" ? 1 : 0; // Pi's Spacer(1) row stays above the frame
|
|
238
251
|
const role = status === "error" ? "error" : status === "ok" ? "success" : "toolTitle";
|
|
@@ -243,7 +256,7 @@ function buildCard(
|
|
|
243
256
|
lines.push(renderSakuraFrameGradient(frameTop(statusText(status, name, stats), width)));
|
|
244
257
|
const innerWidth = width - RAIL_COLUMNS;
|
|
245
258
|
for (let i = prefix; i < inner.length; i++) {
|
|
246
|
-
lines.push(railLine(inner[i]!, innerWidth, left, right, colorMode));
|
|
259
|
+
lines.push(railLine(inner[i]!, innerWidth, left, right, colorMode, bgWrappers));
|
|
247
260
|
}
|
|
248
261
|
lines.push(renderSakuraFrameGradient(frameBottom(width)));
|
|
249
262
|
return { lines, prefix };
|
|
@@ -324,6 +337,8 @@ export function installToolExecutionStyle(
|
|
|
324
337
|
const colorMode = getColorMode();
|
|
325
338
|
const role = status === "error" ? "error" : status === "ok" ? "success" : "toolTitle";
|
|
326
339
|
const statusStyle = theme ? safeThemeFg(theme, role, "x") : "";
|
|
340
|
+
const bgWrappers = collectPanelBgWrappers(TOOL_PANEL_BG_TOKENS, theme);
|
|
341
|
+
const bgSignature = panelBgSignature(bgWrappers);
|
|
327
342
|
const stats = statsForResult(runtime.result);
|
|
328
343
|
const cached = cards.get(receiver as object);
|
|
329
344
|
if (
|
|
@@ -335,6 +350,7 @@ export function installToolExecutionStyle(
|
|
|
335
350
|
cached.name === name &&
|
|
336
351
|
cached.colorMode === colorMode &&
|
|
337
352
|
cached.statusStyle === statusStyle &&
|
|
353
|
+
cached.bgSignature === bgSignature &&
|
|
338
354
|
cached.added === (stats?.added ?? 0) &&
|
|
339
355
|
cached.removed === (stats?.removed ?? 0) &&
|
|
340
356
|
sameLines(cached.inner, lines)
|
|
@@ -342,7 +358,7 @@ export function installToolExecutionStyle(
|
|
|
342
358
|
return cached.lines;
|
|
343
359
|
}
|
|
344
360
|
|
|
345
|
-
const card = buildCard(lines, cardWidth, status, name, stats, theme, colorMode);
|
|
361
|
+
const card = buildCard(lines, cardWidth, status, name, stats, theme, colorMode, bgWrappers);
|
|
346
362
|
cards.set(receiver as object, {
|
|
347
363
|
width,
|
|
348
364
|
innerWidth,
|
|
@@ -351,6 +367,7 @@ export function installToolExecutionStyle(
|
|
|
351
367
|
name,
|
|
352
368
|
colorMode,
|
|
353
369
|
statusStyle,
|
|
370
|
+
bgSignature,
|
|
354
371
|
added: stats?.added ?? 0,
|
|
355
372
|
removed: stats?.removed ?? 0,
|
|
356
373
|
prefix: card.prefix,
|
|
@@ -4,6 +4,14 @@ import { getColorMode, paintFg, type RGB } from "../shared/color";
|
|
|
4
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
|
}
|
|
@@ -99,15 +114,17 @@ export function installUserMessageStyle(
|
|
|
99
114
|
}
|
|
100
115
|
|
|
101
116
|
const lines = inner as string[];
|
|
102
|
-
const
|
|
117
|
+
const activeTheme = getTheme?.();
|
|
118
|
+
const railTheme = config?.colorSources?.userMessages === "theme" ? activeTheme : undefined;
|
|
119
|
+
const bgWrappers = collectPanelBgWrappers(USER_MESSAGE_BG_TOKENS, activeTheme);
|
|
103
120
|
// The brand frame stays gradient; colorSources.userMessages controls the rail only.
|
|
104
121
|
const border = renderSakuraFrameGradient("─".repeat(cardWidth));
|
|
105
122
|
const paintedRail = rail.text
|
|
106
|
-
?
|
|
107
|
-
? safeThemeFg(
|
|
123
|
+
? railTheme
|
|
124
|
+
? safeThemeFg(railTheme, "accent", rail.text)
|
|
108
125
|
: paintFg(RAIL_RGB, rail.text)
|
|
109
126
|
: "";
|
|
110
|
-
const chromeKey = `${cardWidth}\0${paintedRail}\0${border}\0${getColorMode()}`;
|
|
127
|
+
const chromeKey = `${cardWidth}\0${paintedRail}\0${border}\0${getColorMode()}\0${panelBgSignature(bgWrappers)}`;
|
|
111
128
|
const cached = cards.get(receiver as object);
|
|
112
129
|
if (
|
|
113
130
|
cached &&
|
|
@@ -117,7 +134,7 @@ export function installUserMessageStyle(
|
|
|
117
134
|
) {
|
|
118
135
|
return cached.lines;
|
|
119
136
|
}
|
|
120
|
-
const card = renderUserMessageCard(lines, cardWidth, paintedRail, border);
|
|
137
|
+
const card = renderUserMessageCard(lines, cardWidth, paintedRail, border, bgWrappers);
|
|
121
138
|
cards.set(receiver as object, { width, chromeKey, inner: lines, lines: card });
|
|
122
139
|
return card;
|
|
123
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",
|