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.
This commit is contained in:
mitchell 2026-04-18 06:07:41 -04:00
parent 856a3160fe
commit 32bb3acb09
2 changed files with 8 additions and 22 deletions

View file

@ -2,6 +2,7 @@ import os from "node:os";
import { parseArgs } from "node:util"; import { parseArgs } from "node:util";
import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
import { type ModelMessage, streamText } from "ai"; import { type ModelMessage, streamText } from "ai";
import chalk from "chalk";
import Renderer from "./src/render"; import Renderer from "./src/render";
@ -49,6 +50,7 @@ async function main() {
if (saveConfig) { if (saveConfig) {
await configFile.write(JSON.stringify(config, null, " ")); await configFile.write(JSON.stringify(config, null, " "));
console.log(chalk.green("Configuration saved!"));
return; return;
} }

View file

@ -1,4 +1,3 @@
import os from "node:os";
import type { WriteStream } from "node:tty"; import type { WriteStream } from "node:tty";
import type { import type {
AsyncIterableStream, AsyncIterableStream,
@ -10,10 +9,6 @@ import styles from "ansi-styles";
import { chalkStderr, supportsColorStderr } from "chalk"; import { chalkStderr, supportsColorStderr } from "chalk";
import { renderMarkdown } from "./markdown"; import { renderMarkdown } from "./markdown";
const home = os.homedir();
const reasoningFile = Bun.file(`${home}/.aicl_reasoning.md`);
const reasoningWriter = reasoningFile.writer();
export default class Renderer { export default class Renderer {
private lineCount = 0; private lineCount = 0;
private charsSinceNL = 0; private charsSinceNL = 0;
@ -37,12 +32,10 @@ export default class Renderer {
this.memOk = pipe.write(text); 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); this.memOk = pipe.moveCursor(-9999, y);
}
private clearScreenDown(pipe: WriteStream = process.stdout) {
this.memOk = pipe.clearScreenDown(); this.memOk = pipe.clearScreenDown();
this.resetCounts();
} }
private resetCounts() { private resetCounts() {
@ -61,10 +54,8 @@ export default class Renderer {
this.charsSinceNL = this.charsSinceNL - columns; this.charsSinceNL = this.charsSinceNL - columns;
} }
if (this.lineCount >= rows - 5) { if (this.lineCount >= Math.max(rows - 10, 1)) {
this.moveCursor(-this.lineCount, pipe); this.moveClearReset(-this.lineCount, pipe);
this.clearScreenDown(pipe);
this.resetCounts();
} }
} }
@ -85,9 +76,7 @@ export default class Renderer {
} }
private async render(str: string, pipe = process.stdout) { private async render(str: string, pipe = process.stdout) {
this.moveCursor(-this.lineCount, pipe); this.moveClearReset(-this.lineCount, pipe);
this.clearScreenDown(pipe);
this.resetCounts();
const [columns] = pipe.getWindowSize(); const [columns] = pipe.getWindowSize();
const rendered = await renderMarkdown(str, columns); const rendered = await renderMarkdown(str, columns);
@ -108,21 +97,17 @@ export default class Renderer {
); );
this.write("\n", process.stderr); this.write("\n", process.stderr);
reasoningFile.write("");
break; break;
} }
case "reasoning-delta": { case "reasoning-delta": {
this.write(part.text, process.stderr); this.write(part.text, process.stderr);
if (!this.isPlainErr) if (!this.isPlainErr)
this.checkContainment(part.text, process.stderr); this.checkContainment(part.text, process.stderr);
reasoningWriter.write(part.text);
break; break;
} }
case "reasoning-end": { case "reasoning-end": {
if (!this.isPlainErr) { if (!this.isPlainErr) {
this.moveCursor(-this.lineCount - 1, process.stderr); this.moveClearReset(-this.lineCount - 1, process.stderr);
this.clearScreenDown(process.stderr);
this.resetCounts();
} else { } else {
this.write("\n--- Done Thinking ---\n", process.stderr); this.write("\n--- Done Thinking ---\n", process.stderr);
} }
@ -133,7 +118,6 @@ export default class Renderer {
process.stderr, process.stderr,
); );
reasoningWriter.end();
break; break;
} }
case "text-start": { case "text-start": {