Skip to content

Commit 38d49ef

Browse files
committed
refactor: remove printMode in favor of Ink-only streaming
Print Mode (direct stdout.write) conflicts with Ink's terminal control and provides no real benefit over Ink Mode's real-time Markdown rendering. A proper non-interactive mode (like Claude Code's -p flag) would bypass Ink entirely rather than mixing stdout.write within the React tree. Removed: printMode prop, stdout.write branches, printMode state.
1 parent 21b634a commit 38d49ef

2 files changed

Lines changed: 5 additions & 21 deletions

File tree

src/cli/tui/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export function App({
3030
commands: SlashCommand[];
3131
supportProjectWideAllow?: boolean;
3232
}) {
33-
const { streaming, messages, streamingText, printMode, onSubmit, abort } = useAgentLoop();
33+
const { streaming, messages, streamingText, onSubmit, abort } = useAgentLoop();
3434
const { approvalRequest, respondToApproval } = useApprovalManager();
3535
const { askUserQuestionRequest, respondWithAnswers } = useAskUserQuestionManager();
3636
const { latestTodos, todoSnapshots } = useMemo(() => buildTodoViewState(messages), [messages]);
@@ -47,7 +47,7 @@ export function App({
4747
useFlushToScrollback(messages, flushedRef, write);
4848

4949
// Show streaming text in Ink mode (not print mode)
50-
const showStreamingText = streaming && streamingText && !printMode;
50+
const showStreamingText = streaming && !!streamingText;
5151
// Only show the shimmer indicator when there is no streaming text to display
5252
const showShimmer = streaming && !streamingText && !approvalRequest && !askUserQuestionRequest;
5353

src/cli/tui/hooks/use-agent-loop.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ type AgentLoopState = {
1212
streaming: boolean;
1313
messages: NonSystemMessage[];
1414
streamingText: string;
15-
printMode: boolean;
1615
// eslint-disable-next-line no-unused-vars
1716
onSubmit: (submission: PromptSubmission) => Promise<void>;
1817
abort: () => void;
@@ -24,12 +23,10 @@ const AgentLoopContext = createContext<AgentLoopState | null>(null);
2423
export function AgentLoopProvider({
2524
agent,
2625
commands = [],
27-
printMode = false,
2826
children,
2927
}: {
3028
agent: Agent;
3129
commands?: SlashCommand[];
32-
printMode?: boolean;
3330
children: ReactNode;
3431
}) {
3532
const [streaming, setStreaming] = useState(false);
@@ -135,23 +132,11 @@ export function AgentLoopProvider({
135132
setStreamingText("");
136133
enqueueMessage(event.message);
137134
} else if (event.type === "progress" && event.subtype === "thinking") {
138-
if (printMode) {
139-
// Print Mode: write delta directly to stdout for instant output
140-
if (event.delta) {
141-
process.stdout.write(event.delta);
142-
}
143-
} else {
144-
// Ink Mode: update React state for re-rendering
145-
setStreamingText(event.text);
146-
}
135+
setStreamingText(event.text);
147136
}
148137
// tool progress events are handled by StreamingIndicator
149138
}
150139

151-
if (printMode) {
152-
// Ensure a newline after print-mode streaming completes
153-
process.stdout.write("\n");
154-
}
155140
} catch (error) {
156141
if (isAbortError(error)) return;
157142
throw error;
@@ -162,7 +147,7 @@ export function AgentLoopProvider({
162147
setStreaming(false);
163148
}
164149
},
165-
[agent, commands, enqueueMessage, flushPendingMessages, printMode],
150+
[agent, commands, enqueueMessage, flushPendingMessages],
166151
);
167152

168153
const value = useMemo(
@@ -171,12 +156,11 @@ export function AgentLoopProvider({
171156
streaming,
172157
messages,
173158
streamingText,
174-
printMode,
175159
onSubmit,
176160
abort,
177161
tokenCount,
178162
}),
179-
[abort, agent, messages, onSubmit, streaming, streamingText, printMode, tokenCount],
163+
[abort, agent, messages, onSubmit, streaming, streamingText, tokenCount],
180164
);
181165

182166
return createElement(AgentLoopContext.Provider, { value }, children);

0 commit comments

Comments
 (0)