fix(council): handle whitespace around COUNCIL_MEMBER_RESPONSE tags

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
ismeth
2026-03-02 00:33:35 +01:00
committed by YeonGyu-Kim
parent 93b77046cf
commit 3d36f6c5d8
2 changed files with 67 additions and 2 deletions
@@ -275,5 +275,62 @@ describe("extractCouncilResponse", () => {
})
})
})
describe("#given leading spaces before opening tag", () => {
it("#then recognizes the tag as structural and extracts content", () => {
const content = "a".repeat(100)
const text = ` <COUNCIL_MEMBER_RESPONSE>\n${content}\n</COUNCIL_MEMBER_RESPONSE>`
const result = extractCouncilResponse(text)
expect(result).toEqual({
has_response: true,
response_complete: true,
result: content,
})
})
})
describe("#given leading tab before opening tag", () => {
it("#then recognizes the tag as structural and extracts content", () => {
const content = "a".repeat(100)
const text = `\t<COUNCIL_MEMBER_RESPONSE>\n${content}\n</COUNCIL_MEMBER_RESPONSE>`
const result = extractCouncilResponse(text)
expect(result).toEqual({
has_response: true,
response_complete: true,
result: content,
})
})
})
describe("#given trailing spaces after closing tag", () => {
it("#then recognizes the closing tag as structural and extracts content", () => {
const content = "a".repeat(100)
const text = `<COUNCIL_MEMBER_RESPONSE>\n${content}\n</COUNCIL_MEMBER_RESPONSE> `
const result = extractCouncilResponse(text)
expect(result).toEqual({
has_response: true,
response_complete: true,
result: content,
})
})
})
describe("#given inline opening tag (text before tag on same line)", () => {
it("#then rejects the inline tag and returns has_response false", () => {
const content = "a".repeat(100)
const text = `text <COUNCIL_MEMBER_RESPONSE>\n${content}\n</COUNCIL_MEMBER_RESPONSE>`
const result = extractCouncilResponse(text)
expect(result).toEqual({
has_response: false,
response_complete: false,
result: null,
})
})
})
})
@@ -55,12 +55,20 @@ export function hasCouncilResponseTag(sessionMessages: Array<{ info?: { role?: s
}
function isStructuralOpen(text: string, idx: number): boolean {
return idx === 0 || text[idx - 1] === "\n"
if (idx === 0) return true
const prevNewline = text.lastIndexOf("\n", idx - 1)
const lineStart = prevNewline === -1 ? 0 : prevNewline + 1
const between = text.slice(lineStart, idx)
return between.split("").every((ch) => ch === " " || ch === "\t")
}
function isStructuralClose(text: string, idx: number): boolean {
const afterIdx = idx + CLOSING_TAG.length
return afterIdx === text.length || text[afterIdx] === "\n" || text[afterIdx] === "\r"
if (afterIdx === text.length) return true
const nextNewline = text.indexOf("\n", afterIdx)
const lineEnd = nextNewline === -1 ? text.length : nextNewline
const between = text.slice(afterIdx, lineEnd)
return between.split("").every((ch) => ch === " " || ch === "\t" || ch === "\r")
}
function findLastStructuralClose(text: string): number {