@luxass/pi-cost-explorer 0.2.0 → 0.2.2

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
@@ -11,7 +11,7 @@ pi install npm:@luxass/pi-cost-explorer
11
11
  To try the extension from this checkout:
12
12
 
13
13
  ```sh
14
- pi -e ./packages/pi-cost-explorer
14
+ pi -e ./packages/pi/cost-explorer
15
15
  ```
16
16
 
17
17
  ## Use
@@ -26,7 +26,7 @@ Run `/cost` in Pi's terminal interface. The dialog has five tabs:
26
26
 
27
27
  The totals use the same sources as Pi's `/session` command: model responses, usage that tools report for their own model calls, background usage such as cache warming, and compaction and branch summaries.
28
28
 
29
- If you use `@luxass/pi-subagents`, the totals also include what its agents cost, as the source "Agents". Each agent run is one row, with its own model. Pi's `/session` command and the cost in Pi's footer do not include agents, so the total here is higher than theirs by that amount. The Overview says how much went to agents.
29
+ If you use `@luxass/pi-subagents`, the totals include its runs under "Agents". Each run has one row with its model. Runs saved with `pi.appendUsage()` also count in Pi's footer and `/session`. Runs saved in the older format count in `/cost` but not in Pi's totals.
30
30
 
31
31
  A Pi session branches when you go back to an earlier message and continue from there. These session branches are not Git branches. By default the dialog covers every session branch, and rows from other branches are dimmed. Press `b` to show only the current branch. While the dialog is open, it refreshes after each turn.
32
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxass/pi-cost-explorer",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "Explore a Pi session's cost by model, prompt, tool, and request in a tabbed dialog.",
5
5
  "keywords": [
6
6
  "cost",
@@ -14,7 +14,7 @@
14
14
  "repository": {
15
15
  "type": "git",
16
16
  "url": "https://github.com/luxass/agent-extensions",
17
- "directory": "packages/pi-cost-explorer"
17
+ "directory": "packages/pi/cost-explorer"
18
18
  },
19
19
  "files": [
20
20
  "src",
@@ -34,7 +34,7 @@
34
34
  "@earendil-works/pi-tui": "*"
35
35
  },
36
36
  "pi": {
37
- "image": "https://raw.githubusercontent.com/luxass/agent-extensions/main/packages/pi-cost-explorer/docs/cover.png",
37
+ "image": "https://raw.githubusercontent.com/luxass/agent-extensions/main/packages/pi/cost-explorer/docs/cover.png",
38
38
  "extensions": [
39
39
  "./src/index.ts"
40
40
  ]
@@ -44,6 +44,7 @@
44
44
  "lint:fix": "oxlint --fix .",
45
45
  "fmt": "oxfmt .",
46
46
  "fmt:check": "oxfmt --check .",
47
- "typecheck": "tsc -p tsconfig.json"
47
+ "typecheck": "tsc -p tsconfig.json",
48
+ "test": "node --test \"test/**/*.test.ts\""
48
49
  }
49
50
  }
package/src/analysis.ts CHANGED
@@ -160,9 +160,10 @@ function toolCallNames(message: AssistantMessage): string[] {
160
160
  }
161
161
 
162
162
  /**
163
- * Custom entry type that @luxass/pi-subagents writes once for each agent run. The agent's model
164
- * requests are saved in the agent's own session, so this entry is how they reach this session.
163
+ * Native usage kind and legacy custom entry type written by @luxass/pi-subagents.
164
+ * Each run uses one format, depending on which Pi APIs are available.
165
165
  */
166
+ const SUBAGENT_USAGE_KIND = "pi-subagents";
166
167
  const SUBAGENT_USAGE_ENTRY_TYPE = "subagents-usage";
167
168
 
168
169
  /**
@@ -182,7 +183,7 @@ interface SubagentUsageEntryData {
182
183
  *
183
184
  * Accounting follows Pi's `/session` totals: assistant messages, tool results with
184
185
  * nested usage, usage entries, and compaction or branch summaries that report usage.
185
- * Agent runs saved by @luxass/pi-subagents are added on top, as their own source.
186
+ * Agent runs from both native usage and legacy custom entries appear under Agents.
186
187
  */
187
188
  export function analyze(
188
189
  entries: readonly SessionEntry[],
@@ -257,10 +258,11 @@ export function analyze(
257
258
  turnOf.set(entry.id, parentTurn);
258
259
  const base = { entryId: entry.id, timestamp, turnId: parentTurn, toolCalls: [], onBranch };
259
260
  if (entry.type === "usage") {
261
+ const isSubagent = entry.kind === SUBAGENT_USAGE_KIND;
260
262
  addRecord({
261
263
  ...base,
262
- source: "usage",
263
- label: entry.kind,
264
+ source: isSubagent ? "agent" : "usage",
265
+ label: isSubagent ? (entry.note ?? entry.kind) : entry.kind,
264
266
  provider: entry.provider,
265
267
  model: entry.model,
266
268
  usage: entry.usage,