Skip to content

Commit 43d93af

Browse files
cliffhallclaude
andcommitted
fix(sequentialthinking): size the thought box after its summary row
A truncated thought of short lines had a summary row wider than the box (33 characters against a 20-character border). The row texts are now collected first and the box is sized to include the summary; widening cannot change the wrapping, since below the cap no line wrapped and at the cap the summary fits. The very-many-lines test checks every row's width. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent 8da06bc commit 43d93af

2 files changed

Lines changed: 29 additions & 20 deletions

File tree

‎src/sequentialthinking/__tests__/thought-logging.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ ${rows.join("\n")}
242242
expect(out.at(-2)).toContain(
243243
`… ${200_000 - MAX_BOX_ROWS} more lines not shown`,
244244
);
245+
// The summary is wider than every one-character line and the header,
246+
// so it sets the box's width; it must not stick out of it.
247+
expect(new Set(out.slice(1).map((r) => r.length)).size).toBe(1);
245248
});
246249
});
247250

‎src/sequentialthinking/lib.ts‎

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,41 +148,47 @@ export class SequentialThinkingServer {
148148
// A reduce rather than Math.max(...lengths): spreading one argument per
149149
// line would overflow the call stack on a thought with very many lines.
150150
// #5433: never wider than MAX_BOX_TEXT_WIDTH; longer lines wrap below.
151-
const width = Math.min(
151+
const wrapWidth = Math.min(
152152
MAX_BOX_TEXT_WIDTH,
153153
lines.reduce(
154154
(widest, line) => Math.max(widest, line.length),
155155
visibleHeader.length,
156156
),
157157
);
158-
const border = "─".repeat(width + 4);
159-
// Every row, header rows included, is padded to the border's width by the
160-
// visible text's length. Each label's emoji is one surrogate pair, so its
161-
// length of 2 is also its display width in a terminal. A header longer
162-
// than the cap (a long branchId) wraps like a thought line; only its first
163-
// row, which starts with the label, is coloured.
164-
const row = (text: string) => `│ ${text.padEnd(border.length - 2)} │`;
165-
const headerRows = wrapRow(visibleHeader, width).map((text, i) =>
166-
i === 0 ? row(text).replace(label, colour(label)) : row(text),
167-
);
158+
// A header longer than the cap (a long branchId) wraps like a thought
159+
// line; only its first row, which starts with the label, is coloured.
160+
const headerTexts = wrapRow(visibleHeader, wrapWidth);
168161
// Rows are drawn up to MAX_BOX_ROWS; the lines left over are counted, not
169162
// drawn, so a huge thought costs no more than the cap.
170-
const rows: string[] = [];
163+
const texts: string[] = [];
171164
// Lines drawn in full; a line cut off by the cap counts as hidden.
172165
let whole = 0;
173166
for (const line of lines) {
174-
const wrapped = wrapRow(line, width);
175-
const room = MAX_BOX_ROWS - rows.length;
176-
for (const text of wrapped.slice(0, room)) rows.push(row(text));
167+
const wrapped = wrapRow(line, wrapWidth);
168+
const room = MAX_BOX_ROWS - texts.length;
169+
texts.push(...wrapped.slice(0, room));
177170
if (wrapped.length > room) break;
178171
whole++;
179172
}
180173
const hidden = lines.length - whole;
181-
if (hidden > 0) {
182-
rows.push(
183-
row(`… ${hidden} more line${hidden === 1 ? "" : "s"} not shown`),
184-
);
185-
}
174+
const summary =
175+
hidden > 0
176+
? `… ${hidden} more line${hidden === 1 ? "" : "s"} not shown`
177+
: "";
178+
if (summary) texts.push(summary);
179+
// The summary row can be wider than every line it follows, so the box is
180+
// sized after it. Widening cannot change the wrapping above: below the cap
181+
// no line wrapped, and at the cap the summary (under 40 characters) fits.
182+
const width = Math.max(wrapWidth, summary.length);
183+
const border = "─".repeat(width + 4);
184+
// Every row, header rows included, is padded to the border's width by the
185+
// visible text's length. Each label's emoji is one surrogate pair, so its
186+
// length of 2 is also its display width in a terminal.
187+
const row = (text: string) => `│ ${text.padEnd(border.length - 2)} │`;
188+
const headerRows = headerTexts.map((text, i) =>
189+
i === 0 ? row(text).replace(label, colour(label)) : row(text),
190+
);
191+
const rows = texts.map(row);
186192

187193
return `
188194
┌${border}┐

0 commit comments

Comments
 (0)