Add 5 new client metrics event types: ToolCall, McpInvocation, NewMessage, SkillUsed, SubagentEvent#572
Open
Add 5 new client metrics event types: ToolCall, McpInvocation, NewMessage, SkillUsed, SubagentEvent#572
Conversation
…sage, SkillUsed, SubagentEvent - Add MetricEventId variants (5-9) and event value structs with PosEncoded/EventValues traits - Add HookMetadata struct to AgentRunResult for tracking hook context - Emit new metrics events in checkpoint command based on hook_event_name - Add AgentUsage pings on message hooks (UserPromptSubmit, Stop, BeforeModel, etc.) - Update Claude Code hooks: UserPromptSubmit, Stop, SubagentStart, SubagentStop - Update Cursor hooks: beforeMCPExecution support - Update Gemini hooks: BeforeModel, AfterModel, BeforeMCPExecution, AfterMCPExecution - Extract subagent_id/subagent_model from Claude hook data into agent_metadata - Extract MCP server/tool names from Cursor beforeMCPExecution hook data - Add parse_mcp_tool_name helper for mcp__server__tool pattern - Add integration tests for all new event types via TmpRepo harness - Add unit tests for all new event value structs (builder, sparse, roundtrip) Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
|
No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits. |
Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
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.
Add 5 new client metrics event types for agent telemetry
Summary
Adds client-side support for 5 new metrics event types: ToolCall (5), McpInvocation (6), NewMessage (7), SkillUsed (8), and SubagentEvent (9). These are emitted from the checkpoint command based on hook context passed through a new
HookMetadatastruct onAgentRunResult.Key changes:
metrics/types.rs/metrics/events.rs: NewMetricEventIdvariants and corresponding value structs (ToolCallValues,McpInvocationValues,NewMessageValues,SkillUsedValues,SubagentEventValues) with fullPosEncoded/EventValuestrait implementations.checkpoint.rs: Event emission logic keyed onhook_event_namestrings. Also movesbuild_checkpoint_attrsoutside the!entries.is_empty()guard so hook-only events (no file changes) can still emit metrics. AgentUsage pings now fire on message hooks too (gated byshould_emit_agent_usage).agent_presets.rs: NewHookMetadata { hook_event_name, tool_name }struct. Claude preset extracts subagent_id/subagent_model intoagent_metadata. Cursor preset extracts MCP server/tool names onbeforeMCPExecution.parse_mcp_tool_namehelper parsesmcp__server__toolconvention.Note: Server-side work (ClickHouse migrations, metrics_parser, worker-metrics) is not included in this PR. Events will buffer client-side but be rejected server-side until that lands.
Review & Testing Checklist for Human
build_checkpoint_attrsmove is safe. Previously only called when!entries.is_empty(). Now runs unconditionally so hook-only events can use attrs. Check if this causes issues when repo state is unusual (e.g., detached HEAD, no commits).PostToolUse(if tool name hasmcp__prefix) AND explicitbeforeMCPExecutionhooks. If both trigger for the same call, you'll get twoMcpInvocationValuesevents. Confirm this is acceptable or needs deduplication.should_emit_agent_usagegating is intentional. Function currently always returnsfalse, so AgentUsage pings on messages won't fire until rate-limiting is enabled. Is this expected?"UserPromptSubmit","PostToolUse","beforeMCPExecution". Handles multiple casing variants but may miss some. Verify coverage for all agents.~/.git-ai/internal/logs/{PID}.log) and metrics DB.Notes
parse_mcp_tool_nameonly handlesmcp__server__toolformat (2 underscores). Extra segments would be misparsed..get(*hook_name).unwrap()to.and_then(...).unwrap_or_default()to gracefully handle missing hook keys (changes production behavior from panic to silent empty).