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

@ -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": {