diff --git a/packages/app/src/composer/composer.stories.tsx b/packages/app/src/composer/composer.stories.tsx index 9de88cc01a4..b686ac317e7 100644 --- a/packages/app/src/composer/composer.stories.tsx +++ b/packages/app/src/composer/composer.stories.tsx @@ -1,11 +1,17 @@ import { Show, createMemo, onMount, type JSX } from "solid-js" import { createStore } from "solid-js/store" import type { ModelSelection } from "@/providers/models/selection" -import { STORY_MODEL, emptySessionDocument, pendingAndQueuedDocument } from "@opencode/session-ui/storybook" +import { + STORY_MODEL, + emptySessionDocument, + largeCompletedDocument, + pendingAndQueuedDocument, +} from "@opencode/session-ui/storybook" import { Composer } from "./composer" import type { ComposerModel } from "./model" import { createComposerEditor } from "./editor/interaction" import type { ComposerPersistedState, ComposerSuggestion } from "./types" +import { composerLayouts, type ComposerLayout } from "./editor/editor" import { buildPromptRequest } from "./request" import { promptLength } from "./prompt-parts" import { SessionPreview } from "@/session/story-model" @@ -61,6 +67,9 @@ function ComposerStory(props: { alternate?: "queue" | "steer" manySuggestions?: boolean suggestionBoundary?: () => HTMLElement | undefined + layout?: ComposerLayout + // Matches the composer in Kit's capture: Anthropic / Claude Opus 5.5 at the High variant. + opus?: boolean }) { const [draft, setDraft] = createStore({ prompt: props.prompt ?? [{ type: "text", content: "", start: 0, end: 0 }], @@ -71,12 +80,16 @@ function ComposerStory(props: { const [story, setStory] = createStore({ activity: props.label ?? "Ready", - variant: STORY_MODEL.variant, + variant: props.opus ? "high" : STORY_MODEL.variant, }) const modelOption = createMemo(() => ({ ...selectedModel, - name: props.longLabels ? "Claude Sonnet with an unusually long model name" : selectedModel.name, + name: props.longLabels + ? "Claude Sonnet with an unusually long model name" + : props.opus + ? "Claude Opus 5.5" + : selectedModel.name, })) const modelSelection = { @@ -152,14 +165,17 @@ function ComposerStory(props: { readImage: async () => pixel, view: { placeholder: () => "Ask anything, / for commands, @ for context...", - agent: { - options: () => [ - { id: "build", label: props.longLabels ? "Build agent with an unusually long name" : "build" }, - { id: "review", label: "review" }, - ], - current: () => "build", - onSelect: (agent) => setStory("activity", `Selected ${agent}`), - }, + // Kit's composer hides the agent picker (custom agents are off by default). + agent: props.opus + ? undefined + : { + options: () => [ + { id: "build", label: props.longLabels ? "Build agent with an unusually long name" : "build" }, + { id: "review", label: "review" }, + ], + current: () => "build", + onSelect: (agent) => setStory("activity", `Selected ${agent}`), + }, variant: { options: () => [ { id: "default", label: "default" }, @@ -221,7 +237,12 @@ function ComposerStory(props: { const model = { ...editor, - model: { selection: modelSelection, paid: true, loading: false }, + model: { + selection: modelSelection, + paid: true, + loading: false, + providerName: props.opus ? selectedModel.provider.name : undefined, + }, } satisfies ComposerModel onMount(() => { @@ -235,7 +256,7 @@ function ComposerStory(props: { {story.activity} - + ) } @@ -407,6 +428,84 @@ export const ToolbarOverflow = { ), } +const layoutScenarios = ["empty", "text", "long", "multiline", "attachments", "longName"] as const + +function LayoutStory(props: { layout: ComposerLayout; scenario: (typeof layoutScenarios)[number]; width: number }) { + const prompt = () => { + if (props.scenario === "text") return text("Explain this change") + + if (props.scenario === "long") + return text( + "Walk through the composer's padding rules and tell me which ones leave empty space between the text and the controls", + ) + + if (props.scenario === "multiline") return text("Review the implementation\nThen run the focused tests\nThen push") + + if (props.scenario === "attachments") + return [ + ...text("Match this layout"), + { + type: "image" as const, + id: "image-story", + filename: "layout.png", + mime: "image/png", + blob: { id: "image-story", url: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==" }, + }, + ] + + return undefined + } + + return ( +
+ + + +
+ ) +} + +export const Layouts = { + args: { layout: "today", scenario: "empty", width: 720 }, + argTypes: { + layout: { control: "select", options: composerLayouts }, + scenario: { control: "select", options: layoutScenarios }, + width: { control: { type: "range", min: 320, max: 960, step: 4 } }, + }, + render: (args: { layout: ComposerLayout; scenario: (typeof layoutScenarios)[number]; width: number }) => ( + + ), +} + +// The session surface Kit captured: a finished answer with seven subagents running above the composer. +export const LayoutInSession = { + args: { layout: "today" }, + argTypes: { layout: { control: "select", options: composerLayouts } }, + render: (args: { layout: ComposerLayout }) => ( + + {(layout) => ( + ({ + key: `ses_child_${index}`, + type: "subagent" as const, + label: `Detail pass ${index + 1}`, + agent: "general", + sessionID: `ses_child_${index}`, + target: `ses_child_${index}`, + })), + shells: [], + }} + /> + )} + + ), +} + export const DemoFirstClassSkillIDs = { name: "Demo: First-class skill IDs", render: () => ( diff --git a/packages/app/src/composer/composer.tsx b/packages/app/src/composer/composer.tsx index ec6b3d94dea..aa5f97a677b 100644 --- a/packages/app/src/composer/composer.tsx +++ b/packages/app/src/composer/composer.tsx @@ -7,7 +7,7 @@ import { Keybind } from "@opencode/ui/keybind" import { consoleModelGroup } from "@/providers/models/provider-group" import { consoleProviderName } from "@/providers/catalog/console" import { Tooltip } from "@opencode/ui/tooltip" -import { ComposerEditor } from "./editor/editor" +import { ComposerEditor, composerJoinedLayouts, type ComposerLayout } from "./editor/editor" import { DialogSelectModel, ModelSelectorDrawer } from "@/providers/models/select-dialog" import { ModelDetails } from "@/providers/models/details" import { DialogSelectModelUnpaid } from "@/providers/models/unpaid" @@ -21,6 +21,7 @@ export function Composer(props: { borderUnderlay?: boolean readOnly?: boolean suggestionBoundary?: () => HTMLElement | undefined + layout?: ComposerLayout }) { const dialog = useDialog() const command = useCommand() @@ -38,6 +39,16 @@ export function Composer(props: { return language.t("dialog.model.select.title") } + // Joined layouts show the variant inside the model chip; the model dialog changes it with ←/→. + const variantName = () => { + if (!composerJoinedLayouts.includes(props.layout ?? "today")) return + const control = props.model.view.variant + + if (!control || control.options().length < 2 || control.current() === "default") return + + return control.options().find((option) => option.id === control.current())?.label ?? control.current() + } + return (
dialog.show(() => )} /> @@ -77,6 +90,7 @@ function ComposerModelControl(props: { model: ComposerModel["model"]["selection"] providerName?: string modelName: string + variantName?: string onClose: () => void onUnpaidClick: () => void }) { @@ -98,13 +112,16 @@ function ComposerModelControl(props: { {(name) => ( - <> + {name()} {" / "} - + )} {props.modelName} + + {(variant) => {variant()}} + diff --git a/packages/app/src/composer/editor/editor.css b/packages/app/src/composer/editor/editor.css index 88d74d45fe3..8fc694b57c7 100644 --- a/packages/app/src/composer/editor/editor.css +++ b/packages/app/src/composer/editor/editor.css @@ -8,7 +8,7 @@ mask-image: linear-gradient( to bottom, transparent, - black 16px, + black var(--composer-fade-top, 16px), black calc(100% - var(--composer-fade-bottom, 0px)), transparent ); @@ -64,3 +64,104 @@ [data-color-scheme="dark"] [data-component="composer-suggestions"] [data-active] { background: var(--v2-alpha-light-10); } + +/* + * Composer layout exploration. "today" is the shipped geometry; every other layout drops the 60px editor and 96px + * form minimums, whose 16px of unrequested height sits between the text and the control row. + */ +[data-component="composer"]:not([data-layout="today"]) { + min-height: 0; + + [data-component="composer-scroll"], + [data-component="composer-editor"] { + min-height: 0; + } +} + +/* The model chip carries the variant, so it sits straight after the + button. */ +[data-component="composer"]:is([data-layout="joined"], [data-layout="slim"], [data-layout="inline"]) + [data-slot="composer-controls"] { + margin-inline-start: 0; +} + +/* Slim: one 12px text inset, 24px controls 8px from the edges, and the + glyph on the text's 12px spine. */ +[data-component="composer"][data-layout="slim"] { + --composer-fade-top: 12px; + + [data-component="composer-editor"], + [data-slot="composer-placeholder"] { + padding: 12px 12px 4px; + } + + [data-slot="composer-row"] { + height: 40px; + } + + [data-action="composer-attach"], + [data-action="composer-submit"] { + width: 24px; + height: 24px; + } + + [data-action="composer-submit"] { + padding: 4px; + } + + [data-action="composer-model"] { + height: 24px !important; + padding-inline: 8px; + } +} + +/* Inline: one 44px row at rest; it becomes the joined two-row layout once the draft wraps or holds context. */ +[data-component="composer"][data-layout="inline"] [data-slot="composer-model-provider"] { + display: none; +} + +[data-component="composer"][data-layout="inline"]:not([data-expanded]) { + --composer-fade-top: 12px; + display: grid; + grid-template-columns: auto minmax(160px, 1fr) minmax(0, max-content) auto; + grid-template-areas: "add editor controls actions"; + align-items: center; + + [data-component="composer-scroll"] { + grid-area: editor; + } + + [data-slot="composer-row"] { + display: contents; + } + + [data-slot="composer-add"] { + grid-area: add; + padding-inline-start: 8px; + } + + [data-slot="composer-controls"] { + grid-area: controls; + height: 44px; + margin-inline: 0 4px; + } + + [data-action="composer-model"] { + max-width: 240px; + } + + [data-slot="composer-actions"] { + grid-area: actions; + padding-inline-end: 8px; + } + + [data-component="composer-editor"], + [data-slot="composer-placeholder"] { + padding-block: 12px; + padding-inline: 4px 8px; + } + + [data-slot="composer-placeholder"] { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + } +} diff --git a/packages/app/src/composer/editor/editor.tsx b/packages/app/src/composer/editor/editor.tsx index 2032511ee75..5bb318854aa 100644 --- a/packages/app/src/composer/editor/editor.tsx +++ b/packages/app/src/composer/editor/editor.tsx @@ -64,6 +64,14 @@ export type { export type ComposerMode = "normal" | "shell" +// Exploration of tighter composer geometry. "today" is the shipped layout; the others are candidates for Kit's pick. +export const composerLayouts = ["today", "tight", "joined", "slim", "inline"] as const + +export type ComposerLayout = (typeof composerLayouts)[number] + +// Layouts that fold the variant into the model chip instead of showing a second picker. +export const composerJoinedLayouts: ComposerLayout[] = ["joined", "slim", "inline"] + const COMPOSER_SUGGESTION_MAX_HEIGHT = 320 const COMPOSER_SUGGESTION_ROW_HEIGHT = 28 @@ -89,6 +97,7 @@ export type ComposerEditorProps = { alternateKeybind?: string[] exitShellKeybind?: string[] suggestionBoundary?: () => HTMLElement | undefined + layout?: ComposerLayout } export function ComposerEditor(props: ComposerEditorProps) { @@ -112,9 +121,32 @@ export function ComposerEditor(props: ComposerEditorProps) { // The bottom fade shrinks with the remaining scroll so the last line ends clear of it. const [fadeBottom, setFadeBottom] = createSignal(0) + const layout = () => props.layout ?? "today" + const [expanded, setExpanded] = createSignal(false) + + const hasContext = () => + props.controller.attachments().length + + props.controller.uploads().length + + props.controller.comments().length + + props.controller.files().length > + 0 + + // The inline layout is one row while the draft fits on one line. Once it wraps it stays two rows until the draft + // is cleared, so the wider editor of the two-row layout cannot unwrap it and flip back. + createEffect(() => { + if (layout() !== "inline") return + const value = props.controller.value() + + if (!value && !hasContext()) return setExpanded(false) + + if (value.includes("\n") || hasContext()) setExpanded(true) + }) + const updateScroll = () => { if (!viewport) return setFadeBottom(Math.min(16, Math.max(0, viewport.scrollHeight - viewport.clientHeight - viewport.scrollTop))) + + if (layout() === "inline" && !expanded() && editor && editor.scrollHeight > 44) setExpanded(true) } onMount(() => { @@ -200,6 +232,8 @@ export function ComposerEditor(props: ComposerEditorProps) {
-
+
{props.modelControl} - + {(control) => ( 1}> void } timelineDetail?: TimelineDetail + composerLayout?: ComposerLayout } export function SessionPreview(props: SessionPreviewProps) { @@ -303,7 +305,7 @@ function SessionSurfaceState(props: SessionPreviewProps & { onReset: () => void } />
- +
}