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(chat): 按设备打开历史任务链接并补齐搜索回归

Dash53004c036bd3
diff --git a/apps/desktop/src/main/maker-host/__tests__/session-search.test.ts b/apps/desktop/src/main/maker-host/__tests__/session-search.test.ts
index 8714535f5e..4dce32ad11 100644
--- a/apps/desktop/src/main/maker-host/__tests__/session-search.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/session-search.test.ts
@@ -15,6 +15,8 @@ vi.mock('../../logger.js', () => ({
warn: vi.fn(),
}),
}));
+vi.mock('../../authManager.js', () => ({ getDeviceId: () => 'host-device' }));
+vi.mock('electron', () => ({ app: {}, BrowserWindow: class {} }));
import { searchSessionsFn } from '../session-search';
@@ -58,6 +60,7 @@ describe('searchSessionsFn', () => {
{
messageId: 'm1',
sessionId: 's1',
+ sessionUrl: 'cindy://session/s1?device=host-device',
role: 'user',
ts: 1,
snippet: '<mark>登录</mark> 报错了',
diff --git a/apps/desktop/src/renderer/__tests__/makerTransportRouting.test.ts b/apps/desktop/src/renderer/__tests__/makerTransportRouting.test.ts
index b48c1589bb..d257db5674 100644
--- a/apps/desktop/src/renderer/__tests__/makerTransportRouting.test.ts
+++ b/apps/desktop/src/renderer/__tests__/makerTransportRouting.test.ts
@@ -276,6 +276,19 @@ describe('makerApiFor 路由(完整对等会话级操作)', () => {
expect(invoke).toHaveBeenCalledWith('dev-1', 'local-db:sessions:get', ['rs']);
});
+ it('history link origin routes an unmirrored archived task through its device', async () => {
+ const { invoke, localSessions } = stubElectron();
+ invoke.mockResolvedValue({ id: 'archived-task', status: 'archived' });
+ const { remoteProjectsStore } = await import('@/features/device-link/remoteProjectsStore');
+ const { resolveSessionRoute } = await import('@/lib/orcaSessionIdentity');
+
+ remoteProjectsStore.pinSessionOrigin('history-host', 'archived-task');
+ await expect(resolveSessionRoute('archived-task')).resolves.toBe('/cc-agent/archived-task');
+
+ expect(invoke).toHaveBeenCalledWith('history-host', 'local-db:sessions:get', ['archived-task']);
+ expect(localSessions.get).not.toHaveBeenCalled();
+ });
+
it('regenerateSessionTitleFor:镜像清空期间仍在被控端自动起名,不回落控制端本机', async () => {
const { makerSpies, invoke } = stubElectron();
invoke.mockResolvedValue({ title: 'remote title' });
diff --git a/apps/desktop/src/renderer/components/chat/SessionLinkChip.tsx b/apps/desktop/src/renderer/components/chat/SessionLinkChip.tsx
index 4066c61535..a2003d5317 100644
--- a/apps/desktop/src/renderer/components/chat/SessionLinkChip.tsx
+++ b/apps/desktop/src/renderer/components/chat/SessionLinkChip.tsx
@@ -23,11 +23,12 @@ import { useTranslation } from 'react-i18next';
import { projectDraftSessionTitle } from '@cindy/maker-shared/session-title';
import { cn } from '@/lib/utils';
+import { useOptionalAuthDeviceId } from '@/contexts/AuthContext';
import { parseSessionDeepLinkHref } from '@/lib/deepLink';
import { getSessionRouteOwnerId, resolveSessionRoute } from '@/lib/orcaSessionIdentity';
import { resolveSessionMessageText } from '@/lib/sessionMessageText';
import * as sessionService from '@/lib/sessionService';
-import { useRemoteProjectSessions } from '@/features/device-link/remoteProjectsStore';
+import { remoteProjectsStore, useRemoteProjectSessions } from '@/features/device-link/remoteProjectsStore';
import {
useSessionNavigationIntent,
useSessionNavigationMode,
@@ -52,6 +53,7 @@ function compactMessageLinkLabel(text: string): string {
export function SessionLinkChip({ href, label }: SessionLinkChipProps) {
const { t } = useTranslation();
const navigate = useNavigate();
+ const localDeviceId = useOptionalAuthDeviceId();
const navigationMode = useSessionNavigationMode();
const reportSessionNavigation = useSessionNavigationIntent();
const target = useMemo(() => parseSessionDeepLinkHref(href), [href]);
@@ -62,20 +64,22 @@ export function SessionLinkChip({ href, label }: SessionLinkChipProps) {
const sessionId = target?.sessionId ?? null;
const messageClientId = target?.messageClientId ?? null;
+ const targetDeviceId = target?.deviceId ?? null;
+ const targetsOtherDevice = !!targetDeviceId && targetDeviceId !== localDeviceId;
const explicitLabel = label?.trim() || null;
useEffect(
() => () => {
navigationRequestVersionRef.current += 1;
},
- [sessionId, messageClientId, navigationMode],
+ [sessionId, messageClientId, targetDeviceId, navigationMode],
);
useEffect(() => {
// 先清旧值:同一实例被复用渲染另一个 href(虚拟列表 / 消息 patch)时,
// 不能让上一个会话的标题串到新链接上(Codex review P2)。
setFetchedTitle(null);
- if (!sessionId || messageClientId || explicitLabel) return;
+ if (!sessionId || messageClientId || explicitLabel || targetsOtherDevice) return;
let cancelled = false;
sessionService
.get(sessionId)
@@ -88,7 +92,7 @@ export function SessionLinkChip({ href, label }: SessionLinkChipProps) {
return () => {
cancelled = true;
};
- }, [sessionId, messageClientId, explicitLabel]);
+ }, [sessionId, messageClientId, explicitLabel, targetsOtherDevice]);
useEffect(() => {
setMessageText(null);
@@ -113,11 +117,22 @@ export function SessionLinkChip({ href, label }: SessionLinkChipProps) {
const remoteTitle = fetchedTitle ? null : remoteSession?.title?.trim() || null;
const handleClick = () => {
const navigationRequestVersion = ++navigationRequestVersionRef.current;
+ const resolveTargetRoute = async () => {
+ if (targetDeviceId) {
+ const selfDeviceId = localDeviceId ?? await window.electronAPI.getDeviceId();
+ if (navigationRequestVersionRef.current !== navigationRequestVersion) return null;
+ // 归档任务可能尚未进入远程镜像;先登记链接的归属,再由现有传输层按设备读取。
+ if (targetDeviceId !== selfDeviceId) {
+ remoteProjectsStore.pinSessionOrigin(targetDeviceId, sessionId);
+ }
+ }
+ return resolveSessionRoute(sessionId, remoteSession);
+ };
// device-link 远程会话本地无 row,resolveSessionRoute 内部的 sessionService.get
// 会 miss → 远程 Orca 会话被当普通会话路由,后续 redirect 会丢 searchJump 锚点。
// 把远程镜像里的 session 对象直接传入,让 Orca 路由一步到位(Codex review P2)。
- void resolveSessionRoute(sessionId, remoteSession).then((route) => {
- if (navigationRequestVersionRef.current !== navigationRequestVersion) return;
+ void resolveTargetRoute().then((route) => {
+ if (!route || navigationRequestVersionRef.current !== navigationRequestVersion) return;
reportSessionNavigation?.(sessionId, getSessionRouteOwnerId(route) ?? sessionId);
navigate(
route,
diff --git a/apps/desktop/src/renderer/components/chat/__tests__/embeddedSessionNavigation.test.tsx b/apps/desktop/src/renderer/components/chat/__tests__/embeddedSessionNavigation.test.tsx
index 65e8b3f19a..7406030259 100644
--- a/apps/desktop/src/renderer/components/chat/__tests__/embeddedSessionNavigation.test.tsx
+++ b/apps/desktop/src/renderer/components/chat/__tests__/embeddedSessionNavigation.test.tsx
@@ -8,6 +8,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
const mocks = vi.hoisted(() => ({
navigate: vi.fn(),
+ pinSessionOrigin: vi.fn(),
resolveSessionRoute: vi.fn(async (sessionId: string) => `/cc-agent/${sessionId}`),
getSession: vi.fn(async (sessionId: string) => ({
id: sessionId,
@@ -40,7 +41,7 @@ vi.mock('@/features/device-link/remoteProjectsStore', () => ({
getSessionDeviceId: () => undefined,
remoteProjectsStore: {
getSessionDeviceId: () => undefined,
- pinSessionOrigin: () => undefined,
+ pinSessionOrigin: mocks.pinSessionOrigin,
},
}));
vi.mock('@/lib/sessionService', () => ({ get: mocks.getSession }));
@@ -125,6 +126,27 @@ describe('sidebar-embedded session navigation boundary', () => {
expect(mocks.navigate).not.toHaveBeenCalled();
});
+ it('routes an unmirrored remote history link through its host before resolving the task', async () => {
+ render(<SessionLinkChip href="cindy://session/archived-task?device=remote-mac" />);
+ expect(mocks.getSession).not.toHaveBeenCalled();
+ expect(mocks.pinSessionOrigin).not.toHaveBeenCalled();
+
+ fireEvent.click(screen.getByRole('button'));
+
+ await waitFor(() => expect(mocks.navigate).toHaveBeenCalledWith('/cc-agent/archived-task', undefined));
+ expect(mocks.pinSessionOrigin).toHaveBeenCalledWith('remote-mac', 'archived-task');
+ expect(mocks.pinSessionOrigin.mock.invocationCallOrder[0]).toBeLessThan(
+ mocks.resolveSessionRoute.mock.invocationCallOrder[0]!,
+ );
+ });
+
+ it('keeps a link to this computer local', async () => {
+ render(<SessionLinkChip href="cindy://session/local-task?device=this-mac" label="Local task" />);
+ fireEvent.click(screen.getByRole('button'));
+ await waitFor(() => expect(mocks.navigate).toHaveBeenCalledWith('/cc-agent/local-task', undefined));
+ expect(mocks.pinSessionOrigin).not.toHaveBeenCalled();
+ });
+
it('reports split-pane session navigation before changing the route', async () => {
const onSessionNavigate = vi.fn();
render(