mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 17:19:27 +08:00
fix(skill): make skill initialization safe on Windows pipes (#421)
## Summary - Keep the caller's stdout encoding and escape only characters it cannot represent. This prevents the normal skill initializer command from aborting on legacy-encoded Windows pipes and preserves Unicode output on UTF-8 streams. - Write all generated skill templates as UTF-8 so the localized content does not depend on the machine locale. - Exercise the actual CLI with CP1252 and UTF-8 output in the i18n validation workflow, including a non-ASCII destination, generated localized files, and duplicate-directory errors. ## Validation - Reproduced UnicodeEncodeError with the unmodified CLI and CP1252 stdout; both focused regression tests pass on the change. - Catalog and i18n validation passed with zero errors; translation freshness and `git diff --check` passed. - No new dependencies or metadata changes. A native installed-app confirmation still belongs to the consuming product after syncing the bundled Market seed.
This commit is contained in:
3 files changed
+105
-5
No files matched your search
Executable → Regular
+10
-5
@@ -227,7 +227,7 @@ def init_skill(skill_name, path, fmt='desirecore'):
|
||||
|
||||
skill_md_path = skill_dir / 'SKILL.md'
|
||||
try:
|
||||
skill_md_path.write_text(skill_content)
|
||||
skill_md_path.write_text(skill_content, encoding='utf-8')
|
||||
print(f"✅ Created SKILL.md ({fmt} format)")
|
||||
except Exception as e:
|
||||
print(f"❌ Error creating SKILL.md: {e}")
|
||||
@@ -236,7 +236,7 @@ def init_skill(skill_name, path, fmt='desirecore'):
|
||||
if fmt == 'desirecore':
|
||||
source_body = DESIRECORE_SOURCE_BODY.format(skill_title=skill_title)
|
||||
try:
|
||||
(skill_dir / 'SKILL.zh-CN.md').write_text(source_body)
|
||||
(skill_dir / 'SKILL.zh-CN.md').write_text(source_body, encoding='utf-8')
|
||||
print("✅ Created SKILL.zh-CN.md (source locale)")
|
||||
except Exception as e:
|
||||
print(f"❌ Error creating SKILL.zh-CN.md: {e}")
|
||||
@@ -247,20 +247,20 @@ def init_skill(skill_name, path, fmt='desirecore'):
|
||||
scripts_dir = skill_dir / 'scripts'
|
||||
scripts_dir.mkdir(exist_ok=True)
|
||||
example_script = scripts_dir / 'example.py'
|
||||
example_script.write_text(EXAMPLE_SCRIPT.format(skill_name=skill_name))
|
||||
example_script.write_text(EXAMPLE_SCRIPT.format(skill_name=skill_name), encoding='utf-8')
|
||||
example_script.chmod(0o755)
|
||||
print("✅ Created scripts/example.py")
|
||||
|
||||
references_dir = skill_dir / 'references'
|
||||
references_dir.mkdir(exist_ok=True)
|
||||
example_ref = references_dir / 'api_reference.md'
|
||||
example_ref.write_text(EXAMPLE_REFERENCE.format(skill_title=skill_title))
|
||||
example_ref.write_text(EXAMPLE_REFERENCE.format(skill_title=skill_title), encoding='utf-8')
|
||||
print("✅ Created references/api_reference.md")
|
||||
|
||||
assets_dir = skill_dir / 'assets'
|
||||
assets_dir.mkdir(exist_ok=True)
|
||||
example_asset = assets_dir / 'example_asset.txt'
|
||||
example_asset.write_text(EXAMPLE_ASSET)
|
||||
example_asset.write_text(EXAMPLE_ASSET, encoding='utf-8')
|
||||
print("✅ Created assets/example_asset.txt")
|
||||
except Exception as e:
|
||||
print(f"❌ Error creating resource directories: {e}")
|
||||
@@ -276,6 +276,11 @@ def init_skill(skill_name, path, fmt='desirecore'):
|
||||
|
||||
|
||||
def main():
|
||||
# Windows pipes can retain a narrow locale encoding even when the filesystem
|
||||
# supports Unicode. Escape only unrepresentable log characters; keep the
|
||||
# caller's encoding (and, on UTF-8 terminals, all Unicode output) unchanged.
|
||||
sys.stdout.reconfigure(errors='backslashreplace')
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description='Initialize a new skill from template',
|
||||
epilog='Examples:\n'
|
||||
|
||||
Reference in new issue
Block a user