pi-status-footer 1.0.3 → 1.0.4
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 +1 -1
- package/package.json +4 -1
- package/stats-footer.ts +45 -9
package/README.md
CHANGED
|
@@ -74,7 +74,7 @@ The extension hooks into six pi lifecycle events:
|
|
|
74
74
|
- **`session_start`** — registers the footer via `ctx.ui.setFooter()`, discovers repo root, starts branch-change listener
|
|
75
75
|
- **`agent_start` / `agent_settled`** — controls the agent-run timer and a 1-second interval that triggers git diff refresh
|
|
76
76
|
- **`turn_start` / `turn_end`** — drives the per-turn timer
|
|
77
|
-
- **`message_start` / `message_update` / `message_end`** — tracks the generation window for live TPS
|
|
77
|
+
- **`message_start` / `message_update` / `message_end`** — tracks the generation window for live TPS. Most providers only report output-token usage at message end, so `message_update` estimates tokens live from the streamed delta characters (text/thinking/toolcall), calibrated against each message's real usage at `message_end`
|
|
78
78
|
- **`model_select`** — clears stale TPS on model switch
|
|
79
79
|
- **`session_shutdown`** — cleans up all state
|
|
80
80
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-status-footer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Compact two-line status footer for pi: model, thinking level, tokens, TPS, cache hit rate, context usage, live git diff, and working/turn timers.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"monitoring",
|
|
29
29
|
"streaming"
|
|
30
30
|
],
|
|
31
|
+
"scripts": {
|
|
32
|
+
"test": "node --experimental-strip-types test-live-tps.ts"
|
|
33
|
+
},
|
|
31
34
|
"license": "MIT",
|
|
32
35
|
"repository": {
|
|
33
36
|
"type": "git",
|
package/stats-footer.ts
CHANGED
|
@@ -256,6 +256,13 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
256
256
|
let genStart: number | null = null;
|
|
257
257
|
let liveOutput = 0;
|
|
258
258
|
let lastTps: number | null = null;
|
|
259
|
+
// Characters streamed for the current assistant message (text + thinking
|
|
260
|
+
// + toolcall deltas). Used to estimate output tokens live, since most
|
|
261
|
+
// providers only report usage.output at message end.
|
|
262
|
+
let deltaChars = 0;
|
|
263
|
+
// Exponentially-averaged chars-per-token ratio, calibrated from each
|
|
264
|
+
// message's real usage.output at message_end. Default 4 ≈ English prose.
|
|
265
|
+
let charsPerToken = 4;
|
|
259
266
|
// Git status: repo folder name + working-tree diff stats (+N -M), fetched
|
|
260
267
|
// asynchronously (render is synchronous, so results are cached).
|
|
261
268
|
let sessionCwd: string | null = null;
|
|
@@ -309,6 +316,7 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
309
316
|
genStart = null;
|
|
310
317
|
liveOutput = 0;
|
|
311
318
|
lastTps = null;
|
|
319
|
+
deltaChars = 0;
|
|
312
320
|
sessionCwd = ctx.cwd;
|
|
313
321
|
folderName = basename(ctx.cwd);
|
|
314
322
|
const repoRoot = findRepoRoot(ctx.cwd);
|
|
@@ -481,12 +489,12 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
481
489
|
stopTimer();
|
|
482
490
|
tuiRef = null;
|
|
483
491
|
runStart = null;
|
|
484
|
-
lastRunDuration = 0;
|
|
485
492
|
turnStart = null;
|
|
486
493
|
lastTurnDuration = 0;
|
|
487
494
|
genStart = null;
|
|
488
495
|
liveOutput = 0;
|
|
489
496
|
lastTps = null;
|
|
497
|
+
deltaChars = 0;
|
|
490
498
|
sessionCwd = null;
|
|
491
499
|
folderName = null;
|
|
492
500
|
repoName = null;
|
|
@@ -498,28 +506,45 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
498
506
|
// --- Tokens-per-second tracking ---
|
|
499
507
|
// Each assistant message's generation window is measured from its
|
|
500
508
|
// message_start (streaming begins) to message_end (stream done).
|
|
501
|
-
//
|
|
502
|
-
//
|
|
503
|
-
//
|
|
509
|
+
// Each assistant message's generation window is measured from its
|
|
510
|
+
// message_start (streaming begins) to message_end (stream done).
|
|
511
|
+
// message_update carries progressively updated usage.output for providers
|
|
512
|
+
// that report it (e.g. some gateways); most providers (Anthropic, OpenAI)
|
|
513
|
+
// only send output usage at message end, so tokens are estimated live from
|
|
514
|
+
// the streamed delta characters, calibrated by charsPerToken. Real usage
|
|
515
|
+
// is preferred whenever it is reported and has grown past the estimate;
|
|
516
|
+
// message_end keeps the final usage's rate as lastTps for display while
|
|
517
|
+
// idle.
|
|
504
518
|
pi.on("message_start", (event) => {
|
|
505
519
|
if (event.message.role !== "assistant") return;
|
|
506
520
|
genStart = Date.now();
|
|
507
521
|
liveOutput = (event.message as AssistantMessage).usage?.output ?? 0;
|
|
522
|
+
deltaChars = 0;
|
|
508
523
|
});
|
|
509
524
|
pi.on("message_update", (event) => {
|
|
510
525
|
if (event.message.role !== "assistant") return;
|
|
511
|
-
// The raw stream event's partial message carries the most current
|
|
512
|
-
// usage.output (Anthropic reports it progressively; OpenAI only at the
|
|
513
|
-
// end), so prefer it over the session message's usage field.
|
|
514
526
|
const assistantEvent = event.assistantMessageEvent;
|
|
527
|
+
if (
|
|
528
|
+
assistantEvent &&
|
|
529
|
+
"delta" in assistantEvent &&
|
|
530
|
+
typeof assistantEvent.delta === "string"
|
|
531
|
+
) {
|
|
532
|
+
deltaChars += assistantEvent.delta.length;
|
|
533
|
+
}
|
|
515
534
|
const partial =
|
|
516
535
|
assistantEvent && "partial" in assistantEvent
|
|
517
536
|
? (assistantEvent as { partial?: AssistantMessage }).partial
|
|
518
537
|
: undefined;
|
|
519
|
-
const
|
|
538
|
+
const reported =
|
|
520
539
|
partial?.usage?.output ??
|
|
521
540
|
(event.message as AssistantMessage).usage?.output;
|
|
522
|
-
|
|
541
|
+
const estimated = Math.round(deltaChars / charsPerToken);
|
|
542
|
+
const output = Math.max(
|
|
543
|
+
typeof reported === "number" ? reported : 0,
|
|
544
|
+
liveOutput,
|
|
545
|
+
estimated,
|
|
546
|
+
);
|
|
547
|
+
if (output > liveOutput) liveOutput = output;
|
|
523
548
|
});
|
|
524
549
|
pi.on("message_end", (event) => {
|
|
525
550
|
if (event.message.role === "assistant") {
|
|
@@ -529,8 +554,18 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
529
554
|
const tps = computeTps(output, genStart, Date.now());
|
|
530
555
|
lastTps = tps === null ? null : Math.round(tps);
|
|
531
556
|
}
|
|
557
|
+
// Calibrate the live chars-per-token estimate against the real
|
|
558
|
+
// output token count so the next message's estimate is accurate.
|
|
559
|
+
if (deltaChars > 0 && output > 0) {
|
|
560
|
+
const ratio = deltaChars / output;
|
|
561
|
+
charsPerToken = Math.min(
|
|
562
|
+
12,
|
|
563
|
+
Math.max(1.5, charsPerToken * 0.7 + ratio * 0.3),
|
|
564
|
+
);
|
|
565
|
+
}
|
|
532
566
|
genStart = null;
|
|
533
567
|
liveOutput = 0;
|
|
568
|
+
deltaChars = 0;
|
|
534
569
|
}
|
|
535
570
|
rerender();
|
|
536
571
|
});
|
|
@@ -540,6 +575,7 @@ export default function statsFooter(pi: ExtensionAPI) {
|
|
|
540
575
|
lastTps = null;
|
|
541
576
|
genStart = null;
|
|
542
577
|
liveOutput = 0;
|
|
578
|
+
deltaChars = 0;
|
|
543
579
|
rerender();
|
|
544
580
|
});
|
|
545
581
|
pi.on("session_info_changed", rerender);
|