Skip to content

कोड रिव्यू एनोटेशन

AI कोडिंग एजेंट के आउटपुट की समीक्षा करें, GitHub PR जैसी इनलाइन diff टिप्पणियों, फ़ाइल-स्तरीय शुद्धता रेटिंग, और कोड गुणवत्ता मूल्यांकन के लिए approve या reject फ़ैसले के साथ।

v2.4.0 में नया

AI कोडिंग एजेंट के बनाए कोड बदलावों का मूल्यांकन करने के लिए बाइनरी पास/फ़ेल फ़ैसला काफ़ी नहीं है। शोधकर्ताओं और इंजीनियरिंग टीमों को कोड की गुणवत्ता कई स्तरों पर आँकनी होती है: अलग-अलग पंक्तियों में बग या शैली का उल्लंघन हो सकता है, पूरी फ़ाइल सही ढंग से बदली गई हो सकती है या ग़ैरज़रूरी हो सकती है, और बदलावों का पूरा सेट समस्या हल तो कर दे पर तकनीकी क़र्ज़ छोड़ जाए। GitHub पर pull request देखते समय मानव कोड रिव्यूअर यही कार्यप्रवाह अपनाते हैं।

Potato का कोड रिव्यू एनोटेशन मोड GitHub PR रिव्यू का अनुभव एजेंट मूल्यांकन में ले आता है। एजेंट ने जो भी फ़ाइल बदली है, एनोटेटर उसका unified diff देखते हैं। वे diff की किसी भी पंक्ति पर क्लिक करके श्रेणी टैग सहित इनलाइन टिप्पणी छोड़ सकते हैं। हर फ़ाइल को शुद्धता और गुणवत्ता की रेटिंग मिलती है। एनोटेटर आख़िरी फ़ैसला देता है: approve, request changes, या सिर्फ़ comment। यह सब संरचित एनोटेशन डेटा के रूप में दर्ज होता है, जो कोड गुणवत्ता मॉडल के प्रशिक्षण के लिए तैयार होता है।

इनलाइन टिप्पणियाँ

एनोटेटर diff की किसी भी पंक्ति पर क्लिक करके इनलाइन टिप्पणी फ़ॉर्म खोलते हैं। हर टिप्पणी में एक श्रेणी, एक गंभीरता और मुक्त-पाठ सामग्री होती है। टिप्पणी उसी ख़ास पंक्ति से जुड़ी हुई दिखती है, ठीक GitHub PR रिव्यू टिप्पणियों की तरह।

टिप्पणी श्रेणियाँ

डिफ़ॉल्ट टिप्पणी श्रेणियाँ कोड रिव्यू में मिलने वाली सबसे आम प्रतिक्रियाओं को कवर करती हैं:

श्रेणीविवरण
bugकामकाजी बग -- कोड सही ढंग से नहीं चलेगा
logicतर्क की ग़लती -- सिंटैक्स सही होने पर भी तरीक़ा ख़राब है
securityसुरक्षा भेद्यता या असुरक्षित तरीक़ा
performanceप्रदर्शन की समस्या -- ग़ैरज़रूरी गणना, मेमोरी लीक वग़ैरह
styleशैली का उल्लंघन -- नामकरण, फ़ॉर्मैटिंग, मुहावरेदार इस्तेमाल
suggestionवैकल्पिक तरीक़ा जो बेहतर होता
questionस्पष्टीकरण चाहिए -- रिव्यूअर को मंशा साफ़ नहीं है
praiseसकारात्मक प्रतिक्रिया -- एजेंट ने जो अच्छा किया

कॉन्फ़िगरेशन

