fix(core): Skip loop check for dividers (#6893)
This commit is contained in:
parent
1a89d18526
commit
da73f13d02
2 changed files with 34 additions and 2 deletions
|
|
@ -558,6 +558,30 @@ describe('LoopDetectionService', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('Divider Content Detection', () => {
|
||||||
|
it('should not detect a loop for repeating divider-like content', () => {
|
||||||
|
service.reset('');
|
||||||
|
const dividerContent = '-'.repeat(CONTENT_CHUNK_SIZE);
|
||||||
|
let isLoop = false;
|
||||||
|
for (let i = 0; i < CONTENT_LOOP_THRESHOLD + 5; i++) {
|
||||||
|
isLoop = service.addAndCheck(createContentEvent(dividerContent));
|
||||||
|
expect(isLoop).toBe(false);
|
||||||
|
}
|
||||||
|
expect(loggers.logLoopDetected).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not detect a loop for repeating complex box-drawing dividers', () => {
|
||||||
|
service.reset('');
|
||||||
|
const dividerContent = '╭─'.repeat(CONTENT_CHUNK_SIZE / 2);
|
||||||
|
let isLoop = false;
|
||||||
|
for (let i = 0; i < CONTENT_LOOP_THRESHOLD + 5; i++) {
|
||||||
|
isLoop = service.addAndCheck(createContentEvent(dividerContent));
|
||||||
|
expect(isLoop).toBe(false);
|
||||||
|
}
|
||||||
|
expect(loggers.logLoopDetected).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('Reset Functionality', () => {
|
describe('Reset Functionality', () => {
|
||||||
it('tool call should reset content count', () => {
|
it('tool call should reset content count', () => {
|
||||||
const contentEvent = createContentEvent('Some content.');
|
const contentEvent = createContentEvent('Some content.');
|
||||||
|
|
|
||||||
|
|
@ -169,8 +169,16 @@ export class LoopDetectionService {
|
||||||
/(^|\n)\s*[*-+]\s/.test(content) || /(^|\n)\s*\d+\.\s/.test(content);
|
/(^|\n)\s*[*-+]\s/.test(content) || /(^|\n)\s*\d+\.\s/.test(content);
|
||||||
const hasHeading = /(^|\n)#+\s/.test(content);
|
const hasHeading = /(^|\n)#+\s/.test(content);
|
||||||
const hasBlockquote = /(^|\n)>\s/.test(content);
|
const hasBlockquote = /(^|\n)>\s/.test(content);
|
||||||
|
const isDivider = /^[+-_=*\u2500-\u257F]+$/.test(content);
|
||||||
|
|
||||||
if (numFences || hasTable || hasListItem || hasHeading || hasBlockquote) {
|
if (
|
||||||
|
numFences ||
|
||||||
|
hasTable ||
|
||||||
|
hasListItem ||
|
||||||
|
hasHeading ||
|
||||||
|
hasBlockquote ||
|
||||||
|
isDivider
|
||||||
|
) {
|
||||||
// Reset tracking when different content elements are detected to avoid analyzing content
|
// Reset tracking when different content elements are detected to avoid analyzing content
|
||||||
// that spans across different element boundaries.
|
// that spans across different element boundaries.
|
||||||
this.resetContentTracking();
|
this.resetContentTracking();
|
||||||
|
|
@ -179,7 +187,7 @@ export class LoopDetectionService {
|
||||||
const wasInCodeBlock = this.inCodeBlock;
|
const wasInCodeBlock = this.inCodeBlock;
|
||||||
this.inCodeBlock =
|
this.inCodeBlock =
|
||||||
numFences % 2 === 0 ? this.inCodeBlock : !this.inCodeBlock;
|
numFences % 2 === 0 ? this.inCodeBlock : !this.inCodeBlock;
|
||||||
if (wasInCodeBlock || this.inCodeBlock) {
|
if (wasInCodeBlock || this.inCodeBlock || isDivider) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue