@tduyng/pi-cost 0.0.2 → 0.0.3
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 +41 -32
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,45 +1,56 @@
|
|
|
1
1
|
# @tduyng/pi-cost
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
What the session spent, what the provider still allows, and how long each message took. None of it enters the model's context.
|
|
4
4
|
|
|
5
|
-
## What it
|
|
5
|
+
## What it costs
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Zero tokens. No tool, no prompt text, no session entry. The footer segments and the timestamps are display only, and the panels read session files pi already wrote.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
The point is the bill you cannot see otherwise. A long session's spend is one command away instead of one surprise.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## /cost
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
A TUI panel with session spend in USD, token totals, provider rate-limit bars, and a per-provider token table.
|
|
14
14
|
|
|
15
|
-
The
|
|
16
|
-
Command Code shows the session 5h window, the weekly window, and remaining credits (monthly plus purchased plus free). Its section paints only when pi holds a Command Code credential in `auth.json`. Without one the probe returns nothing, the section drops, and its cached rows are deleted.
|
|
17
|
-
OpenCode Go shows the rolling window, weekly, and monthly.
|
|
18
|
-
Claude shows the 5h window and the weekly windows (all models, Opus, Sonnet) as percent bars. It reads the Claude Code login on this machine, and its section paints only when that login exists.
|
|
15
|
+
The panel fits the window: body at most 70% of the rows, each line truncated to the column width, and the header shows the range when the rest scrolls. Up and Down move a row, Page Up and Page Down a screen, Enter or Esc closes it.
|
|
19
16
|
|
|
20
|
-
|
|
17
|
+
An `Extensions` row appears when another extension spent a model call on this session's behalf, such as a `subagent` child or the `harness-loop` writer. Those calls bill to the same plan but cannot land in the parent's transcript, so each appends a line to `<agentDir>/overhead.jsonl` and the panel sums them for this session. The row names the cost, the tokens, the call count, and each extension's share. The `Cost` row stays what the conversation itself cost, so the two are read side by side and never added twice.
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
The token table groups by provider across four trailing windows: 5h, 7d, 30d, and calendar month. Input, output, cache read, and cache write are shown separately, then the total and the cost. A zero column collapses to a dot, and a provider with no tokens in any window is omitted. The cost is the `usage.cost.total` each turn recorded in its session file, so for a subscription provider such as `claude` it is the API-equivalent price rather than a charge.
|
|
23
20
|
|
|
24
|
-
|
|
25
|
-
`tps` shows average output tokens per second across the session.
|
|
26
|
-
`agents` shows the count of running subagent tasks.
|
|
27
|
-
`git` shows changed files and the PR number from `gh pr view`.
|
|
21
|
+
## Rate-limit windows
|
|
28
22
|
|
|
29
|
-
|
|
23
|
+
| Provider | Windows shown |
|
|
24
|
+
| --- | --- |
|
|
25
|
+
| Command Code | session 5h, weekly, remaining credits (monthly plus purchased plus free) |
|
|
26
|
+
| OpenCode Go | rolling, weekly, monthly |
|
|
27
|
+
| Claude | 5h, weekly all models, Opus, Sonnet, as percent bars |
|
|
30
28
|
|
|
31
|
-
|
|
29
|
+
A section paints only when the credential it needs is on the machine. Without one the probe returns nothing, the section drops, and its cached rows are deleted.
|
|
32
30
|
|
|
33
|
-
|
|
31
|
+
## Footer segments
|
|
34
32
|
|
|
35
|
-
|
|
33
|
+
Three extra segments in pi's native footer:
|
|
36
34
|
|
|
37
|
-
|
|
35
|
+
- `tps` is average output tokens per second across the session.
|
|
36
|
+
- `agents` is the count of running subagent tasks.
|
|
37
|
+
- `git` is changed files and the PR number from `gh pr view`.
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
-
|
|
42
|
-
|
|
39
|
+
Session spend and cache hit rate are left to pi's own footer, which already prints both.
|
|
40
|
+
|
|
41
|
+
`/statusline` toggles the segments, and `--statusline-no-pr` skips the `gh pr view` lookup. The git segment refreshes when a run settles and on a debounced watcher on `.git/HEAD` with a 250ms delay, so a branch switch paints at once and an idle session spawns nothing. A worktree that stores `.git` as a file is covered by the settle refresh.
|
|
42
|
+
|
|
43
|
+
## /timestamps
|
|
44
|
+
|
|
45
|
+
Toggles per-message clock markers in the transcript: time of day, a relative offset such as `3m ago`, and whether the entry is a user message, an AI response, or a tool call.
|
|
46
|
+
|
|
47
|
+
Markers are custom session entries, so they never enter model context and the cached prefix stays stable. Two same-role entries within a 2-second window are read as a duplicate from a double-loaded extension and suppressed.
|
|
48
|
+
|
|
49
|
+
## How it reads the bill
|
|
50
|
+
|
|
51
|
+
Token totals come from scanning session `.jsonl` files. A cache at `<agentDir>/cost-cache.json` stores parsed records keyed by file mtime and size, so reopening `/cost` skips unchanged files. Quota data is cached 24 hours, and files older than the scan window are skipped without a stat call.
|
|
52
|
+
|
|
53
|
+
Amounts under $0.01 print with four decimals, under $1 with three, and $1 or more with two. A model with no known pricing contributes zero, so the panel understates spend rather than guessing it.
|
|
43
54
|
|
|
44
55
|
## Install
|
|
45
56
|
|
|
@@ -51,11 +62,9 @@ Local checkout: `pi install /path/to/dotfiles/pi/agent/extensions/pi-cost`
|
|
|
51
62
|
|
|
52
63
|
## Configure
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
- `OPENCODE_API_KEY`: OpenCode Go API key.
|
|
65
|
+
`OPENCODE_API_KEY` is needed for the OpenCode Go windows.
|
|
57
66
|
|
|
58
|
-
`<agentDir>/cost.json` controls the
|
|
67
|
+
`<agentDir>/cost.json` controls the table and the sections. It is read each time `/cost` opens, and an invalid file is ignored with a warning. Every key is optional:
|
|
59
68
|
|
|
60
69
|
```json
|
|
61
70
|
{
|
|
@@ -65,6 +74,6 @@ Environment variables:
|
|
|
65
74
|
}
|
|
66
75
|
```
|
|
67
76
|
|
|
68
|
-
- `providers
|
|
69
|
-
- `cost
|
|
70
|
-
- `limits
|
|
77
|
+
- `providers` lists the providers shown in the token table. Omit it to show every provider except `gmi`, `mistral`, `google`, `claude-bridge`, and `commandcode`, which are hidden unless named.
|
|
78
|
+
- `cost` lists the providers whose cost cell is filled. Omit it to fill every shown provider.
|
|
79
|
+
- `limits` lists the rate-limit sections to fetch by provider id. Omit it to show every section with a credential.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tduyng/pi-cost",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Session spend, live
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Session spend, live rate-limit windows, footer segments, and per-message timestamps. Display only, never in the model context.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi",
|
|
7
7
|
"pi-package",
|