Skip to content

fix(analytics): fix Gemini agent analytics tracking (EPMCDME-14674) - #528

Merged
yanaSelin merged 3 commits into
codemie-ai:mainfrom
BogLesh:fix/EPMCDME-14674-gemini-analytics-tracking
Sep 4, 2026
Merged

fix(analytics): fix Gemini agent analytics tracking (EPMCDME-14674)#528
yanaSelin merged 3 commits into
codemie-ai:mainfrom
BogLesh:fix/EPMCDME-14674-gemini-analytics-tracking

Conversation

@BogLesh

@BogLesh BogLesh commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Ticket

EPMCDME-14674

Summary

When running codemie analytics --report --last 8d, users utilizing Gemini agents received "No analytics data available". This PR resolves parsing, deduplication, and attribution gaps for Gemini CLI transcripts:

  • Streaming JSONL Parsing (GeminiSessionAdapter): Added .jsonl discovery, header extraction, and line-by-line parsing for streaming chat transcripts (session-*.jsonl), handling $set.messages and raw turn chunks without throwing SyntaxError.
  • In-Place Turn Deduplication: Deduplicated turn-level chunks by message id in parseSessionFile, merging partial streaming updates (content, tokens, thoughts, toolCalls) to prevent token double-counting.
  • Defensive Prompt Text Extraction (GeminiMetricsProcessor): Added extractPromptText() supporting strings, structured arrays (content: [{ text: "..." }]), and stripping internal <session_context> XML blocks.
  • Git Branch Attribution: Bound active gitBranch to generated MetricDelta records.
  • Serena MCP Tool Mapping: Mapped Serena MCP tools (mcp_serena_*) to standard file operations (write, edit,
    ead, delete) and extracted line counts across varied argument schemas.
  • Model Pricing Table (pricing.json): Added standard dashed entries (gemini-3-7-flash, gemini-3-5-flash, gemini) and dotted aliases to support lookupPrice() normalization.

Verification

  • Vitest unit tests: 80 passed / 80 tests (100%) (
    pm run test:unit)
  • Typecheck & Lint: sc --noEmit and eslint passed with 0 errors / 0 warnings
  • Build verification:
    pm run build compiled successfully
  • Real-world validation: codemie analytics --report --last 8d --report-format json successfully parsed real Gemini CLI sessions, attributing models, costs, and Serena MCP tool calls.

Note on MCP Tool Mapping & Proposed Follow-Up (Technical Debt)

In this PR, I added explicit mappings for Serena MCP tools (mcp_serena_*) because Serena was the specific MCP server utilized in my Gemini CLI workflows where the missing file operation metrics were identified.

Known Limitation & Technical Debt:
Hardcoding specific MCP server names (mcp_serena_*) solves the immediate issue for this stack, but it introduces technical debt: developers or external contributors using alternative MCP servers (such as @modelcontextprotocol/server-filesystem or custom IDE MCP extensions) will have their tool calls recorded in general usage tables, but their file edits and line diffs will be omitted unless explicitly mapped.

Proposed Solution (Universal / MCP-Agnostic Extraction):
I propose creating a follow-up task/PR to make file operation extraction truly generic and MCP-agnostic by:

  1. Stripping dynamic MCP prefixes: Normalizing incoming tool names (e.g., toolName.replace(/^mcp_[a-z0-9_-]+_/i, '')), so that mcp_serena_write_file, mcp_filesystem_write_file, and native write_file all resolve to a common canonical name.
  2. Semantic intent matching: Classifying operations via action patterns (/write|create/, /replace|edit|patch/, /read|view/, /delete/) and resolving file paths/diffs across standard argument conventions (path, filePath, relative_path, content, replacement, needle/repl).

This will ensure that any current or future MCP coding server works out of the box with zero manual config required.

Comment thread src/utils/pricing.json Outdated
@yanaSelin
yanaSelin merged commit 076ebae into codemie-ai:main Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants