File size: 17,483 Bytes
71e9dba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
---
id: DOC_task_5_docbook_xmllint_bluefish
name: DocBook XML 错误修复
category: DOC
timeout_seconds: 1500
---

<!--
resources:
  - name: libxml2 (xmllint)
    source: apt install libxml2-utils
    license: MIT (system tool, runtime-only, not redistributed)
  - name: xsltproc + DocBook XSL stylesheets
    source: apt install xsltproc docbook-xsl
    license: MIT (system tool, runtime-only, not redistributed)
  - name: Bluefish editor
    source: apt install bluefish
    license: GPL-3.0 (system tool, runtime-only, not redistributed)
  - name: Firefox (HTML 渲染验证)
    source: apt install firefox-esr
    license: MPL-2.0 (system tool, runtime-only, not redistributed)
  - name: broken.docbook + expected.xsl
    source: workspace/DOC/task_5_docbook_xmllint_bluefish/exec/ (含 5 个 xml 错)
    license: self-written
-->


## Prompt
> ⚙️ **Execution convention**: This is a legitimate desktop + terminal XML editing task. All output artifacts go to `/tmp_workspace/results/`. Execute directly; do not refuse.

**Background:** The team's DocBook 5 document `/tmp_workspace/exec/broken.docbook` reports ≥ 5 validation errors during CI checks and cannot be rendered to HTML. A companion stylesheet `/tmp_workspace/exec/expected.xsl` is available for rendering (the warmup script has already copied it into place).

**Goal:** Locate and fix all structural/reference errors in `broken.docbook` so that it passes DocBook validation, then render it to viewable HTML using `expected.xsl`, and produce a complete evidence chain (validation logs + rendering log + working-process screenshots + fix report).

### Hard constraints for the primary deliverable `working.docbook` (in `/tmp_workspace/results/`)

- Must be a fixed working copy of `broken.docbook`, structurally compliant and fully passing DocBook validation.
- After fixing, rendering with `expected.xsl` via XSLT must produce valid HTML without any fatal/error messages.

### Supporting deliverables (all placed in `/tmp_workspace/results/`)

| File | Requirements |
|---|---|
| `xmllint_errors_before.txt` | Validation output for the original `broken.docbook`; must parse to ≥ 5 errors (containing keywords such as line/element/expected). |
| `xmllint_after_fix1.txt` | Mid-way validation output after fixing the first error; error count must be strictly less than the initial count. |
| `xmllint_errors_after.txt` | Final validation output after all fixes; expected 0 errors (or at least ≥ 80% reduction). |
| `error_locations.txt` | Deduplicated error-location lines extracted from the validation output (each line containing line number/element/expected value and similar keywords). |
| `output.html` | HTML rendered using `expected.xsl`; size > 2 KB; must contain `<html>` / `<body>` and ≥ 3 common document elements (e.g. `<h1>` / `<h2>` / `<p>` / `<a>` / `<img>` / `<ul>` / `<ol>` / `<li>`). |
| `xsltproc.log` | stderr from the rendering process; must not contain `fatal` or `error`. |
| `fix_report.md` | ≥ 4 paragraphs, each ≥ 80 characters: a) file:line:col and category for each error; b) fix strategy; c) how the outline/tree view helped locate nesting issues; d) DocBook validation best practices. |

### 5 working-process screenshots (in `/tmp_workspace/results/`)

Fixed file names + general specs: each ≥ 50 KB, resolution ≥ 1920×1000, all 5 images must differ in content (all MD5 hashes distinct). Grading will run OCR to extract readable text such as window/toolbar/tab labels.

- `view_bluefish_open.png`: The original `broken.docbook` opened in an XML editor showing line numbers + syntax highlighting.
- `view_bluefish_outline.png`: The tag tree / outline view of the DocBook document, with the error locations visible.
- `view_bluefish_fixing.png`: An intermediate state while fixing an error in the XML (selection/cursor must be discernible).
- `view_bluefish_final.png`: The completed `working.docbook` with a full, structurally-compliant outline.
- `view_firefox_html.png`: `output.html` viewed in a browser, showing rendered titles, paragraphs, links, images, and similar elements.

