Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(motion): match synthetic markdown fences
david30fa8dd24bc0
diff --git a/apps/desktop/src/renderer/components/chat/__tests__/repairStreamingMarkdown.test.ts b/apps/desktop/src/renderer/components/chat/__tests__/repairStreamingMarkdown.test.tsindex e491891c87..a70f3a5ece 100644--- a/apps/desktop/src/renderer/components/chat/__tests__/repairStreamingMarkdown.test.ts+++ b/apps/desktop/src/renderer/components/chat/__tests__/repairStreamingMarkdown.test.ts@@ -22,6 +22,21 @@ describe('repairStreamingMarkdown', () => {expect(repairStreamingMarkdown('```\nline\n')).toBe('```\nline\n```');});+ it('uses the opener character and length for synthetic closing fences', () => {+ expect(repairStreamingMarkdown('~~~ts\nconst a = 1;')).toBe(+ '~~~ts\nconst a = 1;\n~~~',+ );+ expect(repairStreamingMarkdown('````ts\nconst a = 1;')).toBe(+ '````ts\nconst a = 1;\n````',+ );+ });++ it('does not close a longer fence with a shorter same-character marker', () => {+ expect(repairStreamingMarkdown('````ts\ncode\n```')).toBe(+ '````ts\ncode\n```\n````',+ );+ });+it('围栏内的星号/方括号不触发行内修复', () => {const src = '```\na ** b [x](y';expect(repairStreamingMarkdown(src)).toBe('```\na ** b [x](y\n```');diff --git a/apps/desktop/src/renderer/components/chat/repairStreamingMarkdown.ts b/apps/desktop/src/renderer/components/chat/repairStreamingMarkdown.tsindex c271cbd79c..db65ef4cd5 100644--- a/apps/desktop/src/renderer/components/chat/repairStreamingMarkdown.ts+++ b/apps/desktop/src/renderer/components/chat/repairStreamingMarkdown.ts@@ -26,9 +26,9 @@const FENCE_LINE = /^\s{0,3}(`{3,}|~{3,})/;/** 扫描围栏开合;返回 open 状态与"围栏外"文本(供行内反引号计数)。 */-function scanFences(md: string): { open: boolean; outside: string } {+function scanFences(md: string): { open: boolean; outside: string; fenceMarker: string } {let open = false;- let fenceChar = '';+ let fenceMarker = '';const outside: string[] = [];for (const line of md.split('\n')) {const m = FENCE_LINE.exec(line);@@ -36,19 +36,20 @@ function scanFences(md: string): { open: boolean; outside: string } {const marker = m[1][0];if (!open) {open = true;- fenceChar = marker;+ fenceMarker = m[1];continue;}// 闭合围栏须与开围栏同字符。- if (marker === fenceChar) {+ if (marker === fenceMarker[0] && m[1].length >= fenceMarker.length) {open = false;+ fenceMarker = '';continue;}continue;}if (!open) outside.push(line);}- return { open, outside: outside.join('\n') };+ return { open, outside: outside.join('\n'), fenceMarker };}function isEscaped(text: string, index: number): boolean {@@ -129,10 +130,10 @@ function repairTrailingLink(md: string): string {export function repairStreamingMarkdown(md: string): string {if (md.length === 0) return md;- const { open, outside } = scanFences(md);+ const { open, outside, fenceMarker } = scanFences(md);if (open) {// 围栏内是代码:补闭合即可,行内修复不适用。- return md.endsWith('\n') ? `${md}\`\`\`` : `${md}\n\`\`\``;+ return md.endsWith('\n') ? `${md}${fenceMarker}` : `${md}\n${fenceMarker}`;}// inline code 半开(围栏外反引号计数为奇数):后续星号可能在代码里,不修。let backticks = 0;diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.mdindex e458b933fc..ac828b01d4 100644--- a/docs/design-rules/DESIGN.md+++ b/docs/design-rules/DESIGN.md@@ -686,7 +686,7 @@ long duration to leak into any other hover or transition.- **Scope boundary**: this seal only. The closing-ring language must not leak into other spinners or progress indicators. Implementation: `apps/desktop/src/renderer/components/chat/GhostSummonCard.tsx` + `.summon-seal-*` in `globals.css`.- **Stream-word fade(流式正文逐词淡入)** — the fifth sanctioned motion class (approved 2026-08-07), **only** for streaming assistant prose in the chat message flow:- **Definition**: during streaming, each newly-arrived **word** fades in over `--motion-fast` (150ms, opacity only) instead of popping in — text appears to *surface*, not *type*. This is explicitly **not** the forbidden per-character typewriter: the word is fully rendered and positioned from its first frame; only opacity ramps. CJK is segmented per word via `Intl.Segmenter`, so Chinese prose flows word-by-word too.- - **Architecture red lines**: CSS owns the form, JS owns only the timing — `rehypeStreamWordFade` wraps words in `span.stream-word` and writes a per-word `--wf-delay` (16ms/word stagger per parse tick; backlog past 96ms compresses to 4ms/word as backpressure); the animation itself is a pure-opacity one-shot keyframe in `globals.css` (compositor-only). Words must never replay on re-parse (delay assigned once per document word index). The final (non-streaming) render carries **zero** wrapper spans — the plugin only mounts while `isStreaming`.+ - **Architecture red lines**: CSS owns the form, JS owns only the timing — `rehypeStreamWordFade` wraps words in `span.stream-word` and writes a per-word `--wf-delay`. The nominal tick step is capped at **24ms per word**; when the pending lead would exceed the **320ms** lead budget, the step is compressed adaptively so rendering keeps up with any arrival rate. Words are keyed by stable content matching (same-position matches, prefix continuation, and bounded backward matching), not by document word index. Each word keeps an absolute scheduled start time / remaining delay across re-parse and remount, so already-seen words never replay. The animation itself is a pure-opacity one-shot keyframe in `globals.css` (compositor-only). The final (non-streaming) render carries **zero** wrapper spans — the plugin only mounts while `isStreaming`.- **Degradation**: `prefers-reduced-motion` short-circuits in JS (plugin not mounted, no spans in DOM) *and* the CSS reduce block strips the animation — double coverage, and the CSS side is safe because `.stream-word` has no own opacity declaration to get stuck on.- **Scope boundary**: streaming chat prose only. Skips `code`/`pre` (chips and code blocks keep whole-form) and KaTeX subtrees. Must not be applied to static content, titles, toasts, or any non-streamed text. Implementation: `apps/desktop/src/renderer/components/chat/rehypeStreamWordFade.ts` + `.stream-word` in `globals.css`; tests: `rehypeStreamWordFade.test.ts`.- **Retired: mobile-download QR brand edge** — a rotating app-icon edge on the `MobileDownloadDialog` QR card was briefly registered here as a fourth (persistent) motion class on 2026-07-25 and **removed the same day** at the user's request: read as a strange ring turning behind the code. There is **no sanctioned persistent decorative motion** — the red lines above hold without exception. The card is now a bare QR (no edge, no border, no shadow, no tilt); its only motion is the linked ↔ onboarding size tween. Do not re-add. Contract test: `mobileDownloadDialog.test.tsx` → `keeps the QR card flat with no brand edge`.