Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 5 additions & 3 deletions docs/design/2026-09-03-opentui-batch8-submit-exit-parity.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,15 @@ mismatch.
### U-26 — steered text has no transcript echo

ink's `accept()` adds a `USER` item with `sentToModel: false` when the steered message
lands; OpenTUI's queue shows a count and the drained text disappears. Registered as U-26
rather than silently widening this diff.
lands; OpenTUI's queue shows a count and the drained text disappears. Corrected: this note
first minted a fresh number, U-26, which was retired the same day — the ledger's U-12 row
carries the gap from both fix sites, and U-12 is fixed in Batch 9.

### U-27 — no unsupported-image-format warning on either hop

ink calls `checkImageFormatsSupport` after building the request parts on both the fresh hop
and the steering hop, and adds an INFO row naming the formats the model cannot read. OpenTUI
and the steering hop, and adds an INFO row listing the formats the pipeline supports (ink's
warning text names the supported set, not the offending format). OpenTUI
has no equivalent on either hop, so a `@file` that expands to, say, a TIFF reaches the model
with no disclosure. Registered as U-27 — porting it belongs to one change across both hops,
not to the steering hop only.
Expand Down
402 changes: 402 additions & 0 deletions docs/design/2026-09-03-opentui-batch9-transcript-visibility.md

Large diffs are not rendered by default.

134 changes: 134 additions & 0 deletions integration-tests/interactive/command-output-visibility.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/**
* @license
* Copyright 2026 Qwen Team
* SPDX-License-Identifier: Apache-2.0
*/

import { afterEach, beforeEach, describe, expect, it } from 'vitest';
Comment thread
chiga0 marked this conversation as resolved.
Resolved
import {
startFakeOpenAIServer,
type FakeOpenAIServer,
} from '../fake-openai-server.js';
import {
applyContainerSandboxNoProxy,
fakeServerHostOptions,
TestRig,
} from '../test-helper.js';
import { InteractiveSession } from './interactive-session.js';

/**
* A field label only `/about` renders, and one both renderers spell the same:
* they read the same field table, ink lays the label out in its own column and
* the OpenTUI transcript row prefixes the value with it.
*/
const ABOUT_FIELD = 'Memory Usage';

/** What ink prints when `/about` reaches it before its registry has loaded. */
const ABOUT_UNKNOWN = 'Unknown command: /about';

/**
* Re-send `/about` until its row reaches the screen.
*
* ink loads the slash-command registry asynchronously and gates nothing on it
* (slashCommandProcessor.ts:759), so a command typed the moment the prompt
* appears can land on an empty registry and print `ABOUT_UNKNOWN`. OpenTUI
* reloads the registry and re-parses whenever nothing matched
* (commands-dispatch.ts:471), so the same send renders the row there — and the
* ink leg loses the race on every attempt once a parallel spec file is booting
* a second CLI. The retry keeps this a test of the transcript row rather than
* of ink's boot ordering.
*
* Bounded, so a row that never renders still fails: a projection regression
* produces neither string, `waitForScreen` throws, and the throw leaves the
* loop instead of spinning it.
*/
async function sendAboutUntilRendered(
session: InteractiveSession,
): Promise<void> {
const deadline = Date.now() + 90_000;
for (;;) {
await session.send('/about');
const screen = await session.waitForScreen(
(s) => s.includes(ABOUT_FIELD) || s.includes(ABOUT_UNKNOWN),
`neither the /about row ("${ABOUT_FIELD}") nor "${ABOUT_UNKNOWN}" reached the screen`,
20_000,
);
if (screen.includes(ABOUT_FIELD)) return;
if (Date.now() >= deadline) {
throw new Error(
`the /about transcript row ("${ABOUT_FIELD}") never reached the screen: ` +
`ink still reported "${ABOUT_UNKNOWN}" at the end of the retry window.\n` +
`Screen (last 600):\n${screen.slice(-600)}`,
);
}
}
}