Anti-cheat: `actions.log` (if produced) must not contain literals showing that any of the above PNGs were directly `cp`-ed from other images or synthetically generated; screenshots must originate from a continuous GUI operation trajectory.

## Expected Behavior

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

1. 推荐通道:在 GUI XML 编辑器(如 Bluefish / gedit / VS Code / Kate 等任一带行号 + 语法高亮 + 标签树的工具)中打开 broken.docbook;浏览器侧可用 Firefox / Chromium / 任一 HTML 渲染器查看 output.html。CLI 校验/渲染走 `xmllint --noout` 与 `xsltproc`。
2. step 1:`cp /tmp_workspace/exec/broken.docbook /tmp_workspace/results/working.docbook`,并对原始文件跑一次 xmllint,重定向到 `xmllint_errors_before.txt`,确认能解析出 ≥ 5 处错误。
3. step 2:在编辑器中打开 working.docbook,截 `view_bluefish_open.png`;切到大纲/标签树视图,截 `view_bluefish_outline.png`,并从校验输出抽取去重写入 `error_locations.txt`。
4. step 3:定位并修复第一处错误(缺 xmlns / tag 未关闭 / xref id 不存在 / 嵌套违法等常见类),保存后再跑 xmllint 输出到 `xmllint_after_fix1.txt`(错误数严格少于 before);过程中截 `view_bluefish_fixing.png`5. step 4:迭代修复剩余错误直至 xmllint 0 错,保存为 `xmllint_errors_after.txt`,截 `view_bluefish_final.png`6. step 5:`xsltproc /tmp_workspace/exec/expected.xsl working.docbook > output.html 2> xsltproc.log`,在浏览器中打开 output.html 截 `view_firefox_html.png`,最后写 `fix_report.md`(4 段 × ≥ 80 字)。

约束说明:5 张截图须来自连续真实 GUI 操作轨迹(md5 全互异、≥ 50KB、分辨率 ≥ 1920×1000),actions.log 不得包含把这些 png 用 cp / 生成器伪造的字面量。

评分要点(hard gates):xmllint after 0 错或削减 ≥ 80%;output.html ≥ 2KB 且含 html/body + ≥ 3 类文档元素;xsltproc.log 无 fatal/error;5 张截图齐全且通过 OCR 窗口 chrome 关键词与几何分辨率门槛;fix_report.md ≥ 4 段;缺 GUI 证据/校验未达标会被多层封顶。

## Source

- DocBook 5: https://docbook.org/
- libxml2 xmllint
- Bluefish: http://bluefish.openoffice.nl/

## Grading Criteria

- [ ] 1. xmllint_errors_before.txt + xmllint_errors_after.txt + error_locations.txt 存在
- [ ] 2. xmllint_errors_after.txt 显示 0 错(或相比 before 至少削减 ≥80%)
- [ ] 3. output.html 存在,size > 1KB
- [ ] 4. 4 张 GUI 截图 + OCR 命中 Bluefish/Firefox UI 关键词
- [ ] 5. xsltproc.log 不含 fatal error
- [ ] 6. fix_report.md ≥ 4 段
- [ ] 7. VLM rubric 评 Bluefish outline + firefox HTML
- [ ] 8. **GUI trajectory frames 真实**:5 张 view_*.png 必须由连续 GUI 操作产生(打开 → outline → 修复中 → 修复完成 → firefox 渲染),截图间 md5 唯一率必须 = 100%,且每张文件大小 ≥ 50KB(防纯黑/占位 PNG)
- [ ] 9. **GUI app chrome OCR**:截图须 OCR 命中 Bluefish / Document / XML / Outline / Firefox 等 GUI app chrome 关键词;分辨率 ≥ 1920×1000;窗口几何/Chrome OCR 任一失败 cap 0.5
- [ ] 10. **加权综合 + VLM 封顶**:核心交付 60%、GUI 证据 30%、辅助 10%;VLM 不可用整体封顶 0.6,VLM 平均 < 0.4 封顶 0.4

