feat: Add agent tracking and fix token deduplication (RFC #41)#42
Conversation
Closes #41 ## Problem - Token duplication: Each tool_use in multi-tool messages got full token count, inflating totals 2-3x - No agent tracking: Task subagent work was indistinguishable from main session - Missing metadata: parentUuid, isSidechain, version fields not captured ## Solution - **Event hierarchy**: Assistant events now store tokens; tool_use events link via parent_uuid with no tokens - **Agent tracking**: Extract agentId from agent-*.jsonl files to distinguish subagent work - **New fields**: parent_uuid, agent_id, is_sidechain, version added to events table - **New API**: get_agent_activity MCP tool and CLI command for agent vs main session breakdown ## Changes - storage.py: Schema v5 migration, 4 new Event fields, updated CRUD methods - ingest.py: Refactored parse_entry() to create assistant+tool_use hierarchy - queries.py: Added query_agent_activity() function - server.py: Added get_agent_activity MCP tool - cli.py: Added agents command with formatter - Tests: 282 tests passing with comprehensive RFC #41 coverage 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Code ReviewSummaryThis PR adds agent tracking and fixes token duplication for RFC #41. It introduces new schema fields ( Issues FoundCriticalNone Important
Suggestions
VerdictREQUEST_CHANGES - One important issue (missing query tests) and a few minor suggestions. The implementation is well-structured with good test coverage for ingestion, but the query function for agent activity needs tests. Automated review by Claude Code |
- Add 7 tests for query_agent_activity() covering aggregation, top-tools calculation, and percentage computation - Move `import re` to module level in ingest.py - Use robust regex slugification for command names (handles apostrophes and special chars) - Create issue #43 to track session-level metadata enhancement 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Feedback AddressedImplemented
Deferred
|
Code ReviewSummaryThis PR adds agent tracking and fixes token duplication (RFC #41). It introduces parent_uuid, agent_id, is_sidechain, and version fields to the events table, fixes token counting by storing tokens only on assistant events (eliminating 2-3x inflation from multi-tool messages), and adds the get_agent_activity MCP tool and agents CLI command. Previous Feedback VerificationAll items from the previous Feedback Addressed comment have been verified:
Issues FoundCriticalNone ImportantNone SuggestionsNone VerdictAPPROVE - All previous feedback has been addressed. The implementation is well-structured with comprehensive test coverage (30 new tests), proper schema migration, and clean separation of concerns. Token deduplication fix and agent tracking are correctly implemented. Automated review by Claude Code |
Summary
Closes #41
parent_uuidagentIdfrom agent-*.jsonl files to distinguish Task subagent work from main sessionparent_uuid,agent_id,is_sidechain,versionfields to events tableget_agent_activityMCP tool andagentsCLI command for agent vs main session breakdownTest plan
agentscommand displays formatted outputget_agent_activitytool returns structured data🤖 Generated with Claude Code