Skip to content

feat(ccusage): support comma-separated agent paths#1011

Merged
ryoppippi merged 5 commits into
mainfrom
codex/multi-agent-comma-paths
May 17, 2026
Merged

feat(ccusage): support comma-separated agent paths#1011
ryoppippi merged 5 commits into
mainfrom
codex/multi-agent-comma-paths

Conversation

@ryoppippi
Copy link
Copy Markdown
Owner

@ryoppippi ryoppippi commented May 17, 2026

Summary

  • support comma-separated CODEX_HOME, OPENCODE_DATA_DIR, AMP_DATA_DIR, PI_AGENT_DIR, and --pi-path values
  • aggregate Codex, OpenCode, Amp, and pi-agent usage across all valid directories
  • regenerate config schema so piPath documents comma-separated directories

Verification

  • pnpm run format
  • pnpm typecheck
  • pnpm run test

Summary by cubic

Adds comma-separated directory support for Codex, OpenCode, Amp, and pi-agent, aggregating usage across all valid paths while keeping single-directory defaults. Docs and help are updated; Codex fast-tier auto-detection checks all CODEX_HOME roots; OpenCode DB messages are deduplicated across roots.

  • New Features

    • Accepts comma-separated values for CODEX_HOME, OPENCODE_DATA_DIR, AMP_DATA_DIR, PI_AGENT_DIR, and --pi-path.
    • Aggregates sessions/messages/threads across all valid directories; detection scans each root.
    • Codex speed auto reads config.toml from every CODEX_HOME when --speed auto.
    • Adds a shared path-list utility to parse lists, de-duplicate, and filter existing directories; updates CLI help, config schema, and guides with examples.
  • Bug Fixes

    • Deduplicates OpenCode DB messages by id across multiple OPENCODE_DATA_DIR roots.

Written for commit 7a3d29f. Summary will update on new commits. Review in cubic

Summary by CodeRabbit

  • New Features

    • Support for comma-separated data/session directory paths across AMP, Codex, OpenCode and PI sources — multiple directories are discovered, aggregated and deduplicated.
  • Documentation

    • Updated config schema descriptions, CLI help text and guides to show path fields accept a single path or comma-separated list; examples updated.
  • Tests

    • Added unit tests covering multi-directory behavior across all affected sources.

Review Change Stack

Add shared path-list parsing so Codex, OpenCode, Amp, and pi-agent can read usage data from comma-separated directory lists. This aligns the newer agent adapters with Claude path handling while preserving the existing single-directory defaults.

Codex now aggregates all CODEX_HOME session roots and checks each home for fast pricing config. OpenCode and Amp discover files across all valid data roots, and pi-agent accepts comma-separated --pi-path and PI_AGENT_DIR values.

Regenerate the config schema so piPath autocomplete documents comma-separated session directories.
@ryoppippi
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9f2321d6-ed67-4a97-9726-80fe87ea6d95

📥 Commits

Reviewing files that changed from the base of the PR and between 79aea50 and 7a3d29f.

📒 Files selected for processing (1)
  • apps/ccusage/README.md
✅ Files skipped from review due to trivial changes (1)
  • apps/ccusage/README.md

📝 Walkthrough

Walkthrough

Adapters (AMP, Codex, OpenCode, PI-Agent) now accept comma-separated data-directory inputs, discover multiple existing directories, and aggregate usage/events across them. A new path-list utility normalizes and filters path lists; CLI, schema, README, and guides updated to document comma-separated inputs.

Changes

Multi-directory path support across adapters

