From 32bb3acb09a907141394c68ab708878de0f202c4 Mon Sep 17 00:00:00 2001 From: mitchell Date: Sat, 18 Apr 2026 06:07:41 -0400 Subject: [PATCH] refactor: remove reasoning file persistence and consolidate cursor methods Remove reasoning-delta/end file writing and merge moveCursor/clearScreenDown into a single moveClearReset method. Add config save confirmation message. --- index.ts | 2 ++ src/render/index.ts | 28 ++++++---------------------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/index.ts b/index.ts index 2366afb..484f9c6 100644 --- a/index.ts +++ b/index.ts @@ -2,6 +2,7 @@ import os from "node:os"; import { parseArgs } from "node:util"; import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; import { type ModelMessage, streamText } from "ai"; +import chalk from "chalk"; import Renderer from "./src/render"; @@ -49,6 +50,7 @@ async function main() { if (saveConfig) { await configFile.write(JSON.stringify(config, null, " ")); + console.log(chalk.green("Configuration saved!")); return; } diff --git a/src/render/index.ts b/src/render/index.ts index 6e3a17d..97a6464 100644 --- a/src/render/index.ts +++ b/src/render/index.ts @@ -1,4 +1,3 @@ -import os from "node:os"; import type { WriteStream } from "node:tty"; import type { AsyncIterableStream, @@ -10,10 +9,6 @@ import styles from "ansi-styles"; import { chalkStderr, supportsColorStderr } from "chalk"; import { renderMarkdown } from "./markdown"; -const home = os.homedir(); -const reasoningFile = Bun.file(`${home}/.aicl_reasoning.md`); -const reasoningWriter = reasoningFile.writer(); - export default class Renderer { private lineCount = 0; private charsSinceNL = 0; @@ -37,12 +32,10 @@ export default class Renderer { this.memOk = pipe.write(text); } - private moveCursor(y: number, pipe: WriteStream = process.stdout) { + private moveClearReset(y: number, pipe: WriteStream = process.stdout) { this.memOk = pipe.moveCursor(-9999, y); - } - - private clearScreenDown(pipe: WriteStream = process.stdout) { this.memOk = pipe.clearScreenDown(); + this.resetCounts(); } private resetCounts() { @@ -61,10 +54,8 @@ export default class Renderer { this.charsSinceNL = this.charsSinceNL - columns; } - if (this.lineCount >= rows - 5) { - this.moveCursor(-this.lineCount, pipe); - this.clearScreenDown(pipe); - this.resetCounts(); + if (this.lineCount >= Math.max(rows - 10, 1)) { + this.moveClearReset(-this.lineCount, pipe); } } @@ -85,9 +76,7 @@ export default class Renderer { } private async render(str: string, pipe = process.stdout) { - this.moveCursor(-this.lineCount, pipe); - this.clearScreenDown(pipe); - this.resetCounts(); + this.moveClearReset(-this.lineCount, pipe); const [columns] = pipe.getWindowSize(); const rendered = await renderMarkdown(str, columns); @@ -108,21 +97,17 @@ export default class Renderer { ); this.write("\n", process.stderr); - reasoningFile.write(""); break; } case "reasoning-delta": { this.write(part.text, process.stderr); if (!this.isPlainErr) this.checkContainment(part.text, process.stderr); - reasoningWriter.write(part.text); break; } case "reasoning-end": { if (!this.isPlainErr) { - this.moveCursor(-this.lineCount - 1, process.stderr); - this.clearScreenDown(process.stderr); - this.resetCounts(); + this.moveClearReset(-this.lineCount - 1, process.stderr); } else { this.write("\n--- Done Thinking ---\n", process.stderr); } @@ -133,7 +118,6 @@ export default class Renderer { process.stderr, ); - reasoningWriter.end(); break; } case "text-start": {