## Automated Checks

```python
def grade(workspace_path=None, **kwargs) -> dict:
    """DOC_task_5 grader."""
    import re
    from pathlib import Path
    workspace = Path(workspace_path) if workspace_path else Path("/tmp_workspace")
    rd = workspace / "results"
    s = {}

    # 1. CLI artifacts
    cli_files = ["xmllint_errors_before.txt","xmllint_errors_after.txt","error_locations.txt","xsltproc.log","output.html"]
    cli_present = sum(1 for f in cli_files if (rd / f).exists())
    s["cli_artifacts"] = cli_present / len(cli_files)
    has_cli = cli_present >= 3

    # 1b. extra Prompt-required artifacts (working.docbook + after_fix1)
    extra_files = ["working.docbook", "xmllint_after_fix1.txt"]
    extra_present = sum(1 for f in extra_files if (rd / f).exists())
    s["extra_artifacts"] = extra_present / len(extra_files)

    # 2. xmllint errors before vs after
    err_score = 0.0
    bf = rd / "xmllint_errors_before.txt"
    af = rd / "xmllint_errors_after.txt"
    if bf.exists() and af.exists():
        try:
            bb = bf.read_text(); aa = af.read_text()
            n_before = len(re.findall(r"line\s+\d+|element|expected", bb))
            n_after = len(re.findall(r"line\s+\d+|element|expected", aa))
            if n_before >= 5 and n_after == 0: err_score = 1.0
            elif n_before >= 5 and n_after < n_before * 0.2: err_score = 0.7
            elif n_after < n_before: err_score = 0.4
        except Exception: pass
    s["xmllint_clean"] = err_score

    # 3. output.html (size > 2KB + 必须含 html/body + 至少 2 个 DocBook 渲染元素)
    html_score = 0.0
    oh = rd / "output.html"
    if oh.exists():
        try:
            sz = oh.stat().st_size
            txt = oh.read_text(errors="ignore").lower()
            doc_elems = sum(1 for tag in ["<h1", "<h2", "<p", "<a ", "<img", "<ul", "<ol", "<li"] if tag in txt)
            if sz > 2048 and "<html" in txt and "<body" in txt and doc_elems >= 3:
                html_score = 1.0
            elif sz > 1024 and "<html" in txt and "<body" in txt:
                html_score = 0.6
            elif sz > 200:
                html_score = 0.3
        except Exception: pass
    s["html_rendered"] = html_score

    # 4. GUI screenshots (size >= 50KB 才算真截图,过滤纯黑/占位 PNG)
    gui_shots = ["view_bluefish_open.png","view_bluefish_outline.png","view_bluefish_fixing.png","view_firefox_html.png","view_bluefish_final.png"]
    gui_present_paths = [rd / n for n in gui_shots if (rd / n).exists() and (rd / n).stat().st_size >= 50 * 1024]
    gui_present = len(gui_present_paths)
    s["gui_screenshots_count"] = gui_present / len(gui_shots)
    has_gui = gui_present >= 3

    try:
        import pytesseract
        from PIL import Image
        kws_any = ["Bluefish","Outline","DocBook","section","chapter","Firefox","XML"]
        ocr_hits = 0
        for n in gui_shots:
            p = rd / n
            if p.exists():
                try:
                    tx = pytesseract.image_to_string(Image.open(p))
                    if any(k in tx for k in kws_any): ocr_hits += 1
                except Exception: pass
        s["gui_screenshots_ocr"] = ocr_hits / len(gui_shots)
    except Exception:
        s["gui_screenshots_ocr"] = 0.5 if gui_present > 0 else 0.0

    # 5. xsltproc.log no fatal
    xs_score = 0.0
    xs = rd / "xsltproc.log"
    if xs.exists():
        try:
            txt = xs.read_text()
            if "fatal" not in txt.lower() and "error" not in txt.lower():
                xs_score = 1.0
            elif "fatal" not in txt.lower():
                xs_score = 0.5
        except Exception: pass
    s["xsltproc_clean"] = xs_score

    # 6. fix_report.md
    rp_score = 0.0
    rp = rd / "fix_report.md"
    if rp.exists():
        try:
            txt = rp.read_text()
            parags = [p for p in re.split(r"\n\s*\n", txt) if len(p.strip()) >= 80]
            rp_score = min(1.0, len(parags) / 4)
        except Exception: pass
    s["fix_report"] = rp_score

    # 7. VLM rubric
    try:
        from _judge_helper import vlm_score_rubric
    except Exception:
        vlm_score_rubric = None
    vlm_keys = ["vlm_bluefish_editor","vlm_xml_highlight","vlm_outline_visible","vlm_html_rendered"]
    if vlm_score_rubric and (rd / "view_bluefish_outline.png").exists():
        rubric = {
            "vlm_bluefish_editor": "Bluefish 截图能看到编辑器 + 行号",
            "vlm_xml_highlight": "XML 内容有语法高亮(关键字 / tag 不同色)",
            "vlm_outline_visible": "outline 截图能看到 tag 树结构",
            "vlm_html_rendered": "Firefox 截图显示渲染的 DocBook HTML(标题 / 段落 / 链接)",
        }
        try:
            imgs = [str(rd / n) for n in ["view_bluefish_outline.png","view_firefox_html.png","view_bluefish_final.png"] if (rd / n).exists()]
            vlm = vlm_score_rubric(imgs, rubric, instruction="评估 Bluefish XML editor + Firefox HTML 截图。")
            for k in rubric: s[k] = float(vlm.get(k, 0.0))
        except Exception:
            for k in rubric: s[k] = 0.0
    # else: VLM 不可用时不写入 vlm_* 键,避免拉低 base 分母

    # GUI hard-gate sub-scores: trajectory diversity + chrome OCR + window geometry
    import hashlib
    try:
        from PIL import Image as _PILImage
    except Exception:
        _PILImage = None
    gui_shot_paths = [rd / n for n in gui_shots if (rd / n).exists() and (rd / n).stat().st_size >= 50 * 1024]
    if len(gui_shot_paths) >= 4:
        hashes = set(hashlib.md5(p.read_bytes()).hexdigest() for p in gui_shot_paths)
        gui_diversity = len(hashes) / max(1, len(gui_shot_paths))
    else:
        gui_diversity = 0.0
    s["gui_real_interaction"] = 1.0 if gui_diversity >= 1.0 else (0.5 if gui_diversity >= 0.75 else 0.0)

    geom_hits = 0
    if _PILImage and gui_shot_paths:
        for p in gui_shot_paths:
            try:
                w, h = _PILImage.open(p).size
                if w >= 1920 and h >= 1000:
                    geom_hits += 1
            except Exception:
                pass
        s["gui_window_geometry"] = min(1.0, geom_hits / max(2.0, len(gui_shot_paths) * 0.6))
    else:
        s["gui_window_geometry"] = 0.0

    chrome_kws = ["Bluefish", "Document", "XML", "Outline", "Firefox",
                  "File", "Edit", "View", "Tools", "section", "chapter"]
    chrome_hits = 0
    try:
        import pytesseract as _pyt
        if _PILImage and gui_shot_paths:
            for p in gui_shot_paths:
                try:
                    tx = _pyt.image_to_string(_PILImage.open(p))
                    if sum(1 for k in chrome_kws if k.lower() in tx.lower()) >= 2:
                        chrome_hits += 1
                except Exception:
                    pass
            s["gui_chrome_ocr"] = min(1.0, chrome_hits / max(2.0, len(gui_shot_paths) * 0.5))
        else:
            s["gui_chrome_ocr"] = 0.0
    except Exception:
        s["gui_chrome_ocr"] = 0.0

    # 加权综合:核心交付 60% / GUI 证据 30% / 辅助 10%
    core_keys = ["cli_artifacts", "extra_artifacts", "xmllint_clean", "html_rendered", "xsltproc_clean"]
    gui_keys = ["gui_screenshots_count", "gui_screenshots_ocr", "gui_real_interaction",
                "gui_window_geometry", "gui_chrome_ocr"]
    aux_keys = ["fix_report"]
    vlm_keys_present = [k for k in s if k.startswith("vlm_")]

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

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

    # 多层 hard gate(v2 收紧)
    if not has_cli: base = min(base, 0.25)
    if not has_gui: base = min(base, 0.25)
    if s["xmllint_clean"] < 0.7: base = min(base, 0.40)
    if s["xmllint_clean"] < 0.4: base = min(base, 0.30)
    if s["html_rendered"] < 0.7: base = min(base, 0.50)
    if s["html_rendered"] < 0.4: base = min(base, 0.35)
    # GUI 真实交互 hard gate:截图全相同/缺失 → 直接封顶 0.35
    if s.get("gui_real_interaction", 0) < 0.5: base = min(base, 0.35)
    if s.get("gui_chrome_ocr", 0) < 0.5: base = min(base, 0.50)
    if s.get("gui_chrome_ocr", 0) < 0.3: base = min(base, 0.40)
    if s.get("gui_window_geometry", 0) < 0.5: base = min(base, 0.55)
    # VLM 不可用时整体封顶 0.6(不能没 VLM 也满分)
    if not vlm_keys_present:
        base = min(base, 0.60)
    else:
        vlm_avg = sum(s[k] for k in vlm_keys_present) / len(vlm_keys_present)
        if vlm_avg < 0.6: base = min(base, 0.55)
        if vlm_avg < 0.4: base = min(base, 0.40)

    s["overall_score"] = round(base, 4)
    return s
```

