omp packages

pi-display-runtimes1.2.1

Durable timing, token, and cost accounting for pi: compact run summaries with grouped breakdowns, optional verbose per-operation rows, nested-call rollups, a live activity widget, and a filterable /timings inspector — all persisted across sessions.

prawnbear Published 3 days ago MIT ~228 downloads/mo

Untested on omp

This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.

Did it work for you?

Result

One report per person. A new report replaces your old one.

Reports 0

No reports yet.

Readme

pi-display-runtimes

A pi extension that tells you where the time, tokens, and money went — for every operation, durably, in every session.

When a coding-agent run finishes, pi tells you what the model said. It does not tell you that the request took 8.4 seconds, that 44k of the input was prompt-cache reads, that the tool batch ran 14 seconds of wall time inside a two-minute total, or that you waited 20 minutes before sending the next prompt. This extension records exactly that, and keeps the records in the session so they survive restarts.

It adds three things:

  1. Compact timing rows in the transcript. Simple replies keep their model row. Multi-step runs default to one total with error count, slowest operation, tokens, and cost; failed operations stay visible inline. Expand a total with app.tools.expand (Ctrl+O by default) for a bounded breakdown by tool signature, combined duration, and slowest operations. Every individual record is still persisted.
  2. A live activity widget below the editor. While pi is busy, a one-line widget shows what is happening right now — the current model request, compaction, or up to three parallel tools, each with its running elapsed time — refreshed every 250 ms. It disappears when pi settles and never touches the footer.
  3. /timings. A picker over every record on the active branch, including collapsed child operations. Filter with tools, models, errors, or slow; pick a record (or use last / a number) to open its detail overlay with stream phases, exact usage, status, and timestamps.

Compact display is the default and needs no setup. Display and slow-filter preferences are stored in ~/.pi/agent/pi-display-runtimes.json and persist across sessions. Set PI_DISPLAY_RUNTIMES_CONFIG to use a different file.


