Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(agent-island): 保留跨设备纯文本并收敛摘要解析边界

Dash47559e1e8167
diff --git a/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts b/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts
index 2c81bec5ee..474c9484fc 100644
--- a/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/activityTextStream.test.ts
@@ -1,10 +1,12 @@
-import { describe, expect, it } from 'vitest';
+import { describe, expect, it, vi } from 'vitest';
+import * as previewText from '../../../shared/markdownPreviewText.js';
import {
AGENT_ISLAND_ACTIVITY_TEXT_MAX_LENGTH,
appendActivityTextStream,
createActivityTextStreamState,
normalizeActivityText,
+ normalizeRemoteActivityText,
type ActivityTextStreamMetrics,
} from '../activityTextStream.js';
@@ -96,9 +98,9 @@ describe('Agent Island activity text stream', () => {
it('hides irrecoverable rich protocol from old remote summaries', () => {
const collapsed = richAnswer.replace(/\s+/g, ' ');
- expect(normalizeActivityText(collapsed)).toBe('');
- expect(normalizeActivityText(collapsed.slice(0, 80) + '...')).toBe('');
- expect(normalizeActivityText('已完成\n' + collapsed)).toBe('已完成');
+ expect(normalizeRemoteActivityText(collapsed)).toBe('');
+ expect(normalizeRemoteActivityText(collapsed.slice(0, 80) + '...')).toBe('');
+ expect(normalizeRemoteActivityText('已完成\n' + collapsed)).toBe('已完成');
});
it('keeps rich protocol out of streamed previews across delta boundaries', () => {
@@ -117,6 +119,34 @@ describe('Agent Island activity text stream', () => {
expect(normalizeActivityText(code)).toBe('{"status":"ok"}');
});
+ // #7566 review: transport recovery must not strip a valid local code example.
+ it('preserves a flattened component example inside an outer code fence', () => {
+ const example = '```cindy-ui {"version":1}';
+ expect(normalizeActivityText('````markdown\n' + example + '\n````\n继续说明'))
+ .toBe(example + ' 继续说明');
+ expect(normalizeRemoteActivityText('````markdown\n' + example + '\n````\n继续说明'))
+ .toBe(example + ' 继续说明');
+ });
+
+ // Deterministic work assertion plus visible result; no wall-clock timing.
+ it.each(['', '{"content":"'])('does not parse an unchanged formatted streaming prefix again (%s)', prefix => {
+ const parse = vi.spyOn(previewText, 'markdownPreviewText');
+ try {
+ const stream = createActivityTextStreamState();
+ const visible = appendActivityTextStream(stream, prefix + '**完成** ' + 'x'.repeat(280));
+ expect(visible).toContain('完成');
+ expect(visible).not.toContain('**');
+ const calls = parse.mock.calls.length;
+ expect(calls).toBeGreaterThan(0);
+ for (let i = 0; i < 128; i++) {
+ expect(appendActivityTextStream(stream, ' more output')).toBe(visible);
+ }
+ expect(parse.mock.calls.length).toBe(calls);
+ } finally {
+ parse.mockRestore();
+ }
+ });
+
// Review regression: closing ordinary code fences must not retract their
// content; explicitly quoted component examples remain literal code.
it.each(['`', '~'])('preserves %s code content and examples during streaming', (fenceCharacter) => {
@@ -227,7 +257,7 @@ describe('Agent Island activity text stream', () => {
metrics.jsonParseCodeUnits;
expect(stream.mode).toBe('structured-extracted');
expect(stream.rawChunks).toHaveLength(0);
- expect(stream.structuredDisplayText).toBe(legacyNormalizeActivityText(payload));
+ expect(stream.displayText).toBe(legacyNormalizeActivityText(payload));
expect(metrics.jsonParseCodeUnits).toBe(payload.length);
expect(measuredWork).toBeLessThanOrEqual(payload.length * 3 + 300);
});
diff --git a/apps/desktop/src/main/agent-island/__tests__/deviceSessions.test.ts b/apps/desktop/src/main/agent-island/__tests__/deviceSessions.test.ts
index 1588421eba..ed5c58ffd7 100644
--- a/apps/desktop/src/main/agent-island/__tests__/deviceSessions.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/deviceSessions.test.ts
@@ -189,6 +189,8 @@ describe('Agent Island device sessions', () => {
expect(buildAgentIslandDisplayState(state, 3_000).sessions[0]?.compactDetail).toBe('预览已完成');
sync('completed', detail, 4_000);
expect(buildAgentIslandDisplayState(state, 4_000).sessions[0]?.compactDetail).toBe('Done');
+ sync('completed', '更新完成 ' + detail, 5_000);
+ expect(buildAgentIslandDisplayState(state, 5_000).sessions[0]?.compactDetail).toBe('更新完成');
});
it('does not repeat events for an unchanged phase', () => {
diff --git a/apps/desktop/src/main/agent-island/__tests__/service.test.ts b/apps/desktop/src/main/agent-island/__tests__/service.test.ts
index 70237cebea..0aab8c9122 100644
--- a/apps/desktop/src/main/agent-island/__tests__/service.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/service.test.ts
@@ -1647,7 +1647,9 @@ describe('AgentIslandService native publishing', () => {
);
});
- it('relays the last reply as the completion summary for other devices', async () => {
+ // #7566 review, unit: verify the actual producer marks converted text so a
+ // second host can retain literal code instead of applying Markdown twice.
+ it('relays the last reply as a plain-text completion summary for other devices', async () => {
const { AgentIslandService } = await import('../service.js');
const service = new AgentIslandService({
getMainWindow: () => null,
@@ -1662,7 +1664,7 @@ describe('AgentIslandService native publishing', () => {
const meta = { sessionId: 'summary', agentKind: 'codex' as const };
service.handleUserPrompt(meta, 'fix the login bug');
- service.handleAgentEvent(meta, textEvent('Login is fixed.', true));
+ service.handleAgentEvent(meta, textEvent('**Fixed**: `foo_bar **literal**`', true));
service.handleAgentEvent(meta, doneEvent());
expect(mocks.tapWindowBroadcast).toHaveBeenLastCalledWith(
@@ -1670,7 +1672,8 @@ describe('AgentIslandService native publishing', () => {
expect.objectContaining({
sessionId: 'summary',
phase: 'completed',
- compactDetail: 'Login is fixed.',
+ compactDetail: 'Fixed: foo_bar **literal**',
+ summaryFormat: 'plain-text',
}),
);
});
diff --git a/apps/desktop/src/main/agent-island/activityTextStream.ts b/apps/desktop/src/main/agent-island/activityTextStream.ts
index db22d11964..9ae8c4eaef 100644
--- a/apps/desktop/src/main/agent-island/activityTextStream.ts
+++ b/apps/desktop/src/main/agent-island/activityTextStream.ts
@@ -14,7 +14,7 @@ export interface ActivityTextStreamState {
jsonClosingStack: Array<'}' | ']'>;
jsonInString: boolean;
jsonEscapePending: boolean;
- structuredDisplayText: string;
+ displayText: string;
}
/** Deterministic work counters used by the performance regression test. */
@@ -35,7 +35,7 @@ export function createActivityTextStreamState(): ActivityTextStreamState {
jsonClosingStack: [],
jsonInString: false,
jsonEscapePending: false,
- structuredDisplayText: '',
+ displayText: '',
};
}
@@ -54,15 +54,17 @@ export function appendActivityTextStream(
chunk: string,
metrics?: ActivityTextStreamMetrics,
): string {
+ const previousPreview = state.rawPreview;
appendRawPreview(state, chunk, metrics);
+ const previewChanged = state.rawPreview !== previousPreview;
if (state.mode === 'plain') {
- return rawPreviewText(state);
+ return rawPreviewText(state, previewChanged);
}
if (state.mode === 'structured-extracted') {
if (firstNonWhitespaceIndex(chunk, metrics) < 0) {
- return state.structuredDisplayText;
+ return state.displayText;
}
switchToPlain(state);
return rawPreviewText(state);
@@ -71,27 +73,27 @@ export function appendActivityTextStream(
if (state.mode === 'pending') {
appendRetainedRawChunk(state, chunk);
const firstContentIndex = firstNonWhitespaceIndex(chunk, metrics);
- if (firstContentIndex < 0) return rawPreviewText(state);
+ if (firstContentIndex < 0) return rawPreviewText(state, previewChanged);
const firstContent = chunk[firstContentIndex];
if (firstContent !== '{' && firstContent !== '[') {
switchToPlain(state);
- return rawPreviewText(state);
+ return rawPreviewText(state, previewChanged);
}
state.mode = 'structured';
state.jsonClosingStack.push(firstContent === '{' ? '}' : ']');
if (!scanStructuredChunk(state, chunk, firstContentIndex + 1, metrics)) {
- return rawPreviewText(state);
+ return rawPreviewText(state, previewChanged);
}
} else {
appendRetainedRawChunk(state, chunk);
if (!scanStructuredChunk(state, chunk, 0, metrics)) {
- return rawPreviewText(state);
+ return rawPreviewText(state, previewChanged);
}
}
- if (state.jsonClosingStack.length > 0) return rawPreviewText(state);
+ if (state.jsonClosingStack.length > 0) return rawPreviewText(state, previewChanged);
const rawText = state.rawChunks.join('');
if (metrics) metrics.jsonParseCodeUnits += rawText.length;
@@ -101,9 +103,9 @@ export function appendActivityTextStream(
if (extracted) {
state.mode = 'structured-extracted';
if (metrics) metrics.normalizationCodeUnits += extracted.length;
- state.structuredDisplayText = normalizePlainActivityText(richAnswerText(extracted));
+ state.displayText = normalizePlainActivityText(richAnswerText(extracted));
releaseStructuredParserState(state);
- return state.structuredDisplayText;
+ return state.displayText;
}
} catch {
// Once the outer object/array has closed, a parse failure cannot be repaired
@@ -111,7 +113,7 @@ export function appendActivityTextStream(
}
switchToPlain(state);
- return rawPreviewText(state);
+ return rawPreviewText(state, previewChanged);
}
function appendRetainedRawChunk(state: ActivityTextStreamState, chunk: string): void {
@@ -135,6 +137,25 @@ export function normalizeActivityText(text: string): string {
return normalizePlainActivityText(richAnswerText(extractActivityDisplayText(text)));
}
+/** New hosts send display text; only unmarked legacy summaries need recovery. */
+export function normalizeRemoteActivityText(text: string, summaryFormat?: 'plain-text'): string {
+ if (summaryFormat === 'plain-text') return boundActivityText(text);
+ // Old hosts flattened both the opening newline and any prose/fence boundary.
+ // Check a reconstructed opening with the shared parser so quoted code remains code.
+ const collapsedRich = /(^|\s)(`{3,}|~{3,})cindy-ui[ \t]+\{\s*"(?:version|seq|op)"\s*:/g;
+ for (const match of text.matchAll(collapsedRich)) {
+ const start = match.index! + match[1].length;
+ const prefix = text.slice(0, start);
+ const boundary = prefix && !prefix.endsWith('\n') ? '\n' : '';
+ const key = prefix.length + boundary.length;
+ const candidate = prefix + boundary + match[2] + 'cindy-ui\n';
+ if (splitRichAnswer(candidate).some(part => part.kind === 'rich' && part.key === key)) {
+ return normalizeActivityText(prefix);
+ }
+ }
+ return normalizeActivityText(text);
+}
+
function appendRawPreview(
state: ActivityTextStreamState,
chunk: string,
@@ -229,7 +250,6 @@ function scanStructuredChunk(
function switchToPlain(state: ActivityTextStreamState): void {
state.mode = 'plain';
- state.structuredDisplayText = '';
releaseStructuredParserState(state);
}
@@ -240,7 +260,8 @@ function releaseStructuredParserState(state: ActivityTextStreamState): void {
state.jsonEscapePending = false;
}
-function rawPreviewText(state: ActivityTextStreamState): string {
+function rawPreviewText(state: ActivityTextStreamState, changed = true): string {
+ if (!changed) return state.displayText;
// 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.
let source = state.rawPreview;
@@ -258,18 +279,19 @@ function rawPreviewText(state: ActivityTextStreamState): string {
source = source.slice(0, start);
}
}
- return normalizePlainActivityText(richAnswerText(source));
+ state.displayText = normalizePlainActivityText(richAnswerText(source));
+ return state.displayText;
}
function normalizePlainActivityText(text: string): string {
- // Older remote hosts send an already collapsed/truncated preview. Its fence
- // boundaries and JSON tail are gone: never show that transport as a reply.
- const collapsedRich = /(?:^|\n)[ \t]*(`{3,}|~{3,})cindy-ui[ \t]+\{\s*"(?:version|seq|op)"\s*:/.exec(text);
- const source = collapsedRich ? text.slice(0, collapsedRich.index) : text;
// Keep the hot path for plain bounded streaming prefixes cheap; formatted
// answers use the same projection as notifications and the session list.
- const plain = /[*_`~<>!#|&\n\r]|\](?:\(|\[)|^\s*(?:[-+] |\d+[.)] )/.test(source) ? markdownPreviewText(source) : source;
- return plain
+ const plain = /[*_`~<>!#|&\n\r]|\](?:\(|\[)|^\s*(?:[-+] |\d+[.)] )/.test(text) ? markdownPreviewText(text) : text;
+ return boundActivityText(plain);
+}
+
+function boundActivityText(text: string): string {
+ return text
.split('\n')
.map((line) => line.trim())
.filter(Boolean)
diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.ts
index be9e82026e..12ceef48e8 100644
--- a/apps/desktop/src/main/agent-island/service.ts
+++ b/apps/desktop/src/main/agent-island/service.ts
@@ -333,7 +333,7 @@ function safeSessionActionSummary(snapshot: AgentIslandSessionSnapshot): string
function canonicalSessionActivity(
activity: AgentIslandSessionActivity,
): SessionActivitySnapshot {
- const { compactDetail: _compactDetail, ...snapshot } = activity;
+ const { compactDetail: _compactDetail, summaryFormat: _summaryFormat, ...snapshot } = activity;
return {
...snapshot,
workflow: snapshot.workflow ? { ...snapshot.workflow } : null,
@@ -1911,6 +1911,7 @@ export class AgentIslandService {
interactionKind: s.interactionKind,
// 完成后这份摘要只给其它设备的完成卡片用(本机岛面直接读展示快照)。
compactDetail: s.phase === 'completed' ? completedReplySummary(s) : s.compactDetail,
+ summaryFormat: 'plain-text',
workingPhase: s.workingPhase,
}));
}
diff --git a/apps/desktop/src/main/agent-island/sessionActivityRelay.ts b/apps/desktop/src/main/agent-island/sessionActivityRelay.ts
index ddcc5bc5e7..2a808c6afc 100644
--- a/apps/desktop/src/main/agent-island/sessionActivityRelay.ts
+++ b/apps/desktop/src/main/agent-island/sessionActivityRelay.ts
@@ -307,6 +307,7 @@ function toSessionActivityPayload(activity: AgentIslandSessionActivity): Session
phase: activity.phase,
workingPhase: activity.workingPhase,
compactDetail: activity.compactDetail,
+ ...(activity.summaryFormat ? { summaryFormat: activity.summaryFormat } : {}),
interactionKind: activity.interactionKind,
attention: activity.attention,
};
@@ -339,6 +340,7 @@ function activitySignature(payload: SessionActivityPayload): string {
payload.phase,
payload.completionNotification ?? '',
payload.compactDetail,
+ payload.summaryFormat ?? '',
payload.workingPhase,
payload.interactionKind ?? '',
payload.attention === true ? '1' : '0',
diff --git a/apps/desktop/src/main/agent-island/state.ts b/apps/desktop/src/main/agent-island/state.ts
index d2759971bc..0b43963295 100644
--- a/apps/desktop/src/main/agent-island/state.ts
+++ b/apps/desktop/src/main/agent-island/state.ts
@@ -26,6 +26,7 @@ import {
cloneActivityTextStreamState,
createActivityTextStreamState,
normalizeActivityText,
+ normalizeRemoteActivityText,
type ActivityTextStreamState,
} from './activityTextStream.js';
@@ -1265,7 +1266,7 @@ function applyDeviceSessionPhase(
session.phase = 'running';
session.sortActivityAt = now;
}
- const detail = normalizeActivityText(input.detail);
+ const detail = normalizeRemoteActivityText(input.detail, input.summaryFormat);
const changed = entering || session.detail !== detail || session.workingPhase !== workingPhase;
session.workingPhase = workingPhase;
session.detail = detail;
@@ -1301,14 +1302,14 @@ function applyDeviceSessionPhase(
case 'completed': {
const silent = input.completionNotification === 'silent';
if (previous === 'completed' && (!silent || session.completionNotification === 'silent')) {
- return { changed: mirrorDeviceSessionSummary(session, input.detail, state.strings.done), event: null };
+ return { changed: mirrorDeviceSessionSummary(session, input, state.strings.done), event: null };
}
clearDeviceSessionInteraction(session);
session.running = false;
touchSessionActivity(session, now);
// 先换掉上一轮的摘要,且必须先于 complete:有摘要可显示时就不再补「完成」占位。
session.activityLines = [];
- mirrorDeviceSessionSummary(session, input.detail, state.strings.done);
+ mirrorDeviceSessionSummary(session, input, state.strings.done);
// 对方设备已经仲裁过终态,这里不再套本机「报错后的配对 done」保护。
session.completionAllowedAfterTerminalError = true;
completeAgentIslandSession(state, session, now, observed && !silent
@@ -1340,8 +1341,8 @@ function applyDeviceSessionPhase(
* 设备任务不同步对话,只带对方岛上算好的一行摘要,不带消息角色。记成状态行(不冒充
* 回复):完成卡片取它当文案,连续更新原地替换;没有摘要时才退回「完成」。
*/
-function mirrorDeviceSessionSummary(session: AgentIslandSessionState, detail: string, fallback: string): boolean {
- const text = normalizeActivityText(detail) || fallback;
+function mirrorDeviceSessionSummary(session: AgentIslandSessionState, input: AgentIslandRemoteSessionInput, fallback: string): boolean {
+ const text = normalizeRemoteActivityText(input.detail, input.summaryFormat) || fallback;
const last = session.activityLines.at(-1);
if (last?.kind === 'status' && last.text === text) return false;
appendNormalizedActivityLine(session, 'status', text);
diff --git a/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts b/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts
index 5ad75ce383..4a7ae1f6e8 100644
--- a/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts
+++ b/apps/desktop/src/renderer/features/device-link/__tests__/agentIslandRemoteSessions.test.ts
@@ -4,7 +4,8 @@ import type { Session } from '@/lib/ccAgent.types';
import { buildAgentIslandRemoteSessionInputs } from '../agentIslandRemoteSessions';
import { applyRemoteSessionActivity, clearRemoteSessionActivity, getRemoteSessionActivity, type RemoteSessionActivity } from '../remoteSessionActivityStore';
import { parseAgentIslandRemoteSessions } from '../../../../shared/agentIsland';
-import { agentIslandCompletionToken, createAgentIslandState, syncAgentIslandDeviceSessions } from '../../../../main/agent-island/state';
+import { agentIslandCompletionToken, buildAgentIslandDisplayState, createAgentIslandState, syncAgentIslandDeviceSessions } from '../../../../main/agent-island/state';
+import { normalizeActivityText } from '../../../../main/agent-island/activityTextStream';
import { SessionActivityRelay } from '../../../../main/agent-island/sessionActivityRelay';
import { MACHINE_ALL, MACHINE_LOCAL } from '../selectedMachineStore';
@@ -49,6 +50,36 @@ const readActivity = (sessionId: string): RemoteSessionActivity | undefined =>
activities.get(sessionId);
describe('buildAgentIslandRemoteSessionInputs', () => {
+ // #7566 review, unit: new host plain text survives the complete transport chain;
+ // an old/unknown format still uses Markdown compatibility on the same text.
+ it('preserves literal code through relay, store, IPC and running/completed cards', () => {
+ clearRemoteSessionActivity();
+ const state = createAgentIslandState();
+ const relay = new SessionActivityRelay(payload => {
+ applyRemoteSessionActivity('device-a', payload);
+ const inputs = buildAgentIslandRemoteSessionInputs([remoteSession('a-1', 'device-a')], MACHINE_ALL, getRemoteSessionActivity);
+ syncAgentIslandDeviceSessions(state, parseAgentIslandRemoteSessions(inputs)!, 2000);
+ }, { minIntervalMs: 0 });
+ const plain = normalizeActivityText('`foo_bar **literal**`');
+ const activity = { sessionId: 'a-1', phase: 'running' as const, recordStatus: 'active',
+ compactDetail: plain, summaryFormat: 'plain-text' as const,
+ startedAtMs: 1, lastActivityAtMs: 1, currentActionSummary: plain,
+ attention: true, workflow: null, turnGeneration: null, gracefulStopState: 'none', source: 'live' } as const;
+ try {
+ for (const phase of ['running', 'completed'] as const) {
+ relay.publish([{ ...activity, phase }]);
+ expect(buildAgentIslandDisplayState(state, 2000).sessions[0]?.compactDetail).toBe(plain);
+ }
+ // The text itself does not change: format changes must invalidate relay/store signatures.
+ relay.publish([{ ...activity, phase: 'completed', summaryFormat: undefined }]);
+ expect(buildAgentIslandDisplayState(state, 2000).sessions[0]?.compactDetail).toBe('foo_bar literal');
+ relay.publish([{ ...activity, phase: 'completed' }]);
+ expect(buildAgentIslandDisplayState(state, 2000).sessions[0]?.compactDetail).toBe(plain);
+ } finally {
+ relay.dispose();
+ clearRemoteSessionActivity();
+ }
+ });
// Full production projection chain: a second completion with identical text
// must replace the owner token, while an old host must not gain swipe actions.
it('preserves completion identity through relay, store, parser and native projection', () => {
diff --git a/apps/desktop/src/renderer/features/device-link/agentIslandRemoteSessions.ts b/apps/desktop/src/renderer/features/device-link/agentIslandRemoteSessions.ts
index 98de3688b8..f7985e005b 100644
--- a/apps/desktop/src/renderer/features/device-link/agentIslandRemoteSessions.ts
+++ b/apps/desktop/src/renderer/features/device-link/agentIslandRemoteSessions.ts
@@ -73,12 +73,13 @@ export function buildAgentIslandRemoteSessionInputs(
function remoteActivityInput(activity: RemoteSessionActivity): Pick<
AgentIslandRemoteSessionInput,
- 'phase' | 'detail' | 'completionNotification' | 'completionToken' | 'workingPhase' | 'interactionKind'
+ 'phase' | 'detail' | 'summaryFormat' | 'completionNotification' | 'completionToken' | 'workingPhase' | 'interactionKind'
> {
return {
phase: activity.phase,
...(activity.completionToken ? { completionToken: activity.completionToken } : {}),
detail: activity.compactDetail,
+ ...(activity.summaryFormat ? { summaryFormat: activity.summaryFormat } : {}),
...(activity.completionNotification ? { completionNotification: activity.completionNotification } : {}),
...(activity.workingPhase ? { workingPhase: activity.workingPhase } : {}),
...(activity.interactionKind
diff --git a/apps/desktop/src/renderer/features/device-link/remoteSessionActivityStore.ts b/apps/desktop/src/renderer/features/device-link/remoteSessionActivityStore.ts
index 2373401857..adec966d32 100644
--- a/apps/desktop/src/renderer/features/device-link/remoteSessionActivityStore.ts
+++ b/apps/desktop/src/renderer/features/device-link/remoteSessionActivityStore.ts
@@ -29,6 +29,7 @@ export interface RemoteSessionActivity {
sessionId: string;
phase: RemoteSessionActivityPhase;
compactDetail: string;
+ summaryFormat?: 'plain-text';
workingPhase?: string;
interactionKind?: string;
attention: boolean;
@@ -67,6 +68,7 @@ function sameActivity(a: RemoteSessionActivity, b: RemoteSessionActivity): boole
a.completionToken === b.completionToken &&
a.phase === b.phase &&
a.compactDetail === b.compactDetail &&
+ a.summaryFormat === b.summaryFormat &&
a.workingPhase === b.workingPhase &&
a.interactionKind === b.interactionKind &&
a.completionNotification === b.completionNotification &&
@@ -160,6 +162,7 @@ export function applyRemoteSessionActivity(deviceId: string, payload: unknown):
sessionId,
phase: p.phase,
compactDetail: typeof p.compactDetail === 'string' ? p.compactDetail : '',
+ ...(p.summaryFormat === 'plain-text' ? { summaryFormat: 'plain-text' as const } : {}),
workingPhase: typeof p.workingPhase === 'string' ? p.workingPhase : undefined,
interactionKind: typeof p.interactionKind === 'string' ? p.interactionKind : undefined,
attention,
diff --git a/apps/desktop/src/shared/agentIsland.ts b/apps/desktop/src/shared/agentIsland.ts
index 070829dfc0..639523b28a 100644
--- a/apps/desktop/src/shared/agentIsland.ts
+++ b/apps/desktop/src/shared/agentIsland.ts
@@ -85,6 +85,8 @@ export interface AgentIslandSessionActivity
interactionKind?: AgentIslandInteractionKind;
/** Compatibility/display alias; canonical probe field is currentActionSummary. */
compactDetail: string;
+ /** Only marked summaries can bypass legacy Markdown recovery on another host. */
+ summaryFormat?: 'plain-text';
}
export type AgentIslandDisplayMode = 'compact' | 'expanded';
@@ -855,6 +857,7 @@ export function parseAgentIslandCompanionChats(raw: unknown): AgentIslandCompani
* 只含 running / needs-interaction / 未读终态;范围由 renderer 按侧栏「任务范围」裁剪。
*/
export interface AgentIslandRemoteSessionInput {
+ summaryFormat?: 'plain-text';
completionToken?: string;
completionNotification?: 'pending' | 'teammate' | 'silent';
sessionId: string;
@@ -933,6 +936,7 @@ export function parseAgentIslandRemoteSessions(raw: unknown): AgentIslandRemoteS
...(record.completionNotification === 'pending' || record.completionNotification === 'teammate' || record.completionNotification === 'silent'
? { completionNotification: record.completionNotification } : {}),
detail: readBoundedString(record.detail, AGENT_ISLAND_REMOTE_TEXT_MAX_LENGTH) ?? '',
+ ...(record.summaryFormat === 'plain-text' ? { summaryFormat: 'plain-text' as const } : {}),
...(workingPhase ? { workingPhase } : {}),
...(interactionKind ? { interactionKind } : {}),
...(companion ? { companion } : {}),
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index bd29fa8d76..e46ca77262 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -1,5 +1,19 @@
# 跨端协议兼容
+## 灵动岛摘要的纯文本标记
+
+既有 `local-db:sessions:activity` 可选追加 `summaryFormat: 'plain-text'`,仅标记
+`compactDetail` 已经由所属 Host 转为显示文字。Desktop 控制端经活动 store、远端输入
+投影与 Main IPC 校验保留标记;运行及完成卡片只折叠空白、限制长度,不再解析 Markdown。
+缺省或未知值继续走旧摘要兼容转换:压平截断的组件块不显示源码,前置正文保留,
+仍有围栏上下文时沿用共享 parser 保护代码引用。无法恢复正文时复用本地化“完成”。
+
+旧控制端忽略可选字段,新控制端接受旧 Host 的无标记摘要;双方可独立升级。
+旧 Host 已经压平的代码示例无法可靠还原格式,完整字面符号保留需双方更新。
+不新增 channel、权限、连接恢复、持久化、服务端或 Mobile 原生配置;回滚时忽略标记,
+保持旧摘要显示。回归见 `activityTextStream.test.ts`、`service.test.ts` 与
+`agentIslandRemoteSessions.test.ts`。
+
## 接受已保存的伙伴模型
既有 `local-db:bots:update` 可选接收 `acceptSavedModelSelectionVersion`(读取到的正整数
diff --git a/packages/device-link/src/topics.ts b/packages/device-link/src/topics.ts
index 42fa5d567b..9f6743d832 100644
--- a/packages/device-link/src/topics.ts
+++ b/packages/device-link/src/topics.ts
@@ -54,6 +54,8 @@ export function parseFsWatchTopic(topic: string): string | null {
export type SessionActivityPhase = 'running' | 'needs-interaction' | 'completed' | 'error';
export interface SessionActivityPayload {
+ /** Optional display-text marker; absent/unknown uses legacy Markdown recovery. */
+ summaryFormat?: 'plain-text';
/** Optional owner-issued completion identity. Old hosts omit it; never infer one. */
completionToken?: string;
/** Completion notification policy only; activity/attention remains unchanged.