Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

feat(chat): fold long prompts and reflow subagent messages

v_wyxgwang439779170bc3
diff --git a/apps/desktop/src/components/workpanel/SubagentTranscriptTab.tsx b/apps/desktop/src/components/workpanel/SubagentTranscriptTab.tsx
index 6685b22b0..ea5dde55d 100644
--- a/apps/desktop/src/components/workpanel/SubagentTranscriptTab.tsx
+++ b/apps/desktop/src/components/workpanel/SubagentTranscriptTab.tsx
@@ -1,6 +1,7 @@
import { Fragment, useLayoutEffect, useMemo } from "react";
import { useTranslation } from "react-i18next";
import { AssistantTurnBody } from "../../features/chat/transcript/AssistantTurnBody";
+import { CollapsibleUserText } from "../../features/chat/transcript/CollapsibleUserText";
import { SubagentStopButton } from "../../features/chat/transcript/SubagentStopButton";
import { TranscriptDisclosureProvider } from "../../features/chat/transcript/disclosure";
import { delegateModelId, delegateThinkingLevel } from "../../features/chat/transcript/model";
@@ -103,7 +104,9 @@ function SubagentTranscriptSurface({ sessionId, delegationId }: { sessionId: str
<div className="message-row user">
<div className="message-col">
<div className="message-bubble">
- <div className="message-user-text selectable">{task || t("panel.subagentTaskEmpty")}</div>
+ <CollapsibleUserText messageId={call.id} dir="auto">
+ {task || t("panel.subagentTaskEmpty")}
+ </CollapsibleUserText>
</div>
</div>
</div>
diff --git a/apps/desktop/src/features/chat/transcript/CollapsibleUserText.tsx b/apps/desktop/src/features/chat/transcript/CollapsibleUserText.tsx
new file mode 100644
index 000000000..5660ee173
--- /dev/null
+++ b/apps/desktop/src/features/chat/transcript/CollapsibleUserText.tsx
@@ -0,0 +1,76 @@
+import { useId, useLayoutEffect, useRef, useState, type ReactNode } from "react";
+import { useTranslation } from "react-i18next";
+import { IconChevronDown, IconChevronUp } from "../../../components/icons";
+import { Button } from "../../../components/ui";
+import { disclosureKey, useAutomaticDisclosure } from "./disclosure";
+import { useMessageRevealRequest } from "./shared";
+
+export function CollapsibleUserText({ messageId, dir, children }: {
+ messageId: string;
+ dir?: "ltr" | "rtl" | "auto";
+ children: ReactNode;
+}) {
+ const { t } = useTranslation();
+ const contentId = useId();
+ const previewRef = useRef<HTMLDivElement>(null);
+ const textRef = useRef<HTMLDivElement>(null);
+ const limitRef = useRef<HTMLDivElement>(null);
+ const [overflowing, setOverflowing] = useState(false);
+ const request = useMessageRevealRequest(messageId);
+ const { open, toggle, titleRef } = useAutomaticDisclosure(
+ false, request, disclosureKey("user-text", messageId),
+ );
+
+ useLayoutEffect(() => {
+ const text = textRef.current;
+ const limit = limitRef.current;
+ if (!text || !limit) return;
+ const measure = () => {
+ if (!text.clientWidth) return;
+ // This probe uses the same CSS height as the preview clip.
+ const previewHeight = limit.getBoundingClientRect().height;
+ if (previewHeight > 0) setOverflowing(text.getBoundingClientRect().height > previewHeight + 0.5);
+ };
+ measure();
+ const observer = new ResizeObserver(measure);
+ observer.observe(text);
+ observer.observe(limit);
+ return () => observer.disconnect();
+ }, []);
+
+ return (
+ <div className="user-text-disclosure" data-collapsed={overflowing && !open ? "true" : undefined}>
+ <div className="user-text-preview" ref={previewRef}>
+ <div className="user-text-preview-limit" ref={limitRef} aria-hidden="true" />
+ <div
+ id={contentId}
+ ref={textRef}
+ className="message-user-text selectable"
+ dir={dir}
+ onFocusCapture={(event) => {
+ const preview = previewRef.current;
+ if (preview && overflowing && !open &&
+ event.target.getBoundingClientRect().bottom > preview.getBoundingClientRect().bottom) toggle();
+ }}
+ >
+ {children}
+ </div>
+ </div>
+ {overflowing ? (
+ <Button
+ type="button"
+ variant="ghost"
+ size="sm"
+ className="user-text-toggle"
+ ref={titleRef}
+ aria-expanded={open}
+ aria-controls={contentId}
+ onClick={toggle}
+ >
+ {t(open ? "chat.subagentTaskCollapse" : "chat.subagentTaskExpand")}
+ {open ? <IconChevronUp size={14} aria-hidden /> : <IconChevronDown size={14} aria-hidden />}
+ </Button>
+ ) : null}
+ </div>
+ );
+}
diff --git a/apps/desktop/src/features/chat/transcript/MessageRow.tsx b/apps/desktop/src/features/chat/transcript/MessageRow.tsx
index 047faf6f6..33517dd9b 100644
--- a/apps/desktop/src/features/chat/transcript/MessageRow.tsx
+++ b/apps/desktop/src/features/chat/transcript/MessageRow.tsx
@@ -40,6 +40,7 @@ import {
} from "./TranscriptMenu";
import { getExtraMessageAttachments } from "./extra-attachments";
import { directionAttr } from "../../../lib/text-direction";
+import { CollapsibleUserText } from "./CollapsibleUserText";
/**
* The typed form of a Skill or `@agent` invocation (ADR 0346): each validated
@@ -371,10 +372,7 @@ export const MessageRow = memo(function MessageRow({
</div>
) : null}
{directories.text || message.command ? (
- <div
- className="message-user-text selectable"
- dir={userTextDirection}
- >
+ <CollapsibleUserText messageId={message.id} dir={userTextDirection}>
{editableUserMessage && message.command ? (
<>
{message.skillMentions?.length || message.agentMentions?.length ? (
@@ -398,7 +396,7 @@ export const MessageRow = memo(function MessageRow({
userParagraphs
)}
{attachmentChips}
- </div>
+ </CollapsibleUserText>
) : attachmentChips}
</>
) : (
diff --git a/apps/desktop/src/styles/messages.css b/apps/desktop/src/styles/messages.css
index 325101675..681bf2ac0 100644
--- a/apps/desktop/src/styles/messages.css
+++ b/apps/desktop/src/styles/messages.css
@@ -2005,6 +2005,35 @@
line-height: inherit;
}
+.user-text-disclosure {
+ --user-message-preview-height: 6lh;
+}
+
+.user-text-preview {
+ position: relative;
+}
+
+.user-text-preview-limit {
+ position: absolute;
+ inset-block-start: 0;
+ block-size: var(--user-message-preview-height);
+ inline-size: 0;
+ pointer-events: none;
+}
+
+.user-text-disclosure[data-collapsed="true"] .user-text-preview {
+ max-block-size: var(--user-message-preview-height);
+ overflow: clip;
+ mask-image: linear-gradient(to bottom, #000 calc(100% - 1lh), transparent);
+}
+
+.user-text-toggle {
+ display: flex;
+ width: max-content;
+ max-width: 100%;
+ margin: 2px auto 0;
+}
+
/* #2388: inline chips and links inside a message are isolated runs — the
surrounding RTL/LTR punctuation must not migrate across them. */
.message-user-text .chat-command-chip,
diff --git a/apps/desktop/src/styles/work-panel.css b/apps/desktop/src/styles/work-panel.css
index 0dcc93f8f..192d5e420 100644
--- a/apps/desktop/src/styles/work-panel.css
+++ b/apps/desktop/src/styles/work-panel.css
@@ -400,15 +400,17 @@
}
.subagent-transcript-list {
+ /* Keep the shared turn styles, but size them to this panel, not MainChat. */
+ --chat-prose-max-width: 100%;
display: flex;
min-width: 0;
flex-direction: column;
}
-/* A tab pane is narrower than the chat column, so the user plate's percentage
- cap needs a definite floor of its own; the bubble still shrink-wraps. */
+/* Keep short prompts compact without carrying over MainChat's 600px cap. */
.subagent-transcript-list .message-row.user .message-col {
- max-width: min(100%, 520px);
+ width: min(max-content, 82%);
+ max-width: 82%;
}
.subagent-transcript-empty {
diff --git a/apps/desktop/test/session-message-presentation.test.mjs b/apps/desktop/test/session-message-presentation.test.mjs
index d0b8398f0..fef3a3c31 100644
--- a/apps/desktop/test/session-message-presentation.test.mjs
+++ b/apps/desktop/test/session-message-presentation.test.mjs
@@ -76,6 +76,8 @@ const origin = loadComponent("SessionMessageOrigin");
const { MessageRow } = loadComponent("MessageRow", {
"./SessionMessageOrigin": origin,
"./extra-attachments": { getExtraMessageAttachments },
+ "./CollapsibleUserText": { CollapsibleUserText: ({ children }) =>
+ React.createElement("div", { className: "message-user-text selectable" }, children) },
});
const userMessage = {
id: "incoming-row",
diff --git a/apps/desktop/test/session-reference-ui.test.mjs b/apps/desktop/test/session-reference-ui.test.mjs
index 22177314e..abee7bec6 100644
--- a/apps/desktop/test/session-reference-ui.test.mjs
+++ b/apps/desktop/test/session-reference-ui.test.mjs
@@ -146,6 +146,8 @@ const { MessageRow } = load(new URL("../src/features/chat/transcript/MessageRow.
"./ActionBarSlots": { ActionSlotSide: () => null },
"./SessionMessageOrigin": { SessionMessageOrigin: () => null },
"./extra-attachments": { getExtraMessageAttachments },
+ "./CollapsibleUserText": { CollapsibleUserText: ({ children }) =>
+ React.createElement("div", { className: "message-user-text selectable" }, children) },
"./TranscriptMenu": {
useTranscriptMenu: () => () => {},
useChatTextActions: () => ({ copyText: () => {}, selectText: () => {} }),
diff --git a/apps/desktop/test/subagent-conversation-user-path.test.mjs b/apps/desktop/test/subagent-conversation-user-path.test.mjs
index 532024fac..3f8bd8204 100644
--- a/apps/desktop/test/subagent-conversation-user-path.test.mjs
+++ b/apps/desktop/test/subagent-conversation-user-path.test.mjs
@@ -17,11 +17,13 @@ import { IPC } from "@pi-desktop/shared";
import { en } from "@pi-desktop/i18n/locales/en";
import { ConversationSettings } from "./features/settings/pages/ConversationSettings";
import { AssistantTurn } from "./features/chat/transcript/AssistantTurn";
+import { MessageRow } from "./features/chat/transcript/MessageRow";
import { TranscriptDisclosureProvider } from "./features/chat/transcript/disclosure";
import { SubagentTranscriptTab } from "./components/workpanel/SubagentTranscriptTab";
import { SlotSessionProvider } from "./plugins/renderer-slots/use-slots";
import { buildTranscriptEntries } from "./lib/assistant-turns";
import { useAppStore } from "./stores/app-store";
+import { TranscriptSearchContext } from "./lib/transcript-search-context";
import "./styles/globals.css";
const sessionId = "fixture";
@@ -35,7 +37,7 @@ const task = (id, delegationId, description, status, modelId, resume) => tool(id
toolArgs: { agent: "explorer", task: description, resume },
toolResult: { details: { delegationId, status, modelId, thinkingLevel: "medium" } },
});
-const first = task("task-first", "delegate-first", "Initial inspection", "completed", "earlier-model");
+const first = task("task-first", "delegate-first", "Initial inspection. " + "A long task prompt should wrap to the available panel width. ".repeat(7), "completed", "earlier-model");
const latest = task("task-latest", "delegate-latest", "Follow-up inspection", "running", "latest-model", "delegate-first");
const child = { parentToolCallId: "task-first" };
const messages = [
@@ -46,16 +48,18 @@ const messages = [
message("thinking", "assistant", "", { ...child, thinking: "Delegate reasoning" }),
tool("read", "Read", "delegate search needle", { ...child, toolResult: { content: [{ type: "text", text: "delegate search needle" }] } }),
tool("run", "Bash", "delegate output", { ...child, toolArgs: { command: "echo delegate" } }),
- message("answer", "assistant", "Delegate final answer.", child),
+ message("answer", "assistant", "Delegate final answer. " + "A long reply should reflow instead of leaving space unused. ".repeat(8), child),
latest,
task("task-other", "delegate-other", "Other delegate", "running", "other-model"),
message("main-answer", "assistant", "Main answer."),
];
const entry = buildTranscriptEntries(messages).entries.find((item) => item.kind === "assistant-turn");
+const sixLines = message("six-lines", "user", Array(6).fill("Line").join("\\n"));
+const sevenLines = message("seven-lines", "user", Array(7).fill("Line").join("\\n"));
const requests = [];
-const session = { id: sessionId, title: "Fixture", messages, navigationParent: first };
+const session = { id: sessionId, title: "Fixture", messages: [...messages, sixLines, sevenLines] };
window.piDesktop = { invoke: async (channel, args) => {
- if (channel === IPC.invoke.sessionGet) return { ok: true, data: { session } };
+ if (channel === IPC.invoke.sessionGet) return { ok: true, data: { session: { ...session, navigationParent: args.messageAround === "read" ? first : undefined } } };
requests.push({ channel, args });
return { ok: true, data: { pending: args.delegationIds } };
} };
@@ -66,6 +70,7 @@ useAppStore.setState({ activeSessionId: sessionId, retainedSessionIds: [sessionI
function Harness() {
const settings = useAppStore((state) => state.settings);
+ const focus = useAppStore((state) => state.transcriptViews[sessionId]?.focus ?? null);
const tabs = useAppStore((state) => state.workPanelTabs);
const active = useAppStore((state) => state.activeWorkPanelTabId);
const tab = tabs.find((item) => item.id === active);
@@ -75,10 +80,14 @@ function Harness() {
}} /></section>
<section id="main"><SlotSessionProvider sessionId={sessionId}>
<TranscriptDisclosureProvider sessionId={sessionId}>
+ <TranscriptSearchContext.Provider value={focus}>
+ <MessageRow message={sixLines} isRunning={false} />
+ <MessageRow message={sevenLines} isRunning={false} />
<AssistantTurn entry={entry} isActive={false} delegationsLive />
+ </TranscriptSearchContext.Provider>
</TranscriptDisclosureProvider>
</SlotSessionProvider></section>
- <aside id="panel" style={{ width: 340, height: 370, display: "flex" }}>
+ <aside id="panel" style={{ position: "fixed", top: 0, left: 0, width: 340, height: 540, display: "flex" }}>
{tab?.kind === "subagent" ? <SubagentTranscriptTab delegationId={tab.resource} /> : null}
</aside>
</>;
@@ -102,17 +111,54 @@ window.probe = async () => {
const unfold = (item) => { if (!open(item)) click(item); };
const visible = (selector) => Boolean(q(selector) && !q(selector).closest("[hidden]"));
const until = async (condition, message) => {
- const deadline = performance.now() + 3000;
+ const deadline = performance.now() + 5000;
while (!condition()) {
check(performance.now() < deadline, message);
await new Promise(requestAnimationFrame);
}
};
+ const six = q('[data-message-id="six-lines"]');
+ const seven = q('[data-message-id="seven-lines"]');
+ check(!six.querySelector(".user-text-toggle"), "six rendered lines should not fold");
+ const longToggle = seven.querySelector(".user-text-toggle");
+ const preview = seven.querySelector(".user-text-preview");
+ const height = (element) => element.getBoundingClientRect().height;
+ check(longToggle && !open(longToggle) && longToggle.querySelector("svg"), "seven lines should default to a folded text button with an icon");
+ const collapsedHeight = height(preview);
+ check(Math.abs(collapsedHeight - height(seven.querySelector(".message-user-text")) * 6 / 7) < 1 &&
+ getComputedStyle(preview).maskImage !== "none", "folded preview should show six lines with a fade");
+ click(longToggle);
+ check(open(longToggle) && height(preview) > collapsedHeight && getComputedStyle(preview).maskImage === "none", "expand should reveal the full message without a fade");
+ click(longToggle);
+ check(!open(longToggle) && Math.abs(height(preview) - collapsedHeight) < 1, "collapse should restore the six-line preview");
unfold(q("#main .turn-process > button"));
const node = (id) => q('#main [data-message-id="' + id + '"] .subagent-topology-node-header');
click(node("task-first"));
check(q("#panel").textContent.includes("Initial inspection") && q("#panel").textContent.includes("Follow-up inspection"), "resume chain did not open as two prompts");
check(!open(process()) && visible('#panel [data-message-id="answer"]'), "settled process must be closed while the answer stays visible");
+ const panel = q("#panel");
+ const list = q("#panel .subagent-transcript-list");
+ const prompt = q("#panel .message-row.user .message-bubble");
+ const shortPrompt = [...list.querySelectorAll(".message-row.user .message-bubble")].at(-1);
+ const answer = q('#panel [data-message-id="answer"]');
+ const width = (element) => element.getBoundingClientRect().width;
+ const narrow = { prompt: width(prompt), answer: width(answer), height: answer.getBoundingClientRect().height };
+ panel.style.width = "980px";
+ check(width(answer) >= width(list) - 1, "expanded panel reply did not fill its available width");
+ check(width(prompt) >= width(list) * 0.8, "expanded panel prompt was capped at a fixed width");
+ prompt.scrollIntoView({ block: "start" });
+ await until(() => !prompt.querySelector(".user-text-toggle"), "prompt that fits at full width should stop folding");
+ check(width(shortPrompt) < width(prompt) && answer.getBoundingClientRect().height < narrow.height,
+ "short prompts should remain compact and long replies should reflow");
+ panel.style.width = "244px";
+ prompt.scrollIntoView({ block: "start" });
+ await until(() => Boolean(prompt.querySelector(".user-text-toggle")), "narrowing should make a long wrapped prompt fold again");
+ check(width(answer) < narrow.answer && width(prompt) < narrow.prompt && list.scrollWidth <= list.clientWidth + 1,
+ "messages should reflow without horizontal overflow at the minimum width");
+ panel.style.width = "340px";
+ check(Math.abs(width(answer) - narrow.answer) < 1 && Math.abs(width(prompt) - narrow.prompt) < 1,
+ "messages did not shrink back with the panel");
+ check(list.scrollWidth <= list.clientWidth + 1, "narrow messages overflowed their transcript column");
unfold(process());
check(!open(group()), "settled group must default to folded");
click(toggle("Fold finished groups"));
@@ -161,6 +207,8 @@ window.probe = async () => {
click(footer.querySelector(".stop-btn"));
check(JSON.stringify(requests) === JSON.stringify([{ channel: IPC.invoke.agentStopSubagents,
args: { sessionId, delegationIds: ["delegate-latest"] } }]), "stop was not scoped to the latest delegate");
+ await useAppStore.getState().navigateTranscript({ sessionId, messageId: "seven-lines", query: "Line" });
+ await until(() => open(longToggle), "search should reveal a folded user message");
};
`;
diff --git a/apps/desktop/test/subagent-panel.test.mjs b/apps/desktop/test/subagent-panel.test.mjs
index 5ca47d6fb..a8e78e535 100644
--- a/apps/desktop/test/subagent-panel.test.mjs
+++ b/apps/desktop/test/subagent-panel.test.mjs
@@ -89,7 +89,7 @@ test("the delegation tab renders a message list with a read-only composer", () =
assert.match(tabSource, /data-testid="subagent-transcript-tab"/);
assert.match(tabSource, /buildSubagentTranscript\(messages, delegationId\)/);
assert.match(tabSource, /className="message-row user"/);
- assert.match(tabSource, /className="message-user-text selectable"/);
+ assert.match(tabSource, /<CollapsibleUserText messageId=\{call\.id\}/);
assert.match(tabSource, /<AssistantTurnBody[\s\S]*entry=\{reply\}/);
assert.match(tabSource, /<TranscriptSearchContext.Provider value=\{searchTarget\}>/);
assert.match(tabSource, /className="composer-shell"/);
diff --git a/docs/spec/04-ux/08-component-spec.md b/docs/spec/04-ux/08-component-spec.md
index e47ba368f..9af89cabc 100644
--- a/docs/spec/04-ux/08-component-spec.md
+++ b/docs/spec/04-ux/08-component-spec.md
@@ -2084,6 +2084,11 @@ Single message render — either user (plaintext) or assistant (markdown streami
background or outer border. Its Sparkles/chevron trigger uses secondary text,
and the expanded markdown is indented by a subtle theme-token left rule. It
is never concatenated into answer markdown.
+ - Long user messages default to a six-line preview, measured at the rendered
+ width and font. The preview fades at the bottom and has a centered text
+ button with a chevron to show or hide the full message. Six or fewer lines
+ have no button. The choice is renderer-local; search reveals a matching
+ message, and copying and editing still use the complete original text.
- Hover actions: quiet icon-only action chips under the bubble — Copy on idle
assistant turns; Fork and Regenerate on completed assistant turns; Edit and
Delete on user turns. A streaming assistant turn omits its Copy action until
@@ -2835,6 +2840,9 @@ as a conversation:
activity groups where the selected layout allows them, and individual tool
and thinking details. The final answer stays outside the process. Search
reveals the matching levels; manual choices are scoped to each tab and session.
+ Task bubbles and assistant replies reflow within the available panel width
+ when resized or maximized. Short Task bubbles stay compact; longer Task
+ prompts use the same six-line preview as user messages.
- The footer reuses the main composer shell with a localized read-only notice.
The latest Task’s recorded model and thinking level are passive labels,
omitted when unknown. There is no editor, send path, composer slot, or mode,
diff --git a/docs/spec/06-delivery/e2e/conversation.md b/docs/spec/06-delivery/e2e/conversation.md
index 82875eaca..821762cf2 100644
--- a/docs/spec/06-delivery/e2e/conversation.md
+++ b/docs/spec/06-delivery/e2e/conversation.md
@@ -5069,3 +5069,17 @@ Build two actual runtimes with identical configuration and different scratch dir
- With a side-question plugin, verify the quote preview can be removed
atomically and the first explicitly sent prompt contains only the excerpt
and the new question. The main conversation and its input remain intact.
+
+## E2E-CHAT-long-user-message-preview
+
+- **Steps**: Send a six-line message and a seven-line message. Expand the
+ longer message, then collapse it. Narrow the conversation until an
+ otherwise short message wraps beyond six lines. Search for content after
+ line six. Copy or edit the message, then restart the app.
+- **Expected**: Six lines or fewer have no button. Longer text starts folded
+ with a six-line preview, a bottom fade, and a centered text-and-chevron
+ button. Search reveals the matching message. Copy and edit use the full
+ text, and restart restores the default.
+- **Specs linked**: `04-ux/08-component-spec.md`
+- **Status**: Renderer interactions and resize covered by
+ `apps/desktop/test/subagent-conversation-user-path.test.mjs`.
diff --git a/docs/spec/06-delivery/e2e/plugins-and-extensions.md b/docs/spec/06-delivery/e2e/plugins-and-extensions.md
index 6f33bc4f2..643f6cffe 100644
--- a/docs/spec/06-delivery/e2e/plugins-and-extensions.md
+++ b/docs/spec/06-delivery/e2e/plugins-and-extensions.md
@@ -654,6 +654,9 @@ window; opening a normal panel afterward must still work.
6. Wait for the failed delegate to settle, open its tab, and verify the
ended tab persists until manually closed.
7. Switch to another session and back. Verify the tabs are restored per
+ 8. Drag the panel narrower and wider, then maximize it. Verify prompts and
+ replies reflow without a fixed pixel-width cap or horizontal clipping;
+ a wrapped Task prompt shows the fold button only when it exceeds six lines.
session and closed tabs stay closed.
- **Expected**: No auto-open on delegate start; N subagents = N coexisting
closable tabs with deduplicated `name#n` labels; the tab body is the