Skip to content

Commit cd7da73

Browse files
Gustav-SimonssonTheGreatAxios
authored andcommitted
refactor(tui): compress verbose comments in the long-log retention module
1 parent 0d433e3 commit cd7da73

2 files changed

Lines changed: 32 additions & 33 deletions

File tree

‎src/tui/long-log.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
/**
2-
* Retention budget for a long-running transcript. The paint tree tracks
2+
* Retention cap for a long-running transcript: the paint tree tracks
33
* `streamLog` 1:1 (shell.ts's repaintTranscriptWindow/paintAppendStreamRow),
4-
* so every retained row stays reachable by scrolling; this cap keeps that
4+
* so every retained row stays reachable by scrolling; the cap keeps that
55
* array — and the paint tree — bounded.
66
*/
77

88
/**
9-
* Retained tail of a stream log. Display-only state — the agent's own context
10-
* is kept separately — but an unbounded array still costs memory and O(n)
11-
* snapshot/diff work on every append.
9+
* Retained tail of a stream log, display-only — the agent's own context sits
10+
* elsewhere — but an unbounded array costs memory and O(n) snapshot/diff
11+
* work on every append.
1212
*/
1313
export const MAX_RETAINED_STREAM_ROWS = 600;
1414

15-
/** Rows to drop from the front of a log of this length to fit the cap. */
15+
/** Rows to drop from the front to fit the cap. */
1616
export function retentionOverflow(length: number): number {
1717
return Math.max(0, length - MAX_RETAINED_STREAM_ROWS);
1818
}
1919

2020
/**
21-
* Evict the oldest rows once `log` exceeds the retention cap and return the
22-
* new absolute base (the index `log[0]` now represents).
21+
* Evict the oldest rows past the cap and return the new absolute base (the
22+
* index `log[0]` now represents).
2323
*
2424
* Every index the bridge holds — tool-call rows, the open streaming row, the
25-
* retry boundary — is absolute (base + local position), so eviction only bumps
26-
* the base; it never rewrites a stored index.
25+
* retry boundary — is absolute (base + local position), so eviction only
26+
* bumps the base; it never rewrites a stored index.
2727
*/
2828
export function trimRetainedLog<T>(log: T[], base: number): number {
2929
const drop = retentionOverflow(log.length);
@@ -33,9 +33,9 @@ export function trimRetainedLog<T>(log: T[], base: number): number {
3333
}
3434

3535
/**
36-
* Notice painted above the oldest retained row once the cap has evicted
37-
* anything. Unlike the collapse marker it replaces, scrolling never reveals
38-
* more — these rows are gone, not merely out of the window.
36+
* Notice above the oldest retained row once the cap evicted anything. Unlike
37+
* the collapse marker it replaces, scrolling never reveals more — these rows
38+
* are gone, not merely out of the window.
3939
*
4040
* `evicted` is the count of painted rows actually spliced from the log; do
4141
* not invent 1 to mean "older history exists on disk."
@@ -46,8 +46,8 @@ export function evictedRowsNotice(evicted: number): string {
4646

4747
/**
4848
* Notice when older history exists on disk but no painted row was spliced.
49-
* Resume can load a truncated tail that still fits the cap; the marker must
50-
* still say this is not the start of history, without a fake count.
49+
* Resume can load a truncated tail that fits the cap; the marker must still
50+
* say this is not the start of history, without a fake count.
5151
*/
5252
export function unloadedHistoryNotice(): string {
5353
return " … earlier rows not loaded (past the retention limit)";

‎src/tui/transcript-long-log-scroll.test.ts‎

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
2-
* The full retained transcript (bounded by `MAX_RETAINED_STREAM_ROWS`) has
3-
* to stay reachable by scrolling, and appending a new row must not rebuild
4-
* the whole paint tree to do it.
2+
* The full retained transcript must stay reachable by scrolling, and one
3+
* append must not rebuild the whole paint tree.
54
*/
65
import { describe, expect, test } from "bun:test";
76
import { withTestRenderer } from "./harness";
@@ -11,8 +10,8 @@ import { streamRowCount } from "./shell/transcript";
1110
import { MAX_RETAINED_STREAM_ROWS } from "./long-log";
1211

1312
async function settle(h: { renderOnce: () => Promise<void> }): Promise<void> {
14-
// Markdown highlighting and viewport culling both settle a frame or two
15-
// after the triggering mutation, not within it.
13+
// Markdown highlighting and viewport culling settle a frame or two after
14+
// the mutation, not within it.
1615
for (let i = 0; i < 5; i++) {
1716
await new Promise((resolve) => setTimeout(resolve, 10));
1817
await h.renderOnce();
@@ -38,15 +37,15 @@ describe("long-log transcript scrolling", () => {
3837
await settle(h);
3938
const frame = h.captureCharFrame();
4039

41-
// Rows 0-49 were evicted by the retention cap — gone by design, not
42-
// a scrolling bug. Row 50 is the oldest still-retained row and sits
43-
// 450 rows above the old 200-row paint window; it must be reachable
44-
// in one scroll rather than staying stranded behind a collapsed marker.
40+
// Rows 0-49 were evicted by the cap — gone by design, not a scroll
41+
// bug. Row 50 is the oldest retained row, 450 rows above the old
42+
// 200-row paint window; one scroll must reach it, not leave it
43+
// stranded behind a collapsed marker.
4544
expect(frame).toContain("row-50");
4645
expect(frame).not.toContain("row-49");
47-
// The boundary says rows were dropped rather than reading as the
48-
// true start of history — eviction is permanent, unlike the old
49-
// collapse marker, so scrolling further will never reveal row 0.
46+
// The boundary says rows were dropped, not the true start of
47+
// history — eviction is permanent, unlike the collapse marker, so
48+
// scrolling never reveals row 0.
5049
expect(frame).toContain("50 earlier rows dropped");
5150
} finally {
5251
shell.dispose();
@@ -80,10 +79,10 @@ describe("long-log transcript scrolling", () => {
8079
appendStreamRow(shell, { role: "assistant", text: "one-more" });
8180
await settle(h);
8281

83-
// Before this fix, repaintTranscriptWindow ran on every append once
84-
// the log passed LONG_LOG_COLLAPSE_THRESHOLD (500): it tore down every
85-
// existing child and repainted windowSlice's LONG_LOG_WINDOW (200) rows
86-
// from scratch — 200 removals for this one append, every append after.
82+
// Before this fix, repaintTranscriptWindow ran on every append
83+
// past LONG_LOG_COLLAPSE_THRESHOLD (500): it tore down every child
84+
// and repainted windowSlice's LONG_LOG_WINDOW (200) rows from
85+
// scratch — 200 removals per append.
8786
expect(removed).toBe(1);
8887
} finally {
8988
shell.dispose();
@@ -143,8 +142,8 @@ describe("long-log transcript scrolling", () => {
143142
};
144143

145144
// Streaming token updates hit this path on every delta; past the
146-
// retention cap it must still touch one node, not the eviction
147-
// notice's presence forcing a full repaintTranscriptWindow.
145+
// cap it must still touch one node, not the eviction notice forcing
146+
// a full repaintTranscriptWindow.
148147
const lastIndex = streamRowCount(shell) - 1;
149148
replaceStreamRowAt(shell, lastIndex, {
150149
role: "assistant",

0 commit comments

Comments
 (0)