Skip to content

feat: capture agent-stated intent via MCP tool into session.jsonl #27

@codeprakhar25

Description

@codeprakhar25

Problem

Traces currently record prompt excerpts, line ranges, and files changed — but the intent (the why behind the change) is almost never populated. The intent field exists in AgentdiffMetadata and flows through the full pipeline, but it defaults to "unspecified" because there is no reliable acquisition path.

The prompt excerpt is used as a proxy, but prompts describe what to do, not why:

  • "fix the auth bug" — was this a security incident? a test failure? a refactor?
  • "do the thing we talked about" — completely opaque
  • Multi-step sessions produce many tool calls under one vague prompt

This is the bottleneck for making PR comments and review context meaningful.

Approach

Have the agent state its own intent as a session.jsonl event right before it commits (or at session end). The agent has full context of what it did and why — instead of reverse-engineering intent from diffs/prompts, just ask it.

Mechanism: MCP tool call (Option A)

  1. Add a set_intent MCP tool (or extend record_context) that writes an intent event directly to session.jsonl
  2. Agent rules (.cursor/rules/, CLAUDE.md, etc.) instruct agents: "Before committing, call set_intent with a 1-2 sentence description of why you made these changes"
  3. prepare-ledger.py reads the most recent type: "intent" event from session.jsonl for the matching session and uses it as the intent field
  4. Everything downstream (finalize, report, PR comments) works as-is

New session.jsonl event format

{
  "timestamp": "2026-05-21T12:00:00Z",
  "type": "intent",
  "agent": "cursor",
  "session_id": "conv-xyz",
  "description": "Extract auth middleware into shared module to fix duplicate token validation across 3 route handlers"
}

Implementation Steps

  1. MCP tool: Add set_intent tool to agentdiff-mcp.rs that writes intent events to session.jsonl
  2. prepare-ledger.py: Read type: "intent" events from session.jsonl, use matching session's intent as the intent field in the payload
  3. Agent rules: Add default rules for Cursor and Claude Code that instruct agents to call set_intent before committing
  4. Optional: intent_type field: Add a taxonomy classifier (bugfix/feature/refactor/test/docs/security/config) derived from the diff, as a fallback when no agent-stated intent exists
  5. Report update: Show intent_type + intent together in PR comment output

Why this works

  • Zero latency — no external API calls
  • Zero cost — no LLM inference
  • High quality — the agent has full session context
  • Fits existing architecture — session.jsonl → prepare-ledger → finalize → traces
  • Works across all MCP-capable agents

Acceptance Criteria

  • set_intent MCP tool writes intent events to session.jsonl
  • prepare-ledger.py picks up intent events and populates the intent field
  • PR comments show agent-stated intent instead of raw prompt excerpts
  • Agent rules exist for at least Cursor and Claude Code
  • Traces without agent-stated intent fall back to prompt-derived or "unspecified"

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions