Skip to content

Soul-driven AI agent with permission-hardened tools, token budgets, and multi-channel access. Runs 24/7 from CLI, Telegram or More.

fix(ui): attach TUI input box collapsed to content width

Salman Qureshib52dd67a04bc
diff --git a/src/ui/App.tsx b/src/ui/App.tsx
index 238a59a2..7390a6eb 100644
--- a/src/ui/App.tsx
+++ b/src/ui/App.tsx
@@ -9,6 +9,7 @@ import { renderMarkdown } from '../utils/markdown.js';
import { isDevBuild } from '../utils/dev-build.js';
import { highlightCodeBlock } from '../utils/highlight.js';
import { normalizeTerminalText, getViewportWindow } from './terminal-viewport.js';
+import { useTerminalSize as useSharedTerminalSize } from './use-terminal-size.js';
import { buildMercuryMessageLines, buildMercuryBrandLines, buildStreamTailLines, parseChunkIndex, splitFinalMessage, splitStreamingMessage, type MercuryTranscriptLine } from './mercury-transcript.js';
import { GENERIC_PHASES, PLANNING_VERBS, lastUserText, pickStatusWord } from './status-word.js';
import { nextTip, rotateTip } from './tips.js';
@@ -1342,23 +1343,7 @@ function CodingBody({ state, maxDynamicLines }: { state: TuiState; maxDynamicLin
// ─── Workspace IDE ──────────────────────────────────────────────────────────
function useTerminalSize(): { rows: number; cols: number } {
- const { stdout } = useStdout();
- const [size, setSize] = React.useState({ rows: stdout.rows || 24, cols: stdout.columns || 80 });
- React.useEffect(() => {
- const onResize = () => {
- const rows = stdout.rows || 24;
- const cols = stdout.columns || 80;
- setSize((current) => current.rows === rows && current.cols === cols ? current : { rows, cols });
- };
- stdout.on('resize', onResize);
- const fallback = setInterval(onResize, 500);
- fallback.unref?.();
- return () => {
- stdout.off('resize', onResize);
- clearInterval(fallback);
- };
- }, [stdout]);
- return size;
+ return useSharedTerminalSize();
}
function WorkspaceTabBar({ ws, focusArea, cols }: { ws: WorkspaceState; focusArea: string; cols: number }) {
diff --git a/src/ui/attach-tui.tsx b/src/ui/attach-tui.tsx
index 1bb31c41..9f86ed4b 100644
--- a/src/ui/attach-tui.tsx
+++ b/src/ui/attach-tui.tsx
@@ -2,6 +2,7 @@ import React from 'react';
import { Box, Text, Spacer, Static, useApp, useInput } from 'ink';
import type { AttachClient, AttachEvent, AttachThread, AttachThreadMessage } from '../cli/attach.js';
import { renderMarkdown } from '../utils/markdown.js';
+import { useTerminalSize } from './use-terminal-size.js';
/**
* Attach TUI — the terminal face of `mercury attach`. Native scrollback
@@ -108,6 +109,10 @@ export function AttachTui({ client, pid, onExit }: { client: AttachClient; pid:
const [input, setInput] = React.useState('');
const [cursorPos, setCursorPos] = React.useState(0);
+ // Same input width as the main TUI's chat/Code input (App.tsx).
+ const terminalSize = useTerminalSize();
+ const inputWidth = Math.max(40, terminalSize.cols - 4);
+
React.useEffect(() => {
client.listThreads()
.then((list) => { setThreads(list.slice(0, 6)); setThreadsLoaded(true); })
@@ -406,7 +411,11 @@ export function AttachTui({ client, pid, onExit }: { client: AttachClient; pid:
</Box>
)}
<Box paddingX={2} flexShrink={0}>
- <Box borderStyle="round" borderColor="gray" flexDirection="column" paddingX={1}>
+ {/* Explicit width, mirroring the main TUI's input: this box used to
+ rely on Yoga cross-stretch, but its wrapper is direction='row'
+ (ink's Box default), where stretch never applies — so the input
+ rendered at content width (~5 cols) on every machine. */}
+ <Box borderStyle="round" borderColor="gray" flexDirection="column" paddingX={1} width={inputWidth}>
<Box>
<Text bold color="cyan">&gt; </Text>
<Text>{input.slice(0, cursorPos)}</Text>
diff --git a/src/ui/use-terminal-size.ts b/src/ui/use-terminal-size.ts
new file mode 100644
index 00000000..18659c2a
--- /dev/null
+++ b/src/ui/use-terminal-size.ts
@@ -0,0 +1,28 @@
+import React from 'react';
+import { useStdout } from 'ink';
+
+/**
+ * Live terminal size. Listens to stdout resize and polls as a fallback — some
+ * terminal/pty setups (remote-desktop sessions, multiplexers) don't deliver
+ * the resize event when the window changes, and a stale size breaks any
+ * explicit-width layout.
+ */
+export function useTerminalSize(): { rows: number; cols: number } {
+ const { stdout } = useStdout();
+ const [size, setSize] = React.useState({ rows: stdout.rows || 24, cols: stdout.columns || 80 });
+ React.useEffect(() => {
+ const onResize = () => {
+ const rows = stdout.rows || 24;
+ const cols = stdout.columns || 80;
+ setSize((current) => current.rows === rows && current.cols === cols ? current : { rows, cols });
+ };
+ stdout.on('resize', onResize);
+ const fallback = setInterval(onResize, 500);
+ fallback.unref?.();
+ return () => {
+ stdout.off('resize', onResize);
+ clearInterval(fallback);
+ };
+ }, [stdout]);
+ return size;
+}
\ No newline at end of file