feat(providers): capture user prompts from Pi and Codex#117
Conversation
Before this change only Claude Code surfaced captured prompts to the
Receipts feature, so non-Claude users saw an empty receipt no matter
how much they spent. Extend prompt capture to two more providers.
Shared
- Hoist the 2_000-char cap to `MAX_PROMPT_CHARS` in
packages/core/src/constants.ts and re-export it from @tokenleak/core
so provider parsers share a single truth about prompt length.
- Claude Code now imports the shared constant instead of defining its
own local copy.
Pi (easy — data was already there)
- New `extractPiUserPrompt` parses JSONL records with `role: 'user'`
and handles both string `content` and `[{type: 'text', text: ...}]`
array form, matching the Claude shape.
- `PiProvider.load` tracks `lastUserPrompt` through each session file
and attaches it to the next assistant usage record before clearing.
- Test covers the fixture's user/assistant pair: first event's
`prompt` now equals the preceding user message.
Codex (medium — needed stateful linking)
- Codex JSONL writes user turns twice: a `response_item` with mixed
boilerplate and a cleaner `event_msg` with `payload.type ===
'user_message'` whose `payload.message` is the raw typed input.
New `extractCodexUserPrompt` reads the cleaner event_msg source.
- `CodexProvider.load` adds `lastUserPrompt` tracking parallel to Pi's
pattern; the prompt attaches to the next token_count or response
event and then clears.
- Fixture `codex-current/.../session-current.jsonl` gains a
user_message record to exercise the linkage; tests assert the first
event has the expected prompt and the second has none.
|
Warning Rate limit exceeded
Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 25 minutes and 23 seconds. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
What
Extends prompt capture beyond Claude Code to Pi and Codex, so the Receipts feature surfaces real prompt text for those users instead of empty line items.
Why
Before this change, `tokenleak receipts` on a machine that only uses Pi or Codex logs yields zero captured prompts — every cost rolls into Service Fees. The underlying log formats already carry the user turn data; the parsers just weren't reading it.
How
Shared — hoist `MAX_PROMPT_CHARS = 2_000` to `packages/core/src/constants.ts` and re-export from `@tokenleak/core`. Claude Code now imports the shared constant.
Pi (easy)
Codex (medium — stateful linking)
Test Coverage
Registry package: 162 tests (was 159), 0 failures. Full repo: 785 pass.
End-to-end: `tokenleak receipts --codex --format json | jq '.lines[0].samplePrompts'` now returns real user prompts on my dev machine with live Codex data.
Out of scope
Checklist