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): 远程任务完成卡片显示最后一条回复而非「完成」 (#5486)

Dashf3ac7490f550
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 589ead7c27..5e524e4838 100644
--- a/apps/desktop/src/main/agent-island/__tests__/deviceSessions.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/deviceSessions.test.ts
@@ -109,6 +109,46 @@ describe('Agent Island device sessions', () => {
);
});
+ it('shows the synced summary on a remote completion instead of the done placeholder', () => {
+ const state = createAgentIslandState();
+ syncAgentIslandDeviceSessions(state, [remote('running')], 1_000);
+ syncAgentIslandDeviceSessions(
+ state,
+ [remote('completed', { detail: 'Login is fixed and tests pass.' })],
+ 2_000,
+ );
+
+ const session = buildAgentIslandDisplayState(state, 2_000).sessions[0];
+ expect(session?.compactDetail).toBe('Login is fixed and tests pass.');
+ // 摘要不带消息角色,不能冒充助手回复。
+ expect(session?.activityLines.map((line) => [line.kind, line.text])).toEqual([
+ ['status', 'Login is fixed and tests pass.'],
+ ]);
+
+ const updated = syncAgentIslandDeviceSessions(
+ state,
+ [remote('completed', { detail: 'Login is fixed; PR opened.' })],
+ 3_000,
+ );
+ expect(updated).toEqual(expect.objectContaining({ changed: true, events: [] }));
+ expect(
+ buildAgentIslandDisplayState(state, 3_000).sessions[0]?.activityLines.map((line) => line.text),
+ ).toEqual(['Login is fixed; PR opened.']);
+ });
+
+ it('falls back to the done placeholder instead of the previous turn summary', () => {
+ const state = createAgentIslandState();
+ syncAgentIslandDeviceSessions(state, [remote('running')], 1_000);
+ syncAgentIslandDeviceSessions(state, [remote('completed', { detail: 'First turn done.' })], 2_000);
+ syncAgentIslandDeviceSessions(state, [remote('running')], 3_000);
+ syncAgentIslandDeviceSessions(state, [remote('completed')], 4_000);
+
+ const session = buildAgentIslandDisplayState(state, 4_000).sessions[0];
+ expect(session?.activityLines.map((line) => [line.kind, line.text])).toEqual([
+ ['status', 'Done'],
+ ]);
+ });
+
it('does not repeat events for an unchanged phase', () => {
const state = createAgentIslandState();
syncAgentIslandDeviceSessions(state, [remote('running')], 1_000);
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 ca3cfbfbd3..d65e76fc08 100644
--- a/apps/desktop/src/main/agent-island/__tests__/service.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/service.test.ts
@@ -909,6 +909,7 @@ describe('AgentIslandService native publishing', () => {
service.setEnabled(false);
service.handleUserPrompt({ sessionId: 's1', agentKind: 'codex' }, 'run tests');
+ service.handleAgentEvent({ sessionId: 's1', agentKind: 'codex' }, textEvent('Tests pass.', true));
service.handleAgentEvent({ sessionId: 's1', agentKind: 'codex' }, doneEvent());
const sessions = (
service as unknown as { state: { sessions: Map<string, unknown>; remoteUnreadTerminals: Map<string, unknown> } }
@@ -954,6 +955,7 @@ describe('AgentIslandService native publishing', () => {
service.setEnabled(true);
service.handleUserPrompt({ sessionId: 's1', agentKind: 'codex' }, 'run tests');
+ service.handleAgentEvent({ sessionId: 's1', agentKind: 'codex' }, textEvent('Tests pass.', true));
service.handleAgentEvent({ sessionId: 's1', agentKind: 'codex' }, doneEvent());
expect(publish.mock.calls.at(-1)?.[0]).toMatchObject({
totalCount: 1,
@@ -1153,6 +1155,34 @@ describe('AgentIslandService native publishing', () => {
);
});
+ it('relays the last reply as the completion summary for other devices', async () => {
+ const { AgentIslandService } = await import('../service.js');
+ const service = new AgentIslandService({
+ getMainWindow: () => null,
+ nativeHost: {
+ failed: false,
+ headless: true,
+ publish: () => true,
+ suspend: () => undefined,
+ },
+ });
+ service.setEnabled(false);
+ 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, doneEvent());
+
+ expect(mocks.tapWindowBroadcast).toHaveBeenLastCalledWith(
+ SESSION_ACTIVITY_CHANNEL,
+ expect.objectContaining({
+ sessionId: 'summary',
+ phase: 'completed',
+ compactDetail: 'Login is fixed.',
+ }),
+ );
+ });
+
it('clears pending compact activity relay state during runtime reset', async () => {
vi.useFakeTimers();
vi.setSystemTime(new Date('2026-01-01T00:00:00.000Z'));
diff --git a/apps/desktop/src/main/agent-island/__tests__/state.test.ts b/apps/desktop/src/main/agent-island/__tests__/state.test.ts
index 3b6fc6a874..7ee94996e5 100644
--- a/apps/desktop/src/main/agent-island/__tests__/state.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/state.test.ts
@@ -17,6 +17,7 @@ import {
buildAgentIslandDisplayState,
buildAllSessionActivitySnapshots,
closeAgentIslandSessionPreservingUnread,
+ completedReplySummary,
createAgentIslandState,
dismissAgentIslandActiveReveal,
getNextAgentIslandTimerAt,
@@ -876,6 +877,32 @@ describe('Agent Island display state', () => {
expect(afterAssistantDwell.sessions[0]?.compactDetail).toBe('运行测试');
});
+ it('summarizes a completion for other devices with the last reply only', () => {
+ const state = createAgentIslandState();
+ setAgentIslandStrings(state, { ...DEFAULT_AGENT_ISLAND_STRINGS, done: '完成' });
+ const start = 1_000;
+
+ // 用户提问预览仍在驻留时完成:取回复,不取提问。
+ applyAgentIslandUserPrompt(state, { sessionId: 'reply', title: 'Task' }, 'fix the login bug', start);
+ applyAgentIslandEvent(state, { sessionId: 'reply' }, finalTextEvent('登录问题已修复。'), start + 100);
+ applyAgentIslandEvent(state, { sessionId: 'reply' }, doneEvent(), start + 200);
+ // 本轮没有回复:不取上一轮的回复,也不把本机语言的占位当摘要发出去。
+ applyAgentIslandUserPrompt(state, { sessionId: 'silent', title: 'Task' }, 'first turn', start - 500);
+ applyAgentIslandEvent(state, { sessionId: 'silent' }, finalTextEvent('第一轮的回复'), start - 400);
+ applyAgentIslandEvent(state, { sessionId: 'silent' }, doneEvent(), start - 300);
+ applyAgentIslandUserPrompt(state, { sessionId: 'silent', title: 'Task' }, 'run it', start);
+ applyAgentIslandEvent(state, { sessionId: 'silent' }, doneEvent(), start + 200);
+
+ const sessions = buildAgentIslandDisplayState(state, start + 300).sessions;
+ const reply = sessions.find((session) => session.sessionId === 'reply');
+ const silent = sessions.find((session) => session.sessionId === 'silent');
+ expect(reply?.messagePreview?.kind).toBe('user');
+ expect(reply?.compactDetail).toBe('fix the login bug');
+ expect(reply && completedReplySummary(reply)).toBe('登录问题已修复。');
+ expect(silent?.activityLines.at(-1)?.text).toBe('完成');
+ expect(silent && completedReplySummary(silent)).toBe('');
+ });
+
it('does not display managed dialogue workspace folders as projects', () => {
const state = createAgentIslandState();
diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.ts
index d51af9630f..ad187eacb1 100644
--- a/apps/desktop/src/main/agent-island/service.ts
+++ b/apps/desktop/src/main/agent-island/service.ts
@@ -84,6 +84,7 @@ import {
buildAllSessionActivitySnapshots,
closeAgentIslandSessionPreservingUnread,
completeAgentIslandSessionWithoutAttention,
+ completedReplySummary,
createAgentIslandUserPromptRollbackToken,
createAgentIslandState,
dismissAgentIslandActiveReveal,
@@ -1551,7 +1552,8 @@ export class AgentIslandService {
}),
phase: s.phase,
interactionKind: s.interactionKind,
- compactDetail: s.compactDetail,
+ // 完成后这份摘要只给其它设备的完成卡片用(本机岛面直接读展示快照)。
+ compactDetail: s.phase === 'completed' ? completedReplySummary(s) : s.compactDetail,
workingPhase: s.workingPhase,
}));
}
diff --git a/apps/desktop/src/main/agent-island/state.ts b/apps/desktop/src/main/agent-island/state.ts
index 2d7f966fdd..3df1b6bf19 100644
--- a/apps/desktop/src/main/agent-island/state.ts
+++ b/apps/desktop/src/main/agent-island/state.ts
@@ -1206,10 +1206,15 @@ function applyDeviceSessionPhase(
return { changed, event: entering && previous !== null ? 'needs-reply' : null };
}
case 'completed': {
- if (previous === 'completed') return { changed: false, event: null };
+ if (previous === 'completed') {
+ return { changed: mirrorDeviceSessionSummary(session, input.detail), event: null };
+ }
clearDeviceSessionInteraction(session);
session.running = false;
session.lastActivityAt = now;
+ // 先换掉上一轮的摘要,且必须先于 complete:有摘要可显示时就不再补「完成」占位。
+ session.activityLines = [];
+ mirrorDeviceSessionSummary(session, input.detail);
// 对方设备已经仲裁过终态,这里不再套本机「报错后的配对 done」保护。
session.completionAllowedAfterTerminalError = true;
completeAgentIslandSession(state, session, now, observed
@@ -1237,6 +1242,18 @@ function applyDeviceSessionPhase(
}
}
+/**
+ * 设备任务不同步对话,只带对方岛上算好的一行摘要,不带消息角色。记成状态行(不冒充
+ * 回复):完成卡片取它当文案,连续更新原地替换;没有摘要时才退回「完成」。
+ */
+function mirrorDeviceSessionSummary(session: AgentIslandSessionState, detail: string): boolean {
+ const text = normalizeActivityText(detail);
+ const last = session.activityLines.at(-1);
+ if (!text || (last?.kind === 'status' && last.text === text)) return false;
+ appendActivityLine(session, 'status', text);
+ return true;
+}
+
function clearDeviceSessionInteraction(session: AgentIslandSessionState): void {
// 与本机交互撤销同口径:等待交互的注意力随交互结束一起放下。
if (session.pendingInteractionIds.size > 0) session.unread = false;
@@ -2381,6 +2398,23 @@ function compactDetailForSession(session: AgentIslandSessionState): string {
return detail ? truncateInlineText(detail, AGENT_ISLAND_COMPACT_DETAIL_MAX_LENGTH) : '';
}
+/**
+ * 同步给其它设备的完成摘要:只取本轮(最后一条用户消息之后)的最后一条回复。驻留中的
+ * 用户提问、「完成」占位、工具状态和上一轮的回复都不算结果;没有回复时给空串,由接收端
+ * 用自己的语言显示「完成」。
+ */
+export function completedReplySummary(
+ snapshot: Pick<AgentIslandSessionSnapshot, 'activityLines'>,
+): string {
+ for (const line of snapshot.activityLines.slice().reverse()) {
+ if (line.kind === 'user') break;
+ if (line.kind === 'assistant') {
+ return truncateInlineText(line.text, AGENT_ISLAND_COMPACT_DETAIL_MAX_LENGTH);
+ }
+ }
+ return '';
+}
+
function messagePreviewTextForSession(session: AgentIslandSessionState): string | null {
if (session.phase === 'needs-interaction' || session.phase === 'error') return null;
const line = session.messagePreview?.line;