anthropics / anthropics/skills

skill-creator scripts crash on Windows for any skill containing non-ASCII text (missing encoding on read_text())

Abierto
#1,686 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Python
Estrellas
176k
Forks
20.8k
Merge medio
7 h 21 min
PR fusionados (30 d)
5

Descripción

## Summary

Three scripts in `skills/skill-creator/scripts/` read or write text without
specifying an encoding. On Windows, Python defaults to the ANSI code page
(cp1252 on most systems), so any SKILL.md containing non-ASCII characters
raises `UnicodeDecodeError` before validation begins.

This affects Anthropic's own shipped skills. In a local library of 60 skills,
**28 crashed the validator (47%)**, including `docx`, `pdf`, `pptx`, `xlsx`,
`mcp-builder`, and `webapp-testing`.

The bug is invisible on macOS and Linux, where the default encoding is UTF-8.

## Reproduction

Windows, Python 3.x:

```bash
mkdir crash-demo && cd crash-demo
cat > SKILL.md <<'EOF'
---
name: crash-demo
description: Provjeri dostupnost artikla i rok isporuke.
---
Body.
EOF
cd ..
python skills/skill-creator/scripts/quick_validate.py crash-demo
```

Result:

```
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 1476:
character maps to
```

Any non-ASCII character reproduces it — accented Latin, CJK, emoji, or a
typographic dash.

## Affected locations

**1. `scripts/quick_validate.py`, line 22**
```python
content = skill_md.read_text()
```
Crashes before any validation runs.

**2. `scripts/utils.py`, line 9 (`parse_skill_md`)**
```python
content = (skill_path / "SKILL.md").read_text()
```
Same defect. Reached via `improve_description.py` and `run_eval.py`, so the
description-optimization loop fails on the same skills.

**3. `scripts/package_skill.py`, line 122 (separate but related)**
```python
print(f"\U0001f4e6 Packaging skill: {skill_path}")
```
Raises `UnicodeEncodeError` writing the 📦 emoji to a cp1252 console, so
packaging fails on Windows for *every* skill regardless of content:
```
UnicodeEncodeError: 'charmap' codec can't encode character '\U0001f4e6'
```
Confirmed workaround: `PYTHONIOENCODING=utf-8`.

## Suggested fix

For the two readers:

```python
content = skill_md.read_text(encoding="utf-8-sig")
```

`utf-8-sig` is byte-identical to `utf-8` on files without a byte-order mark
and additionally tolerates one when present. A real BOM was found in the
wild during this investigation, and it silently breaks the
`content.startswith('---')` frontmatter check under plain `utf-8`.

For `package_skill.py`, either reconfigure stdout at entry:

```python
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
```

or drop the emoji from console output.

## Impact

Windows users cannot validate or package a skill whose SKILL.md contains any
non-ASCII character — which includes most non-English skills and several of
Anthropic's own. Because `validate_skill()` is called by `package_skill.py`,
the failure also blocks distribution.

## Notes

`quick_validate.py` reads bytes in the fixed version and normalises newlines
explicitly, since `read_bytes()` bypasses Python's universal-newline
translation that the `^---\n` frontmatter regex depends on. `utils.py` uses
`read_text()` and therefore needs only the encoding argument.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.