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
29 changes: 15 additions & 14 deletions packages/cli/src/ui/views/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import type {
} from "@vegamo/deepcode-core";
import { SessionManager } from "@vegamo/deepcode-core";
import { getCompactPromptTokenThreshold } from "@vegamo/deepcode-core";
import { writeStdout, writeStdoutLine } from "../../utils/stdio-helpers";

type View = "chat" | "session-list" | "undo" | "mcp-status";

Expand Down Expand Up @@ -145,8 +146,8 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
onAssistantMessage: (message: SessionMessage) => {
setMessages((prev) => [...prev, message]);
if (rawModeRef.current === RawMode.Raw) {
process.stdout.write("\n");
process.stdout.write(renderMessageToStdout(message, rawModeRef.current) + "\n\n");
writeStdoutLine("\n");
writeStdoutLine(renderMessageToStdout(message, rawModeRef.current) + "\n\n");
}
},
onSessionEntryUpdated: (entry) => {
Expand Down Expand Up @@ -196,7 +197,7 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
const resetStaticView = useCallback(
(loadedMessages: SessionMessage[], options?: { clearScreen?: boolean }): Promise<void> => {
if (options?.clearScreen) {
process.stdout.write(ANSI_CLEAR_SCREEN);
writeStdout(ANSI_CLEAR_SCREEN);
}
setMessages([]);
setWelcomeNonce((n) => n + 1);
Expand Down Expand Up @@ -298,19 +299,19 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
const session = activeSessionId ? sessionManager.getSession(activeSessionId) : null;
const resumeHint = buildResumeHintText(activeSessionId ?? undefined);

process.stdout.write("\n");
writeStdoutLine("\n");
if (showCommand) {
process.stdout.write(chalk.rgb(34, 154, 195)("> /exit "));
process.stdout.write("\n\n");
writeStdoutLine(chalk.rgb(34, 154, 195)(" > /exit "));
writeStdoutLine("\n");
}
if (showSummary) {
const summary = buildExitSummaryText({ session, sessionId: activeSessionId ?? undefined });
process.stdout.write(summary);
process.stdout.write("\n\n");
writeStdoutLine(summary);
writeStdoutLine("\n");
}
if (resumeHint) {
process.stdout.write(resumeHint);
process.stdout.write("\n");
writeStdoutLine(resumeHint);
writeStdoutLine("\n");
}

sessionManager.dispose();
Expand Down Expand Up @@ -628,7 +629,7 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
setShowWelcome(false);
setMessages([]);
// Clear screen to remove stale formatted text.
process.stdout.write(ANSI_CLEAR_SCREEN);
writeStdout(ANSI_CLEAR_SCREEN);

setTimeout(() => {
if (nextMode === RawMode.Raw) {
Expand Down Expand Up @@ -666,8 +667,8 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp

if (mode === RawMode.Raw) {
// In raw mode, re-render all messages directly to stdout at the new width.
// Use process.stdout.write instead of writeRef to avoid Ink interference.
process.stdout.write(ANSI_CLEAR_SCREEN);
// Use direct stdout instead of writeRef to avoid Ink interference.
writeStdout(ANSI_CLEAR_SCREEN);
const activeSessionId = sessionManager.getActiveSessionId();
const allMessages = activeSessionId ? loadVisibleMessages(sessionManager, activeSessionId) : [];
renderRawModeMessages(allMessages, mode);
Expand Down Expand Up @@ -898,7 +899,7 @@ function App({ projectRoot, initialPrompt, resumeSessionId, onRestart }: AppProp
);
}}
</Static>
{busy || statusLine ? <StatusLine busy={busy} text={statusLine} /> : null}
{(busy || statusLine) && !isExiting ? <StatusLine busy={busy} text={statusLine} /> : null}
{errorLine ? (
<Box>
<Text color="red">Error: {errorLine}</Text>
Expand Down
8 changes: 8 additions & 0 deletions packages/cli/src/utils/stdio-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/**
* Writes a message to stdout exactly as provided.
* Use for terminal control sequences or output that manages its own spacing.
*/
export const writeStdout = (message: string): void => {
process.stdout.write(message);
};

/**
* Writes a message to stdout with a trailing newline.
* Use for normal command output that the user expects to see.
Expand Down
Loading