TypeScript
fix(web): show minimap previews as plain text, not raw markdown (#15715)
Nikhil Nigame6765094cb6b
diff --git a/apps/web/package.json b/apps/web/package.jsonindex e6b1bc8471d..7eb1909a54c 100644--- a/apps/web/package.json+++ b/apps/web/package.json@@ -71,8 +71,10 @@"react-markdown": "^10.1.0","remark-gfm": "catalog:","remark-math": "6.0.0",+ "remark-parse": "catalog:","tailwind-merge": "^3.4.0","unbash": "^5.0.0",+ "unified": "catalog:","use-sync-external-store": "^1.6.0","zustand": "^5.0.11"},@@ -94,7 +96,6 @@"oxc-transform-react": "~0.152.0","playwright": "1.60.0","tailwindcss": "^4.0.0",- "unified": "catalog:","vite": "catalog:","vite-plus": "catalog:"}diff --git a/apps/web/src/components/chat/timelineMinimapItems.test.ts b/apps/web/src/components/chat/timelineMinimapItems.test.tsindex cad6c2a374b..23b29f3af74 100644--- a/apps/web/src/components/chat/timelineMinimapItems.test.ts+++ b/apps/web/src/components/chat/timelineMinimapItems.test.ts@@ -64,6 +64,50 @@ describe("timeline minimap previews", () => {expect(resolveTimelineMinimapPreview(null)).toBeNull();});+ it("renders assistant markdown only when resolving a preview and keeps user text literal", () => {+ const userText = "Explain **operators** and [x] in [the docs](https://example.com/docs)";+ const assistantText = [+ "## Operators",+ "Use **either** option from [the docs](https://example.com/docs).",+ "",+ "| Operator | Meaning |",+ "| --- | :---: |",+ "| `a \\| b` | either |",+ "",+ "- [x] Match `**/*.ts` files",+ "",+ "[x] deployment complete",+ "",+ "> Note: ~~old~~ new ",+ "> Next line",+ "",+ "```sh",+ "# install deps",+ "- **not bold**",+ "const snake_case = a * b;",+ "```",+ "",+ "foo<br>bar",+ "",+ "<div>Critical <em>answer</em></div>",+ ].join("\n");+ const [item] = deriveTimelineMinimapItems(+ rows([+ ["user", userText],+ ["assistant", assistantText],+ ]),+ );++ expect(item).toMatchObject({ userText, assistantText });+ expect(resolveTimelineMinimapPreview(item!)).toEqual({+ ...item,+ userText,+ assistantText:+ "Operators Use either option from the docs. Operator Meaning a | b either Match **/*.ts files [x] deployment complete Note: old new Next line # install deps - **not bold** const snake_case = a * b; foo bar Critical answer",+ });+ expect(item).toMatchObject({ userText, assistantText });+ });+it("shows fresh streaming text without changing the jump target", () => {const first = deriveTimelineMinimapItems(rows([diff --git a/apps/web/src/components/chat/timelineMinimapItems.ts b/apps/web/src/components/chat/timelineMinimapItems.tsindex 9603b9ac3a5..faf6af94154 100644--- a/apps/web/src/components/chat/timelineMinimapItems.ts+++ b/apps/web/src/components/chat/timelineMinimapItems.ts@@ -1,3 +1,8 @@+import type { Nodes } from "mdast";+import remarkGfm from "remark-gfm";+import remarkParse from "remark-parse";+import { unified } from "unified";+import type { MessagesTimelineRow } from "./MessagesTimeline.logic";export interface TimelineMinimapItem {@@ -47,6 +52,39 @@ function resolveFinalAssistantTextForTurn(return finalAssistantText;}+const markdownPreviewParser = unified().use(remarkParse).use(remarkGfm).freeze();++const INLINE_PARENT_TYPES = new Set<Nodes["type"]>([+ "paragraph",+ "heading",+ "tableCell",+ "emphasis",+ "strong",+ "delete",+ "link",+ "linkReference",+]);++function markdownNodeText(node: Nodes): string {+ if (node.type === "html") {+ return node.value+ .replace(/<!--[\s\S]*?(?:-->|$)/g, "")+ .replace(/<\/?([a-z][\w-]*)(?:[^"'<>]|"[^"]*"|'[^']*')*>/gi, (_, tag: string) =>+ /^(?:address|article|aside|blockquote|br|dd|details|div|dl|dt|figcaption|figure|footer|h[1-6]|header|hr|li|main|nav|ol|p|pre|section|summary|table|tbody|td|th|thead|tr|ul)$/i.test(+ tag,+ )+ ? " "+ : "",+ );+ }+ if (node.type === "break") return " ";+ if ("value" in node) return node.value;+ if (node.type === "image" || node.type === "imageReference") return node.alt ?? "";+ if (!("children" in node)) return "";+ const separator = INLINE_PARENT_TYPES.has(node.type) ? "" : " ";+ return node.children.map(markdownNodeText).join(separator);+}+function compactMinimapPreview(text: string | null | undefined) {const compact = text?.replace(/\s+/g, " ").trim() ?? "";return compact.length > 0 ? compact : null;@@ -60,6 +98,11 @@ export function resolveTimelineMinimapPreview(: {...item,userText: compactMinimapPreview(item.userText),- assistantText: compactMinimapPreview(item.assistantText),+ // The tooltip shows three lines; bound parsing work while long responses stream.+ assistantText: compactMinimapPreview(+ item.assistantText === null+ ? null+ : markdownNodeText(markdownPreviewParser.parse(item.assistantText.slice(0, 1_500))),+ ),};}diff --git a/packages/ssh/src/tunnel.test.ts b/packages/ssh/src/tunnel.test.tsindex fb80b1f3717..048104a4268 100644--- a/packages/ssh/src/tunnel.test.ts+++ b/packages/ssh/src/tunnel.test.ts@@ -1460,7 +1460,17 @@ server.listen(Number(flag("--port")), "127.0.0.1", () => {),);process.kill(zombie, "SIGKILL");- assert.include((yield* runScript(home, ["-c", `ps -o stat= -p ${zombie}`])).stdout, "Z");+ // SIGKILL delivery is asynchronous; establish the zombie fixture before launching.+ const zombieState = yield* runScript(home, [+ "-c",+ `attempt=0; while [ "$attempt" -lt 100 ]; do+ state=$(ps -o stat= -p ${zombie}) || exit 1+ case "$state" in *Z*) printf '%s\\n' "$state"; exit 0;; esac+ attempt=$((attempt + 1))+ done; printf '%s\\n' "$state"; exit 1`,+ ]);+ assert.equal(zombieState.exitCode, 0, zombieState.stdout);+ assert.include(zombieState.stdout, "Z");yield* fs.writeFileString(`${stateDir}/pid`, `${zombie}\n`);yield* fs.writeFileString(`${home}/.t3/userdata/server-runtime.json`,diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 62bd52bbbb2..c689f1e4ab6 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -981,12 +981,18 @@ importers:remark-math:specifier: 6.0.0version: 6.0.0+ remark-parse:+ specifier: 'catalog:'+ version: 11.0.0tailwind-merge:specifier: ^3.4.0version: 3.6.0unbash:specifier: ^5.0.0version: 5.0.0+ unified:+ specifier: 'catalog:'+ version: 11.0.5use-sync-external-store:specifier: ^1.6.0version: 1.6.0([email protected])@@ -1045,9 +1051,6 @@ importers:tailwindcss:specifier: 4.3.3version: 4.3.3- unified:- specifier: 'catalog:'- version: 11.0.5vite:specifier: npm:@voidzero-dev/[email protected]version: '@voidzero-dev/[email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected])([email protected])'