mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-17 05:26:47 +03:00
fix(core): keep agents whose description starts with a bracketed tag (#62250)
This commit is contained in:
@@ -21,8 +21,9 @@ export function parseOption(content: string) {
|
||||
}
|
||||
}
|
||||
|
||||
// Other coding agents accept unquoted colons in frontmatter values. Retry
|
||||
// those values as YAML block scalars so existing config files keep working.
|
||||
// Other coding agents accept unquoted colons and leading tags like `[Tag] text`
|
||||
// in frontmatter values. Retry those values as YAML block scalars so existing
|
||||
// config files keep working.
|
||||
export function sanitize(content: string) {
|
||||
const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---/)
|
||||
if (!match) return content
|
||||
@@ -33,7 +34,7 @@ export function sanitize(content: string) {
|
||||
if (!entry) return [line]
|
||||
const value = entry[2].trim()
|
||||
if (value === "" || value === ">" || value === "|" || value.startsWith('"') || value.startsWith("'")) return [line]
|
||||
if (!value.includes(":")) return [line]
|
||||
if (!value.includes(":") && !/^[[{].*[\]}]\s*\S/.test(value)) return [line]
|
||||
return [`${entry[1]}: |-`, ` ${value}`]
|
||||
})
|
||||
return content.replace(frontmatter, () => result.join("\n"))
|
||||
|
||||
@@ -13,6 +13,12 @@ describe("ConfigMarkdown.parse", () => {
|
||||
expect(parsed.content.trim()).toBe("body")
|
||||
})
|
||||
|
||||
test("recovers a frontmatter value that starts with a bracketed tag", () => {
|
||||
const parsed = ConfigMarkdown.parse("---\ndescription: [Team] Does a thing\ntools: [read, edit]\n---\nbody")
|
||||
expect(parsed.data.description).toBe("[Team] Does a thing")
|
||||
expect(parsed.data.tools).toEqual(["read", "edit"])
|
||||
})
|
||||
|
||||
test("recovers the same content again after a previous failed parse", () => {
|
||||
// gray-matter caches by content before parsing; a poisoned entry used to
|
||||
// make every later parse of the same text return silently without data.
|
||||
|
||||
Reference in New Issue
Block a user