@erichll/pi-statusline 0.8.0 → 0.10.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/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.0 - 2026-11-03
4
+
5
+ - Mark the cost segment when the summed USD total is a catalog estimate or
6
+ mixes an estimate with a provider-reported bill (`0.012~`). Totals Pi
7
+ reports as billed, and totals recorded before `totalFromProvider` existed,
8
+ stay unmarked.
9
+ - Verify the type check and the full statusline test suite against Pi 1.5.0.
10
+ The peer floor stays `>=1.4.0`.
11
+
12
+ ## 0.9.0 - 2026-10-28
13
+
14
+ - Raise the development and peer baseline to Pi 1.4.0. Older Pi peer versions
15
+ are no longer supported by this release.
16
+ - Verify the type check and the full statusline test suite against Pi 1.4.0.
17
+
3
18
  ## 0.8.0 - 2026-10-18
4
19
 
5
20
  ### Added
package/README.md CHANGED
@@ -23,7 +23,7 @@ spaces set each label off from the row contents (one in ASCII mode).
23
23
  pi install npm:@erichll/pi-statusline
24
24
  ```
25
25
 
26
- Requires Node.js >=22.19 and Pi >=1.1.0; subscription Usage requires Pi >=1.2.0.
26
+ Requires Node.js >=22.19 and Pi >=1.4.0.
27
27
  Git is optional. The default Powerline layout requires a Nerd Font; choose
28
28
  ASCII icons and plain separators for a font-independent layout.
29
29
  Disable other footer extensions in `pi config`: only one should own the footer.
@@ -88,7 +88,7 @@ Available segments:
88
88
  | `session` | Time since the session was created, on the bottom row | On |
89
89
  | `toolTotal` | Tool calls recorded in the whole session (`󱁤 128`), on the bottom row; hidden at zero | On |
90
90
  | `tokens` | Cumulative session tokens, on the bottom row | On |
91
- | `cost` | Pi-recorded cumulative USD cost | Off |
91
+ | `cost` | Pi-recorded cumulative USD cost. A trailing `~` means the total is a catalog estimate, or mixes an estimate with a provider-reported bill | Off |
92
92
  | `input`, `output`, `cacheRead`, `cacheWrite` | Individual session token counters | Off |
93
93
  | `statuses` | Other extensions' text, at the end of the bottom row | On |
94
94
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erichll/pi-statusline",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "description": "Configurable Pi statusline with live preview, Git and session usage",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -17,14 +17,14 @@
17
17
  "smoke": "python3 test/pty-smoke.py"
18
18
  },
19
19
  "peerDependencies": {
20
- "@earendil-works/pi-ai": ">=1.1.0",
21
- "@earendil-works/pi-coding-agent": ">=1.1.0",
22
- "@earendil-works/pi-tui": ">=1.1.0"
20
+ "@earendil-works/pi-ai": ">=1.4.0",
21
+ "@earendil-works/pi-coding-agent": ">=1.4.0",
22
+ "@earendil-works/pi-tui": ">=1.4.0"
23
23
  },
24
24
  "devDependencies": {
25
- "@earendil-works/pi-ai": "^1.2.0",
26
- "@earendil-works/pi-coding-agent": "^1.2.0",
27
- "@earendil-works/pi-tui": "^1.2.0",
25
+ "@earendil-works/pi-ai": "^1.5.0",
26
+ "@earendil-works/pi-coding-agent": "^1.5.0",
27
+ "@earendil-works/pi-tui": "^1.5.0",
28
28
  "@types/node": "^26.6.5",
29
29
  "typescript": "^7.0.2"
30
30
  }
package/src/render.ts CHANGED
@@ -80,7 +80,10 @@ function segmentText(id: SegmentId, data: StatuslineSnapshot, config: Statusline
80
80
  case "quota": return renderQuota(data.quota, config.icons === "ascii");
81
81
  case "session": return data.sessionMinutes === null ? undefined : formatSessionAge(data.sessionMinutes);
82
82
  case "toolTotal": return data.toolCalls > 0 ? String(data.toolCalls) : undefined;
83
- case "cost": return usage.cost.toFixed(3);
83
+ case "cost": {
84
+ const amount = usage.cost.toFixed(3);
85
+ return usage.costProvenance === "estimated" || usage.costProvenance === "mixed" ? `${amount}~` : amount;
86
+ }
84
87
  case "input": return formatTokens(usage.input);
85
88
  case "output": return formatTokens(usage.output);
86
89
  case "tokens": return formatTokens(usage.input + usage.output + usage.cacheRead + usage.cacheWrite);
package/src/runtime.ts CHANGED
@@ -3,7 +3,7 @@ import type { AssistantMessage, AssistantMessageEvent } from "@earendil-works/pi
3
3
  import type { AgentActivityOutcome } from "@earendil-works/pi-coding-agent";
4
4
  import { cleanText } from "./text.ts";
5
5
  import { toolTarget } from "./tools.ts";
6
- import { emptyUsage, readUsage } from "./usage.ts";
6
+ import { emptyUsage, mergeCostProvenance, readUsage } from "./usage.ts";
7
7
  import type { UsageTotals } from "./types.ts";
8
8
 
9
9
  export type Clock = () => number;
@@ -131,7 +131,13 @@ export class RuntimeState {
131
131
  const hidden = !retainSummary && !this.running;
132
132
  const elapsedMs = hidden || !this.runId ? 0 : Math.max(0, (this.running ? now : this.endMs) - this.startMs);
133
133
  const usage = !hidden && this.messages.size ? emptyUsage() : null;
134
- if (usage) for (const contribution of this.messages.values()) for (const key of Object.keys(usage) as (keyof UsageTotals)[]) usage[key] += contribution[key];
134
+ if (usage) {
135
+ for (const contribution of this.messages.values()) {
136
+ usage.input += contribution.input; usage.output += contribution.output;
137
+ usage.cacheRead += contribution.cacheRead; usage.cacheWrite += contribution.cacheWrite; usage.cost += contribution.cost;
138
+ usage.costProvenance = mergeCostProvenance(usage.costProvenance, contribution.costProvenance);
139
+ }
140
+ }
135
141
  const denominator = usage ? usage.input + usage.cacheRead + usage.cacheWrite : 0;
136
142
  return {
137
143
  runId: hidden ? null : this.runId, status: hidden ? "Idle" : this.state, elapsedMs,
package/src/types.ts CHANGED
@@ -44,12 +44,20 @@ export interface StatuslineConfig {
44
44
  segments: SegmentConfig[];
45
45
  runtime: RuntimeConfig;
46
46
  }
47
+ /** Where a summed USD total came from. `unknown` is Pi before 1.5, or a cost with no flag. */
48
+ export type CostProvenance = "provider" | "estimated" | "mixed" | "unknown";
47
49
  export interface UsageTotals {
48
50
  input: number;
49
51
  output: number;
50
52
  cacheRead: number;
51
53
  cacheWrite: number;
52
54
  cost: number;
55
+ /**
56
+ * `unknown` keeps the historical unmarked display. It does not combine with
57
+ * a later flag: only a real estimate, or both an estimate and a provider bill,
58
+ * mark the total.
59
+ */
60
+ costProvenance: CostProvenance;
53
61
  }
54
62
  export interface GitState {
55
63
  kind: "repository" | "none" | "unknown";
package/src/usage.ts CHANGED
@@ -1,14 +1,33 @@
1
1
  import type { AssistantMessage } from "@earendil-works/pi-ai";
2
2
  import type { SessionEntry } from "@earendil-works/pi-coding-agent";
3
- import type { UsageTotals } from "./types.ts";
3
+ import type { CostProvenance, UsageTotals } from "./types.ts";
4
4
 
5
- export function emptyUsage(): UsageTotals { return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 }; }
5
+ const NUMERIC_KEYS = ["input", "output", "cacheRead", "cacheWrite", "cost"] as const;
6
+ export function emptyUsage(): UsageTotals {
7
+ return { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0, costProvenance: "unknown" };
8
+ }
6
9
  const finite = (value: unknown): number => typeof value === "number" && Number.isFinite(value) && value >= 0 ? value : 0;
10
+ function costProvenance(cost: unknown): CostProvenance {
11
+ if (!cost || typeof cost !== "object") return "unknown";
12
+ const flag = (cost as Record<string, unknown>).totalFromProvider;
13
+ if (flag === true) return "provider";
14
+ if (flag === false) return "estimated";
15
+ return "unknown";
16
+ }
17
+ /** `unknown` is the identity, so missing flags do not mark an otherwise uniform total. */
18
+ export function mergeCostProvenance(current: CostProvenance, next: CostProvenance): CostProvenance {
19
+ if (next === "unknown" || current === next) return current;
20
+ if (current === "unknown") return next;
21
+ return "mixed";
22
+ }
7
23
  export function readUsage(value: unknown): UsageTotals {
8
24
  if (!value || typeof value !== "object") return emptyUsage();
9
25
  const usage = value as Record<string, unknown>;
10
26
  const cost = usage.cost && typeof usage.cost === "object" ? (usage.cost as Record<string, unknown>).total : 0;
11
- return { input: finite(usage.input), output: finite(usage.output), cacheRead: finite(usage.cacheRead), cacheWrite: finite(usage.cacheWrite), cost: finite(cost) };
27
+ return {
28
+ input: finite(usage.input), output: finite(usage.output), cacheRead: finite(usage.cacheRead), cacheWrite: finite(usage.cacheWrite),
29
+ cost: finite(cost), costProvenance: costProvenance(usage.cost),
30
+ };
12
31
  }
13
32
  export function entryUsage(entry: SessionEntry): UsageTotals {
14
33
  if (entry.type === "usage" || entry.type === "compaction" || entry.type === "branch_summary") return readUsage(entry.usage);
@@ -16,7 +35,12 @@ export function entryUsage(entry: SessionEntry): UsageTotals {
16
35
  return emptyUsage();
17
36
  }
18
37
  function add(target: UsageTotals, value: UsageTotals, sign = 1): void {
19
- for (const key of Object.keys(target) as (keyof UsageTotals)[]) target[key] += sign * value[key];
38
+ for (const key of NUMERIC_KEYS) target[key] += sign * value[key];
39
+ }
40
+ function provenanceOf(parts: Iterable<UsageTotals>): CostProvenance {
41
+ let result: CostProvenance = "unknown";
42
+ for (const part of parts) result = mergeCostProvenance(result, part.costProvenance);
43
+ return result;
20
44
  }
21
45
  function messageKey(message: AssistantMessage): string { return `${message.provider}/${message.model}/${message.timestamp}`; }
22
46
 
@@ -46,7 +70,13 @@ export class UsageCache {
46
70
  setLive(message: AssistantMessage | undefined): void { this.live = message; }
47
71
  snapshot(): UsageTotals {
48
72
  const total = { ...this.totals };
49
- if (this.live && !this.persistedMessages.has(messageKey(this.live))) add(total, readUsage(this.live.usage));
73
+ const parts = [...this.contributions.values()];
74
+ if (this.live && !this.persistedMessages.has(messageKey(this.live))) {
75
+ const live = readUsage(this.live.usage);
76
+ add(total, live);
77
+ parts.push(live);
78
+ }
79
+ total.costProvenance = provenanceOf(parts);
50
80
  return total;
51
81
  }
52
82
  }