feat(copilot): parse VS Code Copilot Chat session token usage - #875
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
There was a problem hiding this comment.
1 issue found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="crates/tokscale-core/src/sessions/copilot_vscode.rs">
<violation number="1" location="crates/tokscale-core/src/sessions/copilot_vscode.rs:122">
P2: Model/provider attribution can be wrong for IDs that merely contain a family name, because this parser delegates to substring-based inference. Use the repository's delimited-token model matching so non-family Copilot IDs remain `github-copilot`.
(Based on your team's feedback about model-family token matching.) [FEEDBACK_USED]</violation>
</file>
Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.
Re-trigger cubic
| return None; | ||
| } | ||
|
|
||
| let provider_id = inferred_provider_from_model(&model_id) |
There was a problem hiding this comment.
P2: Model/provider attribution can be wrong for IDs that merely contain a family name, because this parser delegates to substring-based inference. Use the repository's delimited-token model matching so non-family Copilot IDs remain github-copilot.
(Based on your team's feedback about model-family token matching.)
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At crates/tokscale-core/src/sessions/copilot_vscode.rs, line 122:
<comment>Model/provider attribution can be wrong for IDs that merely contain a family name, because this parser delegates to substring-based inference. Use the repository's delimited-token model matching so non-family Copilot IDs remain `github-copilot`.
(Based on your team's feedback about model-family token matching.) </comment>
<file context>
@@ -0,0 +1,334 @@
+ return None;
+ }
+
+ let provider_id = inferred_provider_from_model(&model_id)
+ .unwrap_or("github-copilot")
+ .to_string();
</file context>
There was a problem hiding this comment.
Not a VS Code parser issue — inferred_provider_from_model is the project-wide standard used by all client parsers. Copilot resolvedModel values are canonical model IDs (gpt-5.3-codex, claude-sonnet-4) that match correctly. Unknown models fall back to github-copilot which is the correct attribution for Copilot-routed requests where the underlying provider is opaque.
e336e51 to
bb9a550
Compare
VS Code stores per-request token counts in workspaceStorage chatSessions JSONL files. Parse kind=0 (initial state) and kind=2 (array appends) to extract promptTokens, completionTokens, resolvedModel, and reasoning tokens from toolCallRounds. Scans ~/Library/Application Support/Code/User/workspaceStorage/*/chatSessions/ on macOS and equivalent paths on Linux/Windows. Deduplicates against OTEL and desktop app sessions by dedup_key and session_id+timestamp.
bb9a550 to
290ad7a
Compare
Summary
Add support for parsing VS Code Copilot Chat token usage from local
chatSessions/*.jsonlfiles. Previously, tokscale only tracked Copilot usage when OTEL export was explicitly enabled. Now VS Code panel chat usage is automatically discovered and tracked.What's Changed
sessions/copilot_vscode.rs— JSONL parser for VS Code chat session filessessions/mod.rs— module registrationscanner.rs—copilot_vscode_sessions: Vec<PathBuf>+ auto-discovery across macOS/Linux/Windowslib.rs— wired into both parse paths with dedup against OTEL sessionsData Source
VS Code stores chat sessions in:
~/Library/Application Support/Code/User/workspaceStorage/*/chatSessions/*.jsonl~/.config/Code/User/workspaceStorage/*/chatSessions/*.jsonl%APPDATA%/Code/User/workspaceStorage/*/chatSessions/*.jsonlEach JSONL file contains:
kind=0lines with initialrequests[]arraykind=2lines with appended request itemsFrom each request item we extract:
promptTokensorresult.metadata.promptTokenscompletionTokensorresult.metadata.outputTokenstoolCallRounds[*].thinking.tokensresult.metadata.resolvedModel(fallback:modelIdwithcopilot/prefix stripped)timestamp(epoch ms)Dedup Strategy
copilot-vscode:{session_id}:{timestamp_ms}Tested
cargo test -p tokscale-core --lib— 1177 tests passcargo clippy -p tokscale-core -- -D warnings— cleancargo fmt -p tokscale-core --check— cleangpt-5.3-codex, 22K input, 154 output, 88 reasoning tokens, $0.042 costSummary by cubic
Adds support for parsing VS Code Copilot Chat token usage from local
workspaceStorage/*/chatSessions/*.jsonlfiles. Automatically tracks panel chat usage without OTEL and deduplicates against existing Copilot sources.sessions/copilot_vscode.rsto parsekind=0andkind=2entries, extract input/output/reasoning tokens, resolve model viaresolvedModel(fallback stripscopilot/frommodelId), and ignore non‑Copilot requests.ScanResult.copilot_vscode_sessions.dedup_keyand(session_id, timestamp)with priority to OTEL and desktop app messages.workspace.jsonwhen available.Written for commit 290ad7a. Summary will update on new commits.