Repository navigation
feat(copilot): read session-state usage events #1676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 12 commits
f3b9b01
78be476
46c89a9
981a358
9a2515b
7f8f996
ede7590
a0b738d
7bc1338
73bcdbd
f500258
a1e0866
685f08d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| # ccusage-adapter-copilot | ||
|
|
||
| The GitHub Copilot CLI adapter: it turns OpenTelemetry JSONL that the CLI exports to a file | ||
| The GitHub Copilot CLI adapter: it turns Copilot session-state and OpenTelemetry JSONL files | ||
| into the usage entries the reports render. | ||
|
|
||
| ## Owns | ||
|
|
@@ -15,7 +15,20 @@ Anything that is not specific to this source belongs in `ccusage-core` or | |
|
|
||
| ## Data source | ||
|
|
||
| - `${COPILOT_OTEL_FILE_EXPORTER_PATH:-~/.copilot/otel}/**/*.jsonl` | ||
| - `${COPILOT_HOME:-~/.copilot}/session-state/*/events.jsonl` | ||
| - `${COPILOT_HOME:-~/.copilot}/otel/**/*.jsonl` | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: printf '%s\n' '--- repository conventions ---'
find /tmp/coderabbit-repo-knowledge/ccusage-ccusage-312f2776 -maxdepth 2 -type f -name '*.md' -print
printf '%s\n' '--- scoped convention headers ---'
for f in /tmp/coderabbit-repo-knowledge/ccusage-ccusage-312f2776/*/*.md; do
printf '\n### %s\n' "$f"
head -40 "$f"
done
printf '%s\n' '--- bound implementation and documentation ---'
sed -n '1,220p' rust/adapters/copilot/src/paths.rs
printf '\n### rust/adapters/copilot/README.md\n'
sed -n '1,60p' rust/adapters/copilot/README.md
printf '\n### docs/guide/getting-started.md\n'
sed -n '165,188p' docs/guide/getting-started.md
printf '\n### docs/guide/index.md\n'
sed -n '82,96p' docs/guide/index.mdRepository: ccusage/ccusage Length of output: 19921 🏁 Script executed: printf '%s\n' '--- targeted repository knowledge files ---'
find /tmp/coderabbit-repo-knowledge/ccusage-ccusage-312f2776 -maxdepth 2 -type f -name '*.md' -print
for f in /tmp/coderabbit-repo-knowledge/ccusage-ccusage-312f2776/*/*.md; do
printf '\n### %s\n' "$f"
head -40 "$f"
done
printf '%s\n' '--- implementation ---'
sed -n '1,220p' rust/adapters/copilot/src/paths.rs
printf '%s\n' '--- affected documentation ---'
sed -n '1,60p' rust/adapters/copilot/README.md
sed -n '165,188p' docs/guide/getting-started.md
sed -n '82,96p' docs/guide/index.mdRepository: ccusage/ccusage Length of output: 19810 🏁 Script executed: rg -n -C 8 'fn collect_files_with_extension|collect_files_with_extension' rust/adapters rust/cratesRepository: ccusage/ccusage Length of output: 30198 Use the recursive Copilot OpenTelemetry glob in all guides.
📍 Affects 3 files
🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| - `COPILOT_HOME` (single relocated Copilot data root) | ||
| - `COPILOT_OTEL_FILE_EXPORTER_PATH` (one explicit JSONL file) | ||
|
|
||
| Session-state shutdown records are cumulative per canonical `(session, model)` pair, so only the | ||
| latest shutdown is retained. They are preferred for a matching pair when both sources contain it. | ||
| Matching OpenTelemetry rows are suppressed only when their timestamps are at or before the latest | ||
| canonical shutdown timestamp for that pair; rows emitted after that timestamp by a resumed session | ||
| are retained. Other OpenTelemetry records remain available. Session-state `inputTokens` includes cache reads | ||
| and writes, so the adapter reports the uncached remainder as input and keeps the cache buckets | ||
| separate. Session-state reasoning tokens are already included in output tokens; OpenTelemetry | ||
| reasoning is included when total usage metadata shows it is separate. Internal model suffixes such | ||
| as `-1m` and `-1m-internal` are removed before pricing and source deduplication. | ||
|
|
||
| Reads plain files through `ccusage-adapter-common`, which handles walking, size-balanced | ||
| chunking, and ordered parallel reads. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Correct the directory-list description.
Line 7 contains
a a comma-separ list. Replace it witha comma-separated list.🤖 Prompt for AI Agents