Merged
Conversation
All three metrics are working correctly: - Duration: 41.4s - Tokens: 3.6k - Tools: 1 (Glob was used) ⏺ Implementation complete. Here's a summary of the changes: Files Modified | File | Changes | |-------------------|--------------------------------------------------------------------------| | src/llm.rs | Added Usage struct to parse token counts from API responses | | src/agent.rs | Added CommandStats struct, modified run_turn() to track and return stats | | src/subagent.rs | Modified run_subagent() to track and return stats | | src/tools/task.rs | Updated to propagate stats from subagents | | src/cli.rs | Added print_stats() helper, timing around commands | Output Format [Duration: 0.7s | Tokens: 1.6k | Tools: 0] - Duration: Total wall-clock time for the command - Tokens: Total tokens used (input + output), formatted with 'k' suffix when ≥1000 - Tools: Count of all tool calls (including nested subagent calls) Key Design Decisions 1. Stats struct returned from functions - run_turn() and run_subagent() return CommandStats so callers can aggregate 2. Subagent stats merged - When a Task tool runs a subagent, its stats are merged into the parent's 3. Token parsing from API - The Usage struct parses the standard OpenAI-compatible usage field 4. Output to stderr - Stats print to stderr to avoid mixing with command output
There was a problem hiding this comment.
Pull request overview
This PR adds diagnostic output improvements to the agentic coding assistant, focusing on better visibility into command execution with token usage tracking, tool usage stats, and enhanced console output.
- Adds
CommandStatsstruct to track token usage (input/output) and tool invocations across agent and subagent executions - Implements command history persistence using rustyline's file-based history feature
- Enhances tool output with line/match counts for better diagnostics
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/agent.rs | Adds CommandStats struct and tracking logic for tokens and tool uses in the main agent loop |
| src/cli.rs | Implements stats display with duration/token/tool metrics and adds command history persistence |
| src/llm.rs | Adds Usage struct to capture and deserialize token usage from LLM API responses |
| src/subagent.rs | Propagates CommandStats from subagent execution back to parent agent |
| src/tools/task.rs | Updates return type to include CommandStats alongside task execution results |
| src/tools/write.rs | Adds line counting and diagnostic output for write operations |
| src/tools/read.rs | Adds line counting for text files and includes line count in response |
| src/tools/grep.rs | Adds match counting and diagnostic output for grep results |
| Cargo.toml | Upgrades rustyline to version 17 with file-history feature enabled |
| Cargo.lock | Updates dependency graph for rustyline upgrade and transitive dependencies |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.