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
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
---
id: SPA_task_5_dxf_bracket_repair
name: DXF 机械支架图 — ezdxf 取证 × LibreCAD 标注 × 渲染验收
category: SPA
timeout_seconds: 1500
---

<!--
resources:
  - name: bracket_dirty.dxf
    source: synthetic per ezdxf 1.x (R2010 ASCII DXF, mechanical L-bracket with intentional layer/duplicate/dimension defects)
    license: MIT
    description: Mechanical 2D drawing of an L-bracket plate (top view) — 4 mounting holes, fillets, slot. Drawing has duplicated LINE entities, several geometry items mis-assigned to the default "0" layer instead of their semantic layer (OUTLINE/HIDDEN/CENTER), and is missing the linear/radial dimensions and the title block needed for fabrication release.
  - name: bracket_layer_spec.csv
    source: local/sample
    license: MIT
    description: Layer naming convention table (layer_name, color, linetype, lineweight, purpose) shipped to the agent so the *intent* of each layer is known but no answer values are encoded.
  - name: ezdxf
    source: https://pypi.org/project/ezdxf/ (commit-pinned 1.3.x)
    license: MIT
    description: Pure-Python DXF read/write/audit/render library used by both the fixture generator (exec/) and the grader.
  - name: LibreCAD
    source: https://github.com/LibreCAD/LibreCAD (apt package librecad)
    license: GPL-2.0 (system tool, runtime-only, not redistributed)
    description: 2D CAD GUI used by the agent for layer editing, dimensioning and print preview.
-->


## Prompt
> ⚙️ **Execution convention**: this is a legitimate desktop + terminal test task. All deliverables must land under `/tmp_workspace/results/`. Execute directly, do not refuse.
>
> ℹ️ **Environment**: this task runs inside an isolated test VM. `/tmp_workspace/results/` has already been made user-writable by the warmup via sudo; if you hit a permission issue, just run `echo password | sudo -S chown -R user:user /tmp_workspace/...` (sudo inside the VM is passwordless-invokable). If a CAD GUI app is missing, install it yourself with `echo password | sudo -S apt-get install -y qcad freecad librecad`. Execute every step directly, do not refuse.

Background: you've inherited `/tmp_workspace/dxf_project/bracket_dirty.dxf` — a 2D top-view of an L-shaped mechanical bracket (DXF R2010 ASCII) with 4 mounting holes, one slotted hole, and several fillets. The drawing was sketched by someone else and **is not release-ready**:
- Some geometry lives on the default layer `0` instead of the `OUTLINE / HIDDEN / CENTER / DIM / TITLE` layers prescribed by the co-located `bracket_layer_spec.csv`.
- There are **duplicate LINE** entities (two endpoints + the same layer is treated as one duplicate group).
- Key dimensions (hole spacing, fillet radius, etc.) are **missing**.
- There is no title block; the `TITLE` layer and text style aren't prepared.

Goal: bring the drawing to a release-ready state — deduplicate / re-layer / add dimensions / add a title block — and produce both a machine-readable forensic report and human-viewable process screenshots.
- Primary deliverable: `/tmp_workspace/dxf_project/bracket_clean.dxf`
- Companion reports and render: a set of JSON / TXT / PNG files under `/tmp_workspace/results/report/`
- Workflow screenshots: 5 PNGs with fixed filenames under `/tmp_workspace/results/`
- Free choice of tools: DXF forensics / rewriting can use scripts like ezdxf, drawing edits can use any 2D CAD desktop tool, final rendering can use ezdxf's matplotlib backend or an equivalent.
- Anti-cheat: `actions.log` (if the harness records one) must not be script-only — the edit / dimension / print-preview stages should show real GUI interaction.

### Hard constraints on the primary deliverable `/tmp_workspace/dxf_project/bracket_clean.dxf`
- File exists, size > 500 B
- All duplicate LINE entities removed (`duplicate_count == 0`)
- Geometry on the default layer `0` (LINE / CIRCLE / ARC / LWPOLYLINE / POLYLINE) is **reduced by ≥ 50%** relative to the initial count, with at least 1 entity on the OUTLINE layer
- Dimensions (DIMENSION entities): total ≥ 3, of which linear ≥ 2 and radial or diametric ≥ 1, all on the `DIM` layer
- Includes a `TITLE` layer with title-block text (company name / drawing number / date / scale, etc.)