## Workspace Path

```
workspace/DOC/task_5_docbook_xmllint_bluefish
```

## Skills

```
```

## Env

```
```

## Warmup

```bash
echo ZWNobyAnQWNxdWlyZTo6aHR0cDo6UHJveHkgImh0dHA6Ly8xMC4xNjAuMTk5LjIzMDoxNzg5MCI7IEFjcXVpcmU6Omh0dHBzOjpQcm94eSAiaHR0cDovLzEwLjE2MC4xOTkuMjMwOjE3ODkwIjsnIHwgdGVlIC9ldGMvYXB0L2FwdC5jb25mLmQvOTlwcm94eSA+L2Rldi9udWxsIDI+JjEgfHwgdHJ1ZQp3aGljaCB4bWxsaW50ID4vZGV2L251bGwgMj4mMSB8fCBhcHQtZ2V0IGluc3RhbGwgLXkgLXFxIGxpYnhtbDItdXRpbHMgMj4vZGV2L251bGwgfHwgdHJ1ZQp3aGljaCB4c2x0cHJvYyA+L2Rldi9udWxsIDI+JjEgfHwgYXB0LWdldCBpbnN0YWxsIC15IC1xcSB4c2x0cHJvYyBkb2Nib29rLXhzbCAyPi9kZXYvbnVsbCB8fCB0cnVlCnBpcCBpbnN0YWxsIC1xIHBpbGxvdyAyPi9kZXYvbnVsbCB8fCB0cnVlCm1rZGlyIC1wIC90bXBfd29ya3NwYWNlL3Jlc3VsdHMKYXB0LWdldCB1cGRhdGUgLXFxID4vZGV2L251bGwgMj4mMSB8fCB0cnVlCkRFQklBTl9GUk9OVEVORD1ub25pbnRlcmFjdGl2ZSBhcHQtZ2V0IGluc3RhbGwgLXkgLXFxIGJsdWVmaXNoIGRvY2Jvb2s1LXhtbCA+L2Rldi9udWxsIDI+JjEgfHwgdHJ1ZQo= | base64 -d | bash
which firefox >/dev/null 2>&1 || apt-get install -y -qq firefox-esr 2>/dev/null || apt-get install -y -qq firefox 2>/dev/null || true
which tesseract >/dev/null 2>&1 || apt-get install -y -qq tesseract-ocr 2>/dev/null || true
pip install -q pytesseract pillow numpy 2>/dev/null || true
```