summaryrefslogtreecommitdiff
path: root/packages/core/src/services/loopDetectionService.ts
diff options
context:
space:
mode:
authorSandy Tao <[email protected]>2025-08-07 17:21:42 -0700
committerGitHub <[email protected]>2025-08-08 00:21:42 +0000
commite8815ba43c8d87f3b4393b2f30f319d5f79cb84f (patch)
tree9235e707ba5c215bb2d4efa145d1d6110695cc56 /packages/core/src/services/loopDetectionService.ts
parentbae922a6327a8ae97ca53ac1829ff385ca025460 (diff)
feat(quality): Reset when seeing a new type of Markdown element (#5820)
Diffstat (limited to 'packages/core/src/services/loopDetectionService.ts')
-rw-r--r--packages/core/src/services/loopDetectionService.ts18
1 files changed, 12 insertions, 6 deletions
diff --git a/packages/core/src/services/loopDetectionService.ts b/packages/core/src/services/loopDetectionService.ts
index f71b8434..a01e4ee9 100644
--- a/packages/core/src/services/loopDetectionService.ts
+++ b/packages/core/src/services/loopDetectionService.ts
@@ -161,13 +161,19 @@ export class LoopDetectionService {
* as repetitive code structures are common and not necessarily loops.
*/
private checkContentLoop(content: string): boolean {
- // Code blocks can often contain repetitive syntax that is not indicative of a loop.
- // To avoid false positives, we detect when we are inside a code block and
- // temporarily disable loop detection.
+ // Different content elements can often contain repetitive syntax that is not indicative of a loop.
+ // To avoid false positives, we detect when we encounter different content types and
+ // reset tracking to avoid analyzing content that spans across different element boundaries.
const numFences = (content.match(/```/g) ?? []).length;
- if (numFences) {
- // Reset tracking when a code fence is detected to avoid analyzing content
- // that spans across code block boundaries.
+ const hasTable = /(^|\n)\s*(\|.*\||[|+-]{3,})/.test(content);
+ const hasListItem =
+ /(^|\n)\s*[*-+]\s/.test(content) || /(^|\n)\s*\d+\.\s/.test(content);
+ const hasHeading = /(^|\n)#+\s/.test(content);
+ const hasBlockquote = /(^|\n)>\s/.test(content);
+
+ if (numFences || hasTable || hasListItem || hasHeading || hasBlockquote) {
+ // Reset tracking when different content elements are detected to avoid analyzing content
+ // that spans across different element boundaries.
this.resetContentTracking();
}