anthropics / anthropics/claude-plugins-official
skill-creator: read_text()/write_text() without encoding crashes the description optimizer on Windows
- 主要語言
- Python
- 星號
- 36.3k
- 分支
- 4.1k
- 平均合併
- 2 天 14 小時
- 30 天內合併 PR
- 539
描述
## Summary
`skill-creator`'s scripts call `Path.read_text()` and `Path.write_text()` without an `encoding` argument. On Windows, Python defaults to the locale encoding (cp1252 on a US/Western install), so reading any `SKILL.md` containing a non-cp1252 character — an em dash, an arrow, a curly quote, an accented letter — raises `UnicodeDecodeError` and the run dies.
Since skill descriptions are prose, and prose written for skills routinely contains em dashes, this hits ordinary files rather than exotic ones.
## Reproduction
Any `SKILL.md` containing a UTF-8 character outside cp1252, on a Windows machine whose locale encoding is cp1252:
```
python -m scripts.run_loop --eval-set --skill-path \
--model --max-iterations 1
```
```
Traceback (most recent call last):
File "scripts/run_loop.py", line 268, in main
name, _, _ = parse_skill_md(skill_path)
File "scripts/utils.py", line 9, in parse_skill_md
content = (skill_path / "SKILL.md").read_text()
File "...\Lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input, self.errors, decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 3387: character maps to
```
Environment: Windows 11 Pro 26200, Python 3.14.4 (uv-managed), skill-creator as shipped in `anthropic-skills` 1.0.0.
## Affected call sites
Reads — these raise on input the tool is expected to handle:
| File | Line |
|---|---|
| `scripts/utils.py` | 9 (`SKILL.md` — the one that crashes the optimizer) |
| `scripts/quick_validate.py` | 64 (`SKILL.md`) |
| `scripts/run_eval.py` | 272 (eval set) |
| `scripts/run_loop.py` | 261 (eval set) |
| `scripts/improve_description.py` | 208, 211 (eval results, history) |
| `scripts/generate_report.py` | 314 (report input) |
Writes — these mangle output rather than crashing, so they fail more quietly:
| File | Line |
|---|---|
| `scripts/run_eval.py` | 68 (synthetic command file, carries the description under test) |
| `scripts/improve_description.py` | 189 (transcript log) |
| `scripts/run_loop.py` | 151, 278, 313, 317, 321 (live report, results JSON, HTML report) |
Line 68 of `run_eval.py` is the most consequential write: it stamps the description being evaluated into a command file. If that write silently substitutes or drops characters, the harness measures a description that differs from the one under test.
## Suggested fix
Pass `encoding="utf-8"` explicitly at every site. Skill files and eval sets are UTF-8 by convention, and relying on the platform default makes behavior differ between developer machines for no benefit.
```python
content = (skill_path / "SKILL.md").read_text(encoding="utf-8")
...
command_file.write_text(command_content, encoding="utf-8")
```
Setting `PYTHONUTF8=1` in the environment works as a user-side workaround and confirms the diagnosis — with it set, the crash above disappears and the script proceeds — but it should not be a prerequisite for running a bundled tool.
## Related
A second, independent Windows bug in `scripts/run_eval.py` blocks the optimizer even once this one is worked around: see the companion issue.
貢獻指南
這個儲存庫沒有索引到貢獻指南
研究方向
Start with scripts/utils.py and scripts/run_loop.py, then inspect the other read_text() and write_text() call sites listed in the issue. Verify that skill files, eval sets, logs, reports, and command files use explicit UTF-8 handling, and reproduce the em-dash case on Windows to confirm the optimizer no longer crashes or alters the description.
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 活躍
- 描述清晰度
- 描述清楚
- 新手友好度
- 78/100