浏览代码

fix: use max chunk size for snippet search window

extractSnippet was using the snippet output length (500 chars) to
determine the search window, which was too small even for fixed
chunks. With variable-length smart chunks, this could miss relevant
content entirely.

Now uses CHUNK_SIZE_CHARS as fallback, ensuring the entire chunk
region is searched regardless of actual chunk length.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Tobi Lutke 3 月之前
父节点
当前提交
2d2f53034d
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      src/store.ts

+ 5 - 2
src/store.ts

@@ -2681,14 +2681,17 @@ export type SnippetResult = {
   snippetLines: number;   // Number of lines in snippet
 };
 
-export function extractSnippet(body: string, query: string, maxLen = 500, chunkPos?: number): SnippetResult {
+export function extractSnippet(body: string, query: string, maxLen = 500, chunkPos?: number, chunkLen?: number): SnippetResult {
   const totalLines = body.split('\n').length;
   let searchBody = body;
   let lineOffset = 0;
 
   if (chunkPos && chunkPos > 0) {
+    // Search within the chunk region, with some padding for context
+    // Use provided chunkLen or fall back to max chunk size (covers variable-length chunks)
+    const searchLen = chunkLen || CHUNK_SIZE_CHARS;
     const contextStart = Math.max(0, chunkPos - 100);
-    const contextEnd = Math.min(body.length, chunkPos + maxLen + 100);
+    const contextEnd = Math.min(body.length, chunkPos + searchLen + 100);
     searchBody = body.slice(contextStart, contextEnd);
     if (contextStart > 0) {
       lineOffset = body.slice(0, contextStart).split('\n').length - 1;