Skip to content

Commit fd38d17

Browse files
committed
fix: another MaxListenersExceededWarning fix attempt
1 parent 8540233 commit fd38d17

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

npm-app/src/client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,8 +1419,10 @@ Go to https://www.codebuff.com/config for more information.`) +
14191419
this.freshPrompt()
14201420
}
14211421

1422+
// Always cleanup xmlStreamParser to prevent memory leaks and MaxListenersExceededWarning
1423+
xmlStreamParser.end()
1424+
14221425
if (!ASYNC_AGENTS_ENABLED) {
1423-
xmlStreamParser.end()
14241426
unsubscribeChunks()
14251427
unsubscribeComplete()
14261428
}

npm-app/src/display/markdown-renderer.ts

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,9 @@ export class MarkdownStreamRenderer {
440440

441441
this.isShowingIndicator = false
442442

443-
// Clear the indicator line (3 characters max width: '●●●' + 2 spaces for padding)
444-
process.stderr.write('\r' + ' '.repeat(5) + '\r')
443+
// Clear the indicator line completely and move cursor to beginning of line
444+
// Use enough spaces to clear the longest possible indicator (5 chars + padding)
445+
process.stderr.write('\r' + ' '.repeat(10) + '\r')
445446

446447
// Clear timer
447448
if (this.loadingIndicatorTimer) {
@@ -630,29 +631,16 @@ export class MarkdownStreamRenderer {
630631

631632
let rendered = this.md.render(mdWithPlaceholders)
632633

633-
codeBlockIndex = 0
634634
rendered = rendered.replace(
635-
/CODE_BLOCK_PLACEHOLDER_(\d+)/g,
636-
(match, idx, offset, str) => {
637-
const block = codeBlocks[codeBlockIndex++] || ''
635+
// Match optional newlines before and after the placeholder
636+
/\n*CODE_BLOCK_PLACEHOLDER_(\d+)\n*/g,
637+
(match, idx) => {
638+
// Use the captured index from the placeholder for robustness
639+
const block = codeBlocks[+idx] || ''
638640
if (!block) return ''
639641

640-
// Count surrounding newlines
641-
let leftNL = 0
642-
for (let i = offset - 1; i >= 0 && str[i] === '\n'; i--) leftNL++
643-
let rightNL = 0
644-
for (
645-
let i = offset + match.length;
646-
i < str.length && str[i] === '\n';
647-
i++
648-
)
649-
rightNL++
650-
651-
// Add padding: ensure at least one blank line before and after code blocks
652-
const needLeft = leftNL < 2 ? 2 - leftNL : 0
653-
const needRight = rightNL < 2 ? 2 - rightNL : 0
654-
655-
return `${'\n'.repeat(needLeft)}${block}${'\n'.repeat(needRight)}`
642+
// Ensure exactly one newline before and after the block
643+
return `\n${block.trimEnd()}\n`
656644
},
657645
)
658646

0 commit comments

Comments
 (0)