(
filePath: string,
maxLines: number
)
| 469 | // ------------------------------------------------------------------- |
| 470 | |
| 471 | async function readLastLines( |
| 472 | filePath: string, |
| 473 | maxLines: number |
| 474 | ): Promise<string[]> { |
| 475 | const lines: string[] = []; |
| 476 | const fileStream = fs.createReadStream(filePath, { encoding: "utf-8" }); |
| 477 | const rl = readline.createInterface({ input: fileStream, crlfDelay: Infinity }); |
| 478 | |
| 479 | const buffer: string[] = []; |
| 480 | for await (const line of rl) { |
| 481 | buffer.push(line); |
| 482 | if (buffer.length > maxLines * 2) { |
| 483 | buffer.splice(0, maxLines); // keep a sliding window |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | return buffer.slice(-maxLines); |
| 488 | } |
| 489 | |
| 490 | function extractTaskFromMessages(messages: string[]): string { |
| 491 | // First user message is usually the task |
no outgoing calls
no test coverage detected