Skip to content

feat: add code_locator.py — automated code snippet location fixer - #76

Open
Dametime-0 wants to merge 1 commit into
Tencent:mainfrom
Dametime-0:fix/issue4-code-locator
Open

feat: add code_locator.py — automated code snippet location fixer#76
Dametime-0 wants to merge 1 commit into
Tencent:mainfrom
Dametime-0:fix/issue4-code-locator

Conversation

@Dametime-0

Copy link
Copy Markdown

Add a Python tool that detects and fixes misaligned code snippets in VulnGym entry_point / critical_operation / trace nodes. For each node the tool:

  • Checks out the target repository at its vulnerable commit
  • Verifies the code snippet matches at file:line
  • Searches ±5 lines → full file → full repo when mismatched
  • Auto-fixes line/file when a unique match is found
  • Flags ambiguous cases for human review in needs_human.csv

Also includes comprehensive README documentation covering usage, parameters, output format, and known limitations.

Tool satisfies Issue #4 requirements:

  • Outputs entries.fixed.jsonl, fix_diff.csv, needs_human.csv

  • Whitespace-tolerant matching for multi-line code snippets

  • Conservative: never modifies when unsure

  • Repo caching to avoid repeated clones

  • --skip-clone mode for offline operation

    实现了 Issue 【2026犀牛鸟】修复 VulnGym 数据中的代码片段定位偏差 #4 要求的代码片段定位偏差自动修复工具。

    新增文件

    文件 说明
    tools/code_locator.py 主工具脚本(~1200 行)
    tools/README_code_locator.md 使用文档

    功能

    data/entries.jsonl 中每个 entry_point / critical_operation / trace[*] 节点:

    1. 验证原始位置 — 在对应仓库 commit 处检查 code 是否在 file:line 匹配
    2. ±5 行搜索全文件搜索全仓库搜索 — 逐步扩大搜索范围
    3. 自动修复 — 唯一匹配时修正 file/line,同步更新 desc
    4. 人工复核 — 多处命中/找不到时写入 needs_human.csv

    输出文件

    • entries.fixed.jsonl — 修复后的数据
    • fix_diff.csv — 逐条修改记录
    • needs_human.csv — 人工复核清单

    使用方式

    # 干运行(仅检测)
    python tools/code_locator.py --mode dry-run --verify-filter 0
    
    # 修复
    python tools/code_locator.py --mode fix --verify-filter 0
    
    # 离线模式(使用已缓存仓库)
    python tools/code_locator.py --mode fix --skip-clone

Add a Python tool that detects and fixes misaligned code snippets in
VulnGym entry_point / critical_operation / trace nodes. For each node
the tool:

- Checks out the target repository at its vulnerable commit
- Verifies the code snippet matches at file:line
- Searches ±5 lines → full file → full repo when mismatched
- Auto-fixes line/file when a unique match is found
- Flags ambiguous cases for human review in needs_human.csv

Also includes comprehensive README documentation covering usage,
parameters, output format, and known limitations.

Tool satisfies Issue Tencent#4 requirements:
- Outputs entries.fixed.jsonl, fix_diff.csv, needs_human.csv
- Whitespace-tolerant matching for multi-line code snippets
- Conservative: never modifies when unsure
- Repo caching to avoid repeated clones
- --skip-clone mode for offline operation
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