| ... | ... | @@ -582,12 +582,12 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 582 | 582 | } |
| 583 | 583 | |
| 584 | 584 | private async readHistory(threadId: string, terminalId: string): Promise<string> { |
| 585 | | const historyPath = this.historyPath(threadId, terminalId); |
| 585 | const nextPath = this.historyPath(threadId, terminalId); |
| 586 | 586 | try { |
| 587 | | const raw = await fs.promises.readFile(historyPath, "utf8"); |
| 587 | const raw = await fs.promises.readFile(nextPath, "utf8"); |
| 588 | 588 | const capped = capHistory(raw, this.historyLineLimit); |
| 589 | 589 | if (capped !== raw) { |
| 590 | | await fs.promises.writeFile(historyPath, capped, "utf8"); |
| 590 | await fs.promises.writeFile(nextPath, capped, "utf8"); |
| 591 | 591 | } |
| 592 | 592 | return capped; |
| 593 | 593 | } catch (error) { |
| ... | ... | @@ -600,12 +600,22 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> { |
| 600 | 600 | return ""; |
| 601 | 601 | } |
| 602 | 602 | |
| 603 | const legacyPath = this.legacyHistoryPath(threadId); |
| 603 | 604 | try { |
| 604 | | const raw = await fs.promises.readFile(this.legacyHistoryPath(threadId), "utf8"); |
| 605 | const raw = await fs.promises.readFile(legacyPath, "utf8"); |
| 605 | 606 | const capped = capHistory(raw, this.historyLineLimit); |
| 606 | | if (capped !== raw) { |
| 607 | | await fs.promises.writeFile(this.legacyHistoryPath(threadId), capped, "utf8"); |
| 607 | |
| 608 | // Migrate legacy transcript filename to the terminal-scoped path. |
| 609 | await fs.promises.writeFile(nextPath, capped, "utf8"); |
| 610 | try { |
| 611 | await fs.promises.rm(legacyPath, { force: true }); |
| 612 | } catch (cleanupError) { |
| 613 | this.logger.warn("failed to remove legacy terminal history", { |
| 614 | threadId, |
| 615 | error: cleanupError instanceof Error ? cleanupError.message : String(cleanupError), |
| 616 | }); |
| 608 | 617 | } |
| 618 | |
| 609 | 619 | return capped; |
| 610 | 620 | } catch (error) { |
| 611 | 621 | if ((error as NodeJS.ErrnoException).code === "ENOENT") { |