@ravshansbox/pi-statusline 1.2.0 → 1.4.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/index.ts +8 -17
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
2
|
-
import {
|
|
3
|
-
type ExtensionAPI,
|
|
4
|
-
type ExtensionContext,
|
|
5
|
-
SettingsManager,
|
|
6
|
-
} from '@earendil-works/pi-coding-agent';
|
|
2
|
+
import { type ExtensionAPI, type ExtensionContext } from '@earendil-works/pi-coding-agent';
|
|
7
3
|
import { truncateToWidth, visibleWidth } from '@earendil-works/pi-tui';
|
|
8
4
|
|
|
9
5
|
type Usage = {
|
|
@@ -23,10 +19,8 @@ function sanitizeStatusText(text: string): string {
|
|
|
23
19
|
|
|
24
20
|
function formatTokens(count: number): string {
|
|
25
21
|
if (count < 1000) return count.toString();
|
|
26
|
-
if (count <
|
|
27
|
-
|
|
28
|
-
if (count < 10000000) return `${(count / 1000000).toFixed(1)}M`;
|
|
29
|
-
return `${Math.round(count / 1000000)}M`;
|
|
22
|
+
if (count < 999500) return `${Math.round(count / 1000)}k`;
|
|
23
|
+
return `${Math.round(count / 1000000)}m`;
|
|
30
24
|
}
|
|
31
25
|
|
|
32
26
|
function formatCwd(cwd: string, home: string | undefined): string {
|
|
@@ -71,8 +65,6 @@ function getUsage(ctx: ExtensionContext) {
|
|
|
71
65
|
export default function (pi: ExtensionAPI) {
|
|
72
66
|
pi.on('session_start', (_event, ctx) => {
|
|
73
67
|
if (ctx.mode !== 'tui') return;
|
|
74
|
-
const settings = SettingsManager.create(ctx.cwd);
|
|
75
|
-
|
|
76
68
|
ctx.ui.setFooter((tui, theme, footerData) => {
|
|
77
69
|
const unsub = footerData.onBranchChange(() => tui.requestRender());
|
|
78
70
|
return {
|
|
@@ -85,7 +77,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
85
77
|
const contextWindow = contextUsage?.contextWindow ?? model?.contextWindow ?? 0;
|
|
86
78
|
const contextPercentValue = contextUsage?.percent ?? 0;
|
|
87
79
|
const contextPercent =
|
|
88
|
-
contextUsage?.percent != null ? contextPercentValue.toFixed(
|
|
80
|
+
contextUsage?.percent != null ? contextPercentValue.toFixed(0) : '?';
|
|
89
81
|
|
|
90
82
|
let pwd = formatCwd(
|
|
91
83
|
ctx.sessionManager.getCwd(),
|
|
@@ -102,7 +94,7 @@ export default function (pi: ExtensionAPI) {
|
|
|
102
94
|
if (totals.cacheRead) statsParts.push(`R${formatTokens(totals.cacheRead)}`);
|
|
103
95
|
if (totals.cacheWrite) statsParts.push(`W${formatTokens(totals.cacheWrite)}`);
|
|
104
96
|
if ((totals.cacheRead > 0 || totals.cacheWrite > 0) && latestCacheHitRate !== undefined) {
|
|
105
|
-
statsParts.push(`CH${latestCacheHitRate.toFixed(
|
|
97
|
+
statsParts.push(`CH${latestCacheHitRate.toFixed(0)}%`);
|
|
106
98
|
}
|
|
107
99
|
|
|
108
100
|
const usingSubscription = model
|
|
@@ -111,14 +103,13 @@ export default function (pi: ExtensionAPI) {
|
|
|
111
103
|
ctx.modelRegistry.getProvider(model.provider)?.auth.oauth?.isSubscription === true)
|
|
112
104
|
: false;
|
|
113
105
|
if (totals.cost || usingSubscription) {
|
|
114
|
-
statsParts.push(`$${totals.cost.toFixed(
|
|
106
|
+
statsParts.push(`$${totals.cost.toFixed(2)}${usingSubscription ? ' (sub)' : ''}`);
|
|
115
107
|
}
|
|
116
108
|
|
|
117
|
-
const autoIndicator = settings.getCompactionEnabled() ? ' (auto)' : '';
|
|
118
109
|
const contextDisplay =
|
|
119
110
|
contextPercent === '?'
|
|
120
|
-
? `?/${formatTokens(contextWindow)}
|
|
121
|
-
: `${contextPercent}%/${formatTokens(contextWindow)}
|
|
111
|
+
? `?/${formatTokens(contextWindow)}`
|
|
112
|
+
: `${contextPercent}%/${formatTokens(contextWindow)}`;
|
|
122
113
|
if (contextPercentValue > 90) statsParts.push(theme.fg('error', contextDisplay));
|
|
123
114
|
else if (contextPercentValue > 70) statsParts.push(theme.fg('warning', contextDisplay));
|
|
124
115
|
else statsParts.push(contextDisplay);
|