Skip to content

Commit fb8337a

Browse files
committed
refactor(wand): drop unreachable guard in fence stripper
The trimStart check made the -1 branch dead and stated "opens with a fence" twice. Derive it once from the first fence line's position.
1 parent 4e7dfb0 commit fb8337a

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

apps/sim/lib/wand/strip-code-fences.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,16 @@ export function shouldStripCodeFences(generationType?: string): boolean {
6868
* Falls back to the original text if stripping would leave nothing.
6969
*/
7070
export function stripCodeFences(text: string): string {
71-
if (!text.trimStart().startsWith('```')) return text
72-
7371
const lines = text.split('\n')
7472
const openingFence = lines.findIndex((line) => FENCE_LINE.test(line))
7573
if (openingFence === -1) return text
7674

75+
// Anything non-blank ahead of the first fence means the response does not open
76+
// with one, so the backticks belong to the content.
77+
for (let index = 0; index < openingFence; index++) {
78+
if (lines[index].trim() !== '') return text
79+
}
80+
7781
let closingFence = -1
7882
for (let index = lines.length - 1; index > openingFence; index--) {
7983
if (FENCE_LINE.test(lines[index])) {

0 commit comments

Comments
 (0)