@henryqw/pi-footer 2.1.3 → 2.2.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/README.md CHANGED
@@ -30,7 +30,7 @@ pi-harness · clear-field-f8d2 [+2 ~3 ?1 ↑2] · PR #123 · approved Codex #
30
30
  ```
31
31
 
32
32
  - The first line shows the repository, branch, Git state, and `pi-pr` pull request status beside the checkout identity. The `pi-multi-codex` quota status, when non-empty, occupies the right side. Linked-worktree branches drop the generated `worktree/` prefix.
33
- - The second line shows cumulative input tokens, output tokens, latest cache-hit rate, and tokens per second for the most recent assistant response. It also shows estimated cost and context usage. Totals include reported tool usage and finished `pi-subagent` background workflows. The active model and thinking level are right-aligned.
33
+ - The second line shows cumulative input tokens, output tokens, latest cache-hit rate, and tokens per second for the most recent assistant response. The rate is timed from the response's first streamed content to its end, so request latency and time to first token are excluded for every provider. A response that arrives without streamed content shows `—`. It also shows estimated cost and context usage. Totals include reported tool usage and finished `pi-subagent` background workflows. The active model and thinking level are right-aligned. Under a virtual model, the physical model and thinking level of the latest successful response follow an arrow, for example `auto • high → gpt-5.6-luna • medium`, matching Pi's built-in footer.
34
34
  - The third line shows a compact CodeGraph badge first when loaded: `✓ CG` indexed, `● CG` in use, `◐ CG` checking or indexing, `○ CG` missing, `! CG` setup problem, or `? CG` unknown state. Its icon uses the active theme's state color; `CG` remains plain so the badge is readable without color. When pi-codegraph is not loaded, no badge appears. A middle dot separates the CodeGraph badge from other extension statuses; cumulative agent-work time stays on the right, beneath the active model.
35
35
 
36
36
  Git badges appear only when action is needed:
@@ -58,7 +58,7 @@ Unavailable values render as `—` without a misleading percent sign.
58
58
 
59
59
  Only the non-empty `pi-multi-codex` quota status occupies the right side of the first line. The `pi-pr` pull-request status stays beside checkout identity, and CodeGraph appears separately on the third line.
60
60
 
61
- Statuses from other extensions, including Ponytail and `pi-rewind`, share the left side of the third line. They are sorted by key; colors, links, glyphs, and interior spacing are preserved. Leading and trailing whitespace is trimmed, line breaks become spaces, and long statuses may be clipped to fit the footer. Scripted `mcpScript` calls are not visible as individual tool calls, so they do not trigger the `● CG` badge.
61
+ Statuses from other extensions, including Ponytail and `pi-rewind`, share the left side of the third line. They are sorted by key; colors, links, glyphs, and interior spacing are preserved. Leading and trailing whitespace is trimmed, line breaks become spaces, and long statuses may be clipped to fit the footer. Only direct `codegraph_explore` tool calls trigger the `● CG` badge; CodeGraph queries made from inside scripted tools are not shown.
62
62
 
63
63
  ## Limits and recovery
64
64
 
@@ -1,6 +1,6 @@
1
1
  import { readFile } from "node:fs/promises";
2
2
  import { basename, dirname, join } from "node:path";
3
- import type { ExtensionAPI, Theme } from "@earendil-works/pi-coding-agent";
3
+ import type { ExtensionAPI, ExtensionContext, Theme } from "@earendil-works/pi-coding-agent";
4
4
  import { getCapabilities, hyperlink, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
5
5
  import { configuredOpenUri } from "@henryqw/pi-open-in/open-uri";
6
6
 
@@ -15,6 +15,8 @@ const THINKING_COLORS = {
15
15
  const HENRY_STATUS_KEY = "pi-multi-codex";
16
16
  const AGENT_TIME_ENTRY = "pi-footer:agent-work";
17
17
  const SUBAGENT_BACKGROUND_RESULT = "subagent-background-result";
18
+ /** Pi's VIRTUAL_MODEL_API: catalog entries that route each request to a physical model. */
19
+ const VIRTUAL_MODEL_API = "pi-virtual";
18
20
 
19
21
  type CountedUsage = { input: number; output: number; cost: { total: number } };
20
22
  type GitSummary = { badges: string; detachedOid?: string };
@@ -167,11 +169,15 @@ function rainbow(text: string): string {
167
169
  return [...text].map((character, index) => color(character, colors[index % colors.length]!)).join("");
168
170
  }
169
171
 
170
- function isCodegraphCall(toolName: string, args: unknown): boolean {
171
- if (toolName === "codegraph_explore") return true;
172
- if (toolName !== "mcp" || !args || typeof args !== "object") return false;
173
- const { tool, server } = args as { tool?: unknown; server?: unknown };
174
- return server === "henryqw_pi-codegraph__codegraph" && typeof tool === "string" && tool.startsWith("codegraph_");
172
+ /** Physical model and thinking level of the latest successful response on the branch; failed and aborted requests are skipped. */
173
+ function latestResponse(ctx: ExtensionContext): { model: string; thinkingLevel?: string } | undefined {
174
+ const branch = ctx.sessionManager.getBranch();
175
+ for (let index = branch.length - 1; index >= 0; index--) {
176
+ const entry = branch[index]!;
177
+ if (entry.type !== "message" || entry.message.role !== "assistant") continue;
178
+ const { stopReason, model, thinkingLevel } = entry.message;
179
+ if (stopReason !== "error" && stopReason !== "aborted") return { model, thinkingLevel };
180
+ }
175
181
  }
176
182
 
177
183
  function codegraphBadge(status: string, inUse: boolean, theme: Theme): string {
@@ -196,7 +202,7 @@ export default function footerExtension(pi: ExtensionAPI): void {
196
202
  let refreshGitStatus: (() => Promise<void>) | undefined;
197
203
  const activeCodegraphCalls = new Set<string>();
198
204
  pi.on("tool_execution_start", (event) => {
199
- if (!isCodegraphCall(event.toolName, event.args)) return;
205
+ if (event.toolName !== "codegraph_explore") return;
200
206
  activeCodegraphCalls.add(event.toolCallId);
201
207
  requestRuntimeRender?.();
202
208
  });
@@ -304,9 +310,10 @@ export default function footerExtension(pi: ExtensionAPI): void {
304
310
  }
305
311
 
306
312
  let tps: number | undefined;
313
+ // Start at the first streamed update: providers emit message_start at different points before the first token.
307
314
  let assistantStartedAt: number | undefined;
308
- pi.on("message_start", async (event) => {
309
- if (event.message.role === "assistant") assistantStartedAt = performance.now();
315
+ pi.on("message_update", async (event) => {
316
+ if (event.message.role === "assistant") assistantStartedAt ??= performance.now();
310
317
  });
311
318
  pi.on("message_end", async (event) => {
312
319
  if (event.message.role !== "assistant") return;
@@ -316,8 +323,9 @@ export default function footerExtension(pi: ExtensionAPI): void {
316
323
  tps = seconds > 0 ? output / seconds : undefined;
317
324
  });
318
325
 
319
- // ponytail: keyed on length + last entry (sessions are append-only); revisit if entries ever mutate in place.
326
+ // ponytail: keyed on length + last entry (sessions are append-only) + leaf (tree navigation); revisit if entries ever mutate in place.
320
327
  let usageKey: string | undefined;
328
+ let routed: ReturnType<typeof latestResponse>;
321
329
  let input = 0;
322
330
  let output = 0;
323
331
  let cost = 0;
@@ -365,10 +373,11 @@ export default function footerExtension(pi: ExtensionAPI): void {
365
373
  invalidate() { },
366
374
  render(width: number): string[] {
367
375
  const entries = ctx.sessionManager.getEntries();
368
- const key = `${entries.length}:${entries.at(-1)?.type}`;
376
+ const key = `${entries.length}:${entries.at(-1)?.type}:${ctx.sessionManager.getLeafId()}`;
369
377
  if (key !== usageKey) {
370
378
  usageKey = key;
371
379
  computeUsage();
380
+ routed = latestResponse(ctx);
372
381
  }
373
382
 
374
383
  const reportedBranch = data.getGitBranch()?.replace(/^worktree\//, "");
@@ -387,8 +396,6 @@ export default function footerExtension(pi: ExtensionAPI): void {
387
396
  if (!text) continue;
388
397
  (key === HENRY_STATUS_KEY ? henryStatuses : externalStatuses).push(text);
389
398
  }
390
- const thinking = String(ctx.thinkingLevel ?? "off");
391
- const thinkingColor = THINKING_COLORS[thinking as keyof typeof THINKING_COLORS];
392
399
  const ellipsis = theme.fg("dim", "…");
393
400
  const usage = theme.fg("dim", [
394
401
  `↑ ${formatTokens(input)}`,
@@ -398,10 +405,15 @@ export default function footerExtension(pi: ExtensionAPI): void {
398
405
  `$ ${cost.toFixed(3)}`,
399
406
  `◔ ${context == null ? "—" : `${context.toFixed(1)}%`}`,
400
407
  ].join(" · "));
401
- const thinkingText = thinking === "ultra"
402
- ? rainbow(thinking)
403
- : thinkingColor === undefined ? theme.fg("dim", thinking) : color(thinking, thinkingColor);
404
- const model = theme.fg("dim", `${ctx.model?.id ?? "no-model"} • `) + thinkingText;
408
+ const thinkingText = (level: string) => {
409
+ const thinkingColor = THINKING_COLORS[level as keyof typeof THINKING_COLORS];
410
+ return level === "ultra" ? rainbow(level) : thinkingColor === undefined ? theme.fg("dim", level) : color(level, thinkingColor);
411
+ };
412
+ const selected = theme.fg("dim", `${ctx.model?.id ?? "no-model"} • `) + thinkingText(String(ctx.thinkingLevel ?? "off"));
413
+ // Under a virtual selection, show where the latest request went, as Pi's own footer does.
414
+ const model = ctx.model?.api === VIRTUAL_MODEL_API && routed
415
+ ? selected + theme.fg("dim", ` → ${routed.model}`) + (routed.thinkingLevel ? theme.fg("dim", " • ") + thinkingText(routed.thinkingLevel) : "")
416
+ : selected;
405
417
  const elapsed = activeMilliseconds + (activeStartedAt === undefined ? 0 : performance.now() - activeStartedAt);
406
418
  const runtime = theme.fg("dim", `◷ ${formatDuration(elapsed)}`);
407
419
  const identity = branch ? theme.fg("dim", `${repo} · `) : "";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@henryqw/pi-footer",
3
- "version": "2.1.3",
3
+ "version": "2.2.0",
4
4
  "description": "Show concise repository, branch, and usage details in the Pi footer.",
5
5
  "keywords": [
6
6
  "pi-package",
@@ -24,8 +24,8 @@
24
24
  "pack:check": "npm pack --dry-run"
25
25
  },
26
26
  "peerDependencies": {
27
- "@earendil-works/pi-coding-agent": ">=0.86.0 <0.88.0",
28
- "@earendil-works/pi-tui": ">=0.86.0 <0.88.0"
27
+ "@earendil-works/pi-coding-agent": ">=0.86.0 <0.100.0",
28
+ "@earendil-works/pi-tui": ">=0.86.0 <0.100.0"
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",
@@ -48,7 +48,7 @@
48
48
  "@henryqw/pi-open-in": "^3.0.0"
49
49
  },
50
50
  "devDependencies": {
51
- "@earendil-works/pi-coding-agent": "0.87.0",
52
- "@earendil-works/pi-tui": "0.87.0"
51
+ "@earendil-works/pi-coding-agent": "0.99.1",
52
+ "@earendil-works/pi-tui": "0.99.1"
53
53
  }
54
54
  }