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): sync pinned sessions to mobile (#1492)

天魔5b04cfbfa476
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
index e2836461f7..941102fd75 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
@@ -22,6 +22,7 @@ const h = vi.hoisted(() => ({
persistedSdkSessionId: null,
})),
tapWindowBroadcast: vi.fn(),
+ summarizeSession: vi.fn(async () => undefined),
}));
vi.mock('electron', () => ({
@@ -47,6 +48,9 @@ vi.mock('../recentWorkdirs', () => ({ upsertRecentWorkdir: vi.fn(async () => und
vi.mock('../../../device-link/broadcast-tap.js', () => ({
tapWindowBroadcast: h.tapWindowBroadcast,
}));
+vi.mock('../../../sessionTaskSummary.js', () => ({
+ maybeGenerateSessionTaskSummary: h.summarizeSession,
+}));
vi.mock('../../agentIslandSessionPatch', () => ({ notifyAgentIslandSessionPatch: vi.fn() }));
vi.mock('../../../messagePersistBroadcaster', () => ({ noteSessionClearBoundary: vi.fn() }));
vi.mock('../../../sessionIds', () => ({ resolveBusinessSessionId: (id: string) => id }));
@@ -171,6 +175,51 @@ describe('local-db:sessions:update handler wiring', () => {
);
});
+ it('broadcasts pin and unpin patches to device-link subscribers', async () => {
+ const pinnedAt = '2026-08-03T04:08:26.000Z';
+ await invokeUpdate('codex-local', { pinnedAt });
+ await vi.dynamicImportSettled();
+
+ const pinned = h
+ .sqlite!.prepare('SELECT pinned_at AS pinnedAt FROM sessions WHERE id = ?')
+ .get('codex-local') as { pinnedAt: number | null };
+ expect(pinned.pinnedAt).toBe(Date.parse(pinnedAt));
+ expect(h.tapWindowBroadcast).toHaveBeenCalledWith('local-db:sessions:patched', {
+ sessionId: 'codex-local',
+ patch: { pinnedAt, status: 'active' },
+ });
+ expect(h.summarizeSession).toHaveBeenCalledWith('codex-local');
+
+ h.tapWindowBroadcast.mockClear();
+ h.summarizeSession.mockClear();
+ await invokeUpdate('codex-local', { pinnedAt: null });
+
+ const unpinned = h
+ .sqlite!.prepare('SELECT pinned_at AS pinnedAt FROM sessions WHERE id = ?')
+ .get('codex-local') as { pinnedAt: number | null };
+ expect(unpinned.pinnedAt).toBeNull();
+ expect(h.tapWindowBroadcast).toHaveBeenCalledWith('local-db:sessions:patched', {
+ sessionId: 'codex-local',
+ patch: { pinnedAt: null },
+ });
+ expect(h.summarizeSession).not.toHaveBeenCalled();
+ });
+
+ it('broadcasts the stored value and skips summary generation for an invalid pin date', async () => {
+ await invokeUpdate('codex-local', { pinnedAt: 'not-a-date' });
+ await vi.dynamicImportSettled();
+
+ const persisted = h
+ .sqlite!.prepare('SELECT pinned_at AS pinnedAt FROM sessions WHERE id = ?')
+ .get('codex-local') as { pinnedAt: number | null };
+ expect(persisted.pinnedAt).toBeNull();
+ expect(h.tapWindowBroadcast).toHaveBeenCalledWith('local-db:sessions:patched', {
+ sessionId: 'codex-local',
+ patch: { pinnedAt: null },
+ });
+ expect(h.summarizeSession).not.toHaveBeenCalled();
+ });
+
it('relocates transcripts when workingDir actually changes on a local cc session', async () => {
await invokeUpdate('cc-local', { workingDir: '/new/dir', workspaceKind: 'project' });
diff --git a/apps/desktop/src/main/localDb/ipc/sessions.ts b/apps/desktop/src/main/localDb/ipc/sessions.ts
index 7195619c4c..59335115ea 100644
--- a/apps/desktop/src/main/localDb/ipc/sessions.ts
+++ b/apps/desktop/src/main/localDb/ipc/sessions.ts
@@ -1182,6 +1182,15 @@ export function registerSessionIpc(
}
const row = await selectSessionWithCount(db, sid);
if (!row) throwIpcError('NOT_FOUND', 'Session 不存在');
+ const updated = sessionToCamel(row);
+ const broadcastPatch =
+ p.pinnedAt === undefined
+ ? p
+ : {
+ ...p,
+ pinnedAt: updated.pinnedAt,
+ ...(updated.pinnedAt === null ? {} : { status: updated.status }),
+ };
const projectTargetChanged = p.workspaceKind !== undefined || p.workingDir !== undefined;
const settingsChanged = Object.keys(p).some((key) => REMOTE_PERSIST_FIELDS.has(key));
const titleChanged = p.title !== undefined;
@@ -1193,18 +1202,17 @@ export function registerSessionIpc(
) {
await upsertRecentWorkdir(row.workingDir, Date.now());
}
- if (projectTargetChanged || settingsChanged || titleChanged) {
- broadcastSessionPatched(sid, p);
+ if (projectTargetChanged || settingsChanged || titleChanged || p.pinnedAt !== undefined) {
+ broadcastSessionPatched(sid, broadcastPatch);
}
// sidebar-card-mode: 会话被置顶那一刻补生成任务摘要(turn-done 路径只覆盖
// "置顶后又跑过 turn"的会话)。动态 import 避免 localDb → maker-host 的静态
// 模块环;fire-and-forget,模块内部自带置顶/节流守卫。
- if (p.pinnedAt != null) {
+ if (p.pinnedAt !== undefined && updated.pinnedAt !== null) {
void import('../../sessionTaskSummary.js').then((m) =>
m.maybeGenerateSessionTaskSummary(sid),
);
}
- const updated = sessionToCamel(row);
notifyAgentIslandSessionPatch(updated.id, {
status: updated.status,
title: updated.title,