التعليق التوضيحي لمراجعة الأكواد
راجع مخرجات وكلاء البرمجة بتعليقات مضمّنة على الـ diff بنمط GitHub، وتقييمات صحة على مستوى الملف، وأحكام قبول أو رفض لتقييم جودة الكود.
جديد في الإصدار v2.4.0
يتطلب تقييم تغييرات الكود التي ينتجها وكلاء البرمجة أكثر من حكم ثنائي بالنجاح أو الفشل. فالباحثون وفرق الهندسة يحتاجون إلى تقدير جودة الكود على مستويات دقة متعددة: قد تحتوي أسطر بعينها على أخطاء أو مخالفات أسلوبية، وقد تكون ملفات كاملة معدَّلة تعديلاً صحيحاً أو غير ضرورية أصلاً، وقد تحل مجموعة التغييرات المشكلة لكنها تُدخل ديناً تقنياً. وهذا هو سير العمل نفسه الذي يتبعه مراجعو الأكواد البشر عند مراجعة pull requests على GitHub.
يأتي وضع التعليق التوضيحي لمراجعة الأكواد في Potato بتجربة مراجعة الـ pull request من GitHub إلى تقييم الوكلاء. يرى المعلّقون diffs موحّدة لكل ملف عدّله الوكيل. ويمكنهم النقر على أي سطر في الـ diff لترك تعليق مضمّن مع وسم فئة. ويحصل كل ملف على تقييم للصحة وآخر للجودة. ثم يصدر المعلّق حكماً نهائياً: قبول، أو طلب تعديلات، أو تعليق فقط. ويُلتقط هذا كله في بيانات تعليق توضيحي منظمة جاهزة لتدريب نماذج جودة الكود.
التعليقات المضمّنة
ينقر المعلّقون على أي سطر في الـ diff ليفتحوا نموذج تعليق مضمّن. لكل تعليق فئة، ودرجة خطورة، ومحتوى نصي حر. ويظهر التعليق مربوطاً بالسطر المعني، تماماً كتعليقات مراجعة الـ pull request على GitHub.
فئات التعليقات
تغطي فئات التعليقات الافتراضية أشيع أنواع ملاحظات مراجعة الأكواد:
| الفئة | الوصف |
|---|---|
bug | خلل وظيفي -- الكود لن يعمل بشكل صحيح |
logic | خطأ منطقي -- المقاربة معيبة حتى لو كانت البنية اللغوية سليمة |
security | ثغرة أمنية أو ممارسة غير آمنة |
performance | مشكلة أداء -- حساب غير ضروري، تسرّب ذاكرة، إلخ |
style | مخالفة أسلوبية -- التسمية، التنسيق، الاستخدام الاصطلاحي |
suggestion | مقاربة بديلة كانت ستكون أفضل |
question | يلزم توضيح -- المراجع غير متأكد من المقصد |
praise | ملاحظة إيجابية -- شيء أحسن الوكيل صنعه |
التهيئة
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 مفعّلاً، يمكن للمعلّقين كتابة بديل مقترح لكتلة الكود التي يعلّقون عليها. وهذا يحاكي ميزة suggestion في GitHub. يظهر الاقتراح في كتلة كود تحت التعليق، ويمكن استخدامه في تدريب نماذج إصلاح الكود.
# 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])"
}التقييمات على مستوى الملف
يحصل كل ملف عدّله الوكيل على تقييمين مستقلين: الصحة وجودة الكود.
التهيئة
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صيغة المخرجات
{
"file_ratings": {
"src/parser.py": {
"correctness": 4,
"quality": 3
},
"tests/test_parser.py": {
"correctness": 5,
"quality": 4
},
"src/utils.py": {
"correctness": 2,
"quality": 2
}
}
}الحكم الكلي
بعد مراجعة كل الملفات وترك التعليقات المضمّنة، يصدر المعلّق حكماً كلياً على مجموعة التغييرات بأكملها.
التهيئة
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مرجع التهيئة
إليك تهيئة كاملة لمهمة تعليق توضيحي لمراجعة الأكواد:
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"سير عمل التعليق التوضيحي
إليك ما يراه المعلّقون وما يفعلونه عند إتمام مهمة تعليق توضيحي لمراجعة الأكواد:
-
نظرة عامة على المهمة: يظهر وصف المهمة في الأعلى، موضحاً ما طُلب من الوكيل فعله (مثلاً «أصلح الاختبار الفاشل في test_parser.py»).
-
التنقل في شجرة الملفات: يعرض الشريط الجانبي الأيسر كل الملفات التي مسّها الوكيل. والملفات ملوّنة بالرمز: أخضر للملفات الجديدة، وأصفر للمعدَّلة، وأحمر للمحذوفة.
-
مراجعة الـ diff: تعرض اللوحة الرئيسية diffs موحّدة لكل ملف. يمرّ المعلّقون على الـ diffs ويقرأون كل تغيير.
-
إضافة تعليقات مضمّنة: النقر على رقم سطر يفتح نموذج تعليق. يختار المعلّق فئة (خلل، اقتراح، إلخ)، ويختار درجة خطورة اختيارياً، ويكتب تعليقه، ويضيف اقتراح كود إن شاء.
-
تقييمات الملفات: بعد مراجعة diff كل ملف، يقيّمه المعلّق على الصحة (1-5) وعلى جودة الكود (1-5) عبر أدوات التقييم أسفل diff كل ملف.
-
الحكم الكلي: في الأسفل، يختار المعلّق حكماً (قبول أو طلب تعديلات أو تعليق فقط) ويكتب ملخصاً لمراجعته.
-
الإرسال: ينقر المعلّق على Submit لحفظ كل التعليقات المضمّنة وتقييمات الملفات والحكم في سجل تعليق واحد.
صيغة البيانات
المخرجات الكاملة لتعليق توضيحي واحد لمراجعة أكواد:
{
"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."
}
}
}التصدير
يمكن تصدير تعليقات مراجعة الأكواد بصيغ عدة:
# 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 مفيدة بوجه خاص لتدريب نماذج تولّد تعليقات مراجعة الأكواد أو تتنبأ بموضع مشكلات الكود وفئتها.
انظر أيضاً
- التعليق التوضيحي لوكيل البرمجة -- عرض تتبعات وكلاء البرمجة مع تصيير الـ diff وشجرة الملفات
- تعليق مكافأة العملية -- إشارات مكافأة لكل خطوة لتدريب PRM
- مراقبة وكيل البرمجة المباشر -- مراقبة وكلاء البرمجة والتفاعل معهم في الوقت الفعلي
- التعليق التوضيحي للوكلاء -- التعليق على تتبعات الوكلاء لأغراض عامة
- صيغ التصدير -- كل صيغ التصدير المدعومة
للاطلاع على تفاصيل التنفيذ، راجع الوثائق المصدرية.