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): 灵动岛与通知点进任务不再等待重读伙伴列表

Dashef91237628dd
diff --git a/apps/desktop/src/renderer/components/layout/MainLayout.tsx b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
index 93b24b7b0f..5fb0bafb56 100644
--- a/apps/desktop/src/renderer/components/layout/MainLayout.tsx
+++ b/apps/desktop/src/renderer/components/layout/MainLayout.tsx
@@ -107,7 +107,7 @@ import { makeFolderPickerNewMakerRouteState } from '@/features/cc-agent/lib/newM
import { makeGenericNewMakerRouteState } from '@/features/cc-agent/lib/genericNewMakerRouteState';
import { resolveSessionRoute } from '@/lib/orcaSessionIdentity';
import { ensureBotProfilesLoaded, getBotProfiles } from '@/features/bots/botStore';
-import { createSessionEntryNavigator, resolveBotRouteForSessionEntry } from '@/features/bots/botSessionOwners';
+import { botRouteForOwnedSession, createSessionEntryNavigator, resolveBotRouteForSessionEntry } from '@/features/bots/botSessionOwners';
import { useSessionEntryLocationCommits } from '@/features/bots/useSessionEntryLocationCommits';
import { islandEntryRouteState, requestIslandEntryAlertDisposal } from '@/features/bots/islandEntryAlert';
import { requestProviderShareJoin } from '@/features/provider-share/joinIntent';
@@ -563,6 +563,7 @@ export function MainLayout() {
// One navigator for the layout's lifetime: its sequence must span re-renders so a
// late lookup for an earlier notification cannot override a newer click.
const [navigateToSession] = useState(() => createSessionEntryNavigator({
+ readKnownBotRoute: (sessionId) => botRouteForOwnedSession(getBotProfiles(), sessionId),
resolveBotRoute: (sessionId) => resolveBotRouteForSessionEntry(sessionId, {
readProfiles: getBotProfiles,
loadProfiles: ensureBotProfilesLoaded,
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/botSessionOwners.test.ts b/apps/desktop/src/renderer/features/bots/__tests__/botSessionOwners.test.ts
index e1a9dc3b7c..0427d6eda8 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/botSessionOwners.test.ts
+++ b/apps/desktop/src/renderer/features/bots/__tests__/botSessionOwners.test.ts
@@ -208,12 +208,29 @@ describe('通知入口在伙伴投影未加载时的路由', () => {
expect(loadProfiles).toHaveBeenCalledTimes(1);
});
+ // 灵动岛 / 通知点进普通任务曾要先等整份伙伴列表重读完(实测 0.1–7 秒)才开始跳转。
+ it('投影不认识的任务立刻打开普通任务页,不等伙伴投影重读', () => {
+ const openOrdinary = vi.fn();
+ const resolveBotRoute = vi.fn(() => new Promise<BotSessionEntryTarget | null>(() => undefined));
+ const open = createSessionEntryNavigator({
+ readKnownBotRoute: () => null,
+ resolveBotRoute,
+ openBotRoute: vi.fn(),
+ consumeAlert: vi.fn(),
+ openOrdinary,
+ });
+ open('plain', 'message-1', 'entry-1');
+ expect(openOrdinary).toHaveBeenCalledWith('plain', 'message-1', expect.any(Function));
+ expect(resolveBotRoute).toHaveBeenCalledWith('plain');
+ });
+
it('连续点击时,先点的慢查询不会覆盖后点的导航', async () => {
const pending = new Map<string, (target: BotSessionEntryTarget | null) => void>();
const openBotRoute = vi.fn();
const openOrdinary = vi.fn();
const consumeAlert = vi.fn();
const open = createSessionEntryNavigator({
+ readKnownBotRoute: () => null,
resolveBotRoute: (sessionId) => new Promise((resolve) => pending.set(sessionId, resolve)),
openBotRoute,
consumeAlert,
@@ -221,40 +238,93 @@ describe('通知入口在伙伴投影未加载时的路由', () => {
});
open('first');
open('second', 'message-1');
- pending.get('second')!(null);
- await Promise.resolve();
- expect(openOrdinary).toHaveBeenCalledWith('second', 'message-1', expect.any(Function));
- // A superseded click neither navigates nor disposes its Session's alert.
+ // A superseded click's late re-read neither navigates nor disposes its Session's alert.
pending.get('first')!({ route: '/bots/groups/g-1', consumesAlert: true });
await Promise.resolve();
expect(openBotRoute).not.toHaveBeenCalled();
expect(consumeAlert).not.toHaveBeenCalled();
// The ordinary path's own late async route checks the same latest gate.
- const isLatest = openOrdinary.mock.calls[0]![2] as () => boolean;
- expect(isLatest()).toBe(true);
+ const isFirstLatest = openOrdinary.mock.calls[0]![2] as () => boolean;
+ const isSecondLatest = openOrdinary.mock.calls[1]![2] as () => boolean;
+ expect(isFirstLatest()).toBe(false);
+ expect(isSecondLatest()).toBe(true);
open('third');
- expect(isLatest()).toBe(false);
+ expect(isSecondLatest()).toBe(false);
});
- it('后台任务走普通任务入口,保留消息锚点与灵动岛上报', async () => {
+ it('后台任务走普通任务入口,保留消息锚点与灵动岛上报,也不重读投影', async () => {
const openBotRoute = vi.fn();
const openOrdinary = vi.fn();
const consumeAlert = vi.fn();
+ const resolveBotRoute = vi.fn(async () => null);
const open = createSessionEntryNavigator({
- resolveBotRoute: async () => ({ route: '/cc-agent/s-task', consumesAlert: false }),
+ readKnownBotRoute: () => ({ route: '/cc-agent/s-task', consumesAlert: false }),
+ resolveBotRoute,
consumeAlert,
openBotRoute,
openOrdinary,
});
open('s-task', 'message-9', 'entry-task');
- await Promise.resolve();
- await Promise.resolve();
open.locationCommitted('/cc-agent/s-task');
expect(consumeAlert).not.toHaveBeenCalled();
expect(openBotRoute).not.toHaveBeenCalled();
+ expect(resolveBotRoute).not.toHaveBeenCalled();
expect(openOrdinary).toHaveBeenCalledWith('s-task', 'message-9', expect.any(Function));
});
+ describe('投影尚未认识的伙伴任务:先开普通任务页,重读后转到伙伴页(§6.2)', () => {
+ function setup() {
+ let resolveTarget!: (target: BotSessionEntryTarget | null) => void;
+ const openBotRoute = vi.fn();
+ const openOrdinary = vi.fn();
+ const consumeAlert = vi.fn();
+ const open = createSessionEntryNavigator({
+ readKnownBotRoute: () => null,
+ resolveBotRoute: () => new Promise((resolve) => { resolveTarget = resolve; }),
+ openBotRoute,
+ consumeAlert,
+ openOrdinary,
+ });
+ const isOrdinaryLatest = () => (openOrdinary.mock.lastCall![2] as () => boolean)();
+ return { open, openBotRoute, consumeAlert, resolve: (t: BotSessionEntryTarget | null) => resolveTarget(t), isOrdinaryLatest };
+ }
+ const lane: BotSessionEntryTarget = { route: '/bots/groups/g-1', consumesAlert: true };
+
+ it('已落在该任务的普通页时转到伙伴页,并照常处置这次点击', async () => {
+ const { open, openBotRoute, consumeAlert, resolve } = setup();
+ open.locationCommitted('/cc-agent/new');
+ open('s-lane', undefined, 'entry-1');
+ open.locationCommitted('/cc-agent/s-lane');
+ resolve(lane);
+ await Promise.resolve();
+ expect(openBotRoute).toHaveBeenCalledWith('/bots/groups/g-1', undefined);
+ open.locationCommitted('/bots/groups/g-1');
+ expect(consumeAlert).toHaveBeenCalledWith('s-lane', 'entry-1');
+ });
+
+ it('普通页还没落地就重读完成:取消普通页导航,直接去伙伴页', async () => {
+ const { open, openBotRoute, resolve, isOrdinaryLatest } = setup();
+ open.locationCommitted('/cc-agent/new');
+ open('s-lane');
+ resolve(lane);
+ await Promise.resolve();
+ expect(openBotRoute).toHaveBeenCalledWith('/bots/groups/g-1', undefined);
+ expect(isOrdinaryLatest()).toBe(false);
+ });
+
+ it('用户已去了别处时不再拉回伙伴页,也不处置', async () => {
+ const { open, openBotRoute, consumeAlert, resolve } = setup();
+ open.locationCommitted('/cc-agent/new');
+ open('s-lane', undefined, 'entry-2');
+ open.locationCommitted('/elsewhere');
+ resolve(lane);
+ await Promise.resolve();
+ open.locationCommitted('/bots/groups/g-1');
+ expect(openBotRoute).not.toHaveBeenCalled();
+ expect(consumeAlert).not.toHaveBeenCalled();
+ });
+ });
+
describe('灵动岛点击的处置等目标地址提交后才发', () => {
const targets: Record<string, BotSessionEntryTarget> = {
's-lane': { route: '/bots/groups/g-1', consumesAlert: true },
@@ -265,7 +335,8 @@ describe('通知入口在伙伴投影未加载时的路由', () => {
const openBotRoute = vi.fn(over.openBotRoute ?? (() => undefined));
const consumeAlert = vi.fn();
const open = createSessionEntryNavigator({
- resolveBotRoute: async (sessionId) => targets[sessionId] ?? null,
+ readKnownBotRoute: (sessionId) => targets[sessionId] ?? null,
+ resolveBotRoute: async () => null,
openBotRoute,
consumeAlert,
openOrdinary: vi.fn(),
@@ -359,59 +430,12 @@ describe('通知入口在伙伴投影未加载时的路由', () => {
expect(consumeAlert).not.toHaveBeenCalled();
});
- it('解析尚未完成时地址已提交(改去别处或自己打开了目标):照常导航但不代为处置', async () => {
- let resolveTarget!: (target: BotSessionEntryTarget | null) => void;
- const openBotRoute = vi.fn();
- const consumeAlert = vi.fn();
- const open = createSessionEntryNavigator({
- resolveBotRoute: () => new Promise((resolve) => { resolveTarget = resolve; }),
- openBotRoute,
- consumeAlert,
- openOrdinary: vi.fn(),
- });
- open.locationCommitted('/cc-agent/new');
- // The user moves elsewhere while the Bot projection is still loading.
- open('s-lane', undefined, 'entry-5');
- open.locationCommitted('/elsewhere');
- resolveTarget(targets['s-lane']!);
- await settle();
- expect(openBotRoute).toHaveBeenCalledWith('/bots/groups/g-1', undefined);
- open.locationCommitted('/bots/groups/g-1');
- expect(consumeAlert).not.toHaveBeenCalled();
-
- // The user opens the target address themselves before the lookup returns.
- open('s-lane', undefined, 'entry-6');
+ it('导航抛错时丢弃待处置,之后到达同一地址也不处置', async () => {
+ const { open, consumeAlert } = setup({ openBotRoute: () => { throw new Error('blocked'); } });
open.locationCommitted('/cc-agent/new');
- open.locationCommitted('/bots/groups/g-1');
- resolveTarget(targets['s-lane']!);
- await settle();
+ expect(() => open('s-lane', undefined, 'entry-4')).toThrow('blocked');
open.locationCommitted('/bots/groups/g-1');
expect(consumeAlert).not.toHaveBeenCalled();
-
- // A history target does not get the click id handed to its gate either.
- open('s-old', undefined, 'entry-9');
- open.locationCommitted('/elsewhere');
- resolveTarget(targets['s-old']!);
- await settle();
- expect(openBotRoute).toHaveBeenLastCalledWith('/bots/bot-a/history/s-old', undefined);
- });
-
- it('导航抛错时丢弃待处置,之后到达同一地址也不处置', async () => {
- const failures: unknown[] = [];
- const onRejection = (reason: unknown) => failures.push(reason);
- process.on('unhandledRejection', onRejection);
- try {
- const { open, consumeAlert } = setup({ openBotRoute: () => { throw new Error('blocked'); } });
- open.locationCommitted('/cc-agent/new');
- open('s-lane', undefined, 'entry-4');
- await settle();
- await new Promise((resolve) => setTimeout(resolve, 0));
- open.locationCommitted('/bots/groups/g-1');
- expect(consumeAlert).not.toHaveBeenCalled();
- } finally {
- process.off('unhandledRejection', onRejection);
- }
- expect(failures).toHaveLength(1);
});
});
diff --git a/apps/desktop/src/renderer/features/bots/__tests__/sessionEntryLocationCommits.test.tsx b/apps/desktop/src/renderer/features/bots/__tests__/sessionEntryLocationCommits.test.tsx
index a2e770a028..d3ca10b68a 100644
--- a/apps/desktop/src/renderer/features/bots/__tests__/sessionEntryLocationCommits.test.tsx
+++ b/apps/desktop/src/renderer/features/bots/__tests__/sessionEntryLocationCommits.test.tsx
@@ -16,7 +16,7 @@ const targets: Record<string, BotSessionEntryTarget> = {
lane: { route: '/bots/groups/g-1', consumesAlert: true },
slow: { route: '/bots/groups/slow', consumesAlert: true },
};
-/** Sessions whose route lookup waits for releaseLookup (e.g. Bot profiles still loading). */
+/** Sessions unknown to the in-memory projection whose re-read waits for releaseLookup. */
const slowLookups = new Set(['lane-slow-lookup']);
const routers: Array<ReturnType<typeof createMemoryRouter>> = [];
@@ -33,12 +33,13 @@ function setup() {
function Shell() {
const navigate = useNavigate();
const [entryNavigator] = useState(() => createSessionEntryNavigator({
+ readKnownBotRoute: (sessionId) => targets[sessionId] ?? null,
resolveBotRoute: async (sessionId) => {
if (slowLookups.has(sessionId)) {
await lookupGate;
return targets.lane!;
}
- return targets[sessionId] ?? null;
+ return null;
},
openBotRoute: (route) => { void navigate(route); },
consumeAlert: (sessionId, islandEntryId) => {
@@ -126,16 +127,15 @@ describe('island card disposal waits for the router to commit the target', () =>
expect(consumeAlert).toHaveBeenCalledExactlyOnceWith('slow', 'entry-3');
});
- it('a commit while the lookup is still resolving forfeits disposal but keeps navigation', async () => {
+ it('a re-read that finds a Bot page after the user moved elsewhere neither navigates nor disposes', async () => {
const { router, consumeAlert, open, releaseLookup } = setup();
await screen.findByText('new task');
await act(async () => open()('lane-slow-lookup', undefined, 'entry-5'));
await act(async () => { void router.navigate('/elsewhere'); });
await screen.findByText('elsewhere');
releaseLookup();
- await screen.findByText('group page');
await flush();
- expect(router.state.location.pathname).toBe('/bots/groups/g-1');
+ expect(router.state.location.pathname).toBe('/elsewhere');
expect(consumeAlert).not.toHaveBeenCalled();
});
diff --git a/apps/desktop/src/renderer/features/bots/botSessionOwners.ts b/apps/desktop/src/renderer/features/bots/botSessionOwners.ts
index 64dfc5c1fc..6e3a404ca6 100644
--- a/apps/desktop/src/renderer/features/bots/botSessionOwners.ts
+++ b/apps/desktop/src/renderer/features/bots/botSessionOwners.ts
@@ -130,6 +130,9 @@ export async function resolveBotRouteForSessionEntry(
}
export interface SessionEntryNavigatorDeps {
+ /** The target from the projection already in memory; null when it does not know the Session. */
+ readKnownBotRoute: (sessionId: string) => BotSessionEntryTarget | null;
+ /** Re-reads the projection for a Session it did not know (see resolveBotRouteForSessionEntry). */
resolveBotRoute: (sessionId: string) => Promise<BotSessionEntryTarget | null>;
/** `islandEntryId` is handed to a route whose gate disposes the card (gateConsumesAlert). */
openBotRoute: (route: string, islandEntryId?: string) => void;
@@ -146,7 +149,12 @@ export interface SessionEntryNavigator {
}
/**
- * Session entries (notification clicks, task deep links) resolve asynchronously.
+ * Session entries (notification clicks, task deep links) open at once from the
+ * Bot projection already in memory. A Session it does not know opens on its
+ * ordinary task page right away while the projection is re-read in the
+ * background; a re-read that finds a Bot page moves this entry there, unless the
+ * user has meanwhile gone anywhere other than that ordinary page. Waiting for
+ * the re-read first made every ordinary task click wait on the whole Bot list.
* Only the latest entry may navigate, so a slow lookup for an earlier click can
* never override a newer one.
*
@@ -154,10 +162,9 @@ export interface SessionEntryNavigator {
* control asks main to dispose that card only once the router has committed the
* target location: immediately when it is already the committed location,
* otherwise on the next committed location if it is the target. A newer entry,
- * any location commit while the entry is still resolving (the user moved on, or
- * opened the target address themselves), or a commit to any other location
- * (redirect, another navigation) drops it, so the card stays and a later click
- * can still dispose it.
+ * the user moving on before the target is known, or a commit to any other
+ * location (redirect, another navigation) drops it, so the card stays and a
+ * later click can still dispose it.
*/
export function createSessionEntryNavigator(
deps: SessionEntryNavigatorDeps,
@@ -166,33 +173,42 @@ export function createSessionEntryNavigator(
let committedPath: string | null = null;
let commitCount = 0;
let pending: { entry: number; sessionId: string; islandEntryId: string; route: string } | null = null;
+ const openBotTarget = (entry: number, sessionId: string, target: BotSessionEntryTarget, disposalId: string | undefined) => {
+ if (target.consumesAlert && disposalId) {
+ if (committedPath === target.route) {
+ deps.consumeAlert(sessionId, disposalId);
+ } else {
+ pending = { entry, sessionId, islandEntryId: disposalId, route: target.route };
+ }
+ }
+ try {
+ deps.openBotRoute(target.route, target.gateConsumesAlert ? disposalId : undefined);
+ } catch (error) {
+ if (pending?.entry === entry) pending = null;
+ throw error;
+ }
+ };
const open = (sessionId: string, messageClientId?: string, islandEntryId?: string) => {
const entry = ++sequence;
pending = null;
const commitsAtOpen = commitCount;
const isLatest = () => sequence === entry;
+ const known = deps.readKnownBotRoute(sessionId);
+ // Background tasks keep their ordinary page with message anchors and visible-session reporting.
+ if (known && !known.route.startsWith('/cc-agent/')) {
+ openBotTarget(entry, sessionId, known, islandEntryId);
+ return;
+ }
+ let movedToBotPage = false;
+ deps.openOrdinary(sessionId, messageClientId, () => isLatest() && !movedToBotPage);
+ if (known) return;
+ const ordinaryRoute = `/cc-agent/${encodeURIComponent(sessionId)}`;
void deps.resolveBotRoute(sessionId).then((target) => {
- if (!isLatest()) return;
- // Ordinary task navigation preserves message anchors and visible-session reporting.
- if (!target || target.route.startsWith('/cc-agent/')) {
- deps.openOrdinary(sessionId, messageClientId, isLatest);
- return;
- }
- // Navigation keeps its existing late-resolution behaviour; only disposal is forfeited.
- const disposalId = islandEntryId && commitCount === commitsAtOpen ? islandEntryId : undefined;
- if (target.consumesAlert && disposalId) {
- if (committedPath === target.route) {
- deps.consumeAlert(sessionId, disposalId);
- } else {
- pending = { entry, sessionId, islandEntryId: disposalId, route: target.route };
- }
- }
- try {
- deps.openBotRoute(target.route, target.gateConsumesAlert ? disposalId : undefined);
- } catch (error) {
- if (pending?.entry === entry) pending = null;
- throw error;
- }
+ if (!isLatest() || !target || target.route.startsWith('/cc-agent/')) return;
+ // Correct only this entry's own landing; any other committed location means the user moved on.
+ if (commitCount !== commitsAtOpen && committedPath !== ordinaryRoute) return;
+ movedToBotPage = true;
+ openBotTarget(entry, sessionId, target, islandEntryId);
});
};
return Object.assign(open, {
diff --git a/docs/product-rules/cindy-bots-runtime.md b/docs/product-rules/cindy-bots-runtime.md
index 0d9fd578e9..09158fc185 100644
--- a/docs/product-rules/cindy-bots-runtime.md
+++ b/docs/product-rules/cindy-bots-runtime.md
@@ -603,6 +603,9 @@ Session 任务遵守同一套机制与呈现契约:
只认最近一次点击时的那张卡:被新点击取代(含同一任务再点一次)、导航被重定向或改去别处(含历史
页校验不通过被重定向走)、点击后又开始新一轮、出现新的失败或完成,或只是直接打开地址,都不处置,
新的提醒照常出现。处置只清提醒,任务记录、失败状态与错误行不变。主任务仍只由报错横幅处置。
+- 通知、灵动岛与任务深链点击立即按内存里的伙伴投影跳转,不等待重读伙伴列表。投影还不认识的任务先
+ 打开普通任务页,同时在后台重读一次投影;若它其实是伙伴的主任务、历史或群专线,再转到对应页面——
+ 前提是用户这期间没有去别处。新挂上的伙伴任务因此可能先短暂显示普通任务页,换来普通任务点击即达。
- iOS 的伙伴正常回复使用系统通信通知:伙伴名字、头像与回复摘要,应用角标由系统绘制。
普通任务、报错和待处理事项保留原通知语义。头像仅携带有界缩略图、内置头像标识或
单个字符,不上传公开头像地址;缺失头像回退名字首字,扩展失败仍交付原通知。