Layer / File(s) Summary
Path list utilities
src/adapter/path-list.ts
normalizePathList parses comma-separated inputs with trimming, fallback, absolute resolution, and deduplication. getExistingDirectories filters to existing dirs.
AMP multi-directory support
src/adapter/amp/paths.ts, src/adapter/amp/parser.ts, tests/amp/*
getAmpPaths() returns existing AMP dirs from AMP_DATA_DIR (comma-separated). discoverAmpThreadFiles()/detectAmpThreadFiles() scan all returned paths. Tests cover comma-separated AMP_DATA_DIR.
Codex multi-directory support
src/adapter/codex/paths.ts, src/adapter/codex/pricing.ts, src/adapter/codex/parser.ts, tests/codex/*
Adds getCodexHomePaths()/getCodexSessionsPaths() via normalizePathList; extracts per-directory loader, aggregates/sorts events across all sessions dirs; resolveCodexSpeed() scans configs under all homes. Tests added for multi-dir behavior.
OpenCode multi-directory support
src/adapter/opencode/paths.ts, src/adapter/opencode/index.ts, src/adapter/opencode/loader.ts, tests/opencode/*
getOpenCodePaths() returns existing dirs from OPENCODE_DATA_DIR; detectOpenCode runs checks in parallel; loader aggregates across paths with a shared dedup set. Tests verify combined results from comma-separated dirs.
PI-Agent multi-directory support
src/adapter/pi/paths.ts, src/adapter/pi/parser.ts, tests/pi/*
getPiAgentPaths() normalizes comma-separated PI_AGENT_DIR or explicit customPath lists and returns existing session directories. Parser tests validate loading from multiple explicit session dirs.
Documentation and CLI help
config-schema.json, src/commands/agent.ts, README.md, docs/guide/*
piPath descriptions, CLI help, README examples, and multiple guides updated to state support for single or comma-separated data directory lists and show examples.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through paths, one, two, and three,
Comma crumbs led the way for me,
Adapters learned to seek and fold,
Gathering logs from new-old gold,
A tidy trail of folders free!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(ccusage): support comma-separated agent paths' accurately captures the main change across all modified files—adding support for comma-separated directory paths for multiple agent data sources (Codex, OpenCode, Amp, Pi-agent).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/multi-agent-comma-paths

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 17, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ccusage-guide 7a3d29f Commit Preview URL

Branch Preview URL
May 17 2026, 01:34 AM

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 17, 2026

Open in StackBlitz

@ccusage/amp

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/amp@1011

ccusage

npx https://pkg.pr.new/ryoppippi/ccusage@1011

@ccusage/codex

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/codex@1011

@ccusage/opencode

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/opencode@1011

@ccusage/pi

npx https://pkg.pr.new/ryoppippi/ccusage/@ccusage/pi@1011

commit: 7a3d29f

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 17, 2026

ccusage performance comparison

This compares the PR build against the base branch build on the same CI runner.

Committed fixture performance

Committed small fixtures for stable PR-to-PR feedback and explicit Claude/Codex command coverage.

Fixtures: Claude apps/ccusage/test/fixtures/claude (0.00 MiB, 2 files), Codex apps/ccusage/test/fixtures/codex (0.00 MiB, 1 files)
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 2 warmups and 7 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude daily --offline --json 0.00 MiB 55.3ms 56.0ms 0.99x 0.03 MiB/s 0.03 MiB/s
claude session --offline --json 0.00 MiB 56.0ms 56.0ms 1.00x 0.03 MiB/s 0.03 MiB/s
codex daily --offline --json 0.00 MiB 55.2ms 55.4ms 1.00x 0.02 MiB/s 0.02 MiB/s
codex session --offline --json 0.00 MiB 55.7ms 55.4ms 1.01x 0.02 MiB/s 0.02 MiB/s

Large real-world-shaped fixture performance

Generated fixtures shaped from aggregate local log statistics: thousands of JSONL files, many small sessions, and a long tail of larger sessions. No real prompts, paths, or outputs are stored in the fixtures.

Fixtures: Claude /home/runner/work/_temp/ccusage-large-fixture (1.01 GiB, 2,597 files), Codex /home/runner/work/_temp/ccusage-large-codex-fixture (1.01 GiB, 2,597 files)
Runtime: package ccusage bin from apps/ccusage/package.json through bun -b, --offline --json, measured by hyperfine with 0 warmups and 1 runs.

Command Input Base median PR median PR vs base Base throughput PR throughput
claude --offline --json 1.01 GiB 1.435s 1.435s 1.00x 718.18 MiB/s 718.64 MiB/s
codex --offline --json 1.01 GiB 1.501s 1.569s 0.96x 686.74 MiB/s 657.07 MiB/s

Package size

Package artifact Base PR Delta Ratio
packed ccusage-*.tgz 67.74 KiB 67.75 KiB +0.01 KiB 1.00x

Lower medians and smaller packed package sizes are better. CI runner noise still applies; use same-run ratios as directional PR feedback, not release guarantees.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/ccusage/src/adapter/opencode/loader.ts`:
- Around line 190-196: The loop over openCodePaths currently pushes all
dbMessages.entries regardless of prior seenIds, causing duplicates; update the
logic in the for (const openCodePath of openCodePaths) loop that calls
loadOpenCodeMessagesFromDb to filter dbMessages.entries by whether their id is
already in the seenIds Set before appending to entries, and for each appended
entry add its id to seenIds (or otherwise merge dbMessages.seenIds only for
newly appended ids) so duplicates across roots are not double-counted.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bc27b3ab-fefc-4241-96a5-1863f7acd26d

📥 Commits

Reviewing files that changed from the base of the PR and between ba991b9 and eb64b8d.

📒 Files selected for processing (13)
  • apps/ccusage/config-schema.json
  • apps/ccusage/src/adapter/amp/parser.ts
  • apps/ccusage/src/adapter/amp/paths.ts
  • apps/ccusage/src/adapter/codex/parser.ts
  • apps/ccusage/src/adapter/codex/paths.ts
  • apps/ccusage/src/adapter/codex/pricing.ts
  • apps/ccusage/src/adapter/opencode/index.ts
  • apps/ccusage/src/adapter/opencode/loader.ts
  • apps/ccusage/src/adapter/opencode/paths.ts
  • apps/ccusage/src/adapter/path-list.ts
  • apps/ccusage/src/adapter/pi/parser.ts
  • apps/ccusage/src/adapter/pi/paths.ts
  • apps/ccusage/src/commands/agent.ts

Comment thread apps/ccusage/src/adapter/opencode/loader.ts
ryoppippi added 4 commits May 17, 2026 02:19
Filter OpenCode DB records by message id before appending them to the aggregated result. This prevents repeated database rows from multiple OPENCODE_DATA_DIR roots from being counted twice.

Add a SQLite-backed regression test that creates two OpenCode roots with the same message id and confirms only one usage entry is returned.
Document comma-separated data directory support for Codex, OpenCode, Amp, and pi-agent after the source-focused documentation restructure from main.

The docs now show environment variable examples for multiple roots, note Codex speed auto detection across CODEX_HOME roots, and describe piPath support in the JSON config schema.
Remove a duplicated comma-separated pi-agent path example from the package README after adding the docs coverage.
@ryoppippi ryoppippi merged commit 6e96ff7 into main May 17, 2026
24 checks passed
@ryoppippi ryoppippi deleted the codex/multi-agent-comma-paths branch May 17, 2026 01:40
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.

1 participant