describe('Command output visibility', () => {
let rig: TestRig;
let server: FakeOpenAIServer | undefined;
let session: InteractiveSession | undefined;
let restoreNoProxy: () => void;

beforeEach(() => {
rig = new TestRig();
restoreNoProxy = applyContainerSandboxNoProxy();
});

afterEach(async () => {
await session?.close();
session = undefined;
await server?.close();
server = undefined;
restoreNoProxy();
await rig.cleanup();
});

it('puts a slash command transcript row on screen', async () => {
await rig.setup('command-output-visibility', {
settings: {
memory: {
enableManagedAutoMemory: false,
enableManagedAutoDream: false,
},
ui: {
enableFollowupSuggestions: false,
},
security: {
auth: {
selectedType: 'openai',
},
},
},
});
server = await startFakeOpenAIServer(
() => ({ content: 'VISIBILITY_UNEXPECTED_REQUEST' }),
fakeServerHostOptions(),
);
session = await InteractiveSession.start({
cwd: rig.testDir!,
// The readiness string and the field label below are English UI strings,
// and the session spawns from `process.env` with no per-run override.
env: { QWEN_CODE_LANG: 'en' },
args: [
'--auth-type',
'openai',
'--openai-api-key',
'fake-key',
'--openai-base-url',
server.baseUrl,
'--model',
'fake-model',
],
});

// Differential half: without it the wait below could be satisfied by boot
// output and would prove nothing about the command.
expect(await session.screen()).not.toContain(ABOUT_FIELD);

await sendAboutUntilRendered(session);

// The row came from the command, not from a model turn echoing it.
expect(server.requests).toHaveLength(0);
});
});
16 changes: 16 additions & 0 deletions packages/cli/src/ui/opentui/commands-context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ vi.mock('../../utils/stdioHelpers.js', async (importOriginal) => {
function createFakeHost(): OpenTuiCommandHost & {
calls: string[];
sessionNames: Array<string | null>;
newSessionIds: string[];
} {
const calls: string[] = [];
const sessionNames: Array<string | null> = [];
Expand All @@ -41,6 +42,7 @@ function createFakeHost(): OpenTuiCommandHost & {
return {
calls,
sessionNames,
newSessionIds: [] as string[],
getHistory: () => [{ id: 1, type: 'info', text: 'existing' }] as never,
addItem: record('addItem') as never,
updateItem: record('updateItem') as never,
Expand Down Expand Up @@ -85,6 +87,11 @@ function createFakeHost(): OpenTuiCommandHost & {
presentActionConfirmation: async () => false,
handleResume: record('handleResume') as never,
handleBranch: record('handleBranch') as never,
// Shorthand, not an arrow: the real host's method reads `this.deps`, so a
// reference detached from the host must fail here too.
startNewSession(sessionId: string) {
this.newSessionIds.push(sessionId);
},
};
}

Expand Down Expand Up @@ -114,6 +121,15 @@ describe('createOpenTuiCommandContext (ink commandContext parity)', () => {
expect(host.sessionNames).toEqual([null]);
});

it('keeps the host receiver on session.startNewSession', () => {
const host = createFakeHost();
const context = createOpenTuiCommandContext(host, services);
// `/clear` calls this before `ui.clear()`; a reference detached from the
// host threw here and left the transcript standing.
context.session.startNewSession?.('sess-9');
expect(host.newSessionIds).toEqual(['sess-9']);
});

it('exposes a live history getter backed by the host', () => {
const host = createFakeHost();
const context = createOpenTuiCommandContext(host, services);
Expand Down
5 changes: 4 additions & 1 deletion packages/cli/src/ui/opentui/commands-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ export function createOpenTuiCommandContext(
session: {
stats: host.sessionStats,
sessionShellAllowlist: host.sessionShellAllowlist,
startNewSession: host.startNewSession,
// Bound: the host's method reads `this.deps`, and `/clear` calls this
// before `ui.clear()` — a bare reference threw and left the transcript
// standing.
startNewSession: host.startNewSession?.bind(host),
},
};
}
37 changes: 29 additions & 8 deletions packages/cli/src/ui/opentui/event-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ export interface EventMapperContext {
showCitations?: () => boolean;
}

/**
* Shared with the item projector (item-projection.ts) so the stream mapper
* and the host-history projection render one identical row shape.
*/
export function formatStopHookLoopText(
stopHookCount: number,
reasons: string[],
): string {
return (
`Ran ${stopHookCount} stop hooks\n` +
` ⎿ Stop hook error: ${reasons[reasons.length - 1] ?? ''}`
);
}

/** Shared with the item projector — ink redacts the echoed prompt. */
export function formatUserPromptSubmitBlocked(
reason: string,
originalPrompt: string,
): string {
return (
`✕ UserPromptSubmit operation blocked by hook:\n${reason}\n\n` +
`Original prompt: ${sanitizeSensitiveText(originalPrompt)}`
);
}

/** One-line compact JSON for tool-call args (empty object → undefined). */
export function formatToolArgs(
args: Record<string, unknown> | undefined,
Expand Down Expand Up @@ -655,11 +680,9 @@ export function createEventMapper(
const v = ev.value as { reason: string; originalPrompt: string };
out.push({
type: 'warning',
text:
`✕ UserPromptSubmit operation blocked by hook:\n${v.reason}\n\n` +
// ink redacts the echoed prompt (HistoryItemDisplay): sensitive
// patterns masked and the text capped at 200 chars.
`Original prompt: ${sanitizeSensitiveText(v.originalPrompt)}`,
// ink redacts the echoed prompt (HistoryItemDisplay): sensitive
// patterns masked and the text capped at 200 chars.
text: formatUserPromptSubmitBlocked(v.reason, v.originalPrompt),
});
break;
}
Expand All @@ -672,9 +695,7 @@ export function createEventMapper(
};
out.push({
type: 'info',
text:
`Ran ${v.stopHookCount} stop hooks\n` +
` ⎿ Stop hook error: ${v.reasons[v.reasons.length - 1] ?? ''}`,
text: formatStopHookLoopText(v.stopHookCount, v.reasons),
});
break;
}
Expand Down
Loading
Loading