* Process a text file according to the requested mode.
(content: string, entry: InternalFileEntry)
| 267 | * Process a text file according to the requested mode. |
| 268 | */ |
| 269 | private processTextFile(content: string, entry: InternalFileEntry): string { |
| 270 | const mode = entry.mode || "slice" |
| 271 | |
| 272 | if (mode === "indentation") { |
| 273 | // Indentation mode: semantic block extraction |
| 274 | // When anchor_line is not provided, default to offset (which defaults to 1) |
| 275 | const anchorLine = entry.anchor_line ?? entry.offset ?? 1 |
| 276 | const result = readWithIndentation(content, { |
| 277 | anchorLine, |
| 278 | maxLevels: entry.max_levels, |
| 279 | includeSiblings: entry.include_siblings, |
| 280 | includeHeader: entry.include_header, |
| 281 | limit: entry.limit ?? DEFAULT_LINE_LIMIT, |
| 282 | maxLines: entry.max_lines, |
| 283 | }) |
| 284 | |
| 285 | let output = result.content |
| 286 | |
| 287 | if (result.wasTruncated && result.includedRanges.length > 0) { |
| 288 | const [start, end] = result.includedRanges[0] |
| 289 | const nextOffset = end + 1 |
| 290 | const effectiveLimit = entry.limit ?? DEFAULT_LINE_LIMIT |
| 291 | // Put truncation warning at TOP (before content) to match @ mention format |
| 292 | output = `IMPORTANT: File content truncated. |
| 293 | Status: Showing lines ${start}-${end} of ${result.totalLines} total lines. |
| 294 | To read more: Use the read_file tool with offset=${nextOffset} and limit=${effectiveLimit}. |
| 295 | |
| 296 | ${result.content}` |
| 297 | } else if (result.includedRanges.length > 0) { |
| 298 | const rangeStr = result.includedRanges.map(([s, e]) => `${s}-${e}`).join(", ") |
| 299 | output += `\n\nIncluded ranges: ${rangeStr} (total: ${result.totalLines} lines)` |
| 300 | } |
| 301 | |
| 302 | return output |
| 303 | } |
| 304 | |
| 305 | // Slice mode (default): simple offset/limit reading |
| 306 | // NOTE: read_file offset is 1-based externally; convert to 0-based for readWithSlice. |
| 307 | const offset1 = entry.offset ?? 1 |
| 308 | const offset0 = Math.max(0, offset1 - 1) |
| 309 | const limit = entry.limit ?? DEFAULT_LINE_LIMIT |
| 310 | |
| 311 | const result = readWithSlice(content, offset0, limit) |
| 312 | |
| 313 | let output = result.content |
| 314 | |
| 315 | if (result.wasTruncated) { |
| 316 | const startLine = offset1 |
| 317 | const endLine = offset1 + result.returnedLines - 1 |
| 318 | const nextOffset = endLine + 1 |
| 319 | // Put truncation warning at TOP (before content) to match @ mention format |
| 320 | output = `IMPORTANT: File content truncated. |
| 321 | Status: Showing lines ${startLine}-${endLine} of ${result.totalLines} total lines. |
| 322 | To read more: Use the read_file tool with offset=${nextOffset} and limit=${limit}. |
| 323 | |
| 324 | ${result.content}` |
| 325 | } else if (result.returnedLines === 0) { |
| 326 | output = "Note: File is empty" |
no test coverage detected