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): 静音门补到公共桌面出口,取消静音不补播旧提示音

WZBbiaoec148def732c
diff --git a/apps/desktop/src/main/__tests__/notificationService.test.ts b/apps/desktop/src/main/__tests__/notificationService.test.ts
index 75f70c6849..b9bd55b213 100644
--- a/apps/desktop/src/main/__tests__/notificationService.test.ts
+++ b/apps/desktop/src/main/__tests__/notificationService.test.ts
@@ -223,6 +223,21 @@ describe('notificationService — channels 分发', () => {
expect(feishuIm.sendText).not.toHaveBeenCalled();
});
+ // bot-autonomy / scheduler 这类 main 内直调方不经过 IPC handler,静音门必须在
+ // 公共出口(showDesktopSessionEvent)上,否则静音任务仍会弹出系统 toast。
+ it('main 内直接调公共出口时同样受静音门禁,其它设备任务不受影响', async () => {
+ const { initNotificationService, showDesktopSessionEvent } = await freshService();
+ initNotificationService(baseDeps(makeFeishuIm('owner')));
+ isSessionNotificationsMutedSync.mockReturnValue(true);
+
+ expect(showDesktopSessionEvent(() => null, { sessionId: 'muted', title: 'Muted', kind: 'needs-reply' })).toBe(false);
+ expect(notificationCtor).not.toHaveBeenCalled();
+
+ // 其它设备的任务(markAttention: false)不查本机静音标记,照旧弹。
+ expect(showDesktopSessionEvent(() => null, { sessionId: 'muted', title: 'Remote', kind: 'needs-reply', markAttention: false })).toBe(true);
+ expect(notificationCtor).toHaveBeenCalledOnce();
+ });
+
it('keeps every channel for a task that is not muted', async () => {
const { initNotificationService } = await freshService();
const feishuIm = makeFeishuIm('owner');
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 f1d4f4408e..46f2e2c896 100644
--- a/apps/desktop/src/main/agent-island/__tests__/service.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/service.test.ts
@@ -861,6 +861,43 @@ describe('AgentIslandService native publishing', () => {
expect(published.at(-1)?.sessions.map((session) => session.sessionId)).toEqual(['muted-task']);
}, 20_000);
+ it('取消静音时不为静音期间已经发生的旧状态补播提示音', async () => {
+ const { AgentIslandService } = await import('../service.js');
+ const publish = vi.fn(() => true);
+ const playSound = vi.fn<(sound: AgentIslandSoundChoice) => boolean>(() => true);
+ const service = new AgentIslandService({
+ getMainWindow: () => null,
+ nativeHost: {
+ failed: false,
+ headless: false,
+ publish,
+ suspend: () => undefined,
+ playSound,
+ },
+ });
+ syncEnabledForTest(service, publish);
+ service.setSoundSettings({
+ enabled: true,
+ sounds: {
+ ...DEFAULT_AGENT_ISLAND_SOUND_SETTINGS.sounds,
+ start: customSound('start.wav'),
+ complete: customSound('complete.wav'),
+ },
+ });
+
+ // 静音期间任务跑完:岛面看不到它,自然也不响。
+ mocks.isSessionNotificationsMutedSync.mockImplementation((id: string) => id === 'muted-task');
+ playSound.mockClear();
+ service.handleUserPrompt({ sessionId: 'muted-task', agentKind: 'codex' }, 'run tests');
+ service.handleAgentEvent({ sessionId: 'muted-task', agentKind: 'codex' }, doneEvent());
+ expect(playSound).not.toHaveBeenCalled();
+
+ // 取消静音 → 任务带着「已完成」重新出现在岛面上,但那是旧状态,不该补播完成音。
+ mocks.isSessionNotificationsMutedSync.mockReturnValue(false);
+ service.handleNotificationMuteChanged();
+ expect(playSound).not.toHaveBeenCalled();
+ }, 20_000);
+
it('exposes the canonical snapshot and emits per-session transition edges', async () => {
const { AgentIslandService } = await import('../service.js');
const service = new AgentIslandService({
diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.ts
index 492a6a0f9d..ecb4d7d041 100644
--- a/apps/desktop/src/main/agent-island/service.ts
+++ b/apps/desktop/src/main/agent-island/service.ts
@@ -1308,6 +1308,19 @@ export class AgentIslandService {
* 侧栏卡片的实时活动、等待交互态与远端活动镜像不受影响。
*/
handleNotificationMuteChanged(): void {
+ // 取消静音会让任务重新进入展示面。若它在此期间还在跑 / 已完成 / 报错 / 等确认,
+ // 逐帧比较会把「重新出现」当成一次新转移,补播一次 start / complete / error /
+ // attention 提示音。把刚解除抑制的任务记进本帧的声音基线,只为旧状态重发一次画面。
+ if (this.enabledSynced && this.enabled) {
+ for (const sessionId of this.state.sessions.keys()) {
+ if (
+ this.state.displaySuppressedSessionIds.has(sessionId) &&
+ !isSessionNotificationsMutedSync(sessionId)
+ ) {
+ this.baselineSoundSessionIds.add(sessionId);
+ }
+ }
+ }
this.publish();
}
diff --git a/apps/desktop/src/main/notificationService.ts b/apps/desktop/src/main/notificationService.ts
index b3c09f0b17..ae7fafcac0 100644
--- a/apps/desktop/src/main/notificationService.ts
+++ b/apps/desktop/src/main/notificationService.ts
@@ -174,7 +174,12 @@ export function showDesktopSessionEvent(
},
): boolean {
const { sessionId, title, kind } = payload;
- if (sessionId && payload.markAttention !== false) markSessionNeedsAttention(sessionId);
+ const isLocalSession = !!sessionId && payload.markAttention !== false;
+ if (isLocalSession) markSessionNeedsAttention(sessionId);
+ // 「消息免打扰」门放在这个**公共出口**上:scheduler、伙伴自主跟进等 main 内
+ // 直接调用方都不经过 IPC handler 的那道判定,只挡 handler 会漏出系统 toast。
+ // 其它设备的任务(markAttention === false)不查本机静音标记。
+ if (isLocalSession && isSessionNotificationsMutedSync(sessionId)) return false;
const safeTitle = title?.trim() || sessionId.slice(0, 8) || getSessionNotificationUntitled();
return showDesktopToast(safeTitle, kind, () => focusWindow(getWindow, sessionId), payload.body, payload.teammate);
}