Repository navigation
feat: capture agent-stated intent via MCP tool into session.jsonl #27
Copy link
Copy link
Open
Labels
enhancementNew feature or requestNew feature or request
Description
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)
- Add a
set_intentMCP tool (or extendrecord_context) that writes an intent event directly tosession.jsonl - Agent rules (
.cursor/rules/,CLAUDE.md, etc.) instruct agents: "Before committing, callset_intentwith a 1-2 sentence description of why you made these changes" prepare-ledger.pyreads the most recenttype: "intent"event from session.jsonl for the matching session and uses it as the intent field- 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
- MCP tool: Add
set_intenttool toagentdiff-mcp.rsthat writes intent events to session.jsonl - prepare-ledger.py: Read
type: "intent"events from session.jsonl, use matching session's intent as theintentfield in the payload - Agent rules: Add default rules for Cursor and Claude Code that instruct agents to call
set_intentbefore committing - Optional:
intent_typefield: Add a taxonomy classifier (bugfix/feature/refactor/test/docs/security/config) derived from the diff, as a fallback when no agent-stated intent exists - Report update: Show
intent_type+intenttogether 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_intentMCP tool writes intent events to session.jsonl -
prepare-ledger.pypicks 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
Labels
enhancementNew feature or requestNew feature or request
Activity
MHASK commentedon Jul 17, 2026
This is a strong direction. I would treat agent-stated intent as useful review evidence, but not as the only source of truth. The agent has context, but it is also the actor being audited.
A few schema/design suggestions that may make this more robust:
intent.source, e.g.agent_stated,human_declared,commit_message,issue_title,fallback_classifier. That lets reports distinguish intent captured from the agent from intent declared by a human.intent.scopeorintent_target, e.g. files, symbols, issue number, task id, or PR id the intent claims to address. This helps detect drift later.agent_stated_intentandobserved_change_summary. If they disagree, surface that mismatch instead of overwriting one with the other.risk_categories[]separately fromintent_type, e.g.auth,payments,ci,dependencies,infra,secrets,migrations. A change can be a refactor and still touch auth.confidenceorevidencefield for derived values. Human-declared or issue-linked intent is different from a classifier guess.For PR comments, the most useful output may be:
That makes intent capture actionable for maintainers rather than just another metadata field.
codeprakhar25 commentedon Jul 18, 2026
Thanks, this is very useful!
So the current status is:
set_intentshipped in v0.1.29.intent+intent_type(bugfix/feature/refactor/test/docs/security/performance/config/dependency) flow through session.jsonl → prepare-ledger → finalize-ledger → traces → reports today.Taking two of your suggestions as follow-up work, since they're cheap and add real signal without another schema layer:
intent.source(agent_stated|fallback) — right now intent can come from aset_intentevent or from pending-context payload with no marker distinguishing them. Small addition, closes that gap.risk_categories[]— derivable deterministically from touched paths (auth/, payments/, .github/workflows/, Cargo.toml/package.json, migrations/) with no LLM call, consistent with the zero-cost design goal already in this issue.intent.scope/intent_targetAlready implemented/thoughts:
confidence/evidencefield — redundant withsource; the source tag already implies confidence tier.observed_change_summary+ drift detection against claimed intent — agree this is the highest-value idea here, but it's a real feature (diff summarizer + comparison), not a field. Worth its own issue rather than folding into this one.Session/commit boundary: already handled —
finalize-ledger.pystrips consumedtype: intentevents from session.jsonl right after the commit they belong to, so long sessions with multiple commits don't bleed intent across boundaries.The main challenge with more increasing this is how scalably and eff. we can store this in large codebase!
MHASK commentedon Jul 18, 2026
That breakdown makes sense, especially keeping
sourceas the confidence tier instead of adding another field.For large repos, I would probably avoid storing symbol/file-level derived data directly on every session event. A lighter shape could be:
So the durable ledger stays cheap, and richer drift detection can be opt-in or cached by commit hash. That also leaves room for large monorepos where the same touched-path classification may be enough for review routing without persisting a full semantic summary every time.
codeprakhar25 commentedon Jul 28, 2026
Got late, missed this!
But yeah, this should be the path, opt-in for large repos, especially monorepos. Will double check for the scope/task-ref definition. Also the definition will be evolved as it is developed. Would you be open to contribute to the repo with this one?