fix(cli): SKILL.md frontmatter 用 YAML 引号标量,防 description 破坏解析
runInit 此前裸拼 `description: <raw>`,含 ASCII 冒号或前导 */#/& 等的 description 会破坏 Claude 读取 SKILL.md frontmatter。改为 yamlScalar 双引号 + 转义 \ 与 "(name 同处理)。当前 7 个 description 用全角冒号本无碍,此为加固。 测试 +1(tricky description 含冒号/星号仍输出合法引号标量)。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -722,7 +722,8 @@ public final class Eip4Cli {
|
||||
String rendered = body.replace("{{EIP4_BASE_URL}}", baseUrl);
|
||||
Path skillDir = claudeSkills.resolve(name);
|
||||
Files.createDirectories(skillDir);
|
||||
String doc = "---\nname: " + name + "\ndescription: " + description + "\n---\n\n" + rendered;
|
||||
String doc = "---\nname: " + yamlScalar(name)
|
||||
+ "\ndescription: " + yamlScalar(description) + "\n---\n\n" + rendered;
|
||||
Files.writeString(skillDir.resolve("SKILL.md"), doc, StandardCharsets.UTF_8);
|
||||
catalog.append("- **").append(name).append("** — ").append(description).append('\n');
|
||||
bodies.append("\n---\n\n### Skill: ").append(name).append("\n\n").append(rendered).append('\n');
|
||||
@@ -739,6 +740,11 @@ public final class Eip4Cli {
|
||||
private static final String SKILLS_BEGIN = "<!-- EIP4-SKILLS:BEGIN (managed by `eip4 init`) -->";
|
||||
private static final String SKILLS_END = "<!-- EIP4-SKILLS:END -->";
|
||||
|
||||
/** YAML 双引号标量:转义 \ 与 ",使含 `:`/前导特殊字符的 description 不破坏 SKILL.md frontmatter。 */
|
||||
private static String yamlScalar(String value) {
|
||||
return "\"" + value.replace("\\", "\\\\").replace("\"", "\\\"") + "\"";
|
||||
}
|
||||
|
||||
private Path writeAgentsMd(Path targetDir, String baseUrl, String catalog, String bodies) throws IOException {
|
||||
String block = SKILLS_BEGIN + "\n"
|
||||
+ "## EIP4 平台接入(AI Agent)\n\n"
|
||||
|
||||
Reference in New Issue
Block a user