Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(agent-island): 保留代码围栏并清除已撤回的组件摘要
Dash7dc110886ff7
diff --git a/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts b/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.tsindex 4ccc66ef9d..8922d10627 100644--- a/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts+++ b/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts@@ -100,6 +100,22 @@ describe('Agent Island activity text stream', () => {expect(normalizeActivityText(code)).toBe(legacyNormalizeActivityText(code));});+ // Review regressions: only unfinished rich opening fences may be hidden.+ // Ordinary closing fences and inline/quoted examples must survive every delta.+ it.each(['`', '~'])('preserves %s code fences and examples during streaming', (fenceCharacter) => {+ const fence = fenceCharacter.repeat(3);+ expectEveryStreamingStepToMatchLegacyNormalization([`${fence}json\n`, ...`{"status":"ok"}\n${fence}`]);+ const quoted = `${fenceCharacter.repeat(4)}markdown\n${fence}cindy-ui\n{}\n${fence}\n${fenceCharacter.repeat(4)}`;+ const stream = createActivityTextStreamState();+ expect(appendActivityTextStream(stream, quoted)).toBe(legacyNormalizeActivityText(quoted));+ });++ it('does not turn leading whitespace into a line break inside an inline example', () => {+ const inline = '\n示例 ```cindy-ui\n{}\n```';+ const stream = createActivityTextStreamState();+ expect(appendActivityTextStream(stream, inline)).toBe(normalizeActivityText(inline));+ });+it('hides a truncated rich operation until the full final text is available', () => {const source = '```cindy-ui\n'+ JSON.stringify({ version: 1, seq: 1, op: 'create', id: 'answer', kind: 'text',diff --git a/apps/desktop/src/main/agent-island/__tests__/state.test.ts b/apps/desktop/src/main/agent-island/__tests__/state.test.tsindex bd40b6756d..98b368a641 100644--- a/apps/desktop/src/main/agent-island/__tests__/state.test.ts+++ b/apps/desktop/src/main/agent-island/__tests__/state.test.ts@@ -962,6 +962,41 @@ describe('Agent Island display state', () => {.toMatchObject({ compactDetail: '网络检查完成', phase: 'completed' });});+ // Review regression: a removed/emptied rich node must retract this message's+ // streamed line from both the activity log and active/queued preview (unit tier).+ it.each([+ { operation: 'remove', queued: false, streamed: true },+ { operation: 'remove', queued: true, streamed: false },+ { operation: 'patch', queued: false, streamed: false },+ { operation: 'patch', queued: true, streamed: true },+ ])('retracts an empty rich preview (%j)', ({ operation, queued, streamed }) => {+ const state = createAgentIslandState();+ const meta = { sessionId: 's1' };+ if (queued) applyAgentIslandUserPrompt(state, meta, '检查网络', 1_000);+ else applyAgentIslandEvent(state, meta, statusEvent(true, 'Generating...'), 1_000);+ const prefix = '```cindy-ui\n'+ + '{"version":1,"seq":1,"op":"create","id":"a","kind":"text","props":{"text":"临时结果"}}\n';+ applyAgentIslandEvent(state, meta, textDeltaEvent(prefix), 1_100);+ expect(buildAgentIslandDisplayState(state, 1_150).sessions[0]?.activityLines)+ .toContainEqual(expect.objectContaining({ text: '临时结果' }));+ const update = JSON.stringify({ seq: 2, op: operation, id: 'a',+ ...(operation === 'patch' ? { props: { text: '' } } : {}) }) + '\n```';+ if (streamed) {+ applyAgentIslandEvent(state, meta, textDeltaEvent(update), 1_200);+ const during = buildAgentIslandDisplayState(state, 1_250).sessions[0];+ expect(JSON.stringify(during)).not.toContain('临时结果');+ }+ applyAgentIslandEvent(state, meta, finalTextEvent(prefix + update), 1_300);+ applyAgentIslandEvent(state, meta, doneEvent(), 1_400);+ for (const time of [1_450, 4_000]) {+ const completed = buildAgentIslandDisplayState(state, time).sessions[0];+ expect(JSON.stringify(completed)).not.toContain('临时结果');+ expect(completed?.activityLines).toContainEqual(expect.objectContaining({+ kind: 'status', text: DEFAULT_AGENT_ISLAND_STRINGS.done,+ }));+ }+ });+it('keeps generic running status behind assistant text in compact detail', () => {const state = createAgentIslandState();diff --git a/apps/desktop/src/main/agent-island/activityTextStream.ts b/apps/desktop/src/main/agent-island/activityTextStream.tsindex cc82badbd1..0502a9eefd 100644--- a/apps/desktop/src/main/agent-island/activityTextStream.ts+++ b/apps/desktop/src/main/agent-island/activityTextStream.ts@@ -1,4 +1,4 @@-import { richAnswerText } from '@cindy/maker-shared/rich-answer';+import { richAnswerText, splitRichAnswer } from '@cindy/maker-shared/rich-answer';export const AGENT_ISLAND_ACTIVITY_TEXT_MAX_LENGTH = 280;@@ -145,8 +145,10 @@ function appendRawPreview(if (metrics) metrics.normalizationCodeUnits += 1;const codeUnit = chunk[index] ?? '';if (/\s/.test(codeUnit)) {- if (state.rawPreview) state.rawPreviewHasPendingWhitespace = true;- if (codeUnit === '\n' || codeUnit === '\r') state.rawPreviewHasPendingNewline = true;+ if (state.rawPreview) {+ state.rawPreviewHasPendingWhitespace = true;+ if (codeUnit === '\n' || codeUnit === '\r') state.rawPreviewHasPendingNewline = true;+ }continue;}@@ -240,9 +242,21 @@ function releaseStructuredParserState(state: ActivityTextStreamState): void {function rawPreviewText(state: ActivityTextStreamState): string {// A fence header may itself arrive in several deltas. Do not leave that// temporary header as the last visible activity when the rich block is empty.- const source = state.rawPreview.replace(/(^|\n)(`{1,3}|~{1,3})([^\n]*)$/, (line, _boundary, _fence, language: string) =>- 'cindy-ui'.startsWith(language.trim()) ? '' : line,- );+ let source = state.rawPreview;+ const tail = source.match(/(^|\n)(`+|~+)([^\n]*)$/);+ if (tail && 'cindy-ui'.startsWith(tail[3].trim())) {+ const start = tail.index! + tail[1].length;+ const opening = tail[2][0].repeat(Math.max(3, tail[2].length)) + 'cindy-ui\n';+ // Let the shared fence parser distinguish a new opening from an ordinary+ // closing fence or an example nested inside a larger code fence.+ const candidate = source.slice(0, start) + opening;+ // A bare fence after prose is ambiguous (it may close an inline example).+ // Wait for a language prefix before hiding it; an answer-start fence is safe.+ if ((tail[3].trim() || start === 0)+ && splitRichAnswer(candidate).some(part => part.kind === 'rich' && part.key === start)) {+ source = source.slice(0, start);+ }+ }return normalizePlainActivityText(richAnswerText(source));}diff --git a/apps/desktop/src/main/agent-island/state.ts b/apps/desktop/src/main/agent-island/state.tsindex 919fa6883a..c41630094e 100644--- a/apps/desktop/src/main/agent-island/state.ts+++ b/apps/desktop/src/main/agent-island/state.ts@@ -3075,6 +3075,13 @@ function applyAssistantTextLine(? normalizeActivityText(rawText): appendActivityTextStream(session.assistantStream, rawText);if (!text) {+ const lineId = session.assistantStreamLineId;+ if (lineId) {+ session.activityLines = session.activityLines.filter(line => line.id !== lineId);+ if (session.messagePreview?.line.id === lineId) session.messagePreview = null;+ session.messagePreviewQueue = session.messagePreviewQueue.filter(line => line.id !== lineId);+ session.assistantStreamLineId = null;+ }if (isFinal) {clearAssistantStream(session);}