Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/cli/src/__tests__/pi-transcript.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ describe('Maka Pi TUI transcript', () => {
assert.match(chinese, /\/session\s+切换或恢复会话/);
});

test('keeps every pending-queue preview on exactly one terminal row (#3824)', () => {
const state = createMakaPiTranscriptState();
// limitText appends its truncation suffix behind a newline once the 200-char
// cap trips; an embedded newline shifts every later row down while pi-tui
// still counts one row written, corrupting the frame until the queue drains.
state.steering = ['s'.repeat(250)];
state.followup = ['f'.repeat(250)];

const lines = renderMakaPiPendingQueue(state, 400);
for (const line of lines) {
assert.doesNotMatch(line, /[\r\n]/, `pending-queue row must be a single row: ${line}`);
}
// The truncation notice still reaches the user, just on the same row.
assert.match(stripAnsi(lines[0] ?? ''), /50 chars truncated/);
});

test('renders the pending-queue edit shortcut for the current platform', () => {
const state = createMakaPiTranscriptState();
state.steering = ['Keep going'];
Expand Down
15 changes: 13 additions & 2 deletions packages/cli/src/pi-transcript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import type { MakaSessionDriver } from './session-driver.js';
import { BoundedChunkBuffer } from './bounded-chunk-buffer.js';
import { ansi } from './tui-ansi.js';
import {
collapseToSingleLine,
fitLine,
formatTokenCount,
formatUnknown,
Expand Down Expand Up @@ -1502,14 +1503,24 @@ export function renderMakaPiPendingQueue(
return lines;
}

/** First non-empty line of a queued message, trimmed for a one-line preview. */
/**
* First non-empty line of a queued message, trimmed for a one-line preview.
*
* `limitText` appends its truncation suffix behind a newline, so its output is
* multi-line whenever the cap trips. Each element the pending-bar returns must
* occupy exactly one terminal row — pi-tui writes them between explicit \r\n
* separators and counts one row each, so an embedded newline shifts every
* later row down while the diff accounting still believes one row was written
* (#3824). `fitLine` cannot catch it: visibleWidth treats controls as
* zero-width. Sibling call sites collapse the same output the same way.
*/
function firstLinePreview(text: string): string {
const line =
text
.split('\n')
.map((part) => part.trim())
.find((part) => part.length > 0) ?? '';
return limitText(line, 200);
return collapseToSingleLine(limitText(line, 200));
}

/**
Expand Down