Support GitHub Copilot CLI and improve CLI accounting#141
Support GitHub Copilot CLI and improve CLI accounting#141zhangzqs wants to merge 5 commits intoPiebald-AI:mainfrom
Conversation
Agent-Logs-Url: https://github.com/zhangzqs/splitrail/sessions/4ee476d9-1122-4625-b054-0d5921bb214e Co-authored-by: zhangzqs <34616640+zhangzqs@users.noreply.github.com>
… precise token tracking Separate Copilot CLI parsing from the VS Code analyzer into its own module, add exact output token counts, context compaction handling, and model-based cost calculation.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📝 WalkthroughWalkthroughThis PR introduces GitHub Copilot CLI analyzer support by implementing a new analyzer that discovers and parses Copilot CLI session event logs, updates model definitions with new canonical models and aliases, refines message-processing logic to gate AI-message aggregation on message role, and integrates the new analyzer into the registry. Changes
Sequence Diagram(s)sequenceDiagram
participant FileSystem as File System
participant Discovery as Data Discovery
participant Parser as JSONL Parser
participant Reconstructor as Event Reconstructor
participant Calculator as Token & Cost Calculator
participant Output as Message Output
FileSystem->>Discovery: Discover ~/.copilot/{session-state,history-session-state}
Discovery->>Discovery: Filter events.jsonl files
Discovery->>Parser: Load & read JSONL events
Parser->>Parser: Parse JSON objects sequentially
Parser->>Reconstructor: Feed parsed events
Reconstructor->>Reconstructor: Correlate user.message with assistant/tool events
Reconstructor->>Reconstructor: Build conversation turns
Reconstructor->>Calculator: Extract session ID & workspace identity
Calculator->>Calculator: Compute session/project hashes
Calculator->>Calculator: Estimate tokens (reusable/cache/visible)
Calculator->>Calculator: Accumulate tool call stats
Calculator->>Calculator: Apply shutdown metrics or static overhead
Calculator->>Output: Emit ConversationMessage entries
Output->>Output: Generate deterministic per-message hashes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
src/analyzers/copilot_cli.rs (2)
541-624: Consider grouping parameters into a context struct.The
flush_copilot_cli_turnfunction has 9 parameters. While the#[allow(clippy::too_many_arguments)]annotation acknowledges this, grouping related parameters (likeconversation_hash,project_hash,session_name) into a context struct would improve readability and make future modifications easier.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/analyzers/copilot_cli.rs` around lines 541 - 624, The function flush_copilot_cli_turn currently takes many related params—group conversation_hash, project_hash, session_name (and optionally user_index/assistant_index and live_context) into a small context struct to reduce argument count and improve readability; create a CopilotCliFlushContext (or similar) containing conversation_hash: String (or &str reference type matching callers), project_hash: String, session_name: Option<String>, and if helpful mutable indices user_index: usize and assistant_index: usize (or keep indices separate if you prefer), update flush_copilot_cli_turn signature to accept &mut CopilotCliFlushContext (and keep entries, current_turn, live_context, pending_user as before), then update all call sites to build/pass that context struct and adjust usage inside flush_copilot_cli_turn to reference context.conversation_hash, context.project_hash, context.session_name, and context.assistant_index (or &mut assistant_index) accordingly.
751-755: UsingUtc::now()for missing timestamps may affect reproducibility.When an event lacks a timestamp, the current time is used as a fallback. This means parsing the same file at different times could produce different
datevalues for those messages. Consider logging a warning or using a sentinel value if reproducibility is a concern.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/analyzers/copilot_cli.rs` around lines 751 - 755, The code sets pending_user.date via event_timestamp.unwrap_or_else(Utc::now), which makes parsing non-deterministic; change CopilotCliPendingUser.date to use a reproducible sentinel or optional timestamp instead of calling Utc::now(), and emit a warning when the event timestamp is missing; specifically, update the creation of pending_user (the pending_user assignment and CopilotCliPendingUser struct) to accept either Option<DateTime<Utc>> or a fixed sentinel (e.g., epoch) and add a log call when event_timestamp.is_none() so missing timestamps are recorded for debugging and reproducibility.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/tui.rs`:
- Line 1177: Update the no-data screen label that currently reads "GitHub
Copilot" to "GitHub Copilot (VS Code)" so it matches the analyzer split and
README wording; locate the string literal in src/tui.rs (the quoted message
shown) and replace that occurrence, and also search for other user-facing
occurrences of the plain "GitHub Copilot" label in the UI/strings to make the
naming consistent with "GitHub Copilot (VS Code)".
---
Nitpick comments:
In `@src/analyzers/copilot_cli.rs`:
- Around line 541-624: The function flush_copilot_cli_turn currently takes many
related params—group conversation_hash, project_hash, session_name (and
optionally user_index/assistant_index and live_context) into a small context
struct to reduce argument count and improve readability; create a
CopilotCliFlushContext (or similar) containing conversation_hash: String (or
&str reference type matching callers), project_hash: String, session_name:
Option<String>, and if helpful mutable indices user_index: usize and
assistant_index: usize (or keep indices separate if you prefer), update
flush_copilot_cli_turn signature to accept &mut CopilotCliFlushContext (and keep
entries, current_turn, live_context, pending_user as before), then update all
call sites to build/pass that context struct and adjust usage inside
flush_copilot_cli_turn to reference context.conversation_hash,
context.project_hash, context.session_name, and context.assistant_index (or &mut
assistant_index) accordingly.
- Around line 751-755: The code sets pending_user.date via
event_timestamp.unwrap_or_else(Utc::now), which makes parsing non-deterministic;
change CopilotCliPendingUser.date to use a reproducible sentinel or optional
timestamp instead of calling Utc::now(), and emit a warning when the event
timestamp is missing; specifically, update the creation of pending_user (the
pending_user assignment and CopilotCliPendingUser struct) to accept either
Option<DateTime<Utc>> or a fixed sentinel (e.g., epoch) and add a log call when
event_timestamp.is_none() so missing timestamps are recorded for debugging and
reproducibility.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fc410277-c73f-425d-ab4b-eed5041508f1
📒 Files selected for processing (17)
README.mdsrc/analyzers/copilot.rssrc/analyzers/copilot_cli.rssrc/analyzers/mod.rssrc/analyzers/tests/copilot.rssrc/analyzers/tests/copilot_cli.rssrc/analyzers/tests/mod.rssrc/contribution_cache/single_session.rssrc/main.rssrc/mcp/server.rssrc/models.rssrc/tui.rssrc/tui/logic.rssrc/types.rssrc/utils.rssrc/utils/tests.rsvscode-splitrail/README.md

Summary
What changed
GitHub Copilot CLIanalyzer andApplication::CopilotClisession.shutdown.data.modelMetricsusage to completed sessionsReason TksfromreasoningTextwithout changing the existing output/cost semanticsValidation
cargo fmt --all --quietcargo build --quietcargo test --quietcargo clippy --quiet -- -D warningscargo doc --quietNotes
Summary by CodeRabbit
Release Notes
New Features
Documentation