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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
"""Code editing benchmark adapters (SWE-bench, DebugBench, CanItEdit, CodeEditorBench)."""

from __future__ import annotations

import json
from typing import Any

from adapters import DatasetAdapter

# Injected at runtime by _set_helpers()
_highlight_code = None
_code_offset = None
_extract_test_classes = None


# ---------------------------------------------------------------------------
# SWE-bench Lite adapter  (HuggingFace: princeton-nlp/SWE-bench_Lite)
# ---------------------------------------------------------------------------


class SWEBenchLiteAdapter(DatasetAdapter):
    slug = "swebenchlite"
    display_name = "SWE-bench Lite"
    has_ground_truth = False
    has_tasks = False

    def __init__(self, hf_dataset):
        self._ds = hf_dataset

    def problem_count(self) -> int:
        return len(self._ds)

    def get_problem_summary(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        return {
            "idx": idx,
            "task_id": row["instance_id"],
            "entry_point": row["instance_id"].split("__")[-1],
            "num_inputs": 0,
            "source": row["repo"],
        }

    @staticmethod
    def _github_links(instance_id: str, repo: str, base_commit: str) -> dict[str, str]:
        """Build GitHub URLs from SWE-bench instance metadata."""
        links: dict[str, str] = {}
        if repo:
            links["repo_url"] = f"https://github.com/{repo}"
        # instance_id format: "repo__issue-number" e.g. "astropy__astropy-12907"
        parts = instance_id.rsplit("-", 1)
        if len(parts) == 2 and parts[1].isdigit() and repo:
            links["issue_url"] = f"https://github.com/{repo}/issues/{parts[1]}"
        if base_commit and repo:
            links["commit_url"] = f"https://github.com/{repo}/commit/{base_commit}"
        return links

    def get_problem_detail(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        patch = row["patch"]
        raw_f2p = row["FAIL_TO_PASS"]
        fail_to_pass = raw_f2p if isinstance(raw_f2p, list) else (json.loads(raw_f2p) if raw_f2p else [])
        raw_p2p = row["PASS_TO_PASS"]
        pass_to_pass = raw_p2p if isinstance(raw_p2p, list) else (json.loads(raw_p2p) if raw_p2p else [])
        instance_id = row["instance_id"]
        repo = row["repo"]
        base_commit = row.get("base_commit", "")
        return {
            "idx": idx,
            "task_id": instance_id,
            "entry_point": instance_id.split("__")[-1],
            "code": patch,
            "highlighted_code": "",
            "inputs": [],
            "outputs": [],
            "test": None,
            "tasks": [],
            "source": repo,
            "has_ground_truth": False,
            "has_tasks": False,
            "description": row["problem_statement"],
            "patch": patch,
            "test_patch": row.get("test_patch", ""),
            "fail_to_pass": fail_to_pass,
            "pass_to_pass": pass_to_pass,
            "hints": row.get("hints_text", ""),
            "repo": repo,
            "base_commit": base_commit,
            "version": row.get("version", ""),
            "created_at": row.get("created_at", ""),
            **self._github_links(instance_id, repo, base_commit),
        }


# ---------------------------------------------------------------------------
# SWE-bench Verified adapter  (HuggingFace: princeton-nlp/SWE-bench_Verified)
# ---------------------------------------------------------------------------


class SWEBenchVerifiedAdapter(SWEBenchLiteAdapter):
    slug = "swebenchverified"
    display_name = "SWE-bench Verified"


class SWEBenchFullAdapter(SWEBenchLiteAdapter):
    slug = "swebenchfull"
    display_name = "SWE-bench"


# ---------------------------------------------------------------------------
# DebugBench adapter  (HuggingFace: Rtian/DebugBench)
# ---------------------------------------------------------------------------


class DebugBenchAdapter(DatasetAdapter):
    slug = "debugbench"
    display_name = "DebugBench"
    has_ground_truth = False
    has_tasks = False

    def __init__(self, hf_dataset):
        self._ds = hf_dataset

    def problem_count(self) -> int:
        return len(self._ds)

    def get_problem_summary(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        return {
            "idx": idx,
            "task_id": row["slug"],
            "entry_point": row["slug"],
            "num_inputs": len(row["examples"]),
            "source": f"{row['language']}/{row['category']}",
        }

    def get_problem_detail(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        lang = row["language"]
        buggy = row["buggy_code"]
        fixed = row["solution"]
        return {
            "idx": idx,
            "task_id": row["slug"],
            "entry_point": row["slug"],
            "code": fixed,
            "highlighted_code": _highlight_code(fixed, language=lang),
            "inputs": [],
            "outputs": [],
            "test": None,
            "tasks": [],
            "source": f"{lang}/{row['category']}",
            "has_ground_truth": False,
            "has_tasks": False,
            "description": row["question"],
            "language": lang,
            "buggy_code": buggy,
            "buggy_highlighted_code": _highlight_code(buggy, language=lang),
            "fixed_code": fixed,
            "fixed_highlighted_code": _highlight_code(fixed, language=lang),
            "bug_category": row["category"],
            "bug_subtype": row["subtype"],
            "bug_explanation": row["bug_explanation"],
            "difficulty": row["level"],
            "examples": list(row["examples"]),
        }


# ---------------------------------------------------------------------------
# CanItEdit adapter  (HuggingFace: nuprl/CanItEdit)
# ---------------------------------------------------------------------------


class CanItEditAdapter(DatasetAdapter):
    slug = "canitedit"
    display_name = "CanItEdit"
    has_ground_truth = False
    has_tasks = False

    def __init__(self, hf_dataset):
        self._ds = hf_dataset

    def problem_count(self) -> int:
        return len(self._ds)

    def get_problem_summary(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        taxonomy = row.get("taxonomy", {})
        change_kind = taxonomy.get("change_kind", "") if isinstance(taxonomy, dict) else ""
        return {
            "idx": idx,
            "task_id": row.get("full_name", str(row.get("id", idx))),
            "entry_point": row.get("name", f"edit_{idx}"),
            "num_inputs": 0,
            "source": change_kind or "CanItEdit",
        }

    def get_problem_detail(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        before = row["before"]
        after = row["after"]
        taxonomy = row.get("taxonomy", {})
        if not isinstance(taxonomy, dict):
            taxonomy = {}
        return {
            "idx": idx,
            "task_id": row.get("full_name", str(row.get("id", idx))),
            "entry_point": row.get("name", f"edit_{idx}"),
            "code": after,
            "highlighted_code": _highlight_code(after),
            "inputs": [],
            "outputs": [],
            "test": row.get("tests", ""),
            "tasks": [],
            "source": taxonomy.get("change_kind", "CanItEdit"),
            "has_ground_truth": False,
            "has_tasks": False,
            "description": row.get("instruction_descriptive", ""),
            "buggy_code": before,
            "buggy_highlighted_code": _highlight_code(before),
            "fixed_code": after,
            "fixed_highlighted_code": _highlight_code(after),
            "bug_category": taxonomy.get("change_kind", ""),
            "bug_subtype": taxonomy.get("topic", ""),
            "bug_explanation": row.get("instruction_lazy", ""),
        }


# ---------------------------------------------------------------------------
# CodeEditorBench adapter  (HuggingFace: m-a-p/CodeEditorBench)
# ---------------------------------------------------------------------------


class CodeEditorBenchAdapter(DatasetAdapter):
    slug = "codeeditorbench"
    display_name = "CodeEditorBench"
    has_ground_truth = False
    has_tasks = False

    def __init__(self, rows: list[dict[str, Any]]):
        self._rows = rows

    def problem_count(self) -> int:
        return len(self._rows)

    def get_problem_summary(self, idx: int) -> dict[str, Any]:
        row = self._rows[idx]
        return {
            "idx": idx,
            "task_id": str(row.get("idx", idx)),
            "entry_point": row.get("title", f"problem_{idx}"),
            "num_inputs": 0,
            "source": row.get("_task_type", "unknown"),
        }

    def get_problem_detail(self, idx: int) -> dict[str, Any]:
        row = self._rows[idx]
        task_type = row.get("_task_type", "unknown")
        lang = row.get("code_language", row.get("source_lang", "python")) or "python"
        lang_key = lang.lower()

        if task_type == "code_debug":
            buggy = row.get("incorrect_solutions", "")
            fixed = row.get("solutions", "")
        elif task_type == "code_translate":
            buggy = row.get("source_code", "")
            fixed = row.get("solutions", row.get("source_code", ""))
        elif task_type == "code_polishment":
            buggy = row.get("source_code", "")
            fixed = row.get("solutions", row.get("source_code", ""))
        else:  # code_switch
            buggy = row.get("similar_source_code", row.get("source_code", ""))
            fixed = row.get("solutions", row.get("source_code", ""))

        return {
            "idx": idx,
            "task_id": str(row.get("idx", idx)),
            "entry_point": row.get("title", f"problem_{idx}"),
            "code": fixed,
            "highlighted_code": _highlight_code(fixed, language=lang_key) if fixed else "",
            "inputs": [],
            "outputs": [],
            "test": None,
            "tasks": [],
            "source": task_type,
            "has_ground_truth": False,
            "has_tasks": False,
            "description": "",
            "buggy_code": buggy,
            "buggy_highlighted_code": _highlight_code(buggy, language=lang_key) if buggy else "",
            "fixed_code": fixed,
            "fixed_highlighted_code": _highlight_code(fixed, language=lang_key) if fixed else "",
            "bug_category": task_type,
            "bug_subtype": row.get("difficulty", ""),
            "bug_explanation": "",
            "difficulty": row.get("difficulty", ""),
            "language": lang,
        }


# ---------------------------------------------------------------------------
# CodeXGLUE Code Refinement adapter  (HuggingFace: google/code_x_glue_cc_code_refinement)
# ---------------------------------------------------------------------------


class CodeXGLUERefinementAdapter(DatasetAdapter):
    slug = "codexgluerefinement"
    display_name = "CodeXGLUE Code Refinement"
    has_ground_truth = False
    has_tasks = False

    def __init__(self, hf_dataset):
        self._ds = hf_dataset

    def problem_count(self) -> int:
        return len(self._ds)

    def get_problem_summary(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        return {
            "idx": idx,
            "task_id": str(row.get("id", idx)),
            "entry_point": f"refinement_{row.get('id', idx)}",
            "num_inputs": 0,
            "source": "CodeXGLUE",
        }

    def get_problem_detail(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        buggy = row.get("buggy", "")
        fixed = row.get("fixed", "")
        return {
            "idx": idx,
            "task_id": str(row.get("id", idx)),
            "entry_point": f"refinement_{row.get('id', idx)}",
            "code": fixed,
            "highlighted_code": _highlight_code(fixed, language="java") if fixed else "",
            "inputs": [],
            "outputs": [],
            "test": None,
            "tasks": [],
            "source": "CodeXGLUE",
            "has_ground_truth": False,
            "has_tasks": False,
            "description": "",
            "buggy_code": buggy,
            "buggy_highlighted_code": _highlight_code(buggy, language="java") if buggy else "",
            "fixed_code": fixed,
            "fixed_highlighted_code": _highlight_code(fixed, language="java") if fixed else "",
            "bug_category": "Code Refinement",
            "bug_subtype": "",
            "bug_explanation": "",
            "language": "Java",
        }


# ---------------------------------------------------------------------------
# CommitBench adapter  (HuggingFace: Maxscha/commitbench)
# ---------------------------------------------------------------------------


class CommitBenchAdapter(DatasetAdapter):
    slug = "commitbench"
    display_name = "CommitBench"
    has_ground_truth = False
    has_tasks = False

    def __init__(self, hf_dataset):
        self._ds = hf_dataset

    def problem_count(self) -> int:
        return len(self._ds)

    def get_problem_summary(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        return {
            "idx": idx,
            "task_id": row.get("hash", str(idx))[:12],
            "entry_point": row.get("project", f"commit_{idx}"),
            "num_inputs": 0,
            "source": row.get("diff_languages", "unknown"),
        }

    def get_problem_detail(self, idx: int) -> dict[str, Any]:
        row = self._ds[idx]
        diff = row.get("diff", "")
        message = row.get("message", "")
        return {
            "idx": idx,
            "task_id": row.get("hash", str(idx))[:12],
            "entry_point": row.get("project", f"commit_{idx}"),
            "code": diff,
            "highlighted_code": "",
            "inputs": [],
            "outputs": [],
            "test": None,
            "tasks": [],
            "source": row.get("diff_languages", "unknown"),
            "has_ground_truth": False,
            "has_tasks": False,
            "description": message,
            "patch": diff,
            "repo": row.get("project", ""),
            "commit_hash": row.get("hash", ""),
            "diff_languages": row.get("diff_languages", ""),
        }