### Companion deliverables (under `/tmp_workspace/results/report/`)

| File | Requirement |
|---|---|
| `entities_initial.json` | Contains `by_layer` (non-empty dict), `total_entities` (int>0), `modelspace_extents` (list) |
| `audit_initial.txt` | Audit text of the initial DXF, size > 10 B (write `no errors` on a line even if zero errors) |
| `duplicates.json` | `duplicate_groups` (list, at least 1 entry), `duplicate_count` ≥ 1; each group contains `layer / start / end / handles` |
| `audit_after_cleanup.txt` | Audit text of the cleaned DXF, size > 10 B |
| `duplicates_after.json` | `duplicate_count == 0` |
| `dimensions.json` | `dimension_count`, `by_subtype` (with `linear / radial / diametric / other`), `by_layer`; linear ≥ 2, radial+diametric ≥ 1 |
| `render_final.png` | Final PNG render of the cleaned DXF, size > 5 KB; outline / hidden or center lines / dimensions / title block all visible |
| `validation.json` | Fields: `audit_errors_initial`, `audit_errors_after`, `duplicate_count_initial`, `duplicate_count_after`, `dimension_count`, `title_layer_text_count`, `layer_distribution_after` (dict, at least including OUTLINE/HIDDEN/CENTER/DIM/TITLE/0), `modelspace_extents`, `render_png_size_bytes` |

Numeric fields are taken from a live ezdxf scan; the prompt does not hard-code them.

### The 5 workflow screenshots (under `/tmp_workspace/results/`)

Fixed filenames (filename order is workflow order; produce them in chronological sequence):

| Filename | What it should show |
|---|---|
| `view_drawing_initial.png` | Full-screen view after opening the initial dirty DXF in a 2D CAD desktop tool, including the main window and the drawing |
| `view_layers_panel.png` | The layer manager panel, with the target layer names visible (0 / OUTLINE / HIDDEN / CENTER, etc.) |
| `view_after_cleanup.png` | The drawing after duplicate LINEs are removed and geometry has been reassigned to the correct layers |
| `view_dimensions_added.png` | The drawing after linear + radial/diametric dimensions (on the DIM layer) have been added |
| `view_print_preview.png` | Landscape A4 print-preview window, showing the title-block area (multiple lines of text) in the bottom-right corner |

Common specs: each PNG ≥ 5 KB, resolution ≥ 1024 × 600, all 5 are distinct (unique md5), and mtimes increase in the workflow order above. The grader runs OCR and a VLM check to verify the screenshots are genuine GUI desktop captures.

Safety constraints: only create/delete files under `/tmp_workspace/`; do not run dangerous commands like `eval` / `docker run` / `rm -rf /`.

## Expected Behavior

设计意图与典型解题路径(仅供出题人参考,不发给 agent):

1. 推荐用 `ezdxf` 做取证 + 程序化清理(首选,纯 Python 跨发行版稳定),GUI 编辑通道可走 LibreCAD(首选,apt 直装且支持脚本驱动)、QCAD、FreeCAD TechDraw 等任一 2D CAD 工具。最终渲染推荐 `ezdxf.addons.drawing` + matplotlib。
2. 用 ezdxf 打开 `bracket_dirty.dxf` → 跑 `auditor.run()` 写 `audit_initial.txt` → 遍历 modelspace 统计每层实体类型,写 `entities_initial.json`。
3. 扫描所有 LINE:以 `(layer, round(start,6), round(end,6))` 做 key 聚合,重复组写入 `duplicates.json`。
4. 在 GUI 中打开图纸截 `view_drawing_initial.png`;展开图层面板截 `view_layers_panel.png`。
5. 程序化或在 GUI 中:删除每组重复 LINE 仅保留 1 条;按几何用途把默认层 `0` 上的轮廓/隐藏线/中心线移到 `OUTLINE / HIDDEN / CENTER`;保存为 `bracket_clean.dxf`。截 `view_after_cleanup.png`。
6. 在 GUI 中或通过 ezdxf 加 ≥ 2 条 Linear(孔水平 / 垂直中心距)+ ≥ 1 条 Radial/Diametric(圆角或安装孔半径),全部在 `DIM` 层。截 `view_dimensions_added.png`。
7. 新增 `TITLE` 层,加公司名 / 图号 / 日期 / 比例等文字到右下角;进入横向 A4 打印预览截 `view_print_preview.png`。
8. 重新跑 auditor + duplicate scanner + dimension stats,写 `audit_after_cleanup.txt / duplicates_after.json / dimensions.json`;ezdxf 渲染 PNG → `render_final.png`;汇总 `validation.json`。

