Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.
Migrate legacy terminal history to terminal-scoped log path
Julius Marminged27b08bae68a
diff --git a/apps/server/src/terminalManager.test.ts b/apps/server/src/terminalManager.test.tsindex b8257e07c..9b77d582b 100644--- a/apps/server/src/terminalManager.test.ts+++ b/apps/server/src/terminalManager.test.ts@@ -334,15 +334,18 @@ describe("TerminalManager", () => {manager.dispose();});- it("loads existing legacy transcript filenames and keeps new naming for writes", async () => {+ it("migrates legacy transcript filenames to terminal-scoped history path on open", async () => {const { manager, logsDir } = makeManager();const legacyPath = path.join(logsDir, "thread-1.log");+ const nextPath = historyLogPath(logsDir);fs.writeFileSync(legacyPath, "legacy-line\n", "utf8");const snapshot = await manager.open(openInput());expect(snapshot.history).toBe("legacy-line\n");- expect(fs.existsSync(legacyPath)).toBe(true);+ expect(fs.existsSync(nextPath)).toBe(true);+ expect(fs.readFileSync(nextPath, "utf8")).toBe("legacy-line\n");+ expect(fs.existsSync(legacyPath)).toBe(false);manager.dispose();});diff --git a/apps/server/src/terminalManager.ts b/apps/server/src/terminalManager.tsindex 8c8d18cdf..8fe6d662e 100644--- a/apps/server/src/terminalManager.ts+++ b/apps/server/src/terminalManager.ts@@ -582,12 +582,12 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> {}private async readHistory(threadId: string, terminalId: string): Promise<string> {- const historyPath = this.historyPath(threadId, terminalId);+ const nextPath = this.historyPath(threadId, terminalId);try {- const raw = await fs.promises.readFile(historyPath, "utf8");+ const raw = await fs.promises.readFile(nextPath, "utf8");const capped = capHistory(raw, this.historyLineLimit);if (capped !== raw) {- await fs.promises.writeFile(historyPath, capped, "utf8");+ await fs.promises.writeFile(nextPath, capped, "utf8");}return capped;} catch (error) {@@ -600,12 +600,22 @@ export class TerminalManager extends EventEmitter<TerminalManagerEvents> {return "";}+ const legacyPath = this.legacyHistoryPath(threadId);try {- const raw = await fs.promises.readFile(this.legacyHistoryPath(threadId), "utf8");+ const raw = await fs.promises.readFile(legacyPath, "utf8");const capped = capHistory(raw, this.historyLineLimit);- if (capped !== raw) {- await fs.promises.writeFile(this.legacyHistoryPath(threadId), capped, "utf8");++ // Migrate legacy transcript filename to the terminal-scoped path.+ await fs.promises.writeFile(nextPath, capped, "utf8");+ try {+ await fs.promises.rm(legacyPath, { force: true });+ } catch (cleanupError) {+ this.logger.warn("failed to remove legacy terminal history", {+ threadId,+ error: cleanupError instanceof Error ? cleanupError.message : String(cleanupError),+ });}+return capped;} catch (error) {if ((error as NodeJS.ErrnoException).code === "ENOENT") {