Skip to content

Commit d6fd666

Browse files
cliffhallclaude
andcommitted
fix(sequentialthinking): pad the thought box's header row to the border
The header row was drawn unpadded, so it sat 2 columns short of the border rows. Pad it to the border's width, measured on the visible text, as the thought row already is. Closes #5108 Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent d7f76a6 commit d6fd666

3 files changed

Lines changed: 26 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/server-sequential-thinking": patch
3+
---
4+
5+
Pad the header row of the thought box logged to stderr to the border's width, so its right edge lines up with the rest of the box (#5108).

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe("sequentialthinking thought logging", () => {
4646
const border = "─".repeat(Math.max(header.length, text.length) + 4);
4747
return `
4848
┌${border}┐
49-
│ ${header} │
49+
│ ${header.padEnd(border.length - 2)} │
5050
├${border}┤
5151
│ ${text.padEnd(border.length - 2)} │
5252
└${border}┘`;
@@ -165,6 +165,19 @@ describe("sequentialthinking thought logging", () => {
165165
});
166166
});
167167

168+
// #5108: the header row is padded to the border's width, so every row of
169+
// the box is the same width, whether the header or the thought is longer.
170+
it.each([
171+
["the header", "t"],
172+
["the thought", "a much longer thought than the header line is"],
173+
])("draws every row the same width when %s is longer", async (_l, text) => {
174+
conn = await connect({ disableThoughtLogging: undefined });
175+
await conn.think(thought({ thought: text }));
176+
const rows = logged()[0].split("\n").slice(1);
177+
expect(rows).toHaveLength(5);
178+
expect(new Set(rows.map((row) => row.length)).size).toBe(1);
179+
});
180+
168181
// #5000: when colour is on, the header carries chalk's escape codes, but the
169182
// border is sized from the visible text, so the box matches the uncoloured one.
170183
it("sizes the border from the visible header, not its escape codes", async () => {

‎src/sequentialthinking/lib.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ export class SequentialThinkingServer {
3636
} = thoughtData;
3737

3838
// The label is coloured only after the header is measured, so the border
39-
// is sized from the visible text, not from chalk's escape codes. A missing
39+
// and the header's padding are sized from the visible text, not from
40+
// chalk's escape codes. A missing
4041
// revisesThought or branchId is left out of the header rather than printed
4142
// as "undefined".
4243
let label: string;
@@ -63,10 +64,14 @@ export class SequentialThinkingServer {
6364

6465
const counts = ` ${thoughtNumber}/${totalThoughts}${context}`;
6566
const visibleHeader = `${label}${counts}`;
66-
const header = `${colour(label)}${counts}`;
6767
const border = "─".repeat(
6868
Math.max(visibleHeader.length, thought.length) + 4,
6969
);
70+
// The header row is padded to the border's width like the thought row, by
71+
// the visible text's length. Each label's emoji is one surrogate pair, so
72+
// its length of 2 is also its display width in a terminal.
73+
const padding = " ".repeat(border.length - 2 - visibleHeader.length);
74+
const header = `${colour(label)}${counts}${padding}`;
7075

7176
return `
7277
┌${border}┐

0 commit comments

Comments
 (0)