fix(tui): prune chat log system messages atomically

This commit is contained in:
Shakker
2026-03-27 10:29:32 +00:00
parent 32a3733dbe
commit 14c63ca42a
2 changed files with 24 additions and 2 deletions

View File

@@ -53,6 +53,22 @@ describe("ChatLog", () => {
expect(chatLog.children.length).toBe(20);
});
it("prunes system messages atomically when a non-system entry overflows the log", () => {
const chatLog = new ChatLog(20);
for (let i = 1; i <= 20; i++) {
chatLog.addSystem(`system-${i}`);
}
chatLog.addUser("hello");
const rendered = chatLog.render(120).join("\n");
expect(rendered).not.toMatch(/\bsystem-1\b/);
expect(rendered).toMatch(/\bsystem-2\b/);
expect(rendered).toMatch(/\bsystem-20\b/);
expect(rendered).toContain("hello");
expect(chatLog.children.length).toBe(20);
});
it("renders BTW inline and removes it when dismissed", () => {
const chatLog = new ChatLog(40);

View File

@@ -57,9 +57,15 @@ export class ChatLog extends Container {
this.btwMessage = null;
}
private createSystemMessage(text: string): Container {
const entry = new Container();
entry.addChild(new Spacer(1));
entry.addChild(new Text(theme.system(text), 1, 0));
return entry;
}
addSystem(text: string) {
this.append(new Spacer(1));
this.append(new Text(theme.system(text), 1, 0));
this.append(this.createSystemMessage(text));
}
addUser(text: string) {