fix: frontmatter was adding newlines in some cases causing invalid model ids (#11095)

Co-authored-by: aptdnfapt <aptdnfapt@users.noreply.github.com>
This commit is contained in:
Aiden Cline
2026-01-28 23:40:59 -06:00
committed by GitHub
parent 0fabdccf11
commit 33c5c100ff
4 changed files with 82 additions and 17 deletions

View File

@@ -14,7 +14,9 @@ export namespace ConfigMarkdown {
return Array.from(template.matchAll(SHELL_REGEX))
}
export function preprocessFrontmatter(content: string): string {
// other coding agents like claude code allow invalid yaml in their
// frontmatter, we need to fallback to a more permissive parser for those cases
export function fallbackSanitization(content: string): string {
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/)
if (!match) return content
@@ -53,7 +55,7 @@ export namespace ConfigMarkdown {
// if value contains a colon, convert to block scalar
if (value.includes(":")) {
result.push(`${key}: |`)
result.push(`${key}: |-`)
result.push(` ${value}`)
continue
}
@@ -66,20 +68,23 @@ export namespace ConfigMarkdown {
}
export async function parse(filePath: string) {
const raw = await Bun.file(filePath).text()
const template = preprocessFrontmatter(raw)
const template = await Bun.file(filePath).text()
try {
const md = matter(template)
return md
} catch (err) {
throw new FrontmatterError(
{
path: filePath,
message: `${filePath}: Failed to parse YAML frontmatter: ${err instanceof Error ? err.message : String(err)}`,
},
{ cause: err },
)
} catch {
try {
return matter(fallbackSanitization(template))
} catch (err) {
throw new FrontmatterError(
{
path: filePath,
message: `${filePath}: Failed to parse YAML frontmatter: ${err instanceof Error ? err.message : String(err)}`,
},
{ cause: err },
)
}
}
}