yaml
annotation_schemes:
  - name: inline_comments
    annotation_type: code_review_comments
    description: "Click any diff line to add an inline comment"
 
    inline_comments:
      # Comment categories
      categories:
        - value: bug
          display: "Bug"
          color: "#ef4444"
          icon: "bug"
        - value: logic
          display: "Logic Error"
          color: "#f97316"
          icon: "alert-triangle"
        - value: security
          display: "Security"
          color: "#dc2626"
          icon: "shield-alert"
        - value: performance
          display: "Performance"
          color: "#eab308"
          icon: "zap"
        - value: style
          display: "Style"
          color: "#6b7280"
          icon: "palette"
        - value: suggestion
          display: "Suggestion"
          color: "#3b82f6"
          icon: "lightbulb"
        - value: question
          display: "Question"
          color: "#8b5cf6"
          icon: "help-circle"
        - value: praise
          display: "Praise"
          color: "#22c55e"
          icon: "thumbs-up"
 
      # Severity levels (optional)
      severity:
        enabled: true
        levels:
          - value: critical
            display: "Critical"
          - value: major
            display: "Major"
          - value: minor
            display: "Minor"
          - value: nit
            display: "Nit"
 
      # Behavior
      require_category: true
      require_severity: false
      allow_multi_line: true       # comments can span a range of lines
      allow_suggestions: true      # annotator can write suggested replacement code
      min_comments: 0              # minimum comments required before submission

सुझाए गए कोड बदलाव

जब allow_suggestions चालू हो, तो एनोटेटर जिस कोड ब्लॉक पर टिप्पणी कर रहे हैं उसके लिए बदलकर रखा जाने वाला कोड सुझा सकते हैं। यह GitHub के "suggestion" फ़ीचर जैसा है। सुझाव टिप्पणी के नीचे एक कोड ब्लॉक में दिखता है और उससे कोड मरम्मत मॉडल प्रशिक्षित किए जा सकते हैं।

yaml
# In inline comment output:
{
  "file": "src/parser.py",
  "line_start": 42,
  "line_end": 44,
  "category": "bug",
  "severity": "critical",
  "comment": "Off-by-one error: range should be inclusive of end",
  "suggestion": "for i in range(start, end + 1):\n    process(tokens[i])"
}

फ़ाइल-स्तरीय रेटिंग

एजेंट ने जो भी फ़ाइल बदली है, उसे दो स्वतंत्र रेटिंग मिलती हैं: शुद्धता और कोड गुणवत्ता।

कॉन्फ़िगरेशन

yaml
annotation_schemes:
  - name: file_ratings
    annotation_type: code_review_file_ratings
    description: "Rate each modified file"
 
    file_ratings:
      dimensions:
        - name: correctness
          display: "Correctness"
          description: "Are the changes to this file functionally correct?"
          scale:
            min: 1
            max: 5
            labels:
              1: "Broken -- introduces bugs or breaks existing functionality"
              2: "Mostly broken -- significant functional issues"
              3: "Partially correct -- works but has edge cases or minor bugs"
              4: "Mostly correct -- minor issues only"
              5: "Fully correct -- changes work as intended"
 
        - name: quality
          display: "Code Quality"
          description: "How well-written are the changes to this file?"
          scale:
            min: 1
            max: 5
            labels:
              1: "Very poor -- unreadable, no structure"
              2: "Poor -- hard to follow, inconsistent style"
              3: "Acceptable -- works but could be cleaner"
              4: "Good -- clean, idiomatic, well-structured"
              5: "Excellent -- exemplary code, would merge as-is"
 
      # Files to rate
      include_unchanged: false     # only rate files the agent modified
      include_new_files: true      # include files the agent created
      include_deleted_files: true  # include files the agent deleted
 
      # Behavior
      require_all_files: true      # must rate every modified file

आउटपुट फ़ॉर्मैट

json
{
  "file_ratings": {
    "src/parser.py": {
      "correctness": 4,
      "quality": 3
    },
    "tests/test_parser.py": {
      "correctness": 5,
      "quality": 4
    },
    "src/utils.py": {
      "correctness": 2,
      "quality": 2
    }
  }
}

कुल फ़ैसला

सारी फ़ाइलें देख लेने और इनलाइन टिप्पणियाँ छोड़ देने के बाद एनोटेटर पूरे बदलाव-सेट पर एक कुल फ़ैसला देता है।

