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。

Merge remote-tracking branch 'upstream/main' into fix/pi-thinking-level-on-model-switch

Zhang Yunjin8ce6d2c868b0
diff --cc apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts
index b78826cbbf,8c8130209f..e6d3bf4b83
--- a/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts
+++ b/apps/desktop/src/main/__tests__/sessionRuntimeControlWiring.test.ts
@@@ -758,47 -761,15 +761,48 @@@ describe('session runtime control wirin
);
});
+ it('carries the Pi thinking intent through every staged selection replay', () => {
+ const body = handlerBody(
+ registerSource,
+ 'const handleSetModel = async (',
+ 'const recoverRemoteRuntimeAxisPersistence',
+ );
+ const early = body.slice(body.indexOf('// A picker click'), body.indexOf('const axisPatch:'));
+ // 点选暂存:intent 必须带上思考意图,否则发送时回放会丢档位。
+ expect(early).toContain('{ thinking: atomicSelection.thinking }');
+ // 发送回放 / deferred 结算另两条重建链也不能丢。
+ expect(registerSource).toContain('{ thinking: intent.thinking }');
+ expect(registerSource).toContain('{ thinking: pending.thinking }');
+ expect(
+ registerSource.split('{ thinking: atomicSelection.thinking }').length,
+ ).toBeGreaterThanOrEqual(3);
+ // 回合中延期(deferLockedSelection)的两条登记都要暂存思考意图:只靠结算侧回放
+ // pending.thinking 不够,登记时不写就恒为 undefined,原症状会在「回合中切模」
+ // 场景原样复现。
+ const defer = body.slice(
+ body.indexOf('const deferLockedSelection = async () =>'),
+ body.indexOf('if (runtimeStatus.remoteHostId && isSessionInTurn(sessionId)) {'),
+ );
+ expect(defer).toContain('acceptSessionRuntimeMutation({');
+ expect(defer).toContain('deferSessionRuntimeAxisMutation({');
+ expect(
+ defer.split('{ thinking: atomicSelection.thinking }').length - 1,
+ ).toBeGreaterThanOrEqual(2);
+ // 非 Pi 引擎绝不能收到 thinkingEnabled(只有 Pi 的 set_model 会消费它)。
+ expect(registerSource).toContain(
+ "runtimeAgentKind === 'pi' && atomicSelection?.thinking !== undefined",
+ );
+ });
+
- it('resumes native Codex history across credentials and reserves window rebuilding for send', () => {
- const body = handlerBody(
- registerSource,
- 'const handleSetModel = async (',
- 'const recoverRemoteRuntimeAxisPersistence',
- );
- expect(body).not.toContain('forkSdkSession(');
- expect(body).not.toContain('relinkCodexProviderThread(');
+ it('only relinks retained cross-host writers without rewriting native history', () => {
+ const body = handlerBody(registerSource, 'const handleSetModel = async (', 'const recoverRemoteRuntimeAxisPersistence');
+ expect(body).toContain('requiresCodexThreadRelink: () => maker.requiresCodexThreadHostTransfer(');
+ expect(body).toContain('...(canTransferThread ? {');
+ expect(body).toContain('relinkCodexProviderThread(');
+ expect(body).toContain('stripEncryptedReasoning: false');
+ expect(body).toContain('commitCodexThreadTransfer(transferDb!.client, sourceSnapshot');
+ expect(body).toMatch(/if \(result\.persistedRoute === true && isDeviceLinkInvoke\(\)\) \{\s*markRemoteSettingPersistedInsideHandler\(response\);/);
+ expect(body).toContain('getCurrentDbClientSnapshot()?.clientEpoch !== transferDb.clientEpoch');
expect(body).not.toContain('prepareNativeSessionRecovery(');
expect(body).toContain('codexAuthInjection: getCodexProxyAuthInjectionState()');
expect(body).toContain('confirmedTargetPressure:');
diff --cc apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts
index 744824bab5,470008a370..d36fb1b8f9
--- a/apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/sessionAgentSwitchHandler.test.ts
@@@ -202,57 -168,44 +203,95 @@@ describe('same-engine selection at send
});
describe('performSessionAgentSwitch', () => {
+ it('stages and forwards the Pi thinking intent across an engine switch', async () => {
+ let row = makeRow();
+ const bootstraps: Array<{ thinkingEnabled?: boolean } | undefined> = [];
+ const remembered: Array<{
+ agentKind: string;
+ providerId: string | null;
+ model: string;
+ thinking: boolean;
+ }> = [];
+ const pendingSwitches = createPendingAgentSwitchRegistry();
+ const { deps } = makeDeps({
+ pendingSwitches,
+ rememberThinkingIntent: (input) => {
+ remembered.push(input);
+ },
+ getSessionRow: async () => ({ ...row }),
+ applyAgentSwitchToDb: async (_id, patch) => {
+ row = {
+ ...row,
+ agentKind: patch.agentKind,
+ model: patch.model,
+ providerId: patch.providerId ?? null,
+ };
+ },
+ bootstrapSwitchedSession: async (_id, opts) => {
+ bootstraps.push(opts);
+ },
+ });
+
+ await performSessionAgentSwitch(deps, {
+ sessionId: 's1',
+ targetAgentKind: 'pi',
+ model: 'deepseek-v4.1-flash',
+ providerId: 'opencode-go',
+ thinking: true,
+ });
+ // 跨引擎 intent 也必须记住思考意图,否则发送重建时只能靠被控端镜像/默认值。
+ expect(deps.pendingSwitches?.get('s1')?.thinking).toBe(true);
+
+ await applyPendingAgentSwitchIfIdle(deps, 's1', { bootstrapAfterSwitch: true });
+ expect(bootstraps.at(-1)).toEqual({ thinkingEnabled: true });
+ // 跨引擎提交后把选择落到本机偏好镜像:普通 send 的 lazy-create 只读镜像,
+ // 不经过 bootstrap,远端推送未回流时会用到旧值。
+ expect(remembered.at(-1)).toEqual({
+ agentKind: 'pi',
+ providerId: 'opencode-go',
+ model: 'deepseek-v4.1-flash',
+ thinking: true,
+ });
+ });
+
+ it('keeps the config-staged identity through resume-fallback recovery re-entry', async () => {
+ // 渠道默认触发的跨引擎切换若走 resume 回落恢复, 恢复意图必须保留 configStaged ——
+ // 否则被通用路径消费时当成用户选择打上 manual 墓碑, 任务永久脱离跟随
+ // (chatgpt-codex-connector P2, PR #5155)。
+ let row = makeRow();
+ let failFallback = true;
+ const onUserRouteSelectionLanded = vi.fn();
+ const pending = createPendingAgentSwitchRegistry();
+ const { deps } = makeDeps({
+ pendingSwitches: pending,
+ onUserRouteSelectionLanded,
+ getSessionRow: async () => ({ ...row }),
+ findParkedEngineSession: async (_id, kind) =>
+ kind === 'codex' ? { sdkSessionId: 'broken-codex', watermarkCreatedAt: 0, watermarkRowid: 0 } : null,
+ applyAgentSwitchToDb: async (_id, patch) => {
+ row = { ...row, ...patch, providerId: patch.providerId ?? null, sdkSessionId: patch.sdkSessionId ?? null };
+ },
+ insertBoundaryMessage: async () => 'boundary-1',
+ bootstrapSwitchedSession: async () => {
+ throw new Error('resume failed');
+ },
+ applyResumeFallbackAtomically: async () => {
+ if (failFallback) throw new Error('db locked');
+ row.sdkSessionId = null;
+ },
+ });
+ await performSessionAgentSwitch(deps, { ...validParams, configStaged: true });
+ await applyPendingAgentSwitchIfIdle(deps, 's1');
+ expect(pending.get('s1')?.resumeFallbackRecovery).toBeDefined();
+ expect(onUserRouteSelectionLanded).not.toHaveBeenCalled();
+
+ // 恢复尾段重试成功后被消费: 仍然是系统配置切换, 不立碑。
+ failFallback = false;
+ await applyPendingAgentSwitchIfIdle(deps, 's1');
+ expect(onUserRouteSelectionLanded).not.toHaveBeenCalled();
+ expect(pending.get('s1')).toBeUndefined();
+ });
+
it('cycles Claude → Codex → Pi → Claude → Codex and recovers a broken parked thread once', async () => {
let row = makeRow();
const parked = new Map<string, string>();
diff --cc apps/desktop/src/main/maker-ipc/register.ts
index 4a2a834b8e,9d397c52b4..57c5289ab7
--- a/apps/desktop/src/main/maker-ipc/register.ts
+++ b/apps/desktop/src/main/maker-ipc/register.ts
@@@ -8454,9 -8642,9 +8651,10 @@@ export function registerMakerIpc(maker
const result = await applySessionRuntimeSelection(sessionId, intent.model, intent.providerId, {
effort: (intent.effort ?? null) as SessionRuntimeProfile['effort'],
fastMode: intent.fastMode ?? false,
+ ...(intent.thinking !== undefined ? { thinking: intent.thinking } : {}),
}, { source: 'user', sessionLockHeld: true, applyingUserSelectionOnSend: applyNow,
- runtimeSource: intent.runtimeSource, assertSelectionCurrent });
+ runtimeSource: intent.runtimeSource, configStaged: intent.configStaged === true,
+ assertSelectionCurrent });
return result;
},
onPendingSwitchChanged: (sessionId, intent) => {
diff --cc apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.ts
index e239fee000,8c90780553..f18d1814d4
--- a/apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.ts
+++ b/apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.ts
@@@ -489,9 -456,9 +503,10 @@@ export async function performSessionAge
providerId: normalizedProviderId,
...(typeof params.effort === 'string' ? { effort: params.effort } : {}),
...(typeof params.fastMode === 'boolean' ? { fastMode: params.fastMode } : {}),
+ ...(typeof thinking === 'boolean' ? { thinking } : {}),
sameAgentSelection: true,
...(params.runtimeSource ? { runtimeSource: params.runtimeSource } : {}),
+ ...(params.configStaged === true ? { configStaged: true } : {}),
}, false, params.assertSelectionCurrent);
return {
switched: false,