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(wecom): preserve partial notification updates

DavidShenb939080cce6e
diff --git a/apps/desktop/src/main/localDb/mapper.ts b/apps/desktop/src/main/localDb/mapper.ts
index 762cbe2999..46f48adfd1 100644
--- a/apps/desktop/src/main/localDb/mapper.ts
+++ b/apps/desktop/src/main/localDb/mapper.ts
@@ -443,8 +443,8 @@ function normalizeWorkspaceKind(raw: unknown): WorkspaceKind {
// 与 IPC 边界由 mapper 转 ISO 的旧约定刻意不一致;scheduler 引擎内部就是 ms 算的)。
//
// 关键约束(Phase 2 plan 硬规则):
-// 1. `Schedule.notify` 在内存里是嵌套对象 `{ desktop, feishu }`,DB 端拆成
-// `notify_desktop` / `notify_feishu` 两列;mapper 出口合成回对象,入口拆成两列。
+// 1. `Schedule.notify` 在内存里是嵌套对象 `{ desktop, feishu, wecomGroup? }`,
+// DB 端拆成三列;mapper 出口合成回对象,入口拆成对应列。
// 2. patch mapper(`schedulePatchToRow`)必须区分:
// - key 不存在 → SQL 不更新该列
// - key 存在但值是 undefined → 显式写 NULL
@@ -656,11 +656,17 @@ export function schedulePatchToRow(patch: Partial<Schedule>): Partial<ScheduleIn
out.preRunHookTimeoutMs = patch.preRunHook?.timeoutMs ?? null;
}
if (hasKey(patch, 'notify')) {
- // 嵌套对象整体替换:必须两列同时写
- const n = patch.notify ?? { desktop: false, feishu: false, wecomGroup: false };
- out.notifyDesktop = !!n.desktop;
- out.notifyFeishu = !!n.feishu;
- out.notifyWecomGroup = !!n.wecomGroup;
+ const n = patch.notify;
+ if (n == null) {
+ out.notifyDesktop = false;
+ out.notifyFeishu = false;
+ out.notifyWecomGroup = false;
+ } else {
+ // 兼容不知道新通知渠道的旧客户端:对象内只更新实际出现的 key。
+ if (hasKey(n, 'desktop')) out.notifyDesktop = !!n.desktop;
+ if (hasKey(n, 'feishu')) out.notifyFeishu = !!n.feishu;
+ if (hasKey(n, 'wecomGroup')) out.notifyWecomGroup = !!n.wecomGroup;
+ }
}
if (hasKey(patch, 'status')) out.status = patch.status as ScheduleStatus;
if (hasKey(patch, 'createdAt')) out.createdAt = patch.createdAt as number;
diff --git a/apps/desktop/src/main/notificationService.ts b/apps/desktop/src/main/notificationService.ts
index a529c746ba..c725e64d5f 100644
--- a/apps/desktop/src/main/notificationService.ts
+++ b/apps/desktop/src/main/notificationService.ts
@@ -97,8 +97,8 @@ function buildBody(kind: SessionEventKind): string {
}
/**
- * 飞书私聊文案 — 单行纯文本(lark_md 渲染),保持极简,与桌面 toast 信息一致。
- * 标题 + 状态合并到一行,避免飞书消息列表里显得空荡。
+ * 外部通知通用文案 — 单行纯文本,保持极简并与桌面 toast 信息一致。
+ * 标题 + 状态合并到一行,适用于飞书私聊和企微群消息列表。
*/
function buildExternalNotificationText(title: string, kind: SessionEventKind): string {
const status = kind === 'needs-reply'
diff --git a/apps/desktop/src/main/scheduler-host/__tests__/storage.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/storage.test.ts
index db16fb9674..27fde5eaa2 100644
--- a/apps/desktop/src/main/scheduler-host/__tests__/storage.test.ts
+++ b/apps/desktop/src/main/scheduler-host/__tests__/storage.test.ts
@@ -207,10 +207,20 @@ describe('schedulePatchToRow — patch 清空语义', () => {
expect(out.lastFiredAt).toBeNull();
});
- it('notify 嵌套对象整体替换 → 拆两列', () => {
+ it('notify 对象只更新调用方实际提供的渠道', () => {
const out = schedulePatchToRow({ notify: { desktop: false, feishu: true } });
expect(out.notifyDesktop).toBe(false);
expect(out.notifyFeishu).toBe(true);
+ expect('notifyWecomGroup' in out).toBe(false);
+ });
+
+ it('notify 显式清空时关闭全部渠道', () => {
+ const out = schedulePatchToRow({
+ notify: undefined,
+ });
+ expect(out.notifyDesktop).toBe(false);
+ expect(out.notifyFeishu).toBe(false);
+ expect(out.notifyWecomGroup).toBe(false);
});
it('workspaceKind patch 写 workspace_kind 列', () => {
diff --git a/apps/desktop/src/main/scheduler-host/notifier.ts b/apps/desktop/src/main/scheduler-host/notifier.ts
index e0982ff4b0..504a1917dc 100644
--- a/apps/desktop/src/main/scheduler-host/notifier.ts
+++ b/apps/desktop/src/main/scheduler-host/notifier.ts
@@ -121,7 +121,7 @@ export class DesktopNotifier implements Notifier {
}
/**
- * 把 ScheduleRun 渲染成飞书 lark_md 卡片文案。
+ * 把 ScheduleRun 渲染成外部通知通用文案。
*
* 视觉布局(从上到下):
* 1. 状态标题 — `<emoji> <schedule name>` 加粗,emoji 据 status 区分
@@ -129,9 +129,9 @@ export class DesktopNotifier implements Notifier {
* 3. 元信息 — 时间 · 耗时 · agent · 工作目录(短)
*
* 格式约束:
- * - 用 `**bold**`、列表、emoji,这些 lark_md(div tag) 都支持
- * - URL 直接写,飞书自动识别成可点击链接
- * - 不要带 `code` (cards.ts 里 stripInlineCode 会把 backtick 整对剥掉)
+ * - 仅使用飞书与企微群消息共同支持的 Markdown 子集:`**bold**`、列表、emoji
+ * - URL 直接写,由各渠道按自身能力识别
+ * - 不使用行内 code,避免渠道渲染与清洗规则产生差异
*/
function renderExternalMessage(schedule: Schedule, run: ScheduleRun): string {
const lines: string[] = [`${statusEmoji(run.status)} **${schedule.name}**`];