कॉन्फ़िगरेशन

yaml
annotation_schemes:
  - name: verdict
    annotation_type: code_review_verdict
    description: "Give an overall verdict on the code changes"
 
    verdict:
      options:
        - value: approve
          display: "Approve"
          description: "Changes are correct and ready to merge"
          color: "#22c55e"
          icon: "check-circle"
        - value: request_changes
          display: "Request Changes"
          description: "Changes need fixes before merging"
          color: "#ef4444"
          icon: "x-circle"
        - value: comment_only
          display: "Comment Only"
          description: "Leaving feedback without a verdict"
          color: "#6b7280"
          icon: "message-circle"
 
      # Optional summary text
      require_summary: true
      summary_placeholder: "Summarize your review..."
      summary_min_length: 20

कॉन्फ़िगरेशन संदर्भ

कोड रिव्यू एनोटेशन टास्क का पूरा कॉन्फ़िगरेशन:

yaml
task_name: "Coding Agent Code Review"
task_dir: "."
 
data_files:
  - "data/coding_traces.jsonl"
 
item_properties:
  id_key: id
  text_key: task_description
 
agentic:
  enabled: true
  trace_converter: claude_code
  display_type: coding_trace
 
  coding_trace_display:
    diff_style: unified
    diff_context_lines: 5
    syntax_highlight: true
    show_line_numbers: true
    terminal_theme: dark
    file_tree:
      enabled: true
      position: left
      show_operation_icons: true
      click_to_navigate: true
 
annotation_schemes:
  # Inline comments on diff lines
  - name: inline_comments
    annotation_type: code_review_comments
    inline_comments:
      categories:
        - { value: bug, display: "Bug", color: "#ef4444" }
        - { value: logic, display: "Logic Error", color: "#f97316" }
        - { value: security, display: "Security", color: "#dc2626" }
        - { value: performance, display: "Performance", color: "#eab308" }
        - { value: style, display: "Style", color: "#6b7280" }
        - { value: suggestion, display: "Suggestion", color: "#3b82f6" }
        - { value: question, display: "Question", color: "#8b5cf6" }
        - { value: praise, display: "Praise", color: "#22c55e" }
      severity:
        enabled: true
        levels:
          - { value: critical, display: "Critical" }
          - { value: major, display: "Major" }
          - { value: minor, display: "Minor" }
          - { value: nit, display: "Nit" }
      require_category: true
      allow_multi_line: true
      allow_suggestions: true
 
  # File-level correctness and quality
  - name: file_ratings
    annotation_type: code_review_file_ratings
    file_ratings:
      dimensions:
        - name: correctness
          display: "Correctness"
          scale: { min: 1, max: 5 }
        - name: quality
          display: "Code Quality"
          scale: { min: 1, max: 5 }
      require_all_files: true
 
  # Overall verdict
  - name: verdict
    annotation_type: code_review_verdict
    verdict:
      options:
        - { value: approve, display: "Approve", color: "#22c55e" }
        - { value: request_changes, display: "Request Changes", color: "#ef4444" }
        - { value: comment_only, display: "Comment Only", color: "#6b7280" }
      require_summary: true
      summary_min_length: 20
 
output_annotation_dir: "output/"
output_annotation_format: "jsonl"

एनोटेशन कार्यप्रवाह

