Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/sanitize-task-output.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@moonshot-ai/kimi-code": patch
---

Prevent background task output from disrupting terminal pane borders.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import type { BackgroundTaskInfo, BackgroundTaskStatus } from '@moonshot-ai/kimi

import { currentTheme } from '#/tui/theme';
import { printableChar } from '@/tui/utils/printable-key';
import { sanitizeShellOutput } from '#/tui/utils/shell-output';

const ELLIPSIS = '…';

Expand Down Expand Up @@ -104,7 +105,7 @@ export class TaskOutputViewer extends Container implements Focusable {
}

private splitOutput(output: string): string[] {
return (output.length > 0 ? output : '[no output captured]').split('\n');
return (output.length > 0 ? sanitizeShellOutput(output) : '[no output captured]').split('\n');
}

// ── input ──────────────────────────────────────────────────────────
Expand Down
3 changes: 2 additions & 1 deletion apps/kimi-code/src/tui/components/dialogs/tasks-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import type { BackgroundTaskInfo, BackgroundTaskStatus } from '@moonshot-ai/kimi
import { SELECT_POINTER } from '@/tui/constant/symbols';
import { currentTheme } from '#/tui/theme';
import { printableChar } from '@/tui/utils/printable-key';
import { sanitizeShellOutput } from '#/tui/utils/shell-output';

const ELLIPSIS = '…';

Expand Down Expand Up @@ -603,7 +604,7 @@ export class TasksBrowserApp extends Container implements Focusable {
if (this.props.tailLoading) body = '[loading…]';
else if (this.props.tailOutput === undefined || this.props.tailOutput.length === 0)
body = '[no output captured]';
else body = this.props.tailOutput;
else body = sanitizeShellOutput(this.props.tailOutput);

const rawLines = body.split('\n');
const tailLines = rawLines.slice(-innerHeight);
Expand Down
11 changes: 11 additions & 0 deletions apps/kimi-code/test/tui/task-output-viewer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,17 @@ describe('TaskOutputViewer — rendering', () => {
expect(out).toContain('delta');
expect(out).toContain('echo');
});

it('does not pass terminal controls from task output into the framed body', () => {
const rendered = makeViewer({
output: 'Downloading wheel 25%\rDownloading wheel 75%\u001B[2Jdone',
}).render(120);
const raw = rendered.join('\n');

expect(raw).not.toContain('\r');
expect(raw).not.toContain('\u001B[2J');
expect(strip(raw)).toContain('Downloading wheel 25%Downloading wheel 75%done');
});
});

describe('TaskOutputViewer — scrolling', () => {
Expand Down
13 changes: 13 additions & 0 deletions apps/kimi-code/test/tui/tasks-browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ describe('TasksBrowserApp — full-screen rendering', () => {
expect(out).toContain('listening on :3000');
});

it('does not pass terminal controls from tail output into the framed preview', () => {
const rendered = makeApp({
tasks: [task({ taskId: 'bash-aaaaaaaa' })],
selectedTaskId: 'bash-aaaaaaaa',
tailOutput: 'Downloading wheel 25%\rDownloading wheel 75%\u001B[2Jdone',
}).render(120);
const raw = rendered.join('\n');

expect(raw).not.toContain('\r');
expect(raw).not.toContain('\u001B[2J');
expect(strip(raw)).toContain('Downloading wheel 25%Downloading wheel 75%done');
});

it('shows a loading state when tail is loading', () => {
const out = strip(
makeApp({
Expand Down
Loading