anthropics / anthropics/claude-plugins-official

skill-creator: read_text()/write_text() without encoding crashes the description optimizer on Windows

オープン
#5,927 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
36.2k
フォーク
4.1k
PR マージ指標
PR 指標を取得中

説明

## 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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。