pi-zentui 0.1.12 → 0.1.13

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.
@@ -11,9 +11,11 @@ export type UsageTotals = {
11
11
  };
12
12
 
13
13
  export function formatCount(value: number): string {
14
- if (value < 1000) return `${value}`;
14
+ if (value < 1000) return value.toString();
15
15
  if (value < 10_000) return `${(value / 1000).toFixed(1)}k`;
16
- return `${Math.round(value / 1000)}k`;
16
+ if (value < 1_000_000) return `${Math.round(value / 1000)}k`;
17
+ if (value < 10_000_000) return `${(value / 1_000_000).toFixed(1)}M`;
18
+ return `${Math.round(value / 1_000_000)}M`;
17
19
  }
18
20
 
19
21
  export function formatProviderLabel(provider: string | undefined): string {
@@ -38,19 +40,23 @@ export function getUsageTotals(ctx: ExtensionContext): UsageTotals {
38
40
  let output = 0;
39
41
  let cost = 0;
40
42
 
41
- for (const entry of ctx.sessionManager.getBranch()) {
43
+ const entries = ctx.sessionManager.getEntries?.() ?? ctx.sessionManager.getBranch();
44
+ for (const entry of entries) {
42
45
  if (entry.type !== "message" || entry.message.role !== "assistant") continue;
43
- const message = entry.message as AssistantMessage;
44
- input += message.usage?.input ?? 0;
45
- output += message.usage?.output ?? 0;
46
- cost += message.usage?.cost?.total ?? 0;
46
+ const usage = (entry.message as AssistantMessage).usage;
47
+ input += usage?.input ?? 0;
48
+ output += usage?.output ?? 0;
49
+ cost += usage?.cost?.total ?? 0;
47
50
  }
48
51
 
49
52
  return { input, output, cost };
50
53
  }
51
54
 
52
55
  export function buildTokenLabel(totals: UsageTotals): string {
53
- return `↑${formatCount(totals.input)} ↓${formatCount(totals.output)}`;
56
+ const parts: string[] = [];
57
+ if (totals.input) parts.push(`↑${formatCount(totals.input)}`);
58
+ if (totals.output) parts.push(`↓${formatCount(totals.output)}`);
59
+ return parts.length > 0 ? parts.join(" ") : "↑0 ↓0";
54
60
  }
55
61
 
56
62
  export function buildCostLabel(totals: UsageTotals): string {
@@ -140,6 +140,13 @@ export default function (pi: ExtensionAPI) {
140
140
  activeTheme = undefined;
141
141
  };
142
142
 
143
+ const syncInteractiveState = (_event: unknown, ctx: ExtensionContext) => {
144
+ refreshInteractiveState(ctx);
145
+ };
146
+ const syncInteractiveAndProjectState = (_event: unknown, ctx: ExtensionContext) => {
147
+ refreshInteractiveState(ctx, true);
148
+ };
149
+
143
150
  pi.on("session_start", async (_event, ctx) => {
144
151
  installUi(ctx);
145
152
  });
@@ -164,31 +171,12 @@ export default function (pi: ExtensionAPI) {
164
171
  cleanupUi(ctx);
165
172
  });
166
173
 
167
- pi.on("agent_start", async (_event, ctx) => {
168
- refreshInteractiveState(ctx);
169
- });
170
-
171
- pi.on("agent_end", async (_event, ctx) => {
172
- refreshInteractiveState(ctx, true);
173
- });
174
-
175
- pi.on("model_select", async (_event, ctx) => {
176
- refreshInteractiveState(ctx);
177
- });
178
-
179
- pi.on("thinking_level_select", async (_event, ctx) => {
180
- refreshInteractiveState(ctx);
181
- });
182
-
183
- pi.on("message_end", async (_event, ctx) => {
184
- refreshInteractiveState(ctx, true);
185
- });
186
-
187
- pi.on("tool_execution_end", async (_event, ctx) => {
188
- refreshInteractiveState(ctx, true);
189
- });
190
-
191
- pi.on("session_compact", async (_event, ctx) => {
192
- refreshInteractiveState(ctx, true);
193
- });
174
+ pi.on("agent_start", syncInteractiveState);
175
+ pi.on("agent_end", syncInteractiveAndProjectState);
176
+ pi.on("model_select", syncInteractiveState);
177
+ pi.on("thinking_level_select", syncInteractiveState);
178
+ pi.on("message_end", syncInteractiveAndProjectState);
179
+ pi.on("tool_execution_end", syncInteractiveAndProjectState);
180
+ pi.on("session_compact", syncInteractiveAndProjectState);
181
+ pi.on("session_tree", syncInteractiveAndProjectState);
194
182
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-zentui",
3
- "version": "0.1.12",
3
+ "version": "0.1.13",
4
4
  "description": "A Starship-inspired statusline and Opencode-style TUI for Pi.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -45,6 +45,6 @@
45
45
  "@earendil-works/pi-tui": "^0.74.0",
46
46
  "@types/node": "^25.5.2",
47
47
  "typescript": "^6.0.2",
48
- "vitest": "^3.2.4"
48
+ "vitest": "^4.1.8"
49
49
  }
50
50
  }