[stage2] fix: serialize multiline descriptions in legacy TOML renderer (#2097)

* fix: preserve multiline descriptions in legacy toml renderer

* refactor: reuse toml escape helper for prompt fallback
This commit is contained in:
Hamilton Snow
2026-04-06 21:39:01 +08:00
committed by GitHub
parent 8b099585c7
commit 7f08f31286
2 changed files with 32 additions and 10 deletions

View File

@@ -191,8 +191,9 @@ class CommandRegistrar:
toml_lines = []
if "description" in frontmatter:
desc = frontmatter["description"].replace('"', '\\"')
toml_lines.append(f'description = "{desc}"')
toml_lines.append(
f'description = {self._render_basic_toml_string(frontmatter["description"])}'
)
toml_lines.append("")
toml_lines.append(f"# Source: {source_id}")
@@ -209,17 +210,22 @@ class CommandRegistrar:
toml_lines.append(body)
toml_lines.append("'''")
else:
escaped_body = (
body.replace("\\", "\\\\")
.replace('"', '\\"')
.replace("\n", "\\n")
.replace("\r", "\\r")
.replace("\t", "\\t")
)
toml_lines.append(f'prompt = "{escaped_body}"')
toml_lines.append(f"prompt = {self._render_basic_toml_string(body)}")
return "\n".join(toml_lines)
@staticmethod
def _render_basic_toml_string(value: str) -> str:
"""Render *value* as a TOML basic string literal."""
escaped = (
value.replace("\\", "\\\\")
.replace('"', '\\"')
.replace("\n", "\\n")
.replace("\r", "\\r")
.replace("\t", "\\t")
)
return f'"{escaped}"'
def render_skill_command(
self,
agent_name: str,