pi-usage-hub 1.0.6 → 1.0.7

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 CHANGED
@@ -185,16 +185,18 @@ export default function register(pi: ExtensionAPI) {
185
185
  return panel;
186
186
  }, {
187
187
  overlay: true,
188
- overlayOptions: {
189
- width: "80%",
190
- minWidth: 74,
191
- maxHeight: "80%",
192
- anchor: "center",
193
- // Pass terminal height each frame so the quota view can scroll correctly.
194
- visible: (_tw, termHeight) => {
195
- panelRef.current?.setViewHeight(termHeight);
196
- return true;
197
- },
188
+ overlayOptions: () => {
189
+ const termWidth = process.stdout.columns ?? 80;
190
+ return {
191
+ width: Math.min(Math.floor(termWidth * 0.65), 100),
192
+ minWidth: 74,
193
+ maxHeight: "80%",
194
+ anchor: "center",
195
+ visible: (_tw, termHeight) => {
196
+ panelRef.current?.setViewHeight(termHeight);
197
+ return true;
198
+ },
199
+ };
198
200
  },
199
201
  onHandle: overlayHandle => {
200
202
  handle = overlayHandle;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-usage-hub",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Usage hub for pi — provider quota/balance registry with cache, /usage-hub panel, and pull API",
5
5
  "keywords": [
6
6
  "pi",
@@ -33,7 +33,8 @@ export function shortReport(report: UsageReport, provider: UsageProvider): strin
33
33
  return `${provider.shortLabel} ${text}`;
34
34
  }
35
35
 
36
- export function fullReport(report: UsageReport, provider: UsageProvider): string {
36
+ export function fullReport(report: UsageReport, provider: UsageProvider, contentWidth?: number): string {
37
+ const barWidth = contentWidth ? Math.max(20, Math.min(50, contentWidth - 32)) : 24;
37
38
  const lines: string[] = [];
38
39
  lines.push(`\x1b[1m${provider.label}\x1b[0m`);
39
40
 
@@ -52,15 +53,15 @@ export function fullReport(report: UsageReport, provider: UsageProvider): string
52
53
 
53
54
  if (report.session) {
54
55
  const r = report.session.resetsIn ? ` \u23F1 ${report.session.resetsIn}` : "";
55
- lines.push(` Rolling: ${bar(report.session.pct)} ${report.session.pct.toFixed(1)}%${r}`);
56
+ lines.push(` Rolling: ${bar(report.session.pct, barWidth)} ${report.session.pct.toFixed(1)}%${r}`);
56
57
  }
57
58
  if (report.weekly) {
58
59
  const r = report.weekly.resetsIn ? ` \u23F1 ${report.weekly.resetsIn}` : "";
59
- lines.push(` Weekly: ${bar(report.weekly.pct)} ${report.weekly.pct.toFixed(1)}%${r}`);
60
+ lines.push(` Weekly: ${bar(report.weekly.pct, barWidth)} ${report.weekly.pct.toFixed(1)}%${r}`);
60
61
  }
61
62
  if (report.monthly) {
62
63
  const r = report.monthly.resetsIn ? ` \u23F1 ${report.monthly.resetsIn}` : "";
63
- lines.push(` Monthly: ${bar(report.monthly.pct)} ${report.monthly.pct.toFixed(1)}%${r}`);
64
+ lines.push(` Monthly: ${bar(report.monthly.pct, barWidth)} ${report.monthly.pct.toFixed(1)}%${r}`);
64
65
  }
65
66
 
66
67
  return lines.join("\n");
@@ -23,13 +23,13 @@ const MAX_PROVIDERS = 5;
23
23
 
24
24
  // Column widths shared by period, provider and model rows.
25
25
  const nameW = 18;
26
- const costW = 7;
26
+ const costW = 8;
27
27
  const tokW = 8;
28
28
  const inW = 8;
29
29
  const outW = 7;
30
30
  const cacheW = 8;
31
31
  const msgW = 7;
32
- const sesW = 5;
32
+ const sesW = 6;
33
33
 
34
34
  // Model rows are indented 3 extra spaces, so their name field is narrower to
35
35
  // keep every numeric column aligned with the provider rows above.
@@ -124,12 +124,17 @@ export class SessionPanel {
124
124
  return this.currentPeriod()?.providers.slice(0, MAX_PROVIDERS) ?? [];
125
125
  }
126
126
 
127
- render(theme: Theme): string[] {
127
+ render(theme: Theme, contentWidth?: number): string[] {
128
128
  const th = theme;
129
129
  if (this.loading) return [` ${th.fg("muted", "Loading local session usage...")}`];
130
130
  if (this.error) return [` ${th.fg("warning", this.error)}`];
131
131
  if (!this.usage) return [` ${th.fg("muted", "Loading...")}`];
132
132
 
133
+ // Dynamic column widths
134
+ const fixedCols = sesW + msgW + inW + outW + cacheW + tokW + costW; // = 52
135
+ const dynamicNameW = contentWidth ? Math.max(15, Math.min(36, contentWidth - 3 - fixedCols)) : nameW;
136
+ const sepWidth = contentWidth ?? 72;
137
+
133
138
  const lines: string[] = [];
134
139
 
135
140
  // ── Period tab bar (2nd-level, row 1) ──
@@ -140,11 +145,11 @@ export class SessionPanel {
140
145
  : th.fg("dim", ` ${label} `);
141
146
  });
142
147
  lines.push(` ${tabParts.join(th.fg("borderMuted", "│"))}`);
143
- lines.push(th.fg("borderMuted", " " + "─".repeat(72)));
148
+ lines.push(th.fg("borderMuted", " " + "─".repeat(sepWidth)));
144
149
 
145
150
  // ── Provider table (always MAX_PROVIDERS rows tall for fixed height) ──
146
151
  const providers = this.providers();
147
- lines.push(th.fg("muted", ` ${cols("Provider", "Sess", "Msgs", "↑In", "↓Out", "Cache", "Tokens", "Cost")}`));
152
+ lines.push(th.fg("muted", ` ${cols("Provider", "Sess", "Msgs", "↑In", "↓Out", "Cache", "Tokens", "Cost", dynamicNameW)}`));
148
153
 
149
154
  for (let i = 0; i < MAX_PROVIDERS; i++) {
150
155
  const p = providers[i];
@@ -155,12 +160,12 @@ export class SessionPanel {
155
160
  const selected = i === this.providerIndex;
156
161
  const isExpanded = this.expanded.has(p.provider);
157
162
  const prefix = selected ? (isExpanded ? " ▾ " : " ▸ ") : " ";
158
- const text = `${prefix}${statCols(p.provider, p)}`;
163
+ const text = `${prefix}${statCols(p.provider, p, dynamicNameW)}`;
159
164
  lines.push(selected ? th.fg("accent", text) : th.fg("dim", text));
160
165
 
161
166
  if (isExpanded) {
162
167
  for (const m of p.models) {
163
- lines.push(th.fg("dim", ` └ ${statCols(m.model, m, nameW - 2)}`));
168
+ lines.push(th.fg("dim", ` └ ${statCols(m.model, m, dynamicNameW - 2)}`));
164
169
  }
165
170
  }
166
171
  }
@@ -169,8 +174,8 @@ export class SessionPanel {
169
174
  const period = PERIODS[this.periodIndex]!;
170
175
  const totals = this.usage[period.key].totals;
171
176
  lines.push("");
172
- lines.push(th.fg("borderMuted", " " + "─".repeat(72)));
173
- lines.push(th.fg("accent", ` ${statCols("Total:", totals)}`));
177
+ lines.push(th.fg("borderMuted", " " + "─".repeat(sepWidth)));
178
+ lines.push(th.fg("accent", ` ${statCols("Total:", totals, dynamicNameW)}`));
174
179
 
175
180
  lines.push("");
176
181
  lines.push(` ${th.fg("dim", `←→ period · ↑↓ provider · Space expand · Tab switch · Esc close`)}`);
@@ -116,13 +116,13 @@ export class UsageWindow {
116
116
 
117
117
  let content: string[];
118
118
  if (this.mode === "quota") {
119
- const allLines = this.renderQuotaLines();
119
+ const allLines = this.renderQuotaLines(bodyW);
120
120
  this.lastContentLines = allLines.length;
121
121
  const maxScroll = Math.max(0, this.lastContentLines - this.viewHeight);
122
122
  this.scrollOffset = Math.min(this.scrollOffset, maxScroll);
123
123
  content = allLines.slice(this.scrollOffset, this.scrollOffset + this.viewHeight);
124
124
  } else {
125
- content = this.session.render(th);
125
+ content = this.session.render(th, bodyW);
126
126
  }
127
127
 
128
128
  const lines: string[] = [];
@@ -140,7 +140,7 @@ export class UsageWindow {
140
140
  return lines;
141
141
  }
142
142
 
143
- private renderQuotaLines(): string[] {
143
+ private renderQuotaLines(contentWidth: number): string[] {
144
144
  const th = this.theme;
145
145
  const lines: string[] = [];
146
146
 
@@ -156,7 +156,7 @@ export class UsageWindow {
156
156
  const provider = this.orderedProviders[i]!;
157
157
  const report = this.reports.get(provider);
158
158
  if (report) {
159
- for (const line of fullReport(report, provider).split("\n")) {
159
+ for (const line of fullReport(report, provider, contentWidth).split("\n")) {
160
160
  lines.push(` ${line}`);
161
161
  }
162
162
  } else {