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): preserve Pi agent switch intent echo (#1858)

Chris Zhangcb7b0c16142d
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts
index 893d01a774..61d8191bc6 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts
@@ -132,6 +132,32 @@ describe('performSessionAgentSwitch', () => {
);
});
+ it('codex → pi + OpenAI 关闭旧会话并保持目标 provider route', async () => {
+ const { deps, calls } = makeDeps({
+ getSessionRow: vi.fn(async () =>
+ makeRow({ agentKind: 'codex', model: 'gpt-5.5-codex', sdkSessionId: 'codex-thread' }),
+ ),
+ });
+
+ const result = await performSessionAgentSwitch(deps, {
+ sessionId: 's1',
+ targetAgentKind: 'pi',
+ model: 'chatgpt/gpt-5.5',
+ providerId: 'openai',
+ applyNow: true,
+ });
+
+ expect(result).toMatchObject({ switched: true, agentKind: 'pi', engineReady: true });
+ expect(calls).toEqual(['close', 'db', 'provider', 'boundary', 'pending', 'bootstrap']);
+ expect(deps.applyAgentSwitchToDb).toHaveBeenCalledWith('s1', {
+ agentKind: 'pi',
+ model: 'chatgpt/gpt-5.5',
+ providerId: 'openai',
+ sdkSessionId: null,
+ });
+ expect(deps.setSessionProvider).toHaveBeenCalledWith('s1', 'openai');
+ });
+
it('跨引擎 DB 提交后立即覆盖旧 provider route', async () => {
const { deps } = makeDeps();
diff --git a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts
index 446a98df6e..54b0903e76 100644
--- a/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts
+++ b/apps/desktop/src/renderer/__tests__/sessionAgentSwitchRemoteRouting.test.ts
@@ -118,6 +118,31 @@ describe('makerChatStore.mirrorAgentSwitchIntent', () => {
expect(makerChatStore.getSnapshot(s)).toBe(snap); // 引用不变 = 未触发更新
});
+ it('回归:Pi 权威回声不得被当成非法值清掉切换意图', async () => {
+ const { makerChatStore } = await import('@/lib/makerChatStore');
+ const s = sid();
+ makerChatStore.noteAgentSwitchIntent(s, 'pi', {
+ model: 'chatgpt/gpt-5.5',
+ providerId: 'openai',
+ });
+ const snap = makerChatStore.getSnapshot(s);
+
+ makerChatStore.mirrorAgentSwitchIntent(s, {
+ targetAgentKind: 'pi',
+ model: 'chatgpt/gpt-5.5',
+ providerId: 'openai',
+ });
+
+ expect(makerChatStore.getSnapshot(s)).toBe(snap);
+ expect(makerChatStore.getSnapshot(s).agentSwitchIntent).toEqual({
+ target: 'pi',
+ model: 'chatgpt/gpt-5.5',
+ providerId: 'openai',
+ effort: undefined,
+ fastMode: undefined,
+ });
+ });
+
it('null / 非法值 = 无意图 → 清除', async () => {
const { makerChatStore } = await import('@/lib/makerChatStore');
const s = sid();
diff --git a/apps/desktop/src/renderer/lib/makerChatStore.ts b/apps/desktop/src/renderer/lib/makerChatStore.ts
index 76dd09c0bb..4456ce4b88 100644
--- a/apps/desktop/src/renderer/lib/makerChatStore.ts
+++ b/apps/desktop/src/renderer/lib/makerChatStore.ts
@@ -13500,7 +13500,12 @@ function getAgentSwitchIntentRev(sessionId: string): number {
function normalizeAgentSwitchIntent(value: unknown): AgentSwitchIntentRecord | null {
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
const item = value as Record<string, unknown>;
- if (item.targetAgentKind !== 'claude-code' && item.targetAgentKind !== 'codex') return null;
+ if (
+ item.targetAgentKind !== 'claude-code' &&
+ item.targetAgentKind !== 'codex' &&
+ item.targetAgentKind !== 'pi'
+ )
+ return null;
if (typeof item.model !== 'string' || item.model.length === 0) return null;
// providerId 缺失按 null(与 main projectPendingAgentSwitchIntent 的 `?? null` 对齐);
// 只有出现非 string / 非空值的脏值才判非法,避免协议演进时静默丢掉合法意图。