Skip to content

fix: cursor CLI capture for WSL2 (hook execution + path normalization + transcript lookup)#9

Open
codeprakhar25 wants to merge 5 commits intomainfrom
fix/cursor-cli-capture
Open

fix: cursor CLI capture for WSL2 (hook execution + path normalization + transcript lookup)#9
codeprakhar25 wants to merge 5 commits intomainfrom
fix/cursor-cli-capture

Conversation

@codeprakhar25
Copy link
Copy Markdown
Owner

@codeprakhar25 codeprakhar25 commented Apr 28, 2026

What does this PR do?

Fixes cursor agent traces never appearing in agentdiff when working with Cursor on WSL2. Three independent bugs combined to silently drop every cursor event.

Bug 1 — Hook never executed (src/configure/cursor.rs)
The Windows-side ~/.cursor/hooks.json was written with python3 /home/prakh/.agentdiff/.... Cursor (a Windows app) runs hooks in a Windows shell where that Linux path is invalid, so every hook invocation failed silently. Fixed by prefixing with wsl for any hooks.json under /mnt/ (Windows-side paths).

Bug 2 — UNC paths broke repo detection (scripts/capture-cursor.py)
When Cursor opens a WSL workspace, it passes file paths as Windows UNC strings like \\wsl.localhost\Ubuntu\home\prakh\agentdiff\src\main.rs. After backslash conversion this became /wsl.localhost/Ubuntu/home/... — a path that doesn't exist in WSL. git rev-parse failed, no .git/agentdiff/ was found, and the script exited with SKIP no_agentdiff_init. Fixed in normalize_path to strip the WSL UNC host prefix and convert Windows drive letters (D://mnt/d/).

Bug 3 — Transcript lookup missed (scripts/capture-cursor.py)
get_prompt_from_transcript derived the project slug as home-prakh-agentdiff from the Linux path, but Cursor stores data under wsl-localhost-Ubuntu-home-prakh-agentdiff (the Windows UNC slug). The prompt was always "unknown". Fixed by scanning both the Linux-side and Windows-side cursor projects/ dirs for a matching slug suffix, with Linux $USER used to pick the right Windows user directory (avoids reading from unrelated system accounts on shared machines).

Type of change

  • Bug fix
  • New agent support
  • New feature
  • Refactor / cleanup
  • Docs

Testing

  • cargo test --locked passes
  • python3 -m unittest discover -s scripts/tests -p "test_*.py" passes
  • Manually tested with Cursor on WSL2 — cursor events now appear in session.jsonl and are attributed correctly in agentdiff report

Checklist

  • Follows existing code style
  • No new dependencies without discussion
  • Updated README / CONTRIBUTING if needed

Document the new context command, context-aware reports, and skill installer so users can discover the released workflow from the main README.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

AgentDiff Report

Summary

Agent Lines %
claude-code 1016 96%
Prakhar Khatri 42 4%

Review Context

  • Intent: unspecified (1058 lines, 4 files)
    • Agent/model: Prakhar Khatri, claude-code / claude-sonnet-4-6
    • Prompt: ok it is working now just check the PR comments on the PR I created for it and fill in the description let's complete the PR and make it ready to be merged....., the traces written by cursor agent is not being reported in agentdiff while I work with cursor CLI, what's the main issue let's try and fix it

Files To Review First

File Lines Dominant Agent Intent Context
scripts/test-pipeline-comprehensive.py 897 claude-code unspecified trace 835227e9
scripts/capture-cursor.py 106 claude-code unspecified trace 835227e9
.github/workflows/agentdiff-policy.yml 46 Prakhar Khatri unspecified trace 3b81698e
src/configure/cursor.rs 9 claude-code unspecified trace 835227e9
Trace details
Trace Agent Intent Files Lines
835227e9 claude-code unspecified scripts/capture-cursor.py, scripts/test-pipeline-comprehensive.py, src/configure/cursor.rs 992
3b81698e Prakhar Khatri unspecified .github/workflows/agentdiff-policy.yml 42
761a7e57 claude-code unspecified .github/workflows/agentdiff-policy.yml, scripts/capture-cursor.py 24

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 28, 2026

Greptile Summary

This PR fixes three independent bugs that caused Cursor agent traces to be silently dropped on WSL2: the hook command is now prefixed with wsl for Windows-side paths so the Linux script path resolves correctly, Windows UNC paths and drive letters are normalized before git rev-parse, and transcript lookup now scans both Linux-side and Windows-side Cursor project directories with multiple slug patterns.

Confidence Score: 5/5

Safe to merge; both remaining findings are P2 and do not affect the primary WSL2 code path.

All three targeted bugs are well-diagnosed and correctly fixed. The two P2 findings (dead if in _wsl_distro_name and inconsistent Windows user detection in Rust vs Python) are harmless in the common single-user WSL2 scenario and don't regress any existing behavior.

scripts/capture-cursor.py (_wsl_distro_name logic) and src/configure/cursor.rs (Windows user directory selection).

Important Files Changed

Filename Overview
scripts/capture-cursor.py Adds WSL UNC path normalization, drive-letter mapping, and multi-slug transcript lookup; one logic bug in _wsl_distro_name (dead if branch) causes the function to return the OS name on native Linux instead of empty string, harmlessly adding an extra non-existent candidate path.
src/configure/cursor.rs Correctly introduces wsl_cmd/linux_cmd split and /mnt/ detection for Bug 1 fix; Windows user directory scan doesn't use the Linux $USER env var to prefer a matching Windows username, unlike the corresponding Python code.
.github/workflows/agentdiff-policy.yml New policy-check workflow correctly passes github.head_ref through an env var (HEAD_REF) rather than direct interpolation, avoiding the injection issue flagged on the companion workflow; install step uses `curl
.github/workflows/agentdiff-consolidate.yml Removes the unused BRANCH variable that held the unquoted github.head_ref expression, cleaning up the previously flagged injection surface.
README.md Documentation-only updates adding agentdiff context, agentdiff install-skill, and --context report flag examples; no code changes.

Reviews (2): Last reviewed commit: "fix: address PR review issues — shell in..." | Re-trigger Greptile

Comment thread .github/workflows/agentdiff-policy.yml
codeprakhar25 and others added 2 commits April 28, 2026 09:12
- Fix shell injection in agentdiff-policy.yml: pass github.head_ref and
  head.sha through env vars instead of interpolating directly into the run
  block, preventing branch-name-based code execution in the runner.
- Fix wrong Windows user selection in _cursor_transcript_candidates: use
  the Linux $USER env var to find the matching Windows home directory
  before falling back to alphabetical scan, avoiding reads from unrelated
  user dirs (Administrator, Default, etc.) on shared machines.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codeprakhar25 codeprakhar25 changed the title Fix/cursor cli capture fix: cursor CLI capture for WSL2 (hook execution + path normalization + transcript lookup) Apr 28, 2026
@codeprakhar25 codeprakhar25 reopened this Apr 29, 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.

1 participant