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(desktop): 免打扰写入固定到本机,岛面抑制跳过远端条目

WZBbiaobf5e7feb9360
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 d73006c10d..ac98e366bf 100644
--- a/apps/desktop/src/main/agent-island/__tests__/service.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/service.test.ts
@@ -3,7 +3,7 @@ import { homedir } from 'node:os';
import path from 'node:path';
import { ScriptTarget, transpileModule } from 'typescript';
-import { beforeEach, describe, expect, it, vi } from 'vitest';
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import type { BrowserWindow } from 'electron';
import { SESSION_ACTIVITY_CHANNEL } from '@cindy/device-link';
import type { AgentEvent, InteractionRequest } from '@cindy/maker-core';
@@ -7092,6 +7092,11 @@ describe('会话关闭原因决定条目去留', () => {
});
describe('Agent Island device sessions', () => {
+ // 有的用例会按 id 把静音索引指到某个任务;失败时也要还原,避免污染后面的用例。
+ afterEach(() => {
+ mocks.isSessionNotificationsMutedSync.mockReturnValue(false);
+ });
+
function deviceSession(
phase: 'running' | 'needs-interaction' | 'completed' | 'error',
sessionId = 'remote-1',
@@ -7137,6 +7142,27 @@ describe('Agent Island device sessions', () => {
);
});
+ it('本机同 id 任务被静音时不吞掉其它设备投影来的任务', async () => {
+ const { AgentIslandService } = await import('../service.js');
+ const published: AgentIslandDisplayState[] = [];
+ const publish = vi.fn((display: AgentIslandDisplayState) => {
+ published.push(display);
+ return true;
+ });
+ const service = new AgentIslandService({
+ getMainWindow: () => null,
+ nativeHost: { failed: false, publish, playSound: () => true },
+ });
+ syncEnabledForTest(service, publish);
+
+ // 还原/复制过的库里可能留着同 id 的本地任务行;那一行的静音标记属于另一条任务,
+ // 不能压掉其它设备发来的卡片与提示音。
+ mocks.isSessionNotificationsMutedSync.mockImplementation((id: string) => id === 'remote-1');
+ service.setDeviceSessions([deviceSession('needs-interaction')]);
+
+ expect(published.at(-1)?.sessions.map((session) => session.sessionId)).toEqual(['remote-1']);
+ });
+
it('keeps first-seen remote tasks silent when they arrive before the island setting syncs', async () => {
const { AgentIslandService } = await import('../service.js');
const publish = vi.fn(() => true);
diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.ts
index 1f70c9859a..7162605f6b 100644
--- a/apps/desktop/src/main/agent-island/service.ts
+++ b/apps/desktop/src/main/agent-island/service.ts
@@ -2002,11 +2002,13 @@ export class AgentIslandService {
* 切换、索引重载、直接改库都能自愈,不靠某一条写库路径记得来登记。
*/
private syncDisplaySuppression(): void {
- for (const sessionId of this.state.sessions.keys()) {
+ for (const [sessionId, session] of this.state.sessions) {
+ // 静音标记属于本机那行任务:其它设备投影进来的条目(sourceDeviceId 非空)可能与它
+ // 同 id(还原/复制过的库),不能拿本机标记去压远端的卡片与提示音。
setAgentIslandSessionDisplaySuppressed(
this.state,
sessionId,
- isSessionNotificationsMutedSync(sessionId),
+ session.sourceDeviceId === null && isSessionNotificationsMutedSync(sessionId),
);
}
}
diff --git a/apps/desktop/src/renderer/lib/__tests__/sessionService.test.ts b/apps/desktop/src/renderer/lib/__tests__/sessionService.test.ts
index dbb04e07d1..bf708fd879 100644
--- a/apps/desktop/src/renderer/lib/__tests__/sessionService.test.ts
+++ b/apps/desktop/src/renderer/lib/__tests__/sessionService.test.ts
@@ -6,6 +6,10 @@ vi.mock('@/lib/makerTransport', () => ({
vi.mock('@/features/device-link/remoteProjectsStore', () => ({
getSessionDeviceId: vi.fn(),
}));
+const stickyOrigin = vi.hoisted(() => ({ get: vi.fn((): string | null => null) }));
+vi.mock('@/features/device-link/stickySessionOrigin', () => ({
+ getStickySessionDeviceId: stickyOrigin.get,
+}));
type SessionLike = { id: string };
@@ -100,3 +104,49 @@ describe('sessionService.get in-flight deduplication', () => {
expect(get).toHaveBeenCalledTimes(2);
});
});
+
+describe('sessionService.patchMeta routing', () => {
+ beforeEach(() => {
+ vi.resetModules();
+ stickyOrigin.get.mockReturnValue(null);
+ });
+
+ afterEach(() => {
+ stickyOrigin.get.mockReturnValue(null);
+ });
+
+ function stub(update: ReturnType<typeof vi.fn>) {
+ const invoke = vi.fn(async () => ({ id: 'session-1' }));
+ vi.stubGlobal('window', {
+ electronAPI: { localDb: { sessions: { update } }, deviceLink: { invoke } },
+ });
+ return { invoke };
+ }
+
+ it('writes notificationsMuted locally even when the session has a sticky remote origin', async () => {
+ const update = vi.fn(async () => ({ id: 'session-1' }));
+ const { invoke } = stub(update);
+ stickyOrigin.get.mockReturnValue('device-a');
+ const service = await loadSessionService();
+
+ await service.patchMeta('session-1', { notificationsMuted: true });
+
+ expect(update).toHaveBeenCalledWith('session-1', { notificationsMuted: true });
+ expect(invoke).not.toHaveBeenCalled();
+ });
+
+ it('still tunnels the other metadata writes for a sticky remote session', async () => {
+ const update = vi.fn(async () => ({ id: 'session-1' }));
+ const { invoke } = stub(update);
+ stickyOrigin.get.mockReturnValue('device-a');
+ const service = await loadSessionService();
+
+ await service.patchMeta('session-1', { status: 'archived' });
+
+ expect(invoke).toHaveBeenCalledWith('device-a', 'local-db:sessions:patch-meta', [
+ 'session-1',
+ { status: 'archived' },
+ ]);
+ expect(update).not.toHaveBeenCalled();
+ });
+});
diff --git a/apps/desktop/src/renderer/lib/sessionService.ts b/apps/desktop/src/renderer/lib/sessionService.ts
index 3f55055c30..5010611149 100644
--- a/apps/desktop/src/renderer/lib/sessionService.ts
+++ b/apps/desktop/src/renderer/lib/sessionService.ts
@@ -216,6 +216,7 @@ export async function update(
* 此处仅落盘,使跨重启可恢复(host 加载时回填 session-provider-store)。
*/
providerId?: string | null;
+ notificationsMuted?: boolean;
},
): Promise<Session> {
return wrap(window.electronAPI.localDb.sessions.update(id, patch));
@@ -238,6 +239,12 @@ export async function patchMeta(
notificationsMuted?: boolean;
},
): Promise<Session> {
+ // 「消息免打扰」是**本机**属性(提醒由任务所在的那台设备发出,菜单也对 device-link
+ // 任务隐藏),不随 sticky origin 隧道:被控端 patch-meta 的 allowlist 不收这个字段,
+ // 隧道过去只会抛 INVALID_PARAMS,让开关白回滚一次。
+ if (patch.notificationsMuted !== undefined) {
+ return update(sessionId, { notificationsMuted: patch.notificationsMuted });
+ }
// Metadata writes must stay pinned to the last known device while the
// relay's session mirror is being rebuilt. Otherwise an archived remote
// task's auto-unarchive can fall through to the controller's local DB.