Skip to content

Commit 7a01978

Browse files
Gustav-SimonssonTheGreatAxios
authored andcommitted
refactor(tui): deepen comment compression in the shell chrome
1 parent 46b1ec0 commit 7a01978

1 file changed

Lines changed: 45 additions & 49 deletions

File tree

‎src/tui/shell/chrome.ts‎

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ export function setPluginNeedsAttention(shell: AppShell, needs: boolean): void {
167167
}
168168

169169
/**
170-
* Key over every input chrome paint reads; a missed input leaves stale
171-
* chrome. Keep exhaustive; landing and zone paints read their own state.
170+
* Key over every input a chrome paint reads; a miss leaves stale chrome.
172171
*/
173172
function chromeComposeKey(shell: AppShell, notice: string): string {
174173
const meter = shell.costContext;
@@ -214,7 +213,7 @@ export function paintChrome(
214213
): void {
215214
if (shell.disposed) return;
216215
// Headless tests destroy the renderer without dispose; a flash armed
217-
// before that teardown must not write a buffer the harness freed.
216+
// before that must not write a freed buffer.
218217
if (shell.renderer.isDestroyed || shell.notice.isDestroyed) return;
219218
syncPending(shell);
220219
const notice = noticeText(shell);
@@ -310,7 +309,7 @@ function syncNoticeRow(shell: AppShell, notice: string): void {
310309

311310
/** Re-read the notice after layout: `pinned` reflects the last completed
312311
* layout, so a mid-paint read can misread a following transcript as
313-
* pinned for a frame. */
312+
* pinned. */
314313
export function syncNoticeAfterLayout(shell: AppShell): void {
315314
if (noticeText(shell) !== paintedNotice.get(shell)) paintChrome(shell);
316315
}
@@ -331,9 +330,8 @@ function syncLandingSuggestions(shell: AppShell): void {
331330
paintLandingBelow(landing.below, content, visible);
332331
}
333332

334-
/** Callers own the tick; repaint only when the frame differs. A phase
335-
* change stamps the fade origin; settling snaps to idle — a stuck frame
336-
* is worse than none. */
333+
/** Repaint only when the frame differs. A phase change stamps the fade
334+
* origin; settling snaps to idle — a stuck frame is worse than none. */
337335
export interface LockupFrame {
338336
readonly nowMs: number;
339337
readonly animating: boolean;
@@ -446,9 +444,9 @@ export function overlayAnswerState(shell: AppShell): OverlayAnswerState | null {
446444
/** Stacking order for the floated overlay host; one step clears the landing. */
447445
const OVERLAY_FLOAT_Z = 10;
448446

449-
/** Float the overlay host over the root column, or back in. Landing: it
450-
* floats as a modal so the mark stays beneath; a transcript pushes rows
451-
* instead of covering them. */
447+
/** Float the overlay host over the root column, or back in. Landing: float
448+
* it so the mark stays beneath; transcript: push rows instead of covering
449+
* them. */
452450
function floatOverlayHost(
453451
shell: AppShell,
454452
floating: boolean,
@@ -850,10 +848,10 @@ export function syncPromptRows(shell: AppShell): void {
850848
}
851849

852850
/**
853-
* Resize the leading filler to soak up leftover viewport space, reading
854-
* `scrollHeight` minus the filler. Not at row-mutation time: a mid-layout
855-
* row reads short for a frame, so a filler grown then would bury it. The
856-
* render-frame hook calls it after that pass.
851+
* Resize the leading filler to soak leftover viewport space (`scrollHeight`
852+
* minus filler). Not at row-mutation time: mid-layout rows read short for a
853+
* frame, so a filler grown then would bury one. The render-frame hook calls
854+
* it after that pass.
857855
*/
858856
export function syncTranscriptSpacer(shell: AppShell): void {
859857
const spacer = transcriptSpacers.get(shell);
@@ -953,9 +951,9 @@ export function appendStreamRow(shell: AppShell, row: StreamRow): void {
953951
paintAppendStreamRow(shell, row);
954952
}
955953

956-
/** Paint the dropped-rows notice when on-disk history hit the retention
957-
* cap before trim ran. Does not bump `streamLogBase`: faking the splice
958-
* offset would orphan the first retained row. */
954+
/** Paint the dropped-rows notice when on-disk history hit the retention cap
955+
* before trim ran. Does not bump `streamLogBase` — a fake splice offset
956+
* would orphan the first retained row. */
959957
export function noteUnloadedHistory(shell: AppShell): void {
960958
if (shell.observe !== null && shell.parentStreamLog !== null) {
961959
if (shell.parentStreamLog.length > 0) {
@@ -989,8 +987,8 @@ function paintDroppedHistoryMarker(shell: AppShell): void {
989987
shell.transcript.add(node, 1);
990988
}
991989

992-
/** Append a child stream row while observing a subagent (host-pushed live
993-
* events, not only seed lines). No-op when not observing.
990+
/** Append a child stream row while observing (host-pushed live events, not
991+
* only seed lines). No-op when not observing.
994992
* @returns true when the row reached the observe view */
995993
export function appendObserveStreamRow(
996994
shell: AppShell,
@@ -1002,10 +1000,10 @@ export function appendObserveStreamRow(
10021000
return true;
10031001
}
10041002

1005-
/** Collapse a system row identical to the one on top (startup echoes
1006-
* stutter) only when nothing painted since. Observe rows paint without
1007-
* touching the parent log, so adjacency alone would swallow a "left
1008-
* observe" farewell; the sequence check restores it. */
1003+
/** Collapse a system row identical to the one above (startup echoes stutter)
1004+
* only when nothing painted since. Observe rows paint outside the parent
1005+
* log, so adjacency alone would swallow a "left observe" farewell; the
1006+
* sequence check restores it. */
10091007
const paintSequence = new WeakMap<AppShell, number>();
10101008
const systemPushSequence = new WeakMap<AppShell, number>();
10111009

@@ -1028,8 +1026,8 @@ function isDuplicateSystemEcho(shell: AppShell, row: StreamRow): boolean {
10281026
}
10291027

10301028
/** Push onto the visible streamLog (child while observing, parent
1031-
* otherwise). The paint tree stays 1:1 with the retention-capped log, so
1032-
* a trim past the cap costs one node removal, not a rebuild. */
1029+
* otherwise). The paint tree stays 1:1 with the retention-capped log, so a
1030+
* cap trim costs one node removal, not a rebuild. */
10331031
function paintAppendStreamRow(shell: AppShell, row: StreamRow): void {
10341032
clearLandingMark(shell);
10351033
const seq = (paintSequence.get(shell) ?? 0) + 1;
@@ -1074,8 +1072,8 @@ function paintAppendStreamRow(shell: AppShell, row: StreamRow): void {
10741072
}
10751073

10761074
/** Drop every row from absolute `length` onward. A failed attempt re-streams
1077-
* from scratch, so retract painted rows rather than piling the replay under
1078-
* them. A cap-evicted boundary is a no-op. */
1075+
* from scratch, so retract painted rows rather than pile the replay under
1076+
* them; a cap-evicted boundary is a no-op. */
10791077
export function truncateStreamRows(shell: AppShell, length: number): void {
10801078
const parentLog = shell.parentStreamLog;
10811079
const observing = shell.observe !== null && parentLog !== null;
@@ -1092,10 +1090,10 @@ export function truncateStreamRows(shell: AppShell, length: number): void {
10921090
paintChrome(shell);
10931091
}
10941092

1095-
/** Empty the visible transcript for a fresh session (/clear, /new). Backend
1096-
* rotation lives in the runner — on-screen wipe only. Observe drops first
1097-
* so a child view cannot paint into a cleared parent; retention base
1098-
* resets so no stale marker lingers. */
1093+
/** Empty the visible transcript for a fresh session (/clear, /new); backend
1094+
* rotation lives in the runner, this is the on-screen wipe only. Drop
1095+
* observe first so a child view cannot paint into a cleared parent; reset
1096+
* the retention base so no stale marker lingers. */
10991097
export function clearTranscript(shell: AppShell): void {
11001098
if (shell.observe !== null) {
11011099
// Drop observe without the "left observe" row — the log is about to go,
@@ -1127,9 +1125,9 @@ export function clearTranscript(shell: AppShell): void {
11271125
}
11281126

11291127
/** Rewrite an appended transcript row in place. Streaming bodies grow token
1130-
* by token, so one open row is replaced per delta, not one per token.
1131-
* `index` is absolute (`streamLogBase`); a cap-evicted row is a no-op,
1132-
* not an unrelated-slot write. */
1128+
* by token, so one open row is replaced per delta, not per token. `index`
1129+
* is absolute (`streamLogBase`); a cap-evicted row is a no-op, not an
1130+
* unrelated-slot write. */
11331131
export function replaceStreamRowAt(
11341132
shell: AppShell,
11351133
index: number,
@@ -1180,7 +1178,7 @@ export function replaceStreamRowAt(
11801178

11811179
/** Rebuild the transcript paint tree from `streamLog` — every retained row,
11821180
* not a window. The log caps at `MAX_RETAINED_STREAM_ROWS`, so this is
1183-
* O(cap); painting all keeps history scrollable. */
1181+
* O(cap). */
11841182
export function repaintTranscriptWindow(shell: AppShell): void {
11851183
clearLandingMark(shell);
11861184
shell.agentVoices = new Set(agentVoicesIn(shell.streamLog));
@@ -1219,7 +1217,7 @@ export function repaintTranscriptWindow(shell: AppShell): void {
12191217

12201218
/** Tear the landing down on the first transcript row. The prompt box jumps
12211219
* from mid-screen to the bottom on the same frame — the screen answering,
1222-
* not a layout twitch. Deferred notices flush into the transcript. */
1220+
* not a layout twitch. */
12231221
function clearLandingMark(shell: AppShell): void {
12241222
const bag = shellInternals(shell);
12251223
const landing = bag?.landing;
@@ -1253,11 +1251,10 @@ function clearLandingMark(shell: AppShell): void {
12531251
* needs about half a row per second, so 8fps reads as motion. */
12541252
export const LANDING_IDLE_REPAINT_INTERVAL_MS = 125;
12551253

1256-
/** Repaint the landing mark for `nowMs`. `animating` runs the draw/fill/fade
1257-
* timeline; otherwise it holds its filled frame. No-op once the landing is
1258-
* gone, so callers can always drive it. Idle still repaints — snow drifts.
1259-
* Reduced motion (a mount-time flag) freezes the mark and drops snow even
1260-
* under `animating`. */
1254+
/** Repaint the landing mark for `nowMs`: `animating` runs the draw/fill/fade
1255+
* timeline, else it holds the filled frame. No-op once the landing is gone,
1256+
* so callers can always drive it. Idle still repaints (snow drifts);
1257+
* reduced motion freezes the mark and drops snow even under `animating`. */
12611258
export function paintLanding(
12621259
shell: AppShell,
12631260
nowMs: number,
@@ -1356,9 +1353,8 @@ export function toggleRowExpandedAt(shell: AppShell, index: number): boolean {
13561353
}
13571354

13581355
/** Expand or collapse every collapsed row — same key as overlay payloads.
1359-
* All-or-nothing: opening just the newest of several reads as a miss. Any
1360-
* still-collapsed row opens; only once none are left does the key close
1361-
* them again. */
1356+
* All-or-nothing: opening just the newest of several reads as a miss; only
1357+
* once none are left does the key close them again. */
13621358
export function toggleCollapsedRow(shell: AppShell): boolean {
13631359
const collapsible = shell.streamLog.flatMap((row, local) =>
13641360
row !== undefined && isCollapsibleRow(row)
@@ -1391,14 +1387,14 @@ function taskStatusMarker(status: TaskPanelRow["status"]): string {
13911387
}
13921388

13931389
/** Fit a row's label + tail into `maxWidth`, ellipsizing the label
1394-
* (routinely long, free-form) before the tail the operator glances at.
1395-
* Measured via `stringWidth`/`sliceToWidth`, not `.length` — UTF-16
1396-
* units undercount wide glyphs. */
1390+
* (routinely long, free-form) before the tail. Measure via
1391+
* `stringWidth`/`sliceToWidth`, not `.length` — UTF-16 units undercount
1392+
* wide glyphs. */
13971393
function fitAgentRow(row: AgentPanelRow, maxWidth: number): string {
13981394
const full = ` ${row.label}${row.tail}`;
13991395
if (stringWidth(full) <= maxWidth) {
1400-
// Right-align lane tails so the clocks line up as a column; a lane
1401-
// silent far longer than its neighbours stands out by shape alone.
1396+
// Right-align lane tails so clocks line up as a column; a lane silent
1397+
// far longer than its neighbours stands out by shape.
14021398
if (row.kind === "lane") {
14031399
const pad = maxWidth - stringWidth(full);
14041400
return ` ${row.label}${" ".repeat(Math.max(0, pad))}${row.tail}`;

0 commit comments

Comments
 (0)