| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…ering - New set_intent MCP tool appends type=intent events to session.jsonl - AgentdiffMetadata gains intent_type: Option<String> field - report.rs renders [type] intent in Review Context and trace details table - context_json_report includes intent_type in JSON output - AGENTS.md managed block instructs agents to call set_intent before committing - 6 new tests (tools/list, set_intent happy path, empty description rejection)
…inalize - read_intent_events() scans session.jsonl for type=intent events since last commit - Intent priority: agent-stated event (session-id matched) > pending context > none - intent_type propagated through pending_ledger.json to finalize-ledger.py - 2 new tests: write_agent_trace persists intent_type and full structured metadata
- Fix byte-boundary panic: slice description by chars not bytes (Rust) - Add server-side intent_type enum validation in set_intent() (Rust) - Skip session-id matching when session_id is 'unknown' to prevent cross-session bleed - Separate read-loop from os.replace in remove_consumed_intents to avoid swallowing rename errors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
AgentDiff ReportSummary
Review Context
Files To Review First
|
Sorry, something went wrong.
Greptile SummaryThis PR adds intent capture to the AgentDiff commit flow. The main changes are:
Confidence Score: 3/5This should be fixed before merging because the intent flow can persist the wrong data.
scripts/prepare-ledger.py, scripts/finalize-ledger.py, and src/bin/agentdiff-mcp.rs need the most attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Agent
participant MCP as agentdiff-mcp
participant Session as session.jsonl
participant Prepare as prepare-ledger.py
participant Pending as pending-ledger.json
participant Finalize as finalize-ledger.py
participant Trace as AgentTrace
Agent->>MCP: set_intent(description, intent_type)
MCP->>Session: "append type=intent event"
Prepare->>Session: read intent events
Prepare->>Pending: write intent metadata
Finalize->>Pending: read pending ledger
Finalize->>Trace: persist intent metadata
Finalize->>Session: prune intent events
Comments Outside Diff (1)
Reviews (1): Last reviewed commit: "chore: release v0.1.29 — intent capture ..." | Re-trigger Greptile |
Sorry, something went wrong.
| match set_intent(&args, default_cwd) { | ||
| Ok(out_path) => response_ok( | ||
| rid, | ||
| json!({ | ||
| "content": [{ | ||
| "type":"text", | ||
| "text": format!("intent recorded in {}", out_path.display()) | ||
| }], | ||
| "structuredContent": { | ||
| "status":"recorded", | ||
| "path": out_path.display().to_string() | ||
| } | ||
| }), | ||
| ), | ||
| Err(err) => response_error(rid, -32000, format!("{err:#}")), |
There was a problem hiding this comment.
Return invalid params The set_intent branch maps every set_intent() error to -32000. That includes the new enum validation for intent_type, so a caller that sends an unknown type receives an internal server error instead of the invalid-params error expected for bad tool input. MCP clients can then handle a user input problem as a server failure.
Sorry, something went wrong.
| try: | ||
| event = json.loads(line) | ||
| if isinstance(event, dict) and event.get("type") == "intent": | ||
| continue |
There was a problem hiding this comment.
Prune only consumed intent This removes every type=intent line in session.jsonl, not just the intent that was attached to the commit being finalized. If an agent records the next commit's intent while this post-commit hook is still running, that new event is deleted before the next pre-commit can read it, so the next trace silently loses its intent.
Sorry, something went wrong.
| if not best_intent: | ||
| best_intent = intent_events[-1] |
There was a problem hiding this comment.
Avoid unrelated fallback When the current commit has a known session_id but no intent event matches it, this falls back to the latest intent from any session. A commit attributed to sess-A can therefore receive an intent recorded by sess-B as long as that event is newer than HEAD, which is another cross-session bleed case.
| if not best_intent: | |
| best_intent = intent_events[-1] | |
| if not best_intent and (not session_id or session_id == "unknown"): | |
| best_intent = intent_events[-1] |
Sorry, something went wrong.
| let mut file = fs::OpenOptions::new() | ||
| .create(true) | ||
| .append(true) | ||
| .open(&session_path) | ||
| .with_context(|| format!("opening {}", session_path.display()))?; | ||
| writeln!(file, "{}", event.to_string()) | ||
| .with_context(|| format!("writing to {}", session_path.display()))?; |
There was a problem hiding this comment.
Synchronize session writes set_intent appends directly to session.jsonl without taking a lock. Multiple MCP servers or capture hooks can write at the same time, and finalize-ledger.py can rewrite the same file while this append happens. That can corrupt JSONL or drop a valid intent, and prepare-ledger.py will silently skip malformed lines.
Sorry, something went wrong.
| "prompt": args.prompt or str(payload.get("prompt") or ""), | ||
| "files_read": parse_json_array(args.files_read) or payload.get("files_read") or [], | ||
| "intent": args.intent or str(payload.get("intent") or ""), | ||
| "intent_type": args.intent_type or str(payload.get("intent_type") or ""), |
There was a problem hiding this comment.
Validate merged payload The argparse choices check only applies to the CLI flag. This line still accepts intent_type from stdin JSON without validating it, and that value can be persisted by prepare/finalize into the trace. A caller piping {"intent_type":"other"} through the documented stdin path bypasses the new allowlist.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Intent capture — agents now record why they made changes, not just what they changed. Intent flows from the MCP tool call at edit time through to signed traces and PR comments.
New capability
Bug fixes (this branch)
End-to-end flow
Agent calls set_intent MCP tool (description + intent_type) ↓ type=intent event written to .git/agentdiff/session.jsonl ↓ pre-commit: prepare-ledger reads intent events, session-id matched first → fallback to latest ↓ post-commit: finalize-ledger persists intent + intent_type in AgentTrace metadata ↓ finalize prunes consumed intent events from session.jsonl ↓ agentdiff report --context → "[refactor] Extract auth middleware..."Pre-Landing Review
10 findings reviewed. 4 HIGH/MEDIUM issues fixed before push:
Remaining noted items (non-blocking):
Test Coverage
All 68 tests pass (47 Rust + 21 Python). New tests added:
Test plan
🤖 Generated with Claude Code