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
112 changes: 74 additions & 38 deletions packages/tui/src/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,29 @@ export function Prompt(props: PromptProps) {
)
const borderHighlight = createMemo(() => tint(theme.border, highlight(), agentMetaAlpha()))

// The prompt measures itself: the session sidebar and the home width cap both make it narrower than the terminal.
let boxEl: BoxRenderable | undefined
const [boxWidth, setBoxWidth] = createSignal(0)
const innerWidth = createMemo(() => Math.max(10, (boxWidth() > 0 ? boxWidth() : dimensions().width - 5) - 4))
const showProvider = createMemo(() => innerWidth() >= 60)
const tagsWidth = createMemo(() => {
let width = local.effort.current().length
if (showVariant()) width += 3 + (local.model.variant.current()?.length ?? 0)
if (showVision()) width += 3 + "vision".length
return width
})
// Room left for the model name on the footer row, with a gap before the tags.
const modelRoom = createMemo(() => {
const agentName = store.mode === "shell" ? "Shell".length : (local.agent.current()?.name.length ?? 0)
const provider = showProvider() ? currentProviderLabel().length + 1 : 0
return Math.max(4, innerWidth() - tagsWidth() - 2 - agentName - 3 - provider)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: modelRoom ignores the width of the right-hand slot

props.right (the session_prompt_right / home_prompt_right plugin slot) is rendered in the same right-hand box as the tags and is not accounted for here. When a plugin supplies right content, the left box shrinks and the model name is hard-clipped by overflow="hidden" with no ellipsis, which breaks the invariant this PR introduces. Subtract the right content's width as well.

})
const modelLabel = createMemo(() => Locale.truncate(local.model.parsed().model, modelRoom()))
// The placeholder shares its row with the YOLO tag.
const placeholderRoom = createMemo(() =>
innerWidth() - (store.mode === "normal" && local.permission.mode === "yolo" ? 8 : 0),
)

