86692d5b8227d793fb382d6b249d3f2745d19b07

Author
TheEdgeOfRage <git@theedgeofrage.com>
Committer
TheEdgeOfRage <git@theedgeofrage.com>
Date

Message

Reformat pi footer extension

Diff

This diff is truncated to protect this page.

  1diff --git a/dot_pi/agent/extensions/detailed-footer.ts b/dot_pi/agent/extensions/detailed-footer.ts
  2index adee6394edec5fbf5d7f2a01ea7c52c1d995d797..04483407e8665d6e0792a06d26bf10cd6da2b78d 100644
  3--- a/dot_pi/agent/extensions/detailed-footer.ts
  4+++ b/dot_pi/agent/extensions/detailed-footer.ts
  5@@ -1,164 +1,226 @@
  6 import { isAbsolute, relative, resolve, sep } from "node:path";
  7-import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
  8+import type {
  9+  ExtensionAPI,
 10+  ExtensionContext,
 11+} from "@earendil-works/pi-coding-agent";
 12 import { truncateToWidth, wrapTextWithAnsi } from "@earendil-works/pi-tui";
 13 
 14 type Usage = {
 15-	input?: number;
 16-	output?: number;
 17-	cacheRead?: number;
 18-	cacheWrite?: number;
 19-	cost?: { total?: number };
 20+  input?: number;
 21+  output?: number;
 22+  cacheRead?: number;
 23+  cacheWrite?: number;
 24+  cost?: { total?: number };
 25 };
 26 
 27 type UsageTotals = {
 28-	input: number;
 29-	output: number;
 30-	cacheRead: number;
 31-	cacheWrite: number;
 32-	cost: number;
 33+  input: number;
 34+  output: number;
 35+  cacheRead: number;
 36+  cacheWrite: number;
 37+  cost: number;
 38 };
 39 
 40 const formatTokens = (count: number): string => {
 41-	if (count < 1_000) return count.toString();
 42-	if (count < 10_000) return `${(count / 1_000).toFixed(1)}k`;
 43-	if (count < 1_000_000) return `${Math.round(count / 1_000)}k`;
 44-	if (count < 10_000_000) return `${(count / 1_000_000).toFixed(1)}M`;
 45-	return `${Math.round(count / 1_000_000)}M`;
 46+  if (count < 1_000) return count.toString();
 47+  if (count < 10_000) return `${(count / 1_000).toFixed(1)}k`;
 48+  if (count < 1_000_000) return `${Math.round(count / 1_000)}k`;
 49+  if (count < 10_000_000) return `${(count / 1_000_000).toFixed(1)}M`;
 50+  return `${Math.round(count / 1_000_000)}M`;
 51 };
 52 
 53 const addUsage = (totals: UsageTotals, usage: Usage | undefined): void => {
 54-	if (usage === undefined) return;
 55-	totals.input += usage.input ?? 0;
 56-	totals.output += usage.output ?? 0;
 57-	totals.cacheRead += usage.cacheRead ?? 0;
 58-	totals.cacheWrite += usage.cacheWrite ?? 0;
 59-	totals.cost += usage.cost?.total ?? 0;
 60+  if (usage === undefined) return;
 61+  totals.input += usage.input ?? 0;
 62+  totals.output += usage.output ?? 0;
 63+  totals.cacheRead += usage.cacheRead ?? 0;
 64+  totals.cacheWrite += usage.cacheWrite ?? 0;
 65+  totals.cost += usage.cost?.total ?? 0;
 66 };
 67 
 68 const getUsageTotals = (ctx: ExtensionContext): UsageTotals => {
 69-	const totals: UsageTotals = { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, cost: 0 };
 70-
 71-	for (const entry of ctx.sessionManager.getEntries()) {
 72-		if (entry.type === "message") {
 73-			if (entry.message.role === "assistant" || entry.message.role === "toolResult") {
 74-				addUsage(totals, entry.message.usage);
 75-			}
 76-		} else if (entry.type === "branch_summary" || entry.type === "compaction") {
 77-			addUsage(totals, entry.usage);
 78-		}
 79-	}
 80-
 81-	return totals;
 82+  const totals: UsageTotals = {
 83+    input: 0,
 84+    output: 0,
 85+    cacheRead: 0,
 86+    cacheWrite: 0,
 87+    cost: 0,
 88+  };
 89+
 90+  for (const entry of ctx.sessionManager.getEntries()) {
 91+    if (entry.type === "message") {
 92+      if (
 93+        entry.message.role === "assistant" ||
 94+        entry.message.role === "toolResult"
 95+      ) {
 96+        addUsage(totals, entry.message.usage);
 97+      }
 98+    } else if (entry.type === "branch_summary" || entry.type === "compaction") {
 99+      addUsage(totals, entry.usage);
100+    }
101+  }
102+
103+  return totals;
104 };