कोड रिव्यू एनोटेशन टास्क करते समय एनोटेटर को क्या दिखता है और वे क्या करते हैं:

  1. टास्क का ब्यौरा: ऊपर टास्क का विवरण दिखता है, जिससे पता चलता है कि एजेंट से क्या करने को कहा गया था (जैसे, "test_parser.py में विफल हो रहा टेस्ट ठीक करें")।

  2. फ़ाइल ट्री में आवाजाही: बाएँ साइडबार में एजेंट ने जिन फ़ाइलों को छुआ है वे सब दिखती हैं। फ़ाइलें रंग से चिह्नित होती हैं: नई फ़ाइलों के लिए हरा, बदली गई फ़ाइलों के लिए पीला, हटाई गई फ़ाइलों के लिए लाल।

  3. diff की समीक्षा: मुख्य पैनल हर फ़ाइल का unified diff दिखाता है। एनोटेटर diff में आगे बढ़ते हुए हर बदलाव पढ़ते हैं।

  4. इनलाइन टिप्पणियाँ जोड़ना: किसी पंक्ति संख्या पर क्लिक करने से टिप्पणी फ़ॉर्म खुल जाता है। एनोटेटर एक श्रेणी चुनता है (bug, suggestion वग़ैरह), चाहे तो गंभीरता चुनता है, अपनी टिप्पणी लिखता है, और चाहे तो एक कोड सुझाव भी जोड़ता है।

  5. फ़ाइल रेटिंग: हर फ़ाइल का diff देखने के बाद एनोटेटर उसे उसी diff के नीचे मौजूद रेटिंग विजेट से शुद्धता (1-5) और कोड गुणवत्ता (1-5) पर रेट करता है।

  6. कुल फ़ैसला: सबसे नीचे एनोटेटर एक फ़ैसला चुनता है (approve, request changes, या सिर्फ़ comment) और अपनी समीक्षा का सारांश लिखता है।

  7. जमा करना: एनोटेटर "Submit" पर क्लिक करके सारी इनलाइन टिप्पणियाँ, फ़ाइल रेटिंग और फ़ैसला एक ही एनोटेशन रिकॉर्ड के रूप में सहेज देता है।

डेटा फ़ॉर्मैट

एक कोड रिव्यू एनोटेशन का पूरा आउटपुट:

json
{
  "id": "trace_042",
  "annotator": "reviewer_01",
  "timestamp": "2025-01-15T14:30:00Z",
  "annotations": {
    "inline_comments": [
      {
        "file": "src/parser.py",
        "line_start": 42,
        "line_end": 42,
        "category": "bug",
        "severity": "critical",
        "comment": "This will throw IndexError when tokens list is empty",
        "suggestion": "if tokens:\n    return tokens[0]\nreturn None"
      },
      {
        "file": "src/parser.py",
        "line_start": 15,
        "line_end": 15,
        "category": "style",
        "severity": "nit",
        "comment": "Variable name 'x' is not descriptive"
      },
      {
        "file": "tests/test_parser.py",
        "line_start": 28,
        "line_end": 30,
        "category": "praise",
        "comment": "Good edge case coverage for empty input"
      }
    ],
    "file_ratings": {
      "src/parser.py": { "correctness": 3, "quality": 2 },
      "tests/test_parser.py": { "correctness": 5, "quality": 4 }
    },
    "verdict": {
      "decision": "request_changes",
      "summary": "The core fix is on the right track but has an edge case bug with empty input. The test coverage is good. Fix the IndexError and clean up variable naming."
    }
  }
}

निर्यात

कोड रिव्यू एनोटेशन कई फ़ॉर्मैट में निर्यात किए जा सकते हैं:

bash
# Export as structured code review JSON
python -m potato.export \
  -i output/ \
  -f code_review \
  -o results/reviews.jsonl
 
# Export inline comments only (for training code comment models)
python -m potato.export \
  -i output/ \
  -f code_review_comments \
  -o results/comments.jsonl
 
# Export file ratings as a CSV (for analysis)
python -m potato.export \
  -i output/ \
  -f code_review_file_ratings \
  -o results/file_ratings.csv
 
# Export verdict distribution summary
python -m potato.export \
  -i output/ \
  -f code_review_verdicts \
  -o results/verdicts.json

code_review_comments फ़ॉर्मैट ख़ास तौर पर उन मॉडलों के प्रशिक्षण में काम आता है जो कोड रिव्यू टिप्पणियाँ बनाते हैं या कोड की समस्याओं की जगह और श्रेणी का अनुमान लगाते हैं।

यह भी देखें

कार्यान्वयन के विवरण के लिए स्रोत दस्तावेज़ देखें।