Defer proposed plan rendering until expand in ChatView
- Keep long plan cards collapsed with lightweight preview text by default - Render full plan markdown only after explicit expand to reduce thread open slowness - Add tests for preview/strip helpers and browser coverage for expand behavior
This commit is contained in:
1 parent
9fb9467ed1
commit
eb7c428a2d
5 files changed
+737
-508
No files matched your search
@@ -256,6 +256,61 @@ function createDraftOnlySnapshot(): OrchestrationReadModel {
|
||||
};
|
||||
}
|
||||
|
||||
function createSnapshotWithLongProposedPlan(): OrchestrationReadModel {
|
||||
const snapshot = createSnapshotForTargetUser({
|
||||
targetMessageId: "msg-user-plan-target" as MessageId,
|
||||
targetText: "plan thread",
|
||||
});
|
||||
const planMarkdown = [
|
||||
"# Ship plan mode follow-up",
|
||||
"",
|
||||
"- Step 1: capture the thread-open trace",
|
||||
"- Step 2: identify the main-thread bottleneck",
|
||||
"- Step 3: keep collapsed cards cheap",
|
||||
"- Step 4: render the full markdown only on demand",
|
||||
"- Step 5: preserve export and save actions",
|
||||
"- Step 6: add regression coverage",
|
||||
"- Step 7: verify route transitions stay responsive",
|
||||
"- Step 8: confirm no server-side work changed",
|
||||
"- Step 9: confirm short plans still render normally",
|
||||
"- Step 10: confirm long plans stay collapsed by default",
|
||||
"- Step 11: confirm preview text is still useful",
|
||||
"- Step 12: confirm plan follow-up flow still works",
|
||||
"- Step 13: confirm timeline virtualization still behaves",
|
||||
"- Step 14: confirm theme styling still looks correct",
|
||||
"- Step 15: confirm save dialog behavior is unchanged",
|
||||
"- Step 16: confirm download behavior is unchanged",
|
||||
"- Step 17: confirm code fences do not parse until expand",
|
||||
"- Step 18: confirm preview truncation ends cleanly",
|
||||
"- Step 19: confirm markdown links still open in editor after expand",
|
||||
"- Step 20: confirm deep hidden detail only appears after expand",
|
||||
"",
|
||||
"```ts",
|
||||
"export const hiddenPlanImplementationDetail = 'deep hidden detail only after expand';",
|
||||
"```",
|
||||
].join("\n");
|
||||
|
||||
return {
|
||||
...snapshot,
|
||||
threads: snapshot.threads.map((thread) =>
|
||||
thread.id === THREAD_ID
|
||||
? Object.assign({}, thread, {
|
||||
proposedPlans: [
|
||||
{
|
||||
id: "plan-browser-test",
|
||||
turnId: null,
|
||||
planMarkdown,
|
||||
createdAt: isoAt(1_000),
|
||||
updatedAt: isoAt(1_001),
|
||||
},
|
||||
],
|
||||
updatedAt: isoAt(1_001),
|
||||
})
|
||||
: thread,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function resolveWsRpc(tag: string): unknown {
|
||||
if (tag === ORCHESTRATION_WS_METHODS.getSnapshot) {
|
||||
return fixture.snapshot;
|
||||
@@ -867,4 +922,41 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps long proposed plans lightweight until the user expands them", async () => {
|
||||
const mounted = await mountChatView({
|
||||
viewport: DEFAULT_VIEWPORT,
|
||||
snapshot: createSnapshotWithLongProposedPlan(),
|
||||
});
|
||||
|
||||
try {
|
||||
await waitForElement(
|
||||
() =>
|
||||
Array.from(document.querySelectorAll("button")).find(
|
||||
(button) => button.textContent?.trim() === "Expand plan",
|
||||
) as HTMLButtonElement | null,
|
||||
"Unable to find Expand plan button.",
|
||||
);
|
||||
|
||||
expect(document.body.textContent).not.toContain("deep hidden detail only after expand");
|
||||
|
||||
const expandButton = await waitForElement(
|
||||
() =>
|
||||
Array.from(document.querySelectorAll("button")).find(
|
||||
(button) => button.textContent?.trim() === "Expand plan",
|
||||
) as HTMLButtonElement | null,
|
||||
"Unable to find Expand plan button.",
|
||||
);
|
||||
expandButton.click();
|
||||
|
||||
await vi.waitFor(
|
||||
() => {
|
||||
expect(document.body.textContent).toContain("deep hidden detail only after expand");
|
||||
},
|
||||
{ timeout: 8_000, interval: 16 },
|
||||
);
|
||||
} finally {
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
File diff suppressed because it is too large.
Load diff
@@ -20,6 +20,7 @@ import {
|
||||
buildProposedPlanMarkdownFilename,
|
||||
normalizePlanMarkdownForExport,
|
||||
downloadPlanAsTextFile,
|
||||
stripDisplayedPlanMarkdown,
|
||||
} from "../proposedPlan";
|
||||
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "./ui/menu";
|
||||
import { readNativeApi } from "~/nativeApi";
|
||||
@@ -67,6 +68,7 @@ const PlanSidebar = memo(function PlanSidebar({
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
const planMarkdown = activeProposedPlan?.planMarkdown ?? null;
|
||||
const displayedPlanMarkdown = planMarkdown ? stripDisplayedPlanMarkdown(planMarkdown) : null;
|
||||
const planTitle = planMarkdown ? proposedPlanTitle(planMarkdown) : null;
|
||||
|
||||
const handleCopyPlan = useCallback(() => {
|
||||
@@ -237,7 +239,7 @@ const PlanSidebar = memo(function PlanSidebar({
|
||||
{proposedPlanExpanded ? (
|
||||
<div className="rounded-lg border border-border/50 bg-background/50 p-3">
|
||||
<ChatMarkdown
|
||||
text={planMarkdown}
|
||||
text={displayedPlanMarkdown ?? ""}
|
||||
cwd={markdownCwd}
|
||||
isStreaming={false}
|
||||
/>
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
buildCollapsedProposedPlanPreviewMarkdown,
|
||||
buildPlanImplementationThreadTitle,
|
||||
buildPlanImplementationPrompt,
|
||||
buildProposedPlanMarkdownFilename,
|
||||
proposedPlanTitle,
|
||||
resolvePlanFollowUpSubmission,
|
||||
stripDisplayedPlanMarkdown,
|
||||
} from "./proposedPlan";
|
||||
|
||||
describe("proposedPlanTitle", () => {
|
||||
@@ -26,6 +28,38 @@ describe("buildPlanImplementationPrompt", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildCollapsedProposedPlanPreviewMarkdown", () => {
|
||||
it("drops the redundant title heading and preserves the following markdown lines", () => {
|
||||
expect(
|
||||
buildCollapsedProposedPlanPreviewMarkdown("# Integrate RPC\n\n## Summary\n\n- step 1\n- step 2", {
|
||||
maxLines: 4,
|
||||
}),
|
||||
).toBe("- step 1\n- step 2");
|
||||
});
|
||||
|
||||
it("appends an overflow marker when the preview truncates remaining content", () => {
|
||||
expect(
|
||||
buildCollapsedProposedPlanPreviewMarkdown("# Integrate RPC\n\n- step 1\n- step 2\n- step 3", {
|
||||
maxLines: 2,
|
||||
}),
|
||||
).toBe("- step 1\n- step 2\n\n...");
|
||||
});
|
||||
});
|
||||
|
||||
describe("stripDisplayedPlanMarkdown", () => {
|
||||
it("drops the leading title heading from displayed plan markdown", () => {
|
||||
expect(stripDisplayedPlanMarkdown("# Integrate RPC\n\n## Summary\n\n- step 1\n")).toBe(
|
||||
"- step 1",
|
||||
);
|
||||
});
|
||||
|
||||
it("preserves non-summary headings after dropping the title heading", () => {
|
||||
expect(stripDisplayedPlanMarkdown("# Integrate RPC\n\n## Scope\n\n- step 1\n")).toBe(
|
||||
"## Scope\n\n- step 1",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolvePlanFollowUpSubmission", () => {
|
||||
it("switches to default mode when implementing the ready plan without extra text", () => {
|
||||
expect(
|
||||
|
||||
@@ -3,6 +3,65 @@ export function proposedPlanTitle(planMarkdown: string): string | null {
|
||||
return heading && heading.length > 0 ? heading : null;
|
||||
}
|
||||
|
||||
export function stripDisplayedPlanMarkdown(planMarkdown: string): string {
|
||||
const lines = planMarkdown.trimEnd().split(/\r?\n/);
|
||||
const sourceLines =
|
||||
lines[0] && /^\s{0,3}#{1,6}\s+/.test(lines[0]) ? lines.slice(1) : [...lines];
|
||||
while (sourceLines[0]?.trim().length === 0) {
|
||||
sourceLines.shift();
|
||||
}
|
||||
const firstHeadingMatch = sourceLines[0]?.match(/^\s{0,3}#{1,6}\s+(.+)$/);
|
||||
if (firstHeadingMatch?.[1]?.trim().toLowerCase() === "summary") {
|
||||
sourceLines.shift();
|
||||
while (sourceLines[0]?.trim().length === 0) {
|
||||
sourceLines.shift();
|
||||
}
|
||||
}
|
||||
return sourceLines.join("\n");
|
||||
}
|
||||
|
||||
export function buildCollapsedProposedPlanPreviewMarkdown(
|
||||
planMarkdown: string,
|
||||
options?: {
|
||||
maxLines?: number;
|
||||
},
|
||||
): string {
|
||||
const maxLines = options?.maxLines ?? 8;
|
||||
const lines = stripDisplayedPlanMarkdown(planMarkdown)
|
||||
.trimEnd()
|
||||
.split(/\r?\n/)
|
||||
.map((line) => line.trimEnd());
|
||||
const previewLines: string[] = [];
|
||||
let visibleLineCount = 0;
|
||||
let hasMoreContent = false;
|
||||
|
||||
for (const line of lines) {
|
||||
const isVisibleLine = line.trim().length > 0;
|
||||
if (isVisibleLine && visibleLineCount >= maxLines) {
|
||||
hasMoreContent = true;
|
||||
break;
|
||||
}
|
||||
previewLines.push(line);
|
||||
if (isVisibleLine) {
|
||||
visibleLineCount += 1;
|
||||
}
|
||||
}
|
||||
|
||||
while (previewLines.length > 0 && previewLines.at(-1)?.trim().length === 0) {
|
||||
previewLines.pop();
|
||||
}
|
||||
|
||||
if (previewLines.length === 0) {
|
||||
return proposedPlanTitle(planMarkdown) ?? "Plan preview unavailable.";
|
||||
}
|
||||
|
||||
if (hasMoreContent) {
|
||||
previewLines.push("", "...");
|
||||
}
|
||||
|
||||
return previewLines.join("\n");
|
||||
}
|
||||
|
||||
function sanitizePlanFileSegment(input: string): string {
|
||||
const sanitized = input
|
||||
.toLowerCase()
|
||||
|
||||
Reference in new issue
Block a user