fix(cli): add allow_unicode=True and encoding="utf-8" to YAML I/O (#1936)

None of the yaml.dump() calls specify allow_unicode=True, causing
non-ASCII characters in extension descriptions to be escaped to
\uXXXX sequences in generated .agent.md frontmatter and config files.

Add allow_unicode=True to all 6 yaml.dump() call sites, and
encoding="utf-8" to all corresponding write_text() and read_text()
calls to ensure consistent UTF-8 handling across platforms.
This commit is contained in:
Seiya Kojima
2026-03-23 22:49:10 +09:00
committed by GitHub
parent 6223d10d84
commit a351c826ee
5 changed files with 31 additions and 18 deletions

View File

@@ -3042,7 +3042,7 @@ def preset_catalog_add(
# Load existing config
if config_path.exists():
try:
config = yaml.safe_load(config_path.read_text()) or {}
config = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
except Exception as e:
console.print(f"[red]Error:[/red] Failed to read {config_path}: {e}")
raise typer.Exit(1)
@@ -3070,7 +3070,7 @@ def preset_catalog_add(
})
config["catalogs"] = catalogs
config_path.write_text(yaml.dump(config, default_flow_style=False, sort_keys=False))
config_path.write_text(yaml.dump(config, default_flow_style=False, sort_keys=False, allow_unicode=True), encoding="utf-8")
install_label = "install allowed" if install_allowed else "discovery only"
console.print(f"\n[green]✓[/green] Added catalog '[bold]{name}[/bold]' ({install_label})")
@@ -3098,7 +3098,7 @@ def preset_catalog_remove(
raise typer.Exit(1)
try:
config = yaml.safe_load(config_path.read_text()) or {}
config = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
except Exception:
console.print("[red]Error:[/red] Failed to read preset catalog config.")
raise typer.Exit(1)
@@ -3115,7 +3115,7 @@ def preset_catalog_remove(
raise typer.Exit(1)
config["catalogs"] = catalogs
config_path.write_text(yaml.dump(config, default_flow_style=False, sort_keys=False))
config_path.write_text(yaml.dump(config, default_flow_style=False, sort_keys=False, allow_unicode=True), encoding="utf-8")
console.print(f"[green]✓[/green] Removed catalog '{name}'")
if not catalogs:
@@ -3384,7 +3384,7 @@ def catalog_add(
# Load existing config
if config_path.exists():
try:
config = yaml.safe_load(config_path.read_text()) or {}
config = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
except Exception as e:
console.print(f"[red]Error:[/red] Failed to read {config_path}: {e}")
raise typer.Exit(1)
@@ -3412,7 +3412,7 @@ def catalog_add(
})
config["catalogs"] = catalogs
config_path.write_text(yaml.dump(config, default_flow_style=False, sort_keys=False))
config_path.write_text(yaml.dump(config, default_flow_style=False, sort_keys=False, allow_unicode=True), encoding="utf-8")
install_label = "install allowed" if install_allowed else "discovery only"
console.print(f"\n[green]✓[/green] Added catalog '[bold]{name}[/bold]' ({install_label})")
@@ -3440,7 +3440,7 @@ def catalog_remove(
raise typer.Exit(1)
try:
config = yaml.safe_load(config_path.read_text()) or {}
config = yaml.safe_load(config_path.read_text(encoding="utf-8")) or {}
except Exception:
console.print("[red]Error:[/red] Failed to read catalog config.")
raise typer.Exit(1)
@@ -3457,7 +3457,7 @@ def catalog_remove(
raise typer.Exit(1)
config["catalogs"] = catalogs
config_path.write_text(yaml.dump(config, default_flow_style=False, sort_keys=False))
config_path.write_text(yaml.dump(config, default_flow_style=False, sort_keys=False, allow_unicode=True), encoding="utf-8")
console.print(f"[green]✓[/green] Removed catalog '{name}'")
if not catalogs: