Skip to content

feat: add Pi provider for tracking Pi agent sessions#45

Closed
acennan wants to merge 1 commit intogetagentseal:mainfrom
acennan:add-provider-for-pi
Closed

feat: add Pi provider for tracking Pi agent sessions#45
acennan wants to merge 1 commit intogetagentseal:mainfrom
acennan:add-provider-for-pi

Conversation

@acennan
Copy link
Copy Markdown
Contributor

@acennan acennan commented Apr 15, 2026

Summary

  • Adds support for Pi (pi.ai) as a new session provider.
  • Pi sessions are stored as JSONL files under ~/.pi/agent/sessions/<project-dir>/ and use OpenAI-compatible model IDs (gpt-5, gpt-5.4, gpt-4o, etc.).

Changes

  • src/providers/pi.ts (new): Pi provider - discovers JSONL session files, parses assistant turns, extracts token counts, tool calls, and bash commands, deduplicates via response ID with line-index fallback
  • src/providers/types.ts: added bashCommands field to ParsedProviderCall so all providers carry extracted bash command lists
  • src/providers/index.ts: registered Pi as a core provider alongside Claude and Codex
  • src/providers/codex.ts, cursor.ts: added bashCommands: [] to satisfy the new required field on ParsedProviderCall
  • src/parser.ts: fixed bug where providerCallToTurn always emitted an empty bashCommands array instead of passing through the parsed commands
  • src/classifier.ts: added lowercase tool name variants (bash, edit, read, write) to match Pi's tool naming convention in JSONL output
  • src/bash-utils.ts: exclude true, false, and shell variable assignments from extracted commands; scan past leading NAME=val tokens so FOO=bar ls correctly records ls rather than being dropped
  • package.json: added pi to keywords
  • tests/providers/pi.test.ts (new): 16 unit tests covering session discovery, multi-turn parsing, tool/bash extraction, deduplication, zero-token filtering, and display name mapping
  • tests/provider-registry.test.ts: updated core provider list to include pi

Testing

  • Unit tests pass (npx vitest run, 56 tests across 6 files);
  • Manually verified via npx tsx src/cli.ts report and showing Pi sessions alongside Claude and Codex in the dashboard.

- Adds support for Pi (pi.ai) as a new session provider.
- Pi sessions are stored as JSONL files under `~/.pi/agent/sessions/<project-dir>/` and use OpenAI-compatible model IDs (gpt-5, gpt-5.4, gpt-4o, etc.).

- `src/providers/pi.ts` (new): Pi provider - discovers JSONL session files, parses assistant turns, extracts token counts, tool calls, and bash commands, deduplicates via response ID with line-index fallback
- `src/providers/types.ts`: added bashCommands field to `ParsedProviderCall` so all providers carry extracted bash command lists
- `src/providers/index.ts`: registered Pi as a core provider alongside Claude and Codex
- `src/providers/codex.ts`, `cursor.ts`: added `bashCommands: []` to satisfy the new required field on `ParsedProviderCall`
- `src/parser.ts`: fixed bug where `providerCallToTurn` always emitted an empty bashCommands array instead of passing through the parsed commands
- `src/classifier.ts`: added lowercase tool name variants (bash, edit, read, write) to match Pi's tool naming convention in JSONL output
- `src/bash-utils.ts`: exclude `true`, `false`, and shell variable assignments from extracted commands; scan past leading `NAME=val` tokens so `FOO=bar ls` correctly records `ls` rather than being dropped
- `package.json`: added pi to keywords
- `tests/providers/pi.test.ts` (new): 16 unit tests covering session discovery, multi-turn parsing, tool/bash extraction, deduplication, zero-token filtering, and display name mapping
- `tests/provider-registry.test.ts`: updated core provider list to include pi

- [X] Unit tests pass (`npx vitest run`, 56 tests across 6 files);
- [X] Manually verified via `npx tsx src/cli.ts` report and showing Pi sessions alongside Claude and Codex in the dashboard.
@AgentSeal
Copy link
Copy Markdown
Collaborator

Hey @acennan, this is really solid work. Clean code, good test coverage, and you clearly studied the existing providers. Closest to merge-ready of any PR we've reviewed today.

A few things to address:

Rebase onto current main

We merged an OpenCode provider and the bashCommands type addition in v0.5.1 since you branched. Your changes to types.ts, parser.ts, codex.ts, and cursor.ts are now duplicates of what's already on main. Rebase onto main and drop those -- only pi.ts, pi.test.ts, index.ts, package.json, classifier.ts, bash-utils.ts, and provider-registry.test.ts need your changes.

