diff --git a/docs/guide/skills-and-tools.md b/docs/guide/skills-and-tools.md index a65fcb55ae..ae78ad0a7a 100644 --- a/docs/guide/skills-and-tools.md +++ b/docs/guide/skills-and-tools.md @@ -217,7 +217,7 @@ Discovery follows operator-managed directory symlinks, but skips links back to a Skill Markdown and bundled text resources use UTF-8. Skill-creator CLI and review utilities read and write text explicitly as UTF-8 so localized skills behave consistently across operating systems. -For standalone skill creation, `scripts/init_skill.py --path ` creates a new direct child of the chosen directory. Names can be up to 40 characters long and consist of lowercase ASCII letters and digits, optionally grouped with single hyphens (for example, `data-analyzer`). The creator and packager write progress to stdout and report errors on stderr. +For standalone skill creation, `scripts/init_skill.py --path ` creates a new direct child of the chosen directory. Names can be up to 40 characters long and consist of lowercase ASCII letters and digits, optionally grouped with single hyphens (for example, `data-analyzer`). The initializer rejects Windows reserved device names, such as `nul` and `com1`, on every platform before creating files. The creator and packager write progress to stdout and report errors on stderr. For standalone skill exports, the bundled skill creator's `scripts/package_skill.py` can be run by file path from any directory, or as `python -m scripts.package_skill` from the skill-creator directory. Both entry points validate the skill before writing a `.skill` archive. The packager requires a regular `SKILL.md` file and skips symbolic links to files and directories in the skill. Copy any linked resources the skill needs into its directory before packaging. diff --git a/skills/public/skill-creator/scripts/init_skill.py b/skills/public/skill-creator/scripts/init_skill.py index 0b47e280eb..e4aa8c7176 100755 --- a/skills/public/skill-creator/scripts/init_skill.py +++ b/skills/public/skill-creator/scripts/init_skill.py @@ -217,6 +217,12 @@ def init_skill(skill_name, path): ) return None + # Keep the standalone initializer aligned with SkillStorage creation. + # The name grammar above excludes the other Windows device spellings. + if re.fullmatch(r"con|prn|aux|nul|com[1-9]|lpt[1-9]", skill_name): + print(f"❌ Error: Skill name {skill_name!r} is a reserved Windows device name.", file=sys.stderr) + return None + try: root = Path(path).resolve() skill_dir = root / skill_name diff --git a/tests/skills/test_skill_packager_cli.py b/tests/skills/test_skill_packager_cli.py index bbd7dd4404..f9867fe0fc 100644 --- a/tests/skills/test_skill_packager_cli.py +++ b/tests/skills/test_skill_packager_cli.py @@ -80,8 +80,8 @@ def test_packager_reports_input_errors_on_stderr(tmp_path, source, diagnostic): assert diagnostic not in result.stdout -def test_init_creates_skill_under_requested_root(tmp_path): - name = "example-" + "2" * 32 +@pytest.mark.parametrize("name", ["example-" + "2" * 32, "com0", "nul-report"]) +def test_init_creates_skill_under_requested_root(tmp_path, name): root = tmp_path / "skills" result = run_cli("init_skill", name, "--path", root, cwd=tmp_path) assert result.returncode == 0, result.stdout + result.stderr @@ -143,6 +143,15 @@ def test_init_rejects_invalid_name_before_creating_directories(tmp_path, name): assert not list(tmp_path.iterdir()) +@pytest.mark.parametrize("name", ["con", "prn", "aux", "nul", "com1", "com9", "lpt1", "lpt9"]) +def test_init_rejects_windows_device_names_before_creating_directories(tmp_path, name): + root = tmp_path / "skills" + result = run_cli("init_skill", name, "--path", root, cwd=tmp_path) + assert result.returncode == 1, result.stdout + result.stderr + assert f"Skill name {name!r} is a reserved Windows device name" in result.stderr + assert not root.exists() + + def test_init_rejects_existing_directory_link(tmp_path): root = tmp_path / "skills" root.mkdir()