Skip to content

Add AgentDiff context workflow#8

Merged
codeprakhar25 merged 2 commits into
mainfrom
release/context-workflow-v0.1.26
Apr 27, 2026
Merged

Add AgentDiff context workflow#8
codeprakhar25 merged 2 commits into
mainfrom
release/context-workflow-v0.1.26

Conversation

@codeprakhar25
Copy link
Copy Markdown
Owner

Summary

  • Preserve structured intent, files-read, flags, trust, author, and capture-tool metadata in AgentTrace records.
  • Add context-aware markdown/JSON reports, file-scoped agentdiff context, and agentdiff install-skill for project/global Cursor skill installation.
  • Fix PR comment posting for older gh versions and filter PR comments to current-branch traces.

Test plan

Monorepo validation

  • agentdiff push with 2 new traces: 5.09s
  • agentdiff push with no local traces: 0.00s
  • agentdiff report --format markdown --context: 0.02s
  • agentdiff report --format json --context: 0.02s
  • agentdiff context agentdiff-context-validation.md --json: 0.01s

Preserve structured context in traces, surface it in reports and file-scoped context, and add a Cursor skill installer so agents can use the workflow consistently.
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR adds the agentdiff context and agentdiff install-skill commands, enriches AgentTrace records with intent, files_read, author, and capture_tool metadata, and introduces context-aware markdown/JSON report modes. It also fixes --post-pr-comment compatibility with older gh versions by falling back from --edit-last to a fresh comment creation, and filters PR comment traces to current-branch commits only. Two P2 findings: find_merge_base loop exits early on IO spawn error instead of continuing to the next candidate, and --context is silently ignored for --format json while it meaningfully toggles the markdown path.

Confidence Score: 5/5

Safe to merge; all remaining findings are P2 style suggestions with no impact on correctness or data integrity.

No P0 or P1 issues found. The two flagged items are an unlikely-in-practice early-exit in an error path and a minor flag-consistency gap between markdown and JSON formats. Core logic for context storage, filtering, and PR comment fallback is correct and well-tested.

src/commands/report.rs — find_merge_base loop and --context/JSON inconsistency

Important Files Changed

Filename Overview
src/commands/report.rs Adds markdown_trace_report / context_json_report, PR comment fallback, and branch-filtering logic; loop early-exit on IO error in find_merge_base and --context inconsistency for JSON format noted.
src/commands/context.rs New agentdiff context command; clean path normalization and JSON output; short_id slicing is safe due to .min(8).
src/commands/install_skill.rs New install-skill command; SKILL_CONTENT embedded at compile time; project/global scopes; no user-controlled content in written file.
scripts/record-context.py Adds read_available_stdin() with select() to avoid blocking on TTY; falls back gracefully on Windows.
scripts/finalize-ledger.py Adds intent, files_read, author, and capture_tool fields to AgentTrace metadata; guarded by isinstance/presence checks.
src/store.rs Adds api_ref_path() to percent-escape branch-slash refs; formatting-only changes elsewhere; new unit tests verify correct escaping.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[agentdiff report] --> B{post-pr-comment?}
    B -- yes --> C[current_branch_commits]
    C --> D[filter_traces_by_commit_set]
    D --> E[markdown_trace_report include_context=true]
    E --> F[post_pr_comment try edit-last first]
    F --> G{edit succeeded?}
    G -- yes --> H[Done]
    G -- no --> I[gh pr comment create new]
    I --> J{create succeeded?}
    J -- yes --> H
    J -- no --> K[bail with both stderrs]
    B -- no --> L{format?}
    L -- markdown with context --> M[markdown_trace_report]
    L -- markdown no context --> N[markdown_report legacy]
    L -- json --> O[context_json_report always includes context]
    L -- text --> P[run_text]
    L -- annotations --> Q[format_annotations]
    L -- jsonl --> R[export jsonl]
Loading

Reviews (1): Last reviewed commit: "feat: add AgentDiff context workflow" | Re-trigger Greptile

Comment thread src/commands/report.rs
Comment on lines +151 to +164
for branch in candidates {
let out = std::process::Command::new("git")
.args(["merge-base", "HEAD", &branch])
.current_dir(repo_root)
.output()
.ok()?;
if out.status.success() {
let sha = String::from_utf8(out.stdout).ok()?.trim().to_string();
if !sha.is_empty() {
return Some(sha);
}
}
}
None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 ? exits the function on spawn failure in find_merge_base loop

The ? operator on .ok()? causes the entire find_merge_base function to return None if any Command::output() call produces an IO error (e.g. ENOENT for a missing git binary). The intended behavior is to continue iterating over the remaining candidates. In practice this is a no-op since if git can't spawn nothing else works, but the same early exit applies to the String::from_utf8(...).ok()? on the success path, where garbage output from an unusual git build could prematurely drop the remaining candidates.

Comment thread src/commands/report.rs
Comment on lines +821 to +825
metadata: Some(serde_json::json!({
"agentdiff": {
"intent": "security hardening",
"prompt_excerpt": "add route guard",
"files_read": ["src/auth.rs"],
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 --context flag silently ignored for --format json

The Json arm always calls context_json_report, so --context is a no-op for this format while it meaningfully toggles the Markdown arm. Consider documenting in the --context arg help string (in cli.rs) that it applies only to markdown format.

Move the installable Cursor skill into a packaged template, keep generated project skill files out of the AgentDiff repository, and address PR comment review nits.
@codeprakhar25 codeprakhar25 merged commit b0c4788 into main Apr 27, 2026
2 checks passed
@codeprakhar25 codeprakhar25 deleted the release/context-workflow-v0.1.26 branch April 27, 2026 11:27
@github-actions
Copy link
Copy Markdown

AgentDiff Report

Summary

Agent Lines %
claude-code 2390 57%
Prakhar Khatri 1829 43%

Files Modified

File Lines Dominant Agent
src/configure/mod.rs 421 claude-code
src/commands/status.rs 404 Prakhar Khatri
src/configure/codex.rs 297 claude-code
scripts/tests/test_extension.js 282 Prakhar Khatri
src/configure/antigravity.rs 272 claude-code
src/commands/report.rs 204 Prakhar Khatri
src/commands/remote_status.rs 185 claude-code
scripts/finalize-ledger.py 180 claude-code
scripts/tests/test_capture_prompts.py 166 Prakhar Khatri
README.md 159 Prakhar Khatri
src/configure/cursor.rs 156 claude-code
scripts/capture-codex.py 142 claude-code
src/configure/claude.rs 141 claude-code
src/commands/list.rs 136 Prakhar Khatri
src/commands/install_ci.rs 117 claude-code
src/configure/copilot.rs 114 claude-code
src/configure/windsurf.rs 100 claude-code
scripts/capture-claude.py 76 Prakhar Khatri
src/cli.rs 68 Prakhar Khatri
scripts/tests/test_capture_cursor.py 60 Prakhar Khatri

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.

1 participant