@@ -126,6 +126,12 @@ type McporterState = {
|
126 | 126 | daemonStart: Promise<void> | null; |
127 | 127 | }; |
128 | 128 | |
| 129 | +function normalizePositiveInteger(value: number | undefined, fallback: number): number { |
| 130 | +return typeof value === "number" && Number.isFinite(value) |
| 131 | + ? Math.max(1, Math.floor(value)) |
| 132 | + : fallback; |
| 133 | +} |
| 134 | + |
129 | 135 | type QmdEmbedQueueState = { |
130 | 136 | tail: Promise<void>; |
131 | 137 | }; |
@@ -1333,18 +1339,19 @@ export class QmdMemoryManager implements MemorySearchManager {
|
1333 | 1339 | } |
1334 | 1340 | const contextLimits = this.contextLimits; |
1335 | 1341 | if (params.from !== undefined || params.lines !== undefined) { |
1336 | | -const requestedCount = Math.max( |
1337 | | - 1, |
| 1342 | +const startLine = normalizePositiveInteger(params.from, 1); |
| 1343 | +const requestedCount = normalizePositiveInteger( |
1338 | 1344 | params.lines ?? contextLimits?.memoryGetDefaultLines ?? DEFAULT_MEMORY_READ_LINES, |
| 1345 | +DEFAULT_MEMORY_READ_LINES, |
1339 | 1346 | ); |
1340 | | -const partial = await this.readPartialText(absPath, params.from, requestedCount); |
| 1347 | +const partial = await this.readPartialText(absPath, startLine, requestedCount); |
1341 | 1348 | if (partial.missing) { |
1342 | 1349 | return { text: "", path: relPath }; |
1343 | 1350 | } |
1344 | 1351 | return buildMemoryReadResultFromSlice({ |
1345 | 1352 | selectedLines: partial.selectedLines, |
1346 | 1353 | relPath, |
1347 | | -startLine: Math.max(1, params.from ?? 1), |
| 1354 | + startLine, |
1348 | 1355 | moreSourceLinesRemain: partial.moreSourceLinesRemain, |
1349 | 1356 | maxChars: contextLimits?.memoryGetMaxChars, |
1350 | 1357 | suggestReadFallback: isDefaultMemoryPath(relPath), |
@@ -2205,8 +2212,8 @@ export class QmdMemoryManager implements MemorySearchManager {
|
2205 | 2212 | ): Promise< |
2206 | 2213 | { missing: true } | { missing: false; selectedLines: string[]; moreSourceLinesRemain: boolean } |
2207 | 2214 | > { |
2208 | | -const start = Math.max(1, from ?? 1); |
2209 | | -const count = Math.max(1, lines ?? Number.POSITIVE_INFINITY); |
| 2215 | +const start = normalizePositiveInteger(from, 1); |
| 2216 | +const count = normalizePositiveInteger(lines, Number.MAX_SAFE_INTEGER); |
2210 | 2217 | let handle; |
2211 | 2218 | try { |
2212 | 2219 | handle = await fs.open(absPath); |
|