Skip to content

Commit 907f4ba

Browse files
feat: pi agent integration (#760)
Co-authored-by: ryoppippi <[email protected]>
1 parent ed50ca9 commit 907f4ba

File tree

20 files changed

+3924
-1930
lines changed

20 files changed

+3924
-1930
lines changed

apps/pi/CLAUDE.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# CLAUDE.md - Pi Package
2+
3+
This package provides unified usage tracking across Claude Code and pi-agent.
4+
5+
## Package Overview
6+
7+
**Name**: `@ccusage/pi`
8+
**Description**: Pi-agent usage tracking - unified Claude Max usage across Claude Code and pi-agent
9+
**Type**: CLI tool with TypeScript exports
10+
11+
## Development Commands
12+
13+
**Testing and Quality:**
14+
15+
- `pnpm run test` - Run all tests using vitest
16+
- `pnpm run lint` - Lint code using ESLint
17+
- `pnpm run format` - Format and auto-fix code with ESLint
18+
- `pnpm typecheck` - Type check with TypeScript
19+
20+
**Build and Release:**
21+
22+
- `pnpm run build` - Build distribution files with tsdown
23+
- `pnpm run prerelease` - Full release workflow (lint + typecheck + build)
24+
25+
## Usage
26+
27+
```bash
28+
# Show daily combined usage (Claude Code + pi-agent)
29+
ccusage-pi daily
30+
31+
# Show monthly combined usage
32+
ccusage-pi monthly
33+
34+
# Show session-based usage
35+
ccusage-pi session
36+
37+
# JSON output
38+
ccusage-pi daily --json
39+
40+
# Custom pi-agent path
41+
ccusage-pi daily --pi-path /path/to/sessions
42+
```
43+
44+
## Architecture
45+
46+
This package combines usage data from two sources:
47+
48+
**Data Sources:**
49+
50+
- **Claude Code**: `~/.claude/projects/` or `~/.config/claude/projects/`
51+
- **Pi-agent**: `~/.pi/agent/sessions/`
52+
53+
**Key Modules:**
54+
55+
- `src/index.ts` - CLI entry point with Gunshi-based command routing
56+
- `src/data-loader.ts` - Loads and aggregates pi-agent JSONL data
57+
- `src/_pi-agent.ts` - Pi-agent data parsing and transformation
58+
- `src/commands/` - CLI subcommands (daily, monthly, session)
59+
60+
**Output Labels:**
61+
62+
- `[cc]` - Claude Code entries
63+
- `[pi]` - Pi-agent entries
64+
65+
## Dependencies
66+
67+
**Key Runtime Dependencies:**
68+
69+
- `ccusage` - Main ccusage package (workspace dependency)
70+
- `@ccusage/terminal` - Shared terminal utilities
71+
- `gunshi` - CLI framework
72+
- `valibot` - Schema validation
73+
- `tinyglobby` - File globbing
74+
75+
**Key Dev Dependencies:**
76+
77+
- `vitest` - Testing framework
78+
- `tsdown` - TypeScript build tool
79+
- `eslint` - Linting and formatting
80+
- `fs-fixture` - Test fixture creation
81+
82+
## Testing
83+
84+
- **In-Source Testing**: Uses the same testing pattern as the main package
85+
- **Vitest Globals Enabled**: Use `describe`, `it`, `expect` directly without imports
86+
- **Mock Data**: Uses `fs-fixture` for testing data loading functionality
87+
- **CRITICAL**: NEVER use `await import()` dynamic imports anywhere
88+
89+
## Code Style
90+
91+
Follow the same code style guidelines as the main ccusage package:
92+
93+
- **Error Handling**: Prefer `@praha/byethrow Result` type over try-catch
94+
- **Imports**: Use `.ts` extensions for local imports
95+
- **Exports**: Only export what's actually used
96+
- **Dependencies**: Add as `devDependencies` unless explicitly requested
97+
98+
**Post-Change Workflow:**
99+
Always run these commands in parallel after code changes:
100+
101+
- `pnpm run format` - Auto-fix and format
102+
- `pnpm typecheck` - Type checking
103+
- `pnpm run test` - Run tests
104+
105+
## Environment Variables
106+
107+
| Variable | Description |
108+
| ------------------- | ---------------------------------------------- |
109+
| `PI_AGENT_DIR` | Custom path to pi-agent sessions directory |
110+
| `CLAUDE_CONFIG_DIR` | Custom path(s) to Claude Code data directories |
111+
| `LOG_LEVEL` | Adjust logging verbosity (0 silent … 5 trace) |
112+
113+
## Package Exports
114+
115+
The package provides the following exports:
116+
117+
- `.` - Main CLI entry point
118+
119+
## Binary
120+
121+
The package includes a binary `ccusage-pi` that can be used to run the CLI from the command line.

apps/pi/README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# @ccusage/pi
2+
3+
Pi-agent usage tracking for ccusage - unified Claude Max usage across Claude Code and pi-agent.
4+
5+
## Installation
6+
7+
```bash
8+
# Using npm
9+
npm install -g @ccusage/pi
10+
11+
# Using pnpm
12+
pnpm add -g @ccusage/pi
13+
14+
# Or run directly with npx
15+
npx @ccusage/pi daily
16+
```
17+
18+
## Usage
19+
20+
```bash
21+
# Show daily combined usage (Claude Code + pi-agent)
22+
ccusage-pi daily
23+
24+
# Show monthly combined usage
25+
ccusage-pi monthly
26+
27+
# Show session-based usage
28+
ccusage-pi session
29+
30+
# JSON output
31+
ccusage-pi daily --json
32+
33+
# Custom pi-agent path
34+
ccusage-pi daily --pi-path /path/to/sessions
35+
36+
# Filter by date range
37+
ccusage-pi daily --since 2025-12-01 --until 2025-12-19
38+
```
39+
40+
## What is pi-agent?
41+
42+
[Pi-agent](https://github.com/badlogic/pi-mono) is an alternative Claude coding agent from [shittycodingagent.ai](https://shittycodingagent.ai). It stores usage data in a similar JSONL format to Claude Code but in a different directory structure.
43+
44+
## How it works
45+
46+
This package combines usage data from:
47+
48+
- **Claude Code**: `~/.claude/projects/` or `~/.config/claude/projects/`
49+
- **Pi-agent**: `~/.pi/agent/sessions/`
50+
51+
Reports show data from both sources with labels:
52+
53+
- `[cc]` - Claude Code
54+
- `[pi]` - Pi-agent
55+
56+
## Environment Variables
57+
58+
- `PI_AGENT_DIR` - Custom path to pi-agent sessions directory
59+
60+
## Related
61+
62+
- [ccusage](https://github.com/ryoppippi/ccusage) - Usage analysis tool for Claude Code

apps/pi/eslint.config.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ryoppippi } from '@ryoppippi/eslint-config';
2+
3+
/** @type {import('eslint').Linter.FlatConfig[]} */
4+
const config = ryoppippi({
5+
type: 'app',
6+
}, {
7+
rules: {
8+
'test/no-importing-vitest-globals': 'error',
9+
},
10+
});
11+
12+
export default config;

apps/pi/package.json

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
{
2+
"name": "@ccusage/pi",
3+
"type": "module",
4+
"version": "17.2.0",
5+
"description": "Pi-agent usage tracking - unified Claude Max usage across Claude Code and pi-agent",
6+
"author": "ryoppippi",
7+
"contributors": [
8+
"nicobailon"
9+
],
10+
"license": "MIT",
11+
"funding": "https://github.com/ryoppippi/ccusage?sponsor=1",
12+
"homepage": "https://github.com/ryoppippi/ccusage#readme",
13+
"repository": {
14+
"type": "git",
15+
"url": "git+https://github.com/ryoppippi/ccusage.git"
16+
},
17+
"bugs": {
18+
"url": "https://github.com/ryoppippi/ccusage/issues"
19+
},
20+
"exports": {
21+
".": "./src/index.ts",
22+
"./package.json": "./package.json"
23+
},
24+
"main": "./dist/index.js",
25+
"module": "./dist/index.js",
26+
"types": "./dist/index.d.ts",
27+
"bin": {
28+
"ccusage-pi": "./src/index.ts"
29+
},
30+
"files": [
31+
"README.md",
32+
"dist"
33+
],
34+
"engines": {
35+
"node": ">=20.19.4"
36+
},
37+
"scripts": {
38+
"build": "tsdown",
39+
"dev": "bun -b --watch ./src/index.ts",
40+
"format": "pnpm run lint --fix",
41+
"lint": "eslint --cache .",
42+
"prepack": "pnpm run build && clean-pkg-json",
43+
"prerelease": "pnpm run lint && pnpm run typecheck && pnpm run build",
44+
"start": "bun ./src/index.ts",
45+
"test": "TZ=UTC vitest",
46+
"typecheck": "tsgo --noEmit"
47+
},
48+
"devDependencies": {
49+
"@ccusage/internal": "workspace:*",
50+
"@ccusage/terminal": "workspace:*",
51+
"@praha/byethrow": "catalog:runtime",
52+
"@ryoppippi/eslint-config": "catalog:lint",
53+
"@typescript/native-preview": "catalog:types",
54+
"ccusage": "workspace:*",
55+
"clean-pkg-json": "catalog:release",
56+
"es-toolkit": "catalog:runtime",
57+
"eslint": "catalog:lint",
58+
"fs-fixture": "catalog:testing",
59+
"gunshi": "catalog:runtime",
60+
"path-type": "catalog:runtime",
61+
"picocolors": "catalog:runtime",
62+
"publint": "catalog:lint",
63+
"sort-package-json": "catalog:release",
64+
"tinyglobby": "catalog:runtime",
65+
"tsdown": "catalog:build",
66+
"valibot": "catalog:runtime",
67+
"vitest": "catalog:testing"
68+
},
69+
"publishConfig": {
70+
"bin": {
71+
"ccusage-pi": "./dist/index.js"
72+
},
73+
"exports": {
74+
".": "./dist/index.js",
75+
"./package.json": "./package.json"
76+
}
77+
},
78+
"devEngines": {
79+
"runtime": [
80+
{
81+
"name": "node",
82+
"onFail": "download",
83+
"version": "^24.11.0"
84+
},
85+
{
86+
"name": "bun",
87+
"onFail": "download",
88+
"version": "^1.3.2"
89+
}
90+
]
91+
}
92+
}

apps/pi/src/_consts.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { homedir } from 'node:os';
2+
import path from 'node:path';
3+
4+
export const USER_HOME_DIR = homedir();
5+
6+
export const PI_AGENT_DIR_ENV = 'PI_AGENT_DIR';
7+
export const PI_AGENT_SESSIONS_DIR_NAME = 'sessions';
8+
export const DEFAULT_PI_AGENT_PATH = path.join('.pi', 'agent');

0 commit comments

Comments
 (0)