pi-tui-status-beautifier 1.4.0 → 1.5.0
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/extensions/tui-status-beautifier.ts +119 -11
- package/package.json +1 -1
|
@@ -99,6 +99,7 @@ const BRACKET_PATTERN = /\[(\d+)\]/;
|
|
|
99
99
|
const NUMBER_PATTERN = /\b(\d+)\b/;
|
|
100
100
|
|
|
101
101
|
let currentStyle = "minimal";
|
|
102
|
+
let fullFooterEnabled = false;
|
|
102
103
|
let customStyleConfig: CustomStyleConfig | undefined;
|
|
103
104
|
|
|
104
105
|
/**
|
|
@@ -107,6 +108,7 @@ let customStyleConfig: CustomStyleConfig | undefined;
|
|
|
107
108
|
*/
|
|
108
109
|
export function loadConfig(cwd: string = process.cwd()): {
|
|
109
110
|
style: string;
|
|
111
|
+
fullFooter: boolean;
|
|
110
112
|
custom?: CustomStyleConfig;
|
|
111
113
|
targetSettingsPath: string;
|
|
112
114
|
} {
|
|
@@ -115,6 +117,7 @@ export function loadConfig(cwd: string = process.cwd()): {
|
|
|
115
117
|
const localPath = path.join(cwd, ".pi/settings.json");
|
|
116
118
|
|
|
117
119
|
let resolvedStyle = "minimal";
|
|
120
|
+
let resolvedFullFooter = false;
|
|
118
121
|
let resolvedCustom: CustomStyleConfig | undefined;
|
|
119
122
|
let hasLocalConfig = false;
|
|
120
123
|
|
|
@@ -131,6 +134,9 @@ export function loadConfig(cwd: string = process.cwd()): {
|
|
|
131
134
|
resolvedStyle = s;
|
|
132
135
|
}
|
|
133
136
|
}
|
|
137
|
+
if (typeof data.beautifier.fullFooter === "boolean") {
|
|
138
|
+
resolvedFullFooter = data.beautifier.fullFooter;
|
|
139
|
+
}
|
|
134
140
|
if (data.beautifier.custom && typeof data.beautifier.custom === "object") {
|
|
135
141
|
resolvedCustom = data.beautifier.custom;
|
|
136
142
|
}
|
|
@@ -152,6 +158,9 @@ export function loadConfig(cwd: string = process.cwd()): {
|
|
|
152
158
|
resolvedStyle = s;
|
|
153
159
|
}
|
|
154
160
|
}
|
|
161
|
+
if (typeof data.beautifier.fullFooter === "boolean") {
|
|
162
|
+
resolvedFullFooter = data.beautifier.fullFooter;
|
|
163
|
+
}
|
|
155
164
|
if (data.beautifier.custom && typeof data.beautifier.custom === "object") {
|
|
156
165
|
resolvedCustom = { ...(resolvedCustom || {}), ...data.beautifier.custom };
|
|
157
166
|
}
|
|
@@ -160,11 +169,12 @@ export function loadConfig(cwd: string = process.cwd()): {
|
|
|
160
169
|
} catch (_) {}
|
|
161
170
|
|
|
162
171
|
currentStyle = resolvedStyle;
|
|
172
|
+
fullFooterEnabled = resolvedFullFooter;
|
|
163
173
|
customStyleConfig = resolvedCustom;
|
|
164
174
|
|
|
165
175
|
// Target path for atomic write: local project if exists or in project directory, otherwise global
|
|
166
176
|
const targetSettingsPath = hasLocalConfig || fs.existsSync(localPath) ? localPath : globalPath;
|
|
167
|
-
return { style: resolvedStyle, custom: resolvedCustom, targetSettingsPath };
|
|
177
|
+
return { style: resolvedStyle, fullFooter: resolvedFullFooter, custom: resolvedCustom, targetSettingsPath };
|
|
168
178
|
}
|
|
169
179
|
|
|
170
180
|
loadConfig();
|
|
@@ -466,26 +476,66 @@ export function renderBeautifiedFooter(
|
|
|
466
476
|
const modelName = ctx?.model?.name || ctx?.model?.id || "";
|
|
467
477
|
const styledModel = modelName ? (hasThemeFg ? theme.fg("muted", modelName) : modelName) : "";
|
|
468
478
|
|
|
469
|
-
// 3. Token metrics
|
|
470
|
-
let input = 0, output = 0;
|
|
471
|
-
|
|
479
|
+
// 3. Token metrics & context usage (full fidelity matching native Pi footer)
|
|
480
|
+
let input = 0, output = 0, cacheRead = 0, cacheWrite = 0, cost = 0;
|
|
481
|
+
let latestCacheHitRate: number | undefined;
|
|
482
|
+
|
|
483
|
+
if (ctx?.sessionManager?.getEntries) {
|
|
472
484
|
try {
|
|
473
|
-
for (const
|
|
474
|
-
if (
|
|
475
|
-
|
|
485
|
+
for (const entry of ctx.sessionManager.getEntries()) {
|
|
486
|
+
if (entry.type === "usage" && entry.usage) {
|
|
487
|
+
input += entry.usage.input || 0;
|
|
488
|
+
output += entry.usage.output || 0;
|
|
489
|
+
cacheRead += entry.usage.cacheRead || 0;
|
|
490
|
+
cacheWrite += entry.usage.cacheWrite || 0;
|
|
491
|
+
cost += entry.usage.cost?.total || 0;
|
|
492
|
+
} else if (entry.type === "message" && entry.message?.role === "assistant" && entry.message?.usage) {
|
|
493
|
+
const u = entry.message.usage;
|
|
476
494
|
input += u.input || 0;
|
|
477
495
|
output += u.output || 0;
|
|
496
|
+
cacheRead += u.cacheRead || 0;
|
|
497
|
+
cacheWrite += u.cacheWrite || 0;
|
|
498
|
+
cost += u.cost?.total || 0;
|
|
499
|
+
const promptTokens = (u.input || 0) + (u.cacheRead || 0) + (u.cacheWrite || 0);
|
|
500
|
+
if (promptTokens > 0 && u.cacheRead) {
|
|
501
|
+
latestCacheHitRate = (u.cacheRead / promptTokens) * 100;
|
|
502
|
+
}
|
|
478
503
|
}
|
|
479
504
|
}
|
|
480
505
|
} catch (_) {}
|
|
481
506
|
}
|
|
482
|
-
|
|
483
|
-
const
|
|
507
|
+
|
|
508
|
+
const fmt = (n: number) => {
|
|
509
|
+
if (n < 1000) return `${n}`;
|
|
510
|
+
if (n < 10000) return `${(n / 1000).toFixed(1)}k`;
|
|
511
|
+
if (n < 1000000) return `${Math.round(n / 1000)}k`;
|
|
512
|
+
if (n < 10000000) return `${(n / 1000000).toFixed(1)}M`;
|
|
513
|
+
return `${Math.round(n / 1000000)}M`;
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const statParts: string[] = [];
|
|
517
|
+
if (input > 0) statParts.push(`↑${fmt(input)}`);
|
|
518
|
+
if (output > 0) statParts.push(`↓${fmt(output)}`);
|
|
519
|
+
if (cacheRead > 0) statParts.push(`R${fmt(cacheRead)}`);
|
|
520
|
+
if (latestCacheHitRate !== undefined) statParts.push(`CH${latestCacheHitRate.toFixed(1)}%`);
|
|
521
|
+
if (cost > 0) statParts.push(`$${cost.toFixed(3)}`);
|
|
522
|
+
|
|
523
|
+
const contextUsage = ctx?.getContextUsage?.();
|
|
524
|
+
const contextWindow = contextUsage?.contextWindow || ctx?.model?.contextWindow || 0;
|
|
525
|
+
if (contextUsage?.percent !== undefined && contextUsage?.percent !== null) {
|
|
526
|
+
statParts.push(`${contextUsage.percent.toFixed(1)}%/${fmt(contextWindow)} (auto)`);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const tokenStr = statParts.join(" ");
|
|
484
530
|
const styledTokens = tokenStr ? (hasThemeFg ? theme.fg("dim", tokenStr) : tokenStr) : "";
|
|
485
531
|
|
|
532
|
+
// Thinking level
|
|
533
|
+
const thinking = ctx?.thinkingLevel && ctx.thinkingLevel !== "off" ? ` • ${ctx.thinkingLevel}` : "";
|
|
534
|
+
const fullModelStr = styledModel ? `${styledModel}${hasThemeFg ? theme.fg("dim", thinking) : thinking}` : "";
|
|
535
|
+
|
|
486
536
|
// Left & right parts of Line 1
|
|
487
537
|
const leftText = styledBranch;
|
|
488
|
-
const rightParts = [styledTokens,
|
|
538
|
+
const rightParts = [styledTokens, fullModelStr].filter(Boolean);
|
|
489
539
|
const rightText = rightParts.join(styledSep);
|
|
490
540
|
|
|
491
541
|
const leftVis = getStringWidth(leftText);
|
|
@@ -534,7 +584,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
534
584
|
originalStatuses.clear();
|
|
535
585
|
lastRenderedStatus.clear();
|
|
536
586
|
|
|
537
|
-
// Hook setStatus for clean status badge formatting (
|
|
587
|
+
// 1. Hook setStatus for clean status badge formatting (always active unless style === "off")
|
|
538
588
|
const originalSetStatus = ctx.ui.setStatus;
|
|
539
589
|
if (originalSetStatus && !(originalSetStatus as any).__beautifierHooked) {
|
|
540
590
|
const wrapped = function (key: string, value: string | undefined) {
|
|
@@ -553,6 +603,28 @@ export default function (pi: ExtensionAPI) {
|
|
|
553
603
|
(wrapped as any).__beautifierHooked = true;
|
|
554
604
|
ctx.ui.setStatus = wrapped;
|
|
555
605
|
}
|
|
606
|
+
|
|
607
|
+
// 2. Hook setFooter ONLY if user explicitly opted in with fullFooter === true!
|
|
608
|
+
// By default fullFooter is FALSE: Pi's native top two lines remain 100% native and untouched!
|
|
609
|
+
if (fullFooterEnabled && currentStyle !== "off" && typeof (ctx.ui as any).setFooter === "function") {
|
|
610
|
+
(ctx.ui as any).setFooter((tui: any, theme: any, footerData: any) => {
|
|
611
|
+
const unsub =
|
|
612
|
+
typeof footerData?.onBranchChange === "function"
|
|
613
|
+
? footerData.onBranchChange(() => tui.requestRender())
|
|
614
|
+
: undefined;
|
|
615
|
+
|
|
616
|
+
return {
|
|
617
|
+
dispose: unsub,
|
|
618
|
+
invalidate() {},
|
|
619
|
+
render(width: number): string[] {
|
|
620
|
+
if (currentStyle === "off" || !fullFooterEnabled) return [];
|
|
621
|
+
return renderBeautifiedFooter(width, tui, theme, footerData, ctx, currentStyle, customStyleConfig);
|
|
622
|
+
},
|
|
623
|
+
};
|
|
624
|
+
});
|
|
625
|
+
} else if (typeof (ctx.ui as any).setFooter === "function") {
|
|
626
|
+
(ctx.ui as any).setFooter(undefined); // Restore native Pi footer
|
|
627
|
+
}
|
|
556
628
|
});
|
|
557
629
|
|
|
558
630
|
// Dynamic status bar style controller registry
|
|
@@ -569,6 +641,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
569
641
|
"matrix - Dot-matrix brackets & stars (e.g. name ⦗✦ ready⦘)",
|
|
570
642
|
"glow - High-contrast inverse pill (e.g. name [ ● ready ])",
|
|
571
643
|
"custom - [AI Prompt Recipe] Let your agent tailor your bespoke style",
|
|
644
|
+
`footer - Toggle Full-Footer beautification (Git/Model/Tokens) [Currently: ${fullFooterEnabled ? "ON" : "OFF"}]`,
|
|
572
645
|
"off - Revert to native Pi status bar & clean settings",
|
|
573
646
|
];
|
|
574
647
|
|
|
@@ -578,6 +651,41 @@ export default function (pi: ExtensionAPI) {
|
|
|
578
651
|
|
|
579
652
|
const styleKey = choice.split(" ")[0].trim();
|
|
580
653
|
|
|
654
|
+
if (styleKey === "footer") {
|
|
655
|
+
fullFooterEnabled = !fullFooterEnabled;
|
|
656
|
+
const { targetSettingsPath } = loadConfig(ctx.cwd || process.cwd());
|
|
657
|
+
try {
|
|
658
|
+
if (fs.existsSync(targetSettingsPath)) {
|
|
659
|
+
const data = fs.readFileSync(targetSettingsPath, "utf-8");
|
|
660
|
+
const config = JSON.parse(data);
|
|
661
|
+
if (!config.beautifier) config.beautifier = {};
|
|
662
|
+
config.beautifier.fullFooter = fullFooterEnabled;
|
|
663
|
+
const tempSettings = `${targetSettingsPath}.tmp.${process.pid}.${Date.now()}`;
|
|
664
|
+
fs.writeFileSync(tempSettings, JSON.stringify(config, null, 2), "utf-8");
|
|
665
|
+
fs.renameSync(tempSettings, targetSettingsPath);
|
|
666
|
+
}
|
|
667
|
+
} catch (_) {}
|
|
668
|
+
|
|
669
|
+
if (fullFooterEnabled && currentStyle !== "off" && typeof (ctx.ui as any).setFooter === "function") {
|
|
670
|
+
(ctx.ui as any).setFooter((tui: any, theme: any, footerData: any) => {
|
|
671
|
+
const unsub = typeof footerData?.onBranchChange === "function" ? footerData.onBranchChange(() => tui.requestRender()) : undefined;
|
|
672
|
+
return {
|
|
673
|
+
dispose: unsub,
|
|
674
|
+
invalidate() {},
|
|
675
|
+
render(width: number): string[] {
|
|
676
|
+
if (currentStyle === "off" || !fullFooterEnabled) return [];
|
|
677
|
+
return renderBeautifiedFooter(width, tui, theme, footerData, ctx, currentStyle, customStyleConfig);
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
});
|
|
681
|
+
} else if (typeof (ctx.ui as any).setFooter === "function") {
|
|
682
|
+
(ctx.ui as any).setFooter(undefined);
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
ctx.ui.notify(`Full-footer beautification is now ${fullFooterEnabled ? "ENABLED" : "DISABLED (Native Pi Footer)"}`, "info");
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
|
|
581
689
|
if (styleKey === "off") {
|
|
582
690
|
currentStyle = "off";
|
|
583
691
|
customStyleConfig = undefined;
|
package/package.json
CHANGED