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(im): IM 侧交互完成后默认不产生 App 未读提醒 (#5446)

Dash4bb40cb5fd10
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 3bd6a4fccb..f1bb21e868 100644
--- a/apps/desktop/src/main/agent-island/__tests__/service.test.ts
+++ b/apps/desktop/src/main/agent-island/__tests__/service.test.ts
@@ -3569,6 +3569,72 @@ describe('AgentIslandService native publishing', () => {
]);
});
+ it.each([
+ [false, 'user'], [true, 'user'], [false, 'scheduler'], [true, 'scheduler'],
+ ] as const)('keeps direct IM completions quiet (headless=%s, kind=%s)', async (headless, kind) => {
+ const { AgentIslandService } = await import('../service.js');
+ const publish = vi.fn(() => true);
+ const playSound = vi.fn(() => true);
+ const onSessionActivityChange = vi.fn();
+ const service = new AgentIslandService({
+ getMainWindow: () => null,
+ nativeHost: { failed: false, headless, publish, playSound },
+ onSessionActivityChange,
+ });
+ syncEnabledForTest(service, publish);
+ service.setSoundSettings({ enabled: true, sounds: {
+ ...DEFAULT_AGENT_ISLAND_SOUND_SETTINGS.sounds,
+ complete: customSound('complete.wav'),
+ } });
+ const meta = { sessionId: 'im', agentKind: 'codex' as const };
+ const turnOrigin = { kind, surface: 'im' } as const;
+ // Both IM runners send directly without the App's handleUserPrompt path.
+ service.handleAgentEvent(meta, { type: 'status', data: { isRunning: true }, turnOrigin });
+ service.setCompletionDeferResolver(() => true);
+ playSound.mockClear();
+ service.handleAgentEvent(meta, { type: 'status', data: { isRunning: false, status: 'Done' }, turnOrigin });
+ service.handleAgentEvent(meta, { ...doneEvent(), turnOrigin });
+ service.notifyQueueEmptied(meta.sessionId);
+ expect(playSound).not.toHaveBeenCalled();
+ // Quiet completions are removed from the compact activity list, like silent schedules.
+ expect(onSessionActivityChange.mock.calls.at(-1)?.[0]).toEqual([]);
+
+ service.setCompletionDeferResolver(() => false);
+ service.handleUserPrompt(meta, 'App message');
+ service.handleAgentEvent(meta, doneEvent());
+ expect(onSessionActivityChange.mock.calls.at(-1)?.[0]).toEqual([
+ expect.objectContaining({ sessionId: 'im', phase: 'completed', attention: true }),
+ ]);
+ // A later IM reply must not erase the earlier unread App reply.
+ service.handleAgentEvent(meta, { type: 'status', data: { isRunning: true }, turnOrigin });
+ service.handleAgentEvent(meta, { type: 'status', data: { isRunning: false, status: 'Done' }, turnOrigin });
+ service.handleAgentEvent(meta, { ...doneEvent(), turnOrigin });
+ expect(onSessionActivityChange.mock.calls.at(-1)?.[0]).toEqual([
+ expect.objectContaining({ sessionId: 'im', attention: true }),
+ ]);
+ service.resetRuntimeState();
+ syncEnabledForTest(service, publish);
+ service.handleAgentEvent(meta, { type: 'status', data: { isRunning: true }, turnOrigin });
+ service.handleAgentEvent(meta, {
+ type: 'error', data: { message: 'model unavailable' }, turnOrigin,
+ });
+ expect(onSessionActivityChange.mock.calls.at(-1)?.[0]).toEqual([
+ expect.objectContaining({ sessionId: 'im', phase: 'error', attention: true }),
+ ]);
+ service.handleAgentEvent(meta, { type: 'status', data: { isRunning: true }, turnOrigin });
+ service.handleAgentEvent(meta, { ...doneEvent(), turnOrigin });
+ expect(onSessionActivityChange.mock.calls.at(-1)?.[0]).toEqual([
+ expect.objectContaining({ sessionId: 'im', attention: true }),
+ ]);
+ // Reading the old result during the IM turn must not resurrect it on completion.
+ service.handleAgentEvent(meta, { type: 'status', data: { isRunning: true }, turnOrigin });
+ service.handleSessionAttentionCleared(meta.sessionId, 'explicit');
+ service.handleAgentEvent(meta, { type: 'status', data: { isRunning: false, status: 'Done' }, turnOrigin });
+ service.handleAgentEvent(meta, { ...doneEvent(), turnOrigin });
+ expect(onSessionActivityChange.mock.calls.at(-1)?.[0]).toEqual([]);
+ service.resetRuntimeState();
+ });
+
it('does not play a completion sound or reveal card for a silenced scheduler completion', async () => {
vi.useFakeTimers();
try {
diff --git a/apps/desktop/src/main/agent-island/service.ts b/apps/desktop/src/main/agent-island/service.ts
index 06bf578cac..7ba015912e 100644
--- a/apps/desktop/src/main/agent-island/service.ts
+++ b/apps/desktop/src/main/agent-island/service.ts
@@ -786,7 +786,13 @@ export class AgentIslandService {
const suppressCompletionAttention = this.isCompletionEventSilenced(hydrated.sessionId, event);
const changed = applyAgentIslandEvent(this.state, hydrated, event, now, {
suppressCompletionAttention,
- preserveCompletionAttention: suppressCompletionAttention && this.hadAttentionBeforeSilencedRun(hydrated.sessionId),
+ // Direct IM sends bypass handleUserPrompt. Running preserves unread in the
+ // live state/ledger, so use that state (including any intervening read ack).
+ preserveCompletionAttention: suppressCompletionAttention && (
+ event.turnOrigin?.surface === 'im'
+ ? hasAgentIslandSessionAttention(this.state, hydrated.sessionId)
+ : this.hadAttentionBeforeSilencedCompletion(hydrated.sessionId)
+ ),
allowCompletionAfterTerminalError:
isRemoteDaemonClosedErrorEvent(event) &&
this.deps.isPlannedRemoteDaemonClose?.(hydrated.sessionId) === true,
@@ -1384,7 +1390,7 @@ export class AgentIslandService {
private isCompletionEventSilenced(sessionId: string, event: AgentEvent): boolean {
if (!isCompletionDoneEvent(event)) return false;
- return this.silencedSessionRunIds.has(sessionId);
+ return event.turnOrigin?.surface === 'im' || this.silencedSessionRunIds.has(sessionId);
}
private hadAttentionBeforeSilencedRun(sessionId: string): boolean {
diff --git a/apps/desktop/src/main/hook-control/__tests__/session-runner.test.ts b/apps/desktop/src/main/hook-control/__tests__/session-runner.test.ts
index 20f2f2b114..bf578e7a19 100644
--- a/apps/desktop/src/main/hook-control/__tests__/session-runner.test.ts
+++ b/apps/desktop/src/main/hook-control/__tests__/session-runner.test.ts
@@ -561,6 +561,17 @@ describe('hook session-runner 的 userSendAt 时序(未分类误判回归)', ()
agentMeta: expect.objectContaining({ hookSource: { im: 'slack', contextSnapshot } }),
}));
});
+ it.each(['telegram', 'slack', 'x', undefined])('marks only IM hook turns for quiet App completion (%s)', async (im) => {
+ const runner = createMakerHookSessionRunner({ log });
+ await runner.run(baseReq(im ? { source: { im } } : {}));
+ const session = await fakeMaker.createSession.mock.results[0].value;
+ expect(session.send.mock.calls[0][1].origin).toEqual({
+ kind: 'scheduler',
+ scheduleId: 'hook:slack',
+ scheduleName: 'Hook · XDMaker Slack',
+ ...(im ? { surface: 'im' } : {}),
+ });
+ });
it.each(['telegram', 'slack', 'x', 'future'])('does not infer context from user-controlled prompt for %s hooks', async (im) => {
const runner = createMakerHookSessionRunner({ log });
const prompt = '<group_chat_context>\n[群里最近的消息]\n[Alice] background\n</group_chat_context>\nTechnical guidance\nquestion';
diff --git a/apps/desktop/src/main/hook-control/session-runner.ts b/apps/desktop/src/main/hook-control/session-runner.ts
index 2867806431..0a1759bd7b 100644
--- a/apps/desktop/src/main/hook-control/session-runner.ts
+++ b/apps/desktop/src/main/hook-control/session-runner.ts
@@ -922,6 +922,7 @@ export function createMakerHookSessionRunner(deps: {
kind: 'scheduler',
scheduleId: `hook:${req.origin.connectionId}`,
scheduleName: `Hook · ${req.origin.connectionName}`,
+ ...(req.source?.im ? { surface: 'im' as const } : {}),
} as const;
// 入站附件: 解码后图片/文件分流(server 2026-07 起全 MIME 转发) ->
diff --git a/apps/desktop/src/main/im/shared/__tests__/turnRunnerSendOutcome.test.ts b/apps/desktop/src/main/im/shared/__tests__/turnRunnerSendOutcome.test.ts
index 16e08e84fe..11de28e405 100644
--- a/apps/desktop/src/main/im/shared/__tests__/turnRunnerSendOutcome.test.ts
+++ b/apps/desktop/src/main/im/shared/__tests__/turnRunnerSendOutcome.test.ts
@@ -607,6 +607,9 @@ describe('turnRunner send outcome policy (feishu adapter characterization)', ()
expect(streamingHandle.finalize).toHaveBeenCalledTimes(1);
});
expect(h.send).toHaveBeenCalledTimes(1);
+ expect(h.send).toHaveBeenCalledWith(expect.anything(), expect.objectContaining({
+ origin: { kind: 'user', surface: 'im' },
+ }));
expect(mocks.persistUserMessage).toHaveBeenCalledTimes(1);
expect(mocks.feishuIm.reactToMessage).toHaveBeenCalledTimes(1);
expect(mocks.feishuIm.removeMessageReaction).toHaveBeenCalledTimes(1);
diff --git a/apps/desktop/src/main/im/shared/turnRunner.ts b/apps/desktop/src/main/im/shared/turnRunner.ts
index 4c619f7225..f722c3955a 100644
--- a/apps/desktop/src/main/im/shared/turnRunner.ts
+++ b/apps/desktop/src/main/im/shared/turnRunner.ts
@@ -1311,6 +1311,8 @@ export function createTurnRunner(
const sendResult = await state.makerSession.send(outgoingMessage as typeof item.userMessage, {
planMode: false,
+ // IM owns successful replies, including turns in an attached desktop task.
+ origin: { kind: 'user', surface: 'im' },
// The channel adapter and routing state live in Main. A symbol-keyed
// context survives the in-process Session → Agent handoff but cannot be
// fabricated by Renderer/device-link structured-clone input.
diff --git a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
index deed17b6e9..b0da05d159 100644
--- a/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerChatStoreTextDeltaBatching.test.ts
@@ -513,6 +513,29 @@ const flushPromises = async () => {
};
describe('makerChatStore text delta batching', () => {
+ it.each(['local', 'remote'])('retains IM completion provenance through %s ingress and resets it for App turns', (source) => {
+ if (source === 'remote') remoteProjectsStore.pinSessionOrigin('device-1', SESSION_ID);
+ const emit = (event: unknown) => {
+ const payload = { sessionId: SESSION_ID, event };
+ if (source === 'remote') onRemotePush?.({ deviceId: 'device-1', channel: 'maker:event', payload });
+ else onEvent?.(payload);
+ };
+ const turnOrigin = { kind: 'user', surface: 'im' };
+ emit({ type: 'status', data: { isRunning: true }, turnOrigin });
+ emit({ type: 'status', data: { isRunning: false, status: 'Done' }, turnOrigin });
+ expect(makerChatStore.wasLastStopQuietCompletion(SESSION_ID)).toBe(true);
+ emit({ type: 'done', data: {}, turnOrigin });
+ expect(makerChatStore.wasLastStopQuietCompletion(SESSION_ID)).toBe(true);
+ emit({ type: 'done', data: {} });
+ expect(makerChatStore.wasLastStopQuietCompletion(SESSION_ID)).toBe(true);
+ emit({ type: 'status', data: { isRunning: false } });
+ expect(makerChatStore.wasLastStopQuietCompletion(SESSION_ID)).toBe(true);
+ emit({ type: 'status', data: { isRunning: true } });
+ expect(makerChatStore.wasLastStopQuietCompletion(SESSION_ID)).toBe(false);
+ emit({ type: 'done', data: {} });
+ expect(makerChatStore.wasLastStopQuietCompletion(SESSION_ID)).toBe(false);
+ });
+
it('repairs remote text before new deltas and ignores a repair after durable takeover', () => {
remoteProjectsStore.pinSessionOrigin('device-1', SESSION_ID);
const send = (channel: string, payload: unknown, deviceId = 'device-1') => onRemotePush?.({ deviceId, channel, payload });
diff --git a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts
index 255400a82c..d66463d370 100644
--- a/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts
+++ b/apps/desktop/src/renderer/__tests__/useSessionRunningStatusSilence.test.ts
@@ -26,6 +26,7 @@ const storeMock = vi.hoisted(() => ({
terminalErrorSessions: new Set<string>(),
sideTaskStopSessions: new Set<string>(),
privateReplySessions: new Set<string>(),
+ imSessions: new Set<string>(),
groupLaneSessions: new Set<string>(),
recoverySessions: new Set<string>(),
heldByAgentIsland: new Set<string>(),
@@ -49,7 +50,8 @@ vi.mock('@/lib/makerChatStore', () => ({
getRunningSnapshot: () => storeMock.snapshot,
hasSessionTerminalError: (sessionId: string) => storeMock.terminalErrorSessions.has(sessionId),
hasSessionRecoveryPending: (sessionId: string) => storeMock.recoverySessions.has(sessionId),
- wasLastStopPrivateReply: (sessionId: string) => storeMock.privateReplySessions.has(sessionId),
+ wasLastStopQuietCompletion: (sessionId: string) =>
+ storeMock.privateReplySessions.has(sessionId) || storeMock.imSessions.has(sessionId),
wasLastStopGroupLane: (sessionId: string) => storeMock.groupLaneSessions.has(sessionId),
wasLastStopSideTask: (sessionId: string) => storeMock.sideTaskStopSessions.has(sessionId),
hasPausedQueue: (sessionId: string) => storeMock.pausedQueueSessions.has(sessionId),
@@ -94,6 +96,7 @@ describe('useSessionRunningStatus silenced completion handling', () => {
storeMock.terminalErrorSessions.clear();
storeMock.sideTaskStopSessions.clear();
storeMock.privateReplySessions.clear();
+ storeMock.imSessions.clear();
storeMock.recoverySessions.clear();
storeMock.heldByAgentIsland.clear();
storeMock.pausedQueueSessions.clear();
@@ -104,6 +107,33 @@ describe('useSessionRunningStatus silenced completion handling', () => {
vi.useRealTimers();
});
+ it.each(['before-stop', 'during-debounce', 'missing-snapshot'])('keeps IM completion quiet (%s), but alerts for the next App turn and errors', async (timing) => {
+ vi.useFakeTimers();
+ const onSessionDone = vi.fn();
+ const onSessionError = vi.fn();
+ renderHook(() => useSessionRunningStatus(undefined, { onSessionDone, onSessionError }));
+ await emitSnapshot(new Map([['im', status(true)]]));
+ if (timing !== 'during-debounce') storeMock.imSessions.add('im');
+ await emitSnapshot(timing === 'missing-snapshot' ? new Map() : new Map([['im', status(false)]]));
+ storeMock.imSessions.add('im');
+ await act(async () => { await vi.advanceTimersByTimeAsync(1000); });
+ expect(addSessionAttention).not.toHaveBeenCalled();
+ expect(onSessionDone).not.toHaveBeenCalled();
+
+ storeMock.imSessions.clear();
+ await emitSnapshot(new Map([['im', status(true)]]));
+ await emitSnapshot(new Map([['im', status(false)]]));
+ await act(async () => { await vi.advanceTimersByTimeAsync(1000); });
+ expect(addSessionAttention).toHaveBeenCalledWith('im', 'done');
+ expect(onSessionDone).toHaveBeenCalledExactlyOnceWith('im');
+
+ await emitSnapshot(new Map([['im', status(true)]]));
+ storeMock.imSessions.add('im');
+ await emitSnapshot(new Map([['im', status(false, true)]]));
+ expect(addSessionAttention).toHaveBeenCalledWith('im', 'error');
+ expect(onSessionError).toHaveBeenCalledExactlyOnceWith('im');
+ });
+
it.each([false, true])('keeps recovery quiet until final success (missing stop snapshot: %s)', async (missing) => {
vi.useFakeTimers();
const onSessionDone = vi.fn();
diff --git a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts
index 7c0450b6c4..30f440bc0c 100644
--- a/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts
+++ b/apps/desktop/src/renderer/hooks/useSessionRunningStatus.ts
@@ -210,7 +210,7 @@ export function useSessionRunningStatus(
// 把系统通知发出去。标记的清除只由 scheduler 事件驱动,见
// silencedSessionDoneStore 的文件头注释。
const isSilencedDone = !hasError && (isSessionDoneSilenced(sessionId)
- || makerChatStore.wasLastStopPrivateReply(sessionId));
+ || makerChatStore.wasLastStopQuietCompletion(sessionId));
// Scheduler 已按 schedule.notify 接管这次终态的桌面 / 飞书通知。这里只
// 抑制 callback。成功绿点改认 schedule 未读,不再从这条 running→done 点
// `done` attention;失败红点仍立即挂。debounce 落地还会再读一次标记,
@@ -286,7 +286,7 @@ export function useSessionRunningStatus(
cur.hasPendingPluginSetup);
// silenced 可能在 debounce 窗口内才到:转换当时没静默、进了 debounce,落地必须再读。
if (!hasTerminalError && (isSessionDoneSilenced(sessionId)
- || makerChatStore.wasLastStopPrivateReply(sessionId))) return;
+ || makerChatStore.wasLastStopQuietCompletion(sessionId))) return;
const ownedNow = isSessionTerminalNotificationOwnedByScheduler(sessionId);
if (
!wasActiveAtCompletion &&
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 1a49261ca0..9dfc08a7fd 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -2734,6 +2734,8 @@ export interface SessionChatState {
lastStopWasSideTask: boolean;
/** Successful automatic private replies remain in history without completion alerts. */
lastStopWasPrivateReply?: boolean;
+ /** IM owns this turn's successful reply; do not duplicate its unread indicator. */
+ lastStopWasIm?: boolean;
/** The last turn ran in a hidden Bot group lane; the group chat owns its alerts. */
lastStopWasGroupLane?: boolean;
/**
@@ -6208,6 +6210,9 @@ export function handleStreamEvent(
pendingRemoteDesktopConfirmation: null,
pendingRemoteDesktopConfirmationQueue: [],
lastStopWasPrivateReply: (incomingMeta ?? state.lastAgentMeta)?.botPrivateReply === true,
+ // An originless terminal tail must retain the provenance from status.
+ // The next running transition resets this marker for a new App turn.
+ lastStopWasIm: event.turnOrigin ? event.turnOrigin.surface === 'im' : state.lastStopWasIm,
lastStopWasGroupLane: (incomingMeta ?? state.lastAgentMeta)?.botGroupLane === true,
// agent-meta: turn 结束清空,下一 turn 重新累积。
lastAgentMeta: null,
@@ -7125,6 +7130,7 @@ function handleStatusUpdate(
// 真实 turn 的起/止都把 side-task 标记复位(它只描述「最近一次 stop」)。
lastStopWasSideTask: false,
lastStopWasPrivateReply: update.isRunning ? false : state.lastStopWasPrivateReply,
+ lastStopWasIm: update.isRunning ? false : state.lastStopWasIm,
lastStopWasGroupLane: update.isRunning ? false : state.lastStopWasGroupLane,
// 唤醒桥接:仅在 wake turn 真正启动(isRunning:true)时消费一个计数,或 wake turn
// 失败时消费——后者表现为 Done + !isRunning 且主 turn 已经结束
@@ -7215,6 +7221,7 @@ type MakerEventPayload = {
agentMeta?: Record<string, unknown>;
turnContinuationId?: number;
turnScope?: 'turn' | 'background';
+ turnOrigin?: CCAgentStreamEvent['turnOrigin'];
};
persistId?: string;
resolvedContent?: string;
@@ -7459,6 +7466,7 @@ function dispatchStreamEventPayload(
? { turnContinuationId: event.turnContinuationId }
: {}),
...(event.turnScope !== undefined ? { turnScope: event.turnScope } : {}),
+ ...(event.turnOrigin !== undefined ? { turnOrigin: event.turnOrigin } : {}),
persistId,
resolvedContent,
} as CCAgentStreamEvent;
@@ -7867,7 +7875,13 @@ function initGlobalListeners(options: GlobalListenerOptions = {}): void {
if (!isTurnContinuationBoundaryEvent(event) && !update.skipTurnReset && !update.isRunning) {
supersedeInputProjectionRequests(sessionId, { supersedeOperations: true });
}
- setState(sessionId, (s) => handleStatusUpdate(s, update));
+ setState(sessionId, (s) => {
+ const next = handleStatusUpdate(s, update);
+ if (isTurnContinuationBoundaryEvent(event) || update.skipTurnReset || update.isRunning) return next;
+ return event.turnOrigin
+ ? { ...next, lastStopWasIm: event.turnOrigin.surface === 'im' }
+ : next;
+ });
scheduleWakeBridgeReconciliation(sessionId);
return;
}
@@ -17369,8 +17383,10 @@ export const makerChatStore = {
hasSessionTerminalError,
hasSessionRecoveryPending,
wasLastStopSideTask,
- wasLastStopPrivateReply: (sessionId: string): boolean =>
- sessions.get(sessionId)?.lastStopWasPrivateReply === true,
+ wasLastStopQuietCompletion: (sessionId: string): boolean => {
+ const state = sessions.get(sessionId);
+ return state?.lastStopWasPrivateReply === true || state?.lastStopWasIm === true;
+ },
wasLastStopGroupLane: (sessionId: string): boolean =>
sessions.get(sessionId)?.lastStopWasGroupLane === true,
/** 输入框推荐后台完成配对用的 non-creating turn 起点。 */
diff --git a/apps/desktop/src/renderer/vite-env.d.ts b/apps/desktop/src/renderer/vite-env.d.ts
index c75952486c..f090c84928 100644
--- a/apps/desktop/src/renderer/vite-env.d.ts
+++ b/apps/desktop/src/renderer/vite-env.d.ts
@@ -727,6 +727,8 @@ interface CodexUsageSnapshot {
interface CCAgentStreamEvent {
sessionId: string;
+ /** Host-owned per-turn source, independent of the session's original channel. */
+ turnOrigin?: import('@cindy/maker-core').SendOrigin;
type:
| 'text'
| 'tool_use'
diff --git a/docs/product-rules/core-product-principles.md b/docs/product-rules/core-product-principles.md
index 3a15ad7f5b..204e4fd308 100644
--- a/docs/product-rules/core-product-principles.md
+++ b/docs/product-rules/core-product-principles.md
@@ -87,6 +87,13 @@ UI 的责任是隐藏系统复杂度,让用户看懂状态、理解结果、
- 渠道没有保存快照属于数据接入缺口,不是采用另一套展示规则的理由;不得为视觉统一
擅自扩大持久化范围,受保护内容不落库等边界仍然有效。
+#### IM 交互的 App 未读提示
+
+IM 侧发起的交互主要在 IM 平台查看,成功回复默认不在 Cindy App 产生完成未读绿点,
+也不重复发送 App 完成提醒;桌面、手机和远程控制端使用同一口径。按本轮输入来源判断,
+同一任务改由 App 发起的后续交互仍正常提醒。消息历史保留,已有未读、错误及待确认提示
+不因这次成功回复被清除或静默。
+
### 4.2 Agent 与模型连接
Cindy 应让用户方便地接入、选择和使用不同 Agent 与模型,同时保持统一的产品体验。
diff --git a/docs/product-rules/telegram-bot-parity.md b/docs/product-rules/telegram-bot-parity.md
index db863ac319..c48a5b920f 100644
--- a/docs/product-rules/telegram-bot-parity.md
+++ b/docs/product-rules/telegram-bot-parity.md
@@ -37,6 +37,13 @@ Cindy 有两个 Telegram bot,用户看到的是同一个产品:
## 一、已同源
+官方与个人 bot 的 IM 轮次都通过 `SendOrigin.surface = 'im'` 标记成功回复的查看入口;
+App 完成未读与提醒统一由 `renderer/hooks/useSessionRunningStatus.ts` 和
+`main/agent-island/service.ts` 静默处理,后者也负责手机/远程状态。消息历史、错误、
+待确认提示及先前已有未读保留;同一任务由 App 发起的后续轮次恢复正常完成提醒。
+来源分别由 `hook-control/session-runner.ts` 与 `im/shared/turnRunner.ts` 在发送时标记,
+不改变两侧既有工具授权或 Telegram 消息呈现规则。
+
> **这一节只放两侧真的跑同一份代码/同一份数据的东西。** 一旦列进来,维护者就会跳过
> 双路核对——所以「个人侧独有」「官方侧独有」的能力不能放这里,哪怕它在共享目录下。
>
diff --git a/packages/maker-core/src/session.origin.test.ts b/packages/maker-core/src/session.origin.test.ts
index e71ab556cc..36332d388d 100644
--- a/packages/maker-core/src/session.origin.test.ts
+++ b/packages/maker-core/src/session.origin.test.ts
@@ -318,19 +318,19 @@ describe('Session per-turn origin 打标', () => {
releaseLease();
});
- it('带 origin 的 send → 本轮每个事件都带同一 turnOrigin;done 后清空', async () => {
+ it.each([SCHED_ORIGIN, { kind: 'user', surface: 'im' } as const])('带 origin 的 send → 本轮每个事件都带同一 turnOrigin;done 后清空 (%j)', async (origin) => {
const { handle, emit } = createControllableHandle();
const session = makeSession(handle);
const seen: AgentEvent[] = [];
session.onEvent((e) => seen.push({ ...e }));
- await session.send('go', { origin: SCHED_ORIGIN });
+ await session.send('go', { origin });
await emit({ type: 'text', data: { text: 'hi', isFinal: false } });
await emit({ type: 'done', data: {} });
expect(seen.map((e) => e.type)).toEqual(['text', 'done']);
- expect(seen[0]!.turnOrigin).toEqual(SCHED_ORIGIN);
- expect(seen[1]!.turnOrigin).toEqual(SCHED_ORIGIN); // 终止事件本身也带 origin
+ expect(seen[0]!.turnOrigin).toEqual(origin);
+ expect(seen[1]!.turnOrigin).toEqual(origin); // 终止事件本身也带 origin
// done 之后的事件(下一轮还没 send)不应再带 origin —— 已清空
await emit({ type: 'status', data: { isRunning: false } });
diff --git a/packages/maker-core/src/types/events.ts b/packages/maker-core/src/types/events.ts
index a89cb395cc..2058bd6f73 100644
--- a/packages/maker-core/src/types/events.ts
+++ b/packages/maker-core/src/types/events.ts
@@ -138,6 +138,8 @@ export interface AgentTaskUpdateEventData {
*/
export interface SendOrigin {
kind: 'user' | 'scheduler' | 'goal';
+ /** IM user turns deliver their successful replies on that surface, without App completion alerts. */
+ surface?: 'im';
/** scheduler 来源时的任务标识(供 IM 转播时显示"哪个自动任务")。 */
scheduleId?: string;
scheduleName?: string;