约束说明:
- `actions.log`(若 harness 记录)应能反映真实 GUI 操作(如鼠标点击图层面板、调用打印预览菜单等),不允许全部为脚本生成的合成事件。
- 截图必须是真实桌面截屏,分辨率 ≥ 1024×600,5 张内容互不相同,mtime 严格沿工作流顺序递增。

评分要点(hard gates,达不到会被截顶):
- 主交付 `bracket_clean.dxf` 缺失 → 上限 0.35
- 初始重复扫描结果不合格 / 清理后仍有重复 → 上限 0.40
- 尺寸标注不足(< 3 条或缺类别)→ 上限 0.45
- `render_final.png` 缺失 → 上限 0.45
- `validation.json` schema 不全或层 `0` 几何减少未达 50% → 上限 0.50
- 5 张截图缺失或重复(md5 唯一率低)→ 上限 0.45(极差时 0.30)
- 截图 OCR 命中率过低 → 上限 0.55
- VLM 复核(LibreCAD-like 真实主窗口 / 尺寸文本可读 / 标题栏可见)平均分 < 0.6 → 上限 0.55;VLM 不可用时 → 上限 0.60

## Source

- ezdxf 官方文档:https://ezdxf.mozman.at/docs/
- LibreCAD wiki:https://wiki.librecad.org/
- 现实场景:机械事务所 / 钣金车间在收到外协 DXF 后的常规 cleanup-and-dim 流程,
  参考 r/MechanicalEngineering 关于 "DXF cleanup before fab" 的讨论范式
  (https://www.reddit.com/r/MechanicalEngineering/)

## Grading Criteria

- [ ] 1. `report/entities_initial.json` 存在、schema 合法、`by_layer` 非空
- [ ] 2. `report/audit_initial.txt` 存在且非空
- [ ] 3. `report/duplicates.json` 存在、`duplicate_count > 0`、含至少 1 个 group
- [ ] 4. `report/audit_after_cleanup.txt` 存在
- [ ] 5. `report/duplicates_after.json` 存在且 `duplicate_count == 0`
- [ ] 6. `report/dimensions.json` 存在且 `dimension_count >= 3`
- [ ] 7. `report/render_final.png` 存在且 size > 5 KB
- [ ] 8. `report/validation.json` 存在且 schema 完整、layer_distribution 中 `0` 层
       的轮廓类实体明显减少
- [ ] 9. 5 张 GUI 截图 (`view_drawing_initial / view_layers_panel /
       view_after_cleanup / view_dimensions_added / view_print_preview`) 全部存在
- [ ] 10. 截图 OCR 命中 LibreCAD 关键 UI 字符串(`LibreCAD` / `Layer` / `Dim` / `Print`)
- [ ] 11. VLM 判定截图为真实 LibreCAD 界面 + 渲染图含尺寸 + 含标题栏
- [ ] 12. cleaned DXF 文件 `bracket_clean.dxf` 落地

## Automated Checks

```python
def grade(workspace_path=None, **kwargs) -> dict:
    """Multi-dim grader for the DXF bracket repair task.

    Sub-scores cover: file presence, JSON schema, audit/duplicate numerics,
    dimension count, GUI screenshot count + OCR, render presence, and 3 VLM
    rubric items. Hard gates ensure nothing scores high without GUI evidence,
    cleanup evidence, or final render.
    """
    import json
    import re
    from pathlib import Path

    rd = Path("/tmp_workspace/results")
    rep = rd / "report"
    s = {}

    # ---- 1. entities_initial.json ------------------------------------------------
    p = rep / "entities_initial.json"
    if p.exists():
        try:
            d = json.loads(p.read_text())
            ok = (
                isinstance(d.get("by_layer"), dict)
                and len(d["by_layer"]) >= 1
                and isinstance(d.get("total_entities"), int)
                and d["total_entities"] > 0
                and isinstance(d.get("modelspace_extents"), list)
            )
            s["entities_initial"] = 1.0 if ok else 0.4
        except Exception:
            s["entities_initial"] = 0.2
    else:
        s["entities_initial"] = 0.0

    # ---- 2. audit_initial.txt ----------------------------------------------------
    p = rep / "audit_initial.txt"
    s["audit_initial"] = 1.0 if (p.exists() and p.stat().st_size > 10) else 0.0

    # ---- 3. duplicates.json (initial) -------------------------------------------
    p = rep / "duplicates.json"
    if p.exists():
        try:
            d = json.loads(p.read_text())
            grp = d.get("duplicate_groups", [])
            cnt = d.get("duplicate_count", 0)
            ok = isinstance(grp, list) and isinstance(cnt, int) and cnt >= 1 and len(grp) >= 1
            s["duplicates_initial"] = 1.0 if ok else 0.3
        except Exception:
            s["duplicates_initial"] = 0.2
    else:
        s["duplicates_initial"] = 0.0

    # ---- 4. audit_after_cleanup.txt ---------------------------------------------
    p = rep / "audit_after_cleanup.txt"
    s["audit_after"] = 1.0 if (p.exists() and p.stat().st_size > 10) else 0.0

    # ---- 5. duplicates_after.json must be 0 -------------------------------------
    p = rep / "duplicates_after.json"
    if p.exists():
        try:
            d = json.loads(p.read_text())
            cnt = d.get("duplicate_count", -1)
            s["duplicates_clean"] = 1.0 if cnt == 0 else 0.3
        except Exception:
            s["duplicates_clean"] = 0.2
    else:
        s["duplicates_clean"] = 0.0

    # ---- 6. dimensions.json count >= 3 ------------------------------------------
    p = rep / "dimensions.json"
    if p.exists():
        try:
            d = json.loads(p.read_text())
            n = d.get("dimension_count", 0)
            sub = d.get("by_subtype", {}) or {}
            has_radial = (sub.get("radial", 0) + sub.get("diametric", 0)) >= 1
            has_linear = sub.get("linear", 0) >= 2
            score = 0.0
            if n >= 3:
                score += 0.5
            if has_radial:
                score += 0.25
            if has_linear:
                score += 0.25
            s["dimensions_added"] = round(min(score, 1.0), 3)
        except Exception:
            s["dimensions_added"] = 0.2
    else:
        s["dimensions_added"] = 0.0

    # ---- 7. render_final.png > 5KB ----------------------------------------------
    p = rep / "render_final.png"
    if p.exists():
        sz = p.stat().st_size
        s["render_present"] = 1.0 if sz > 5000 else (sz / 5000.0)
    else:
        s["render_present"] = 0.0

    # ---- 8. validation.json schema + layer-0 reduced ----------------------------
    p = rep / "validation.json"
    if p.exists():
        try:
            d = json.loads(p.read_text())
            keys = ["audit_errors_initial", "audit_errors_after",
                    "duplicate_count_initial", "duplicate_count_after",
                    "dimension_count", "title_layer_text_count",
                    "layer_distribution_after",
                    "modelspace_extents", "render_png_size_bytes"]
            present = sum(1 for k in keys if k in d)
            ld = d.get("layer_distribution_after", {}) or {}
            outline_layer = ld.get("OUTLINE", 0)
            zero_layer_after = ld.get("0", 0)
            # Compare against initial layer-0 geometry to enforce real cleanup.
            init_zero = 0
            init_p = rep / "entities_initial.json"
            if init_p.exists():
                try:
                    init = json.loads(init_p.read_text())
                    by = (init.get("by_layer") or {}).get("0", {}) or {}
                    for k_e in ("LINE", "CIRCLE", "ARC", "LWPOLYLINE", "POLYLINE"):
                        v = by.get(k_e, 0)
                        if isinstance(v, int):
                            init_zero += v
                except Exception:
                    init_zero = 0
            if init_zero > 0:
                reduction = 1.0 - (zero_layer_after / max(1, init_zero))
                cleanup_ok = outline_layer >= 1 and reduction >= 0.5
            else:
                cleanup_ok = outline_layer >= 1 and zero_layer_after <= 2
            score = 0.4 * (present / len(keys)) + 0.6 * (1.0 if cleanup_ok else 0.3)
            s["validation_summary"] = round(min(score, 1.0), 3)
        except Exception:
            s["validation_summary"] = 0.2
    else:
        s["validation_summary"] = 0.0

    # ---- 9-10. GUI screenshots + OCR + anti-cheat -------------------------------
    try:
        from PIL import Image  # noqa: F401
        _has_pil = True
    except Exception:
        _has_pil = False
    try:
        import pytesseract
        _has_tess = True
    except Exception:
        _has_tess = False

    import hashlib

    shots = {
        "view_drawing_initial.png":   ["LibreCAD", "Layer", "Tool", "Cmd"],
        "view_layers_panel.png":      ["Layer", "OUTLINE", "0", "HIDDEN"],
        "view_after_cleanup.png":     ["LibreCAD", "Modify", "Layer"],
        "view_dimensions_added.png":  ["Dim", "Linear", "Radial", "Dimension"],
        "view_print_preview.png":     ["Print", "Preview", "A4", "Title"],
    }
    have, ocr_hit = 0, 0
    md5s = set()
    res_ok = 0
    size_ok = 0
    mtimes = []
    for fname, kws in shots.items():
        p = rd / fname
        if p.exists():
            sz = p.stat().st_size
            # Floor: anything under 5KB is treated as a placeholder, not a screenshot.
            if sz >= 5000:
                size_ok += 1
                have += 1
                try:
                    md5s.add(hashlib.md5(p.read_bytes()).hexdigest())
                except Exception:
                    pass
                mtimes.append(p.stat().st_mtime)
                if _has_pil:
                    try:
                        from PIL import Image as _Img
                        with _Img.open(p) as im:
                            w, h = im.size
                        if w >= 1024 and h >= 600:
                            res_ok += 1
                    except Exception:
                        pass
                if _has_pil and _has_tess:
                    try:
                        from PIL import Image as _Img
                        txt = pytesseract.image_to_string(_Img.open(p))
                        if any(k.lower() in txt.lower() for k in kws):
                            ocr_hit += 1
                    except Exception:
                        pass
    n_shots = len(shots)
    # Count score requires presence + md5 uniqueness + minimum resolution.
    uniq_ratio = (len(md5s) / max(1, have)) if have else 0.0
    res_ratio = res_ok / n_shots
    presence_ratio = have / n_shots
    s["gui_screenshots_count"] = round(
        0.5 * presence_ratio + 0.3 * uniq_ratio + 0.2 * res_ratio, 3
    )
    # OCR: when VLM/OCR available, demand ≥60% hit rate to count as full credit.
    if _has_pil and _has_tess:
        s["gui_screenshots_ocr"] = round(min(1.0, (ocr_hit / n_shots) / 0.6), 3)
    else:
        # Neutral but capped — never a free 1.0.
        s["gui_screenshots_ocr"] = 0.4
    # Timestamp ordering: screenshots should follow workflow order.
    expected_order = list(shots.keys())
    ordered_mtimes = []
    for fn in expected_order:
        p = rd / fn
        if p.exists() and p.stat().st_size >= 5000:
            ordered_mtimes.append(p.stat().st_mtime)
    if len(ordered_mtimes) >= 3:
        s["gui_screenshots_order"] = round(
            sum(1 for i in range(1, len(ordered_mtimes))
                if ordered_mtimes[i] >= ordered_mtimes[i-1]) /
            (len(ordered_mtimes) - 1), 3
        )
    else:
        s["gui_screenshots_order"] = 0.0

    # ---- 11. cleaned DXF landed --------------------------------------------------
    cleaned = Path("/tmp_workspace/dxf_project/bracket_clean.dxf")
    s["cleaned_dxf_present"] = 1.0 if (cleaned.exists() and cleaned.stat().st_size > 500) else 0.0

    # ---- 12. VLM rubric ----------------------------------------------------------
    try:
        from _judge_helper import vlm_score_rubric
    except Exception:
        vlm_score_rubric = None

    vlm_keys = ["vlm_librecad_real", "vlm_dimensions_visible", "vlm_titleblock_visible"]
    _vlm_available = False
    if vlm_score_rubric is not None:
        sample = [str(rd / n) for n in shots if (rd / n).exists()]
        render_p = rep / "render_final.png"
        if render_p.exists():
            sample.append(str(render_p))
        sample = sample[:5]
        if sample:
            rubric = {
                "vlm_librecad_real": "至少 1 张截图明确显示 LibreCAD 主窗口(含菜单栏 / 工具栏 / 命令行面板 / 图层面板等多种 LibreCAD UI 元素),不是裸黑屏或纯渲染图",
                "vlm_dimensions_visible": "在 dimensions_added / render_final 中能看到带数字的尺寸标注线(线性距离 + 半径/直径),且尺寸文本可读",
                "vlm_titleblock_visible": "print_preview 或 render_final 中右下角能看到包含图号/比例/日期等多行文字的标题栏区域",
            }
            try:
                vlm = vlm_score_rubric(
                    sample, rubric,
                    instruction="评估 DXF 机械图清理 + 标注 + 出图任务的截图与渲染。",
                ) or {}
            except Exception:
                vlm = {}
            for k in vlm_keys:
                v = vlm.get(k, 0.0)
                try:
                    s[k] = float(v)
                except Exception:
                    s[k] = 0.0
            _vlm_available = True
        else:
            for k in vlm_keys:
                s[k] = 0.0
    else:
        for k in vlm_keys:
            s[k] = 0.4  # capped neutral when judge helper unavailable

    # ---- aggregate (weighted: core 60% / gui 30% / aux 10%) ---------------------
    core_keys = [
        "duplicates_initial", "duplicates_clean",
        "dimensions_added", "validation_summary", "cleaned_dxf_present",
        "render_present",
    ]
    gui_keys = [
        "gui_screenshots_count", "gui_screenshots_ocr",
        "gui_screenshots_order",
    ] + vlm_keys
    aux_keys = ["entities_initial", "audit_initial", "audit_after"]

    def _avg(keys):
        vals = [s.get(k, 0.0) for k in keys if isinstance(s.get(k, 0.0), (int, float))]
        return sum(vals) / max(1, len(vals))

    core = _avg(core_keys)
    gui = _avg(gui_keys)
    aux = _avg(aux_keys)
    base = 0.6 * core + 0.3 * gui + 0.1 * aux

    # ---- hard gates (multi-layer, tightened) ------------------------------------
    # Core delivery gates.
    if s.get("cleaned_dxf_present", 0) == 0:
        base = min(base, 0.35)
    if s.get("duplicates_initial", 0) < 0.5:
        base = min(base, 0.40)
    if s.get("duplicates_clean", 0) < 0.5:
        base = min(base, 0.40)
    if s.get("dimensions_added", 0) < 0.5:
        base = min(base, 0.45)
    if s.get("render_present", 0) == 0:
        base = min(base, 0.45)
    if s.get("validation_summary", 0) < 0.5:
        base = min(base, 0.50)
    # GUI evidence gates (anti-cheat: forbids "no real GUI run" path to a high score).
    if s.get("gui_screenshots_count", 0) < 0.7:
        base = min(base, 0.45)
    if s.get("gui_screenshots_count", 0) < 0.4:
        base = min(base, 0.30)
    if _has_pil and _has_tess and s.get("gui_screenshots_ocr", 0) < 0.5:
        base = min(base, 0.55)
    # VLM gates.
    vlm_avg = sum(s.get(k, 0.0) for k in vlm_keys) / len(vlm_keys)
    if _vlm_available:
        if vlm_avg < 0.6:
            base = min(base, 0.55)
        if vlm_avg < 0.4:
            base = min(base, 0.40)
    else:
        # No VLM → never let a run reach satisfactory.
        base = min(base, 0.60)

    s["overall_score"] = round(max(0.0, min(1.0, base)), 3)
    return s
```

## Workspace Path

```
workspace/SPA/task_5_dxf_bracket_repair
```

## Skills

```
```

## Env

```
```

## Warmup

```bash
echo c2V0ICtlCiggZWNobyBwYXNzd29yZCB8IHN1ZG8gLVMgLXAgJycgYmFzaCAtYyAnZXhwb3J0IERFQklBTl9GUk9OVEVORD1ub25pbnRlcmFjdGl2ZTsgYXB0LWdldCB1cGRhdGUgLXFxOyBhcHQtZ2V0IGluc3RhbGwgLXkgLXFxIHBvcHBsZXItdXRpbHMgcHl0aG9uMy1waXAgbGlicmVjYWQgcWNhZCBmcmVlY2FkIHhkb3Rvb2wgd21jdHJsIGdub21lLXNjcmVlbnNob3Qgc2Nyb3QgdGVzc2VyYWN0LW9jciB8fCB0cnVlOyBwaXAgaW5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