Also drop the package-lock.json changes -- the "peer": true additions are lockfile artifacts from a different npm version.

Normalize tool names in the provider

Right now Pi yields lowercase tool names (read, edit, bash) and toolDisplayName returns them as-is. Every other provider normalizes to capitalized names (Read, Edit, Bash). Add a toolNameMap in pi.ts like OpenCode and Codex do:

const toolNameMap: Record<string, string> = {
  bash: 'Bash',
  read: 'Read',
  edit: 'Edit',
  write: 'Write',
  glob: 'Glob',
  grep: 'Grep',
}

Map tool names through it in the parser and in toolDisplayName. This keeps the dashboard consistent across providers.

Drop the classifier.ts changes

The lowercase additions to EDIT_TOOLS, READ_TOOLS, BASH_TOOLS are a workaround for not normalizing tool names. Once you add the toolNameMap above, the classifier works without modification since it already handles the capitalized names.

bash-utils.ts improvements are welcome

The true/false filtering and FOO=bar env prefix handling are legit improvements. Keep those. Just make sure the existing bash-commands tests still pass after your changes (npx vitest run tests/bash-commands.test.ts).

Registry test

The provider-registry test now expects ['claude', 'codex'] as core providers (with cursor and opencode lazy-loaded). If Pi stays as a core provider (reasonable since it's JSONL, no native deps), update the assertion to ['claude', 'codex', 'pi'].

That's it. The parsing logic, test fixtures, dedup strategy, and session discovery are all good. Looking forward to the updated PR.

@AgentSeal
Copy link
Copy Markdown
Collaborator

One more thing -- once you've applied the changes, please run npx codeburn report --provider pi and post a screenshot in the PR. We don't have Pi data locally to verify end-to-end, so seeing it work with real sessions would help us merge faster.

Copilot AI added a commit to tuchg/codeburn-rs that referenced this pull request Apr 16, 2026
…, upstream test cases

- Add thiserror 2.0 + anyhow 1.0 + rayon 1.12 to Cargo.toml
- Add Period enum (Week/Today/Days30/Month/All) with clap::ValueEnum to types.rs
- Add ProviderKind enum (Claude/Codex/Cursor/Opencode/Gemini/Copilot/Pi) with clap::ValueEnum to types.rs
- Add codeburn::Error type with thiserror in lib.rs
- Rewrite main.rs to use Period and ProviderKind enums throughout
- Add Send+Sync bounds to Provider trait and all provider boxes
- Use rayon::par_iter to parallelize non-Claude provider parsing in discover_and_parse
- Add lowercase 'bash' to BASH_TOOL_NAMES (matches Pi provider tool names)
- Add lowercase 'edit','write','read','grep','glob' to classifier tool lists
- Add 17 new provider_test.rs tests ported from upstream PRs getagentseal#41/getagentseal#44/getagentseal#45:
  Pi: multi-project discovery, zero-token skip, multi-turn, bash extraction, dedup
  Copilot: model-change tracking, zero-token skip, dedup, tool display names, missing file
  Gemini: multi-message session, plain-string user message
  Types: Period enum values, ProviderKind::as_str, ProviderKind CLI parsing
- Fix tempdir() in provider_test.rs to use atomic counter (unique per test)
- 102 tests total (36 unit + 17 integration + 49 provider), all passing
- cargo clippy -- -D warnings: clean

Agent-Logs-Url: https://github.com/tuchg/codeburn-rs/sessions/c9f2c300-e57c-487e-a117-10a592eee4c1

Co-authored-by: tuchg <24775733+tuchg@users.noreply.github.com>
@AgentSeal
Copy link
Copy Markdown
Collaborator

Hey @acennan, merged your Pi provider to main. Your original commit (7ac512a) is preserved with your authorship intact.

We added a few follow-ups on top:

  • Normalized Pi's lowercase tool names via a toolNameMap so they match the rest of the dashboard (bash -> Bash, dispatch_agent -> Agent, etc.). This let us drop the lowercase additions to classifier.ts.
  • Hoisted the model display sort out of the per-call function.
  • Added bash-utils tests for the env-var prefix and true/false skip behaviors you introduced.
  • Added Pi to PROVIDER_COLORS, PROVIDER_DISPLAY_NAMES, and the README.

Verified the cost math against your real Pi session data on our system: input + cacheRead + cacheWrite + output exactly equals totalTokens, confirming Anthropic-style accounting. No double-counting.

Three review agents (code quality, regression, end-to-end) ran on separate sessions before merge. All clean. 93 tests pass.

Will ship in the next npm release. Thanks for the contribution.

@AgentSeal AgentSeal closed this Apr 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants