mirror of
https://github.com/github/spec-kit.git
synced 2026-07-03 12:28:06 +08:00
fix(skills): preserve non-ASCII characters in skill frontmatter (#2917)
* fix(skills): preserve non-ASCII chars in skill frontmatter Skill SKILL.md frontmatter descriptions containing non-ASCII characters were escaped to \uXXXX / \xXX sequences because yaml.safe_dump() was called without allow_unicode=True. - Add allow_unicode=True to the 7 skill/command frontmatter safe_dump sites (extensions, presets, claude integration) - Add regression tests for the render and extension-install paths Follows the approach of #1936; encoding="utf-8" is already set on the affected write paths, so no encoding change is needed here. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * refactor(_utils): add dump_frontmatter helper Centralize skill/command frontmatter YAML serialization into a single _utils.dump_frontmatter helper so no call site can drop allow_unicode or diverge on formatting. Route the 7 existing sites through it and drop a now-unused local yaml import. Switch the extension test fixtures to yaml.safe_dump for parity with the production safe-dump/safe-load codepaths. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import shutil
|
||||
import stat
|
||||
import subprocess
|
||||
import tempfile
|
||||
import yaml
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from ._console import console
|
||||
@@ -16,6 +17,16 @@ CLAUDE_LOCAL_PATH = Path.home() / ".claude" / "local" / "claude"
|
||||
CLAUDE_NPM_LOCAL_PATH = Path.home() / ".claude" / "local" / "node_modules" / ".bin" / "claude"
|
||||
|
||||
|
||||
def dump_frontmatter(data: dict[str, Any]) -> str:
|
||||
"""Serialize skill/command frontmatter to a YAML string.
|
||||
|
||||
Centralizes the dump options used for SKILL.md frontmatter: ``allow_unicode``
|
||||
preserves Unicode descriptions and ``sort_keys=False`` keeps key order, so no
|
||||
call site can silently drop either.
|
||||
"""
|
||||
return yaml.safe_dump(data, sort_keys=False, allow_unicode=True).strip()
|
||||
|
||||
|
||||
def run_command(cmd: list[str], check_return: bool = True, capture: bool = False, shell: bool = False) -> str | None:
|
||||
"""Run a shell command and optionally capture output."""
|
||||
try:
|
||||
|
||||
@@ -28,6 +28,7 @@ from packaging.specifiers import InvalidSpecifier, SpecifierSet
|
||||
|
||||
from ._init_options import is_ai_skills_enabled
|
||||
from ._invocation_style import is_slash_skills_agent
|
||||
from ._utils import dump_frontmatter
|
||||
from .catalogs import CatalogEntry as BaseCatalogEntry
|
||||
from .catalogs import CatalogStackBase
|
||||
|
||||
@@ -1073,7 +1074,7 @@ class ExtensionManager:
|
||||
and hasattr(integration, "inject_argument_hint")
|
||||
):
|
||||
frontmatter_data["argument-hint"] = str(argument_hint)
|
||||
frontmatter_text = yaml.safe_dump(frontmatter_data, sort_keys=False).strip()
|
||||
frontmatter_text = dump_frontmatter(frontmatter_data)
|
||||
|
||||
# Derive a human-friendly title from the command name
|
||||
short_name = cmd_name
|
||||
|
||||
@@ -5,10 +5,9 @@ from __future__ import annotations
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
from ..base import SkillsIntegration
|
||||
from ..manifest import IntegrationManifest
|
||||
from ..._utils import dump_frontmatter
|
||||
|
||||
# Mapping of command template stem → argument-hint text shown inline
|
||||
# when a user invokes the slash command in Claude Code.
|
||||
@@ -103,7 +102,7 @@ class ClaudeIntegration(SkillsIntegration):
|
||||
skill_frontmatter = self._build_skill_fm(
|
||||
skill_name, description, f"templates/commands/{template_name}.md"
|
||||
)
|
||||
frontmatter_text = yaml.safe_dump(skill_frontmatter, sort_keys=False).strip()
|
||||
frontmatter_text = dump_frontmatter(skill_frontmatter)
|
||||
return f"---\n{frontmatter_text}\n---\n\n{body.strip()}\n"
|
||||
|
||||
def _build_skill_fm(self, name: str, description: str, source: str) -> dict:
|
||||
|
||||
@@ -30,6 +30,7 @@ from packaging.specifiers import SpecifierSet, InvalidSpecifier
|
||||
from ..extensions import REINSTALL_COMMAND, ExtensionRegistry, normalize_priority
|
||||
from .._init_options import is_ai_skills_enabled
|
||||
from ..integrations.base import IntegrationBase
|
||||
from .._utils import dump_frontmatter
|
||||
|
||||
|
||||
def _substitute_core_template(
|
||||
@@ -1068,7 +1069,7 @@ class PresetManager:
|
||||
skill_name, desc,
|
||||
f"override:{cmd_name}",
|
||||
)
|
||||
fm_text = yaml.safe_dump(fm_data, sort_keys=False).strip()
|
||||
fm_text = dump_frontmatter(fm_data)
|
||||
skill_title = self._skill_title_from_command(cmd_name)
|
||||
skill_content = (
|
||||
f"---\n{fm_text}\n---\n\n"
|
||||
@@ -1345,7 +1346,7 @@ class PresetManager:
|
||||
enhanced_desc,
|
||||
f"preset:{manifest.id}",
|
||||
)
|
||||
frontmatter_text = yaml.safe_dump(frontmatter_data, sort_keys=False).strip()
|
||||
frontmatter_text = dump_frontmatter(frontmatter_data)
|
||||
skill_content = (
|
||||
f"---\n"
|
||||
f"{frontmatter_text}\n"
|
||||
@@ -1441,7 +1442,7 @@ class PresetManager:
|
||||
enhanced_desc,
|
||||
f"templates/commands/{short_name}.md",
|
||||
)
|
||||
frontmatter_text = yaml.safe_dump(frontmatter_data, sort_keys=False).strip()
|
||||
frontmatter_text = dump_frontmatter(frontmatter_data)
|
||||
skill_title = self._skill_title_from_command(short_name)
|
||||
skill_content = (
|
||||
f"---\n"
|
||||
@@ -1478,7 +1479,7 @@ class PresetManager:
|
||||
frontmatter.get("description", f"Extension command: {command_name}"),
|
||||
extension_restore["source"],
|
||||
)
|
||||
frontmatter_text = yaml.safe_dump(frontmatter_data, sort_keys=False).strip()
|
||||
frontmatter_text = dump_frontmatter(frontmatter_data)
|
||||
skill_content = (
|
||||
f"---\n"
|
||||
f"{frontmatter_text}\n"
|
||||
@@ -3276,7 +3277,7 @@ class PresetResolver:
|
||||
if top_fm:
|
||||
top_frontmatter_text = (
|
||||
"---\n"
|
||||
+ yaml.safe_dump(top_fm, sort_keys=False).strip()
|
||||
+ dump_frontmatter(top_fm)
|
||||
+ "\n---"
|
||||
)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user