const placeholderText = createMemo(() => {
if (props.showPlaceholder === false) return undefined
if (store.mode === "shell") {
Expand All @@ -1374,6 +1397,10 @@ export function Prompt(props: PromptProps) {
if (!list().length) return undefined
return `Ask anything... "${list()[store.placeholder % list().length]}"`
})
const clippedPlaceholder = createMemo(() => {
const text = placeholderText()
return text ? Locale.truncate(text, placeholderRoom()) : undefined
})

const spinnerDef = createMemo(() => {
const agent =
Expand Down Expand Up @@ -1402,6 +1429,10 @@ export function Prompt(props: PromptProps) {
}}
>
<box
ref={(el: BoxRenderable) => {
boxEl = el
}}
onSizeChange={() => boxEl && setBoxWidth(boxEl.width)}
paddingLeft={2}
paddingRight={2}
paddingTop={1}
Expand All @@ -1410,9 +1441,16 @@ export function Prompt(props: PromptProps) {
flexGrow={1}
width="100%"
>
<Show when={store.mode === "normal" && local.permission.mode === "yolo"}>
<box position="absolute" top={1} right={2} paddingLeft={1} paddingRight={1} backgroundColor={theme.warning}>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: The YOLO badge overlays the editable first input row

The badge is absolutely positioned on the textarea's first row (the textarea is width="100%" of the same content box, and top={1} lands on the first content row). Only the placeholder is shortened to make room (placeholderRoom); typed text is not. The last ~6 columns of the first input line therefore sit under the badge, so the tail of what the user typed is hidden. If the textarea paints above the badge instead, the badge is covered by the textarea's own background (focusedBackgroundColor).

Reserve space for the badge inside the input row (e.g. reduce the textarea width or add right padding while the badge is visible) rather than overlaying the editable area.

<text fg={selectedForeground(theme, theme.warning)} attributes={TextAttributes.BOLD}>
YOLO
</text>
</box>
</Show>
<textarea
width="100%"
placeholder={placeholderText()}
placeholder={clippedPlaceholder()}
placeholderColor={theme.textMuted}
textColor={leader() ? theme.textMuted : theme.text}
focusedTextColor={leader() ? theme.textMuted : theme.text}
Expand Down Expand Up @@ -1486,7 +1524,7 @@ export function Prompt(props: PromptProps) {
syntaxStyle={syntax()}
/>
<box flexDirection="row" flexShrink={0} paddingTop={1} gap={1} justifyContent="space-between">
<box flexDirection="row" gap={1}>
<box flexDirection="row" gap={1} flexShrink={1} minWidth={0} height={1} overflow="hidden">
<Show when={local.agent.current()} fallback={<box height={1} />}>
{(agent) => (
<>
Expand All @@ -1500,50 +1538,48 @@ export function Prompt(props: PromptProps) {
flexShrink={0}
fg={fadeColor(leader() ? theme.textMuted : theme.text, modelMetaAlpha())}
>
{local.model.parsed().model}
</text>
<text fg={fadeColor(theme.textMuted, modelMetaAlpha())}>{currentProviderLabel()}</text>
{/* Agent effort is its own dial and shows even for
models without thinking variants. Its hue (fast
green, medium orange, thorough red) is drawn
beside the always-visible level name. */}
<text fg={fadeColor(theme.textMuted, modelMetaAlpha())}>·</text>
<text>
<span
style={{
fg: fadeColor(effortColor(local.effort.current(), theme), modelMetaAlpha()),
bold: true,
}}
>
{local.effort.current()}
</span>
{modelLabel()}
</text>
<Show when={showVariant()}>
<text fg={fadeColor(theme.textMuted, variantMetaAlpha())}>·</text>
<text>
<span style={{ fg: fadeColor(theme.warning, variantMetaAlpha()), bold: true }}>
{local.model.variant.current()}
</span>
</text>
</Show>
<Show when={showVision()}>
<text fg={fadeColor(theme.textMuted, visionMetaAlpha())}>·</text>
<text>
<span style={{ fg: fadeColor(theme.accent, visionMetaAlpha()), bold: true }}>vision</span>
</text>
<Show when={showProvider()}>
<text fg={fadeColor(theme.textMuted, modelMetaAlpha())}>{currentProviderLabel()}</text>
</Show>
</box>
</Show>
</>
)}
</Show>
</box>
<box flexDirection="row" gap={1} alignItems="center">
<Show when={store.mode === "normal" && local.permission.mode === "yolo"}>
<box paddingLeft={1} paddingRight={1} backgroundColor={theme.warning}>
<text fg={selectedForeground(theme, theme.warning)} attributes={TextAttributes.BOLD}>
YOLO
</text>
<box flexDirection="row" gap={1} alignItems="center" flexShrink={0}>
<Show when={store.mode === "normal"}>
<box flexDirection="row" gap={1} flexShrink={0}>
{/* Agent effort is its own dial and shows even for

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SUGGESTION: Moved block kept the old indentation, and one line exceeds the print width

The children of the new tags box are still indented as if they were in the previous nesting level, and the badge line (1433) is 122 characters — over the repo's prettier printWidth of 120. Running prettier on the file normalizes both.

models without thinking variants. Its hue (fast
green, medium orange, thorough red) is drawn
beside the always-visible level name. */}
<text>

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: The · separator that preceded the effort tag was dropped, breaking two existing tests

The effort label moved into the right-hand group without its leading separator, so the footer row now reads ... model provider medium · high · vision instead of ... model provider · medium · high · vision. Two existing assertions depend on the old separator and will fail:

  • packages/tui/test/prompt/vision-tag.test.tsx:436 — expect(highRow).toContain("· medium")
  • packages/tui/test/cli/tui/dialog-agent-effort.test.tsx:805 — expect(after).toContain("· fast")

Either keep a separator at the start of the new group, or update both tests in this PR.

<span
style={{
fg: fadeColor(effortColor(local.effort.current(), theme), modelMetaAlpha()),
bold: true,
}}
>
{local.effort.current()}
</span>
</text>
<Show when={showVariant()}>
<text fg={fadeColor(theme.textMuted, variantMetaAlpha())}>·</text>
<text>
<span style={{ fg: fadeColor(theme.warning, variantMetaAlpha()), bold: true }}>
{local.model.variant.current()}
</span>
</text>
</Show>
<Show when={showVision()}>
<text fg={fadeColor(theme.textMuted, visionMetaAlpha())}>·</text>
<text>
<span style={{ fg: fadeColor(theme.accent, visionMetaAlpha()), bold: true }}>vision</span>
</text>
</Show>
</box>
</Show>
<Show when={hasRightContent()}>{props.right}</Show>
Expand Down
2 changes: 1 addition & 1 deletion packages/tui/test/cli/tui/dialog-agent-effort.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ describe("agent effort selector", () => {
},
"effort label beside thinking",
)
expect(after).toContain("· fast")
expect(after).toContain("fast · high")
} finally {
await harness.dispose()
}
Expand Down
2 changes: 1 addition & 1 deletion packages/tui/test/prompt/vision-tag.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ describe("prompt vision tag", () => {
// the same meta row: effort and explicit HIGH thinking are both shown
// and stay distinct.
const highRow = frame.split("\n").find((line) => line.includes("VisionCapableModel")) ?? ""
expect(highRow).toContain("· medium")
expect(highRow).toContain("medium · high")
expect(highRow).toContain("· high")

// Set variant to "medium" on text-only model -> "medium" visible, "vision" absent
Expand Down
Loading