Quick start

  1. Drop the package in ~/.pi/agent/extensions/pi-display-runtimes/ (pi auto-discovers extensions/*/index.ts) — or install it from your package sources with pi install.

  2. Send any prompt. Watch the rows appear under each assistant reply:

    ⏱ model 8.40s · ↑3.21k ↓812 R44.10k · $0.0237
    

    With tool use, successful child rows collapse into the run total:

    ⏱ total 24.31s · 3 model calls · 2 tools · ↑12.4k ↓3.1k R120k $0.0891
      0 errors · slowest: bash node --test 14.20s · ctrl+o for breakdown
    

    Failures remain visible above the total. Use /timings display verbose to restore the old one-row-per-model-and-tool transcript.

  3. Press Ctrl+O to expand a row into its detail view.

  4. Run /timings to browse every record, /timings tools for tool calls, /timings errors for failures, or /timings last for the newest record. Add last or a record number after a filter to open it directly.

Display modes and commands

Compact is the default. A simple model-only reply is unchanged. Once a run has multiple model calls, tools, or compaction, successful child rows are hidden and only its total remains, plus any error, aborted, or interrupted child rows. This is presentation-only: all records stay in the session and in /timings, on the active branch and after resume.

Verbose preserves the original behavior: one transcript row for every model request and tool call. Switch modes at any time; existing rows update.

/timings display compact       one run total plus failures
/timings display verbose       every operation
/timings                       all records, newest first
/timings tools [last|N]        tool records only
/timings models [last|N]       model requests only
/timings errors [last|N]       unsuccessful operations only
/timings slow [last|N]         model/tool records at or above the threshold
/timings threshold 5           set the slow threshold to 5 seconds
/timings threshold off         disable the slow filter

The default slow threshold is five seconds. The compact total always names the single slowest child; expansion lists the slowest three and up to eight tool groups. Use /timings for the complete chronological picker rather than expanding hundreds of operations into the chat.

How to read a timing row

⏱ model 8.40s · ↑3.21k ↓812 R44.10k · $0.0237
  • ⏱ marks a model-side row (model, total, compaction, branch summary, user response). Tool rows are deliberately unmarked and indented, so they are never mistaken for the model request around them.
  • 8.40s — wall-clock duration, two decimals, unit escalates automatically (s → m → h → d).
  • ↑ / ↓ — input / output tokens for that request.
  • R / W — prompt-cache reads / writes, shown when present.
  • $ — cost, as calculated by pi from provider usage and model pricing metadata (4 decimals; sub-$0.0001 costs render as <$0.0001).
  • A trailing word (error, aborted, interrupted) appears whenever the operation did not end cleanly.

Tool rows show the tool name and a preview of its primary argument (path, command, or pattern — collapsed to one line, capped at 50 characters, and only for tools whose argument key is known, so nothing sensitive leaks from unknown tools). A tool that makes its own nested model call and reports usage gets that usage on its row: nested LLM ↑100 ↓10 $0.0020.

A user-response row is written for each prompt you send while pi was idle:

⏱ replied after 3.27m

What gets measured

Row Kind When it is written
⏱ model … one assistant turn after each model request finalizes
tool … one tool execution, including nested calls after its result message, or at settlement for nested calls
⏱ total … whole agent request when a multi-step run settles
⏱ compaction … context compaction after each compaction
⏱ branch summary … branch summary after each /tree navigation that summarizes
⏱ replied after … user think-time when you submit after pi was idle

For each model request, the detail view additionally breaks the stream into phases, measured from the events pi receives:

  • First stream event — request start to the first event (the "time to first token" the provider actually exposes);
  • Thinking stream — total time covered by thinking_* events;
  • Text stream — time covered by text_* events;
  • Tool-call stream — time covered by toolcall_* events.

A multi-step request (several model calls and tool batches) records each child operation and adds a total row, so no single tool is blamed for time that belonged to the whole run. Its expanded breakdown groups tools by name and normalized primary argument, with count, combined duration, average, maximum, errors, and paid nested-model usage when present. Combined tool time is a sum of operation durations, not wall time, because parallel and nested calls can overlap.

Nested calls carry Pi's parentToolCallId. They roll into their calling tool and the run breakdown instead of appearing as a flood of top-level rows after the response. Parent details show descendant and error counts; all descendants remain individually inspectable through /timings tools.

The total's usage is the sum of every model call, every nested model call reported by tools, and compaction usage, with statuses merged by severity (interrupted > aborted > error > success).

What the numbers mean — and don't

  • Tokens are per-request, not per-phase. Providers report usage once per request, so phases have separate durations but share one token total.
  • A user message has no token estimate. The next request's input also contains system instructions, tools, and prior context; assigning it backward would be fiction, so the extension doesn't.
  • Durations come from a monotonic clock (performance.now), so NTP adjustments and clock skew cannot distort them; wall-clock timestamps are stored separately for display and resume.
  • Agent totals never double-count. Totals sum model, nested-tool, and compaction usage only; tool wall time lives on tool rows.

Persistence, resume, and the wait anchor

Every completed record is appended to the session as a custom operation-timing entry. These are TUI metadata: they render in the transcript, are fully branch-aware (/timings shows only the active branch), and never enter model context.

On resume, the renderer reconstructs the rows from the session file, and /timings works immediately.

User-wait tracking survives restarts too. When a run settles, the exact settlement time is recorded (a visible total row for multi-step runs, or a hidden operation-timing-wait-anchor entry for simple ones). Your next interactive prompt is measured from that moment — even if you sent it hours later, after closing pi. Anchors render as nothing.

Two caveats: an --no-session run cannot preserve records across processes, and an operation cut short by a hard kill is lost if it never finalized — already-written records stay durable. Graceful shutdowns (quit, /resume, /fork, Ctrl+C) finalize any in-flight operation as interrupted first.

Boundaries

The extension measures what pi exposes, nothing more:

  • startup time before extensions load is invisible;
  • provider-internal stages that emit no stream events are not measurable — the phases show when pi received events;
  • work inside uninstrumented third-party extensions is only visible if it reports usage through a tool result;
  • pi also renders its own native elapsed line for Bash; during the originating process you may see both. Pi's line belongs to the immediate Bash renderer; this extension's row is the consistent, persisted, expandable, branch-aware account.

Validation

From the package root:

npm test      # unit tests for the pure helpers (23 tests)
npm run smoke  # full lifecycle simulation with a fake clock:
              # multi-step runs, parallel tools, errors, interrupted
              # shutdown, restart reconstruction, compact/verbose
              # switching, nested-call settlement floods, filters,
              # preferences, /timings, widget
npm run check # strict type check against the installed pi types

Both test scripts run in plain Node — no TypeScript toolchain and no local node_modules needed. They load the extension through jiti, the same transform pi itself uses, aliasing the @earendil-works/* peer packages to the installed pi distribution, so they exercise the code exactly as pi runs it. The installed pi package is found via PI_CODING_AGENT_DIR, the directory tree above the scripts, or the global npm root.

Files

File Purpose
index.ts the extension: event wiring, record lifecycle, live widget, /timings
helpers.ts pure formatting, usage math, record schema, resume reconstruction — unit-testable without pi
scripts/test.mjs unit tests for helpers.ts
scripts/smoke.mjs lifecycle simulation over the real index.ts with a stubbed pi API
scripts/lib/load.mjs jiti-based module loader shared by both scripts