Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Auto-grow the agent prompt box up to six lines

Bittif4cdad283270
diff --git a/src/components/workspace/AgentDock.test.tsx b/src/components/workspace/AgentDock.test.tsx
index 1795188..a91105e 100644
--- a/src/components/workspace/AgentDock.test.tsx
+++ b/src/components/workspace/AgentDock.test.tsx
@@ -5,7 +5,7 @@ import { act, cleanup, fireEvent, render, screen, waitFor, within } from "@testi
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
import { createProjectConfig, type ProjectRecord } from "../../lib/project";
import { AGENT_TURN_EVENT, cancelAgentTurn, runAgentTurn, type AgentTurnEventPayload, type ProviderStatus } from "../../lib/runtime";
-import { AgentDock, readableProviderOutput } from "./AgentDock";
+import { AgentDock, COMPOSER_MAX_LINES, readableProviderOutput } from "./AgentDock";
let eventHandler: ((event: { payload: AgentTurnEventPayload }) => void) | undefined;
@@ -50,6 +50,29 @@ afterEach(() => {
});
describe("Slop output panel", () => {
+ it("grows the prompt box with its text up to six lines, then scrolls", async () => {
+ // jsdom lays nothing out: report 20px per line of text as the content height.
+ const spy = vi.spyOn(HTMLTextAreaElement.prototype, "scrollHeight", "get").mockImplementation(function (this: HTMLTextAreaElement) {
+ return Math.max(2, this.value.split("\n").length) * 20;
+ });
+ try {
+ render(<AgentDock context="this project" record={project()} providers={providers} onPromptStart={() => undefined} onCommands={async () => undefined} />);
+ await act(async () => { await Promise.resolve(); });
+ const box = screen.getByRole("textbox", { name: /Ask Slop about/ }) as HTMLTextAreaElement;
+ // jsdom gives a textarea a 1px border, which is added to the content height.
+ const border = 2;
+ expect(box.style.height).toBe(`${40 + border}px`);
+ fireEvent.change(box, { target: { value: "one\ntwo\nthree\nfour" } });
+ expect(box.style.height).toBe(`${80 + border}px`);
+ expect(box.style.overflowY).toBe("hidden");
+ fireEvent.change(box, { target: { value: Array.from({ length: 12 }, (_, i) => `line ${i}`).join("\n") } });
+ const style = getComputedStyle(box);
+ const padding = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0);
+ expect(box.style.height).toBe(`${COMPOSER_MAX_LINES * 20 + padding + border}px`);
+ expect(box.style.overflowY).toBe("auto");
+ } finally { spy.mockRestore(); }
+ });
+
it("is a docked pane with a header, a provider picker and a one-line empty state", async () => {
const available: ProviderStatus[] = [
providers[0],
diff --git a/src/components/workspace/AgentDock.tsx b/src/components/workspace/AgentDock.tsx
index 74f9151..9efa8c0 100644
--- a/src/components/workspace/AgentDock.tsx
+++ b/src/components/workspace/AgentDock.tsx
@@ -1,6 +1,6 @@
import { listen } from "@tauri-apps/api/event";
import { ArrowUp, Eraser, Square, X } from "lucide-react";
-import { useEffect, useMemo, useRef, useState } from "react";
+import { useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
import { describeDiagnosticError, errorContext, writeDiagnostic } from "../../lib/diagnostics";
import { isTauri } from "../../lib/persistence";
import {
@@ -18,6 +18,9 @@ import type { ProjectRecord } from "../../lib/project";
import type { AgentMessage } from "../../lib/project";
import { ComboBox, PaneHeader, ProgressRing, tooltipProps } from "../ui";
+/** How tall the prompt box grows before it scrolls. */
+export const COMPOSER_MAX_LINES = 6;
+
interface AgentActivity {
kind: "output" | "diagnostic" | "validation";
text: string;
@@ -57,6 +60,21 @@ export function AgentDock({ context, record, providers, onPromptStart, onCommand
const conversation = useRef<HTMLDivElement | null>(null);
const field = useRef<HTMLTextAreaElement | null>(null);
const cancelButton = useRef<HTMLButtonElement | null>(null);
+ /* The prompt box grows with what is typed, up to six lines, then scrolls —
+ the way the Windows Copilot and Teams composers behave — instead of a
+ resize grip. */
+ useLayoutEffect(() => {
+ const element = field.current;
+ if (!element) return;
+ const style = getComputedStyle(element);
+ const line = parseFloat(style.lineHeight) || 20;
+ const chrome = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0) + (parseFloat(style.borderTopWidth) || 0) + (parseFloat(style.borderBottomWidth) || 0);
+ const max = Math.round(line * COMPOSER_MAX_LINES + chrome);
+ element.style.height = "auto";
+ const wanted = element.scrollHeight + (parseFloat(style.borderTopWidth) || 0) + (parseFloat(style.borderBottomWidth) || 0);
+ element.style.height = `${Math.min(wanted, max)}px`;
+ element.style.overflowY = wanted > max ? "auto" : "hidden";
+ }, [prompt]);
const selected = providers.find((item) => item.id === provider);
const ready = selected?.state === "ready";
const messages = useMemo(() => sessionMessages.slice(-4), [sessionMessages]);
@@ -189,7 +207,7 @@ export function AgentDock({ context, record, providers, onPromptStart, onCommand
<div ref={conversation} className="agent-conversation" role="log" aria-label="Slop output" aria-live="polite">
{empty && <p className="agent-conversation__empty">Ask Slop to write scenes from a prompt, refine shots or edit {context}.</p>}
{messages.map((message) => <p key={message.id} className={`agent-conversation__${message.role}`}><b>{message.role === "user" ? "You" : "Slop"}</b><span>{message.content}</span></p>)}
- {pendingPrompt && <p className="agent-conversation__user agent-conversation__pending"><b>You</b><span>{pendingPrompt}</span></p>}
+ {pendingPrompt && <p className="agent-conversation__pending"><b>You</b><span>{pendingPrompt}</span></p>}
{activity.map((item, index) => <p key={`${item.kind}-${index}`} className={`agent-conversation__${item.kind}`}>
<b>{activityLabel(item.kind)}</b><span>{item.text}</span>
</p>)}
diff --git a/src/styles/agent-dock.css b/src/styles/agent-dock.css
index 156f070..9e404f1 100644
--- a/src/styles/agent-dock.css
+++ b/src/styles/agent-dock.css
@@ -138,8 +138,8 @@
}
/* --- Composer -------------------------------------------------------------------
- A flush TextBox (4px corners, the accent underline on focus) with the send
- button beside it. */
+ A flush TextBox (4px corners, the accent underline on focus) that grows
+ with its text, with the send button beside it. */
.agent-composer {
flex: 0 0 auto;
@@ -150,16 +150,17 @@
border-top: 1px solid var(--line);
}
+/* Two lines at rest; AgentDock grows it with the text up to six lines
+ (COMPOSER_MAX_LINES) and then it scrolls, so there is no resize grip. */
.agent-composer__field.text-field {
min-width: 0;
flex: 1 1 auto;
height: auto;
- min-height: 56px;
- max-height: 200px;
+ min-height: 54px;
padding: 6px var(--space-2);
font-family: inherit;
line-height: var(--leading-normal);
- resize: vertical;
+ resize: none;
}
.agent-composer__field::placeholder {