Skip to content

Commit 3ad5797

Browse files
committed
fix(tui): eliminate command flash during exec mode transitions
The !! command and prompt would briefly vanish (replaced by >) when executing a container command, because setMode('chat') fired in a separate render batch from setConversation/setIsStreaming. Fix: add onStart callback to runSpawnCommand that fires in the same synchronous block as the conversation/streaming state updates, so React batches them together. The mode transition and conversation update now render atomically — no flash.
1 parent dd10764 commit 3ad5797

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/cli/tui/hooks/useDevServer.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,13 @@ export function useDevServer(options: {
394394
spawnOpts: { cwd?: string; env?: NodeJS.ProcessEnv },
395395
label: string,
396396
prefix: string,
397-
command: string
397+
command: string,
398+
onStart?: () => void
398399
) => {
399400
setConversation(prev => [...prev, { role: 'user', content: `${prefix} ${command}`, isExec: true }]);
400401
setStreamingResponse(null);
401402
setIsStreaming(true);
403+
onStart?.();
402404

403405
let output = '';
404406

@@ -440,18 +442,19 @@ export function useDevServer(options: {
440442
}
441443
};
442444

443-
const execCommand = async (command: string) => {
445+
const execCommand = async (command: string, onStart?: () => void) => {
444446
await runSpawnCommand(
445447
'bash',
446448
['-c', command],
447449
{ cwd: options.workingDir, env: { ...process.env, ...envVars } },
448450
'exec',
449451
'!',
450-
command
452+
command,
453+
onStart
451454
);
452455
};
453456

454-
const execInContainer = async (command: string) => {
457+
const execInContainer = async (command: string, onStart?: () => void) => {
455458
const containerName = `agentcore-dev-${config?.agentName ?? ''}`.toLowerCase();
456459
const detection = await detectContainerRuntime();
457460
if (!detection.runtime) {
@@ -472,7 +475,8 @@ export function useDevServer(options: {
472475
{},
473476
'container exec',
474477
'!!',
475-
command
478+
command,
479+
onStart
476480
);
477481
};
478482

src/cli/tui/screens/dev/DevScreen.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,15 @@ export function DevScreen(props: DevScreenProps) {
320320
};
321321

322322
const handleExec = async (command: string) => {
323-
setMode('chat');
324323
setUserScrolled(false);
325-
await execCommand(command);
324+
await execCommand(command, () => setMode('chat'));
326325
setExecInputEmpty(true);
327326
setMode('input');
328327
};
329328

330329
const handleContainerExec = async (command: string) => {
331-
setMode('chat');
332330
setUserScrolled(false);
333-
await execInContainer(command);
331+
await execInContainer(command, () => setMode('chat'));
334332
setExecInputEmpty(true);
335333
setMode('input');
336334
};

0 commit comments

Comments
 (0)