Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
Merge upstream/main into fix/pi-thinking-level-on-model-switch(解冲突:思考意图与确认窗口两个字段并存)
Zhang Yunjin7389029f21c4
diff --cc apps/desktop/src/main/maker-ipc/register.tsindex e5d99d2735,6bc8889d4f..c7d1388d01--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@@ -9187,8 -10239,7 +10258,9 @@@ export function registerMakerIpc(makerconst 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 } : {}),+ // 只有 Agent 在另一台电脑运行的任务会在意图里带确认过的目标窗口。+ // Preserve the exact window acknowledged by the picker until send....(intent.confirmedContextWindow ? { confirmedContextWindow: intent.confirmedContextWindow } : {}),}, { source: 'user', sessionLockHeld: true, applyingUserSelectionOnSend: applyNow,runtimeSource: intent.runtimeSource, configStaged: intent.configStaged === true,@@@ -18822,7 -20877,7 +20909,8 @@@providerId: effectiveProviderId === undefined ? currentProviderId : effectiveProviderId,effort: atomicSelection ? atomicSelection.effort ?? undefined : runtimeStatus.effort ?? undefined,fastMode: atomicSelection?.fastMode ?? runtimeStatus.fastMode,+ ...(atomicSelection?.thinking !== undefined ? { thinking: atomicSelection.thinking } : {}),+ ...(acknowledgedWindow !== undefined ? { confirmedContextWindow: acknowledgedWindow } : {}),};agentSwitchPending.set(sessionId, intent);agentSwitchDeps.onPendingSwitchChanged?.(sessionId, projectPendingAgentSwitchIntent(intent));diff --cc apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.tsindex 80eb8f8e63,c284af6d5b..5edcd324e1--- a/apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.ts+++ b/apps/desktop/src/main/maker-ipc/sessionAgentSwitchHandler.ts@@@ -415,17 -475,90 +488,101 @@@ export async function applySetModelThenreturn result;}+ /**+ * 打开任务时 Agent 没能启动、要换到另一个位置重新打开(供应商组启动阶段换电脑,docs/product-rules/provider-groups.md §6):+ * 原生会话在原来那个位置上,换过去不能续接,与换电脑同一套交接——全量交接 + 全新原生会话 + 分隔条。没有开着的会话+ * (这次就是要打开它),也不在这里启动:调用方正在启动 Agent,按返回后的任务记录接着打开,这次发送带上交接。+ * `sharedRelocation`:位置仍是同一个分享、由分享者的组换一台(分隔条不写电脑名称)。+ */+ export async function relocateForFreshStart(+ deps: Pick<+ MakerSessionAgentSwitchHandlerDeps,+ | 'getSessionRow'+ | 'listMessagesForHandoff'+ | 'readWorkingMemoryNote'+ | 'applyAgentSwitchToDb'+ | 'setSessionProvider'+ | 'insertBoundaryMessage'+ | 'setPendingHandoff'+ | 'readPendingHandoffGeneration'+ | 'describeAgentDevice'+ | 'log'+ >,+ params: {+ sessionId: string;+ agentDeviceId: string | null;+ providerId: string | null;+ /** 原来那个位置(调用方可能已把任务记录改到了目标位置);不给 = 按任务记录。 */+ from?: { agentDeviceId: string | null; providerId: string | null };+ sharedRelocation?: boolean;+ },+ ): Promise<void> {+ const { sessionId, agentDeviceId, providerId } = params;+ const row = await deps.getSessionRow(sessionId);+ if (!row || row.status === 'deleted') throwIpcError('NOT_FOUND', `Session ${sessionId} not found`);+ if (!row.model) throwIpcError('PRECONDITION_FAILED', `Session ${sessionId} has no model to relocate`);+ const model = row.model;+ const dbKind = normalizeDbAgentKind(row.agentKind);+ const handoffGeneration = deps.readPendingHandoffGeneration?.(sessionId);+ const handoff = buildHandoffText(await deps.listMessagesForHandoff(sessionId), {+ fromLabel: `${agentEngineLabel(dbKind)} (on a different computer)`,+ toLabel: agentEngineLabel(dbKind),+ sessionId,+ workingMemory: (await deps.readWorkingMemoryNote?.(sessionId)) ?? null,+ });+ const fromAgentDeviceId = params.from ? params.from.agentDeviceId : row.agentDeviceId ?? null;+ const fromProviderId = params.from ? params.from.providerId : row.providerId;+ await deps.applyAgentSwitchToDb(sessionId, {+ agentKind: dbKind,+ model,+ providerId,+ sdkSessionId: null,+ agentDeviceId,+ });+ deps.setSessionProvider(sessionId, providerId);+ const boundaryContent: AgentSwitchBoundaryContent = {+ fromAgentKind: dbKind,+ toAgentKind: dbKind,+ fromModel: row.model,+ toModel: row.model,+ fromProviderId,+ toProviderId: providerId,+ fromSdkSessionId: row.sdkSessionId,+ handoff,+ resumed: false,+ consumed: false,+ fromAgentDeviceId,+ toAgentDeviceId: agentDeviceId,+ fromAgentDeviceName: params.sharedRelocation ? null : deps.describeAgentDevice?.(fromAgentDeviceId) ?? null,+ toAgentDeviceName: params.sharedRelocation ? null : deps.describeAgentDevice?.(agentDeviceId) ?? null,+ };+ try {+ await deps.insertBoundaryMessage(sessionId, boundaryContent);+ } catch (err) {+ deps.log.warn('agent-switch: boundary message insert failed on fresh-start relocation (degraded)', {+ sessionId,+ err: err instanceof Error ? err.message : String(err),+ });+ }+ deps.setPendingHandoff(sessionId, handoff, handoffGeneration);+ deps.log.info('agent-switch: relocated for a fresh start', {+ sessionId,+ handoffChars: handoff.length,+ agentDeviceChange: params.sharedRelocation ? 'reassigned-by-provider-group' : agentDeviceId ? 'other-device' : 'task-device',+ });+ }++/** 带思考意图重建?不传时保持单参调用形状(既有调用方/断言都不受影响)。 */+function bootstrapSwitchedSessionWithThinking(+ deps: MakerSessionAgentSwitchHandlerDeps,+ sessionId: string,+ thinkingEnabled: boolean | undefined,+): Promise<void> {+ return thinkingEnabled === undefined+ ? deps.bootstrapSwitchedSession(sessionId)+ : deps.bootstrapSwitchedSession(sessionId, { thinkingEnabled });+}+/** 业务体(纯依赖注入,单测直接调):校验 → 交接 → 提交 → 重建。 */export async function performSessionAgentSwitch(deps: MakerSessionAgentSwitchHandlerDeps,@@@ -471,10 -613,12 +642,15 @@@},): Promise<SessionAgentSwitchResult> {const { sessionId, targetAgentKind, model, providerId, signal } = params;+ // Pi 跨引擎重建时同样要带上思考开关意图:不传就容易落到被控端镜像/默认值,+ // 与用户在意图期内刚改的开关不一致(device-link 远程场景最明显)。+ const thinkingEnabled = typeof params.thinking === 'boolean' ? params.thinking : undefined;throwIfAgentSwitchAborted(signal);+ const confirmedContextWindow = params.confirmedContextWindow;+ if (confirmedContextWindow !== undefined &&+ (typeof confirmedContextWindow !== 'number' || !Number.isSafeInteger(confirmedContextWindow) || confirmedContextWindow <= 0)) {+ throwIpcError('INVALID_PARAMS', 'confirmedContextWindow must be a positive integer');+ }if (typeof sessionId !== 'string' || sessionId.length === 0) {throwIpcError('INVALID_PARAMS', 'sessionId required');}@@@ -559,36 -761,29 +793,42 @@@throwIfAgentSwitchAborted(signal);params.assertSelectionCurrent?.();}- if (fromDbKind === toDbKind && !agentDeviceChanges) {+ if (fromDbKind === toDbKind && !relocating && !orcaGroupReturnRebuild) {// Only picker calls stage a model choice here. Internal cross-engine apply/recovery// callers retain the existing same-engine no-op; send consumes staged choices below.- if (deps.selectSameAgentModel && !params.applyNow) {- // 组把换电脑的意图选回了当前位置(groupResolvedToCurrentPosition):这次 applyNow 提交- // 本身就是模型 / effort / fastMode 要落地的时刻,必须走真正的同引擎模型应用路径,- // 不能当成已经应用过的 no-op 直接丢弹(greptile-apps P1, PR #5792 review)。+ if (deps.selectSameAgentModel && (!params.applyNow || groupResolvedToCurrentPosition)) {+ // 重登记可能不带思考意图(旧调用方 / 只改 effort·Fast):仍指向同一个目标时+ // 继承既有 intent,否则登记时的快照被覆盖成 undefined,结算回放会丢掉思考+ // 档位收敛;目标已换(改选到别的模型)时不继承——旧模型的开关不适用,+ // 宁可当未提供,让运行时按目标模型自己的能力处理。+ const existingIntent = deps.pendingSwitches?.get?.(sessionId);+ const sameTarget =+ existingIntent !== undefined &&+ existingIntent.model === model &&+ (existingIntent.providerId ?? null) === (normalizedProviderId ?? null);+ const thinking =+ typeof params.thinking === 'boolean'+ ? params.thinking+ : sameTarget+ ? existingIntent?.thinking+ : undefined;const result = await deps.selectSameAgentModel(sessionId, {targetAgentKind,model,providerId: normalizedProviderId,...(typeof params.effort === 'string' ? { effort: params.effort } : {}),...(typeof params.fastMode === 'boolean' ? { fastMode: params.fastMode } : {}),+ ...(typeof thinking === 'boolean' ? { thinking } : {}),sameAgentSelection: true,+ ...(confirmedContextWindow !== undefined ? { confirmedContextWindow } : {}),...(params.runtimeSource ? { runtimeSource: params.runtimeSource } : {}),...(params.configStaged === true ? { configStaged: true } : {}),- }, false, params.assertSelectionCurrent, params.beforeMutation);+ }, params.applyNow === true, params.assertSelectionCurrent, params.beforeMutation);+ // 组选回当前位置并且模型应用真正成功(非 deferred/superseded)时才持久化新绑定;+ // 没落地的调用不应该殊到已纳入组(chatgpt-codex-connector P2, PR #5792 review)。+ if (groupResolvedToCurrentPosition && !result.deferred && !result.superseded) {+ await commitBindingAfterSwitch();+ }return {switched: false,agentKind: targetAgentKind,@@@ -752,16 -952,12 +1012,22 @@@if (normalizedProviderId !== undefined) {deps.setSessionProvider(sessionId, normalizedProviderId);}+ if (typeof thinkingEnabled === 'boolean') {+ // 跨引擎切换提交后把用户的思考选择落到本机偏好镜像:普通 send 的 lazy-create+ // 只读镜像(不经过 bootstrap),否则远端推送未回流时会用旧值建会话。+ deps.rememberThinkingIntent?.({+ agentKind: targetAgentKind,+ providerId: normalizedProviderId ?? row.providerId ?? null,+ model,+ thinking: thinkingEnabled,+ });+ }+ // DB 已过 commit point,切换生效:此刻再持久化组内绑定,前面的目录校验 /+ // closeSession / assertModelRouteUsable 任何一步抛错都不会让新绑定抔先持久化+ // (chatgpt-codex-connector P2, PR #5792 review)。+ if (commitProviderGroupBinding) {+ await commitBindingAfterSwitch();+ }const boundaryContent: AgentSwitchBoundaryContent = {fromAgentKind: fromDbKind,@@@ -888,9 -1086,10 +1156,10 @@@deps.setPendingHandoff(sessionId, fullHandoff, handoffGeneration);if (fallbackCommitted) {try {- await deps.bootstrapSwitchedSession(sessionId);+ await bootstrapSwitchedSessionWithThinking(deps, sessionId, thinkingEnabled);} catch (err2) {engineReady = false;+ bootstrapError = err2 instanceof Error ? err2.message : String(err2);deps.log.warn('agent-switch: fresh bootstrap after resume fallback failed', {sessionId,targetAgentKind,@@@ -1153,9 -1354,15 +1425,16 @@@ export function registerMakerSessionAge// 第 7 参(可选):{ agentDeviceId } —— 同时换 Agent 所在电脑。旧被控端忽略多余参数,// 位置保持不变(与今天一致)。options?: unknown,+ thinking?: unknown,) => {const context = getDeviceLinkInvokeContext();+ const confirmedContextWindow = options && typeof options === 'object' && !Array.isArray(options)+ ? (options as { confirmedContextWindow?: unknown }).confirmedContextWindow : undefined;+ // Same trust boundary as SET_MODEL: remote controllers cannot authorize a+ // destructive local-context rebuild by supplying a confirmation number.+ if (isDeviceLinkInvoke() && confirmedContextWindow !== undefined) {+ throwIpcError('PRECONDITION_FAILED', 'remote model-window confirmation is unsupported');+ }const agentDeviceId =options && typeof options === 'object' && !Array.isArray(options) && 'agentDeviceId' in options? (options as { agentDeviceId?: unknown }).agentDeviceId@@@ -1172,8 -1379,8 +1451,9 @@@providerId,effort,fastMode,+ ...(confirmedContextWindow !== undefined ? { confirmedContextWindow } : {}),...(agentDeviceId !== undefined ? { agentDeviceId } : {}),+ thinking,assertSelectionCurrent: guard.admit,});return typeof sessionId === 'string' && sessionId && deps.withSessionLockdiff --cc apps/desktop/src/preload/preload.tsindex 2d7662411b,5b4bc9b023..10a4801cff--- a/apps/desktop/src/preload/preload.ts+++ b/apps/desktop/src/preload/preload.ts@@@ -6928,8 -7133,7 +7135,8 @@@ contextBridge.exposeInMainWorld('electreffort?: string,fastMode?: boolean,// 远程 Agent:同时换 Agent 所在电脑(null = 任务所在电脑)。不传 = 位置不变。- options?: { agentDeviceId?: string | null },+ options?: { agentDeviceId?: string | null; confirmedContextWindow?: number },+ thinking?: boolean,): Promise<{switched: boolean;agentKind: 'claude-code' | 'codex' | 'pi';diff --cc apps/desktop/src/renderer/components/new-chat/ChatInput.tsxindex 1f5359cc8c,16529034e1..b811e72b47--- a/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx+++ b/apps/desktop/src/renderer/components/new-chat/ChatInput.tsx@@@ -6865,8 -6904,7 +6935,8 @@@ export function ChatInput(providerId,newEffort,targetFast,- { agentDeviceId: relocateTo },+ switchOptions,+ targetThinking,): await switchApi.switchSessionAgent(sourceSessionId,diff --cc apps/desktop/src/renderer/vite-env.d.tsindex a83336b06f,8cd154f4b8..801484850b--- a/apps/desktop/src/renderer/vite-env.d.ts+++ b/apps/desktop/src/renderer/vite-env.d.ts@@@ -6258,8 -6400,7 +6400,8 @@@ interface ElectronAPIeffort?: string,fastMode?: boolean,/** 远程 Agent:同时换 Agent 所在电脑(null = 任务所在电脑)。不传 = 位置不变。 */- options?: { agentDeviceId?: string | null },+ options?: { agentDeviceId?: string | null; confirmedContextWindow?: number },+ thinking?: boolean,) => Promise<{switched: boolean;agentKind: 'claude-code' | 'codex' | 'pi';diff --cc docs/dev-rules/pi-harness.mdindex ab62eddd26,33e92e3cae..3a1928f75e--- a/docs/dev-rules/pi-harness.md+++ b/docs/dev-rules/pi-harness.md@@@ -84,27 -92,13 +92,31 @@@ Cindy 以 `pi --mode rpc` spawn pi 二�时仍保持仅文本;此默认值不写回用户配置,也不代表上游接口保证支持图片。活动任务沿用启动时能力快照。回归见 `pi-provider-routing.test.ts` 与 `piNativeProviders.test.ts`。+ Codex / Claude Code 复用的 `pi-provider-transport.ts` 原生桥接也沿用此缺省口径:+ 活动目录的显式图片开关或模态声明优先于原生兜底资料,只有均未声明时才允许图片。+ 此行为只决定图片是否进入原生 SDK 请求,不保证上游识图;回归见 `piProviderTransport.test.ts`。+Cindy 显式设置:models.json、`settings.json` 的 `transport:sse` 与 `retry.maxRetries=6`(`retry.provider.maxRetries` 保持 0)、`--append-system-prompt`、`--session-dir`、启动时 RPC-`set_auto_compaction{enabled:true}` / `set_thinking_level`。Pi 原生负责 threshold 与 overflow 压缩;+`set_auto_compaction{enabled:true}` / `set_thinking_level`。切换模型成功后按目标模型的思考意图+再下发一次 `set_thinking_level`(Pi 的 `set_model` 不重置 level;不收敛会让上一个模型的 off/旧档位+漂移给新模型——实测推理模型在 off 下把思考写进正文)。思考意图由 renderer 的原子 selection 携带+(主进程只对 Pi 转成 `thinkingEnabled`,点选暂存与 deferred 重放一并回放);目标档位不在启动快照内时+按默认档/首档回落(同 `reconcilePiStartupEffort` 口径),目标声明不支持思考时明确 `off`,能力未知+则不动。**载体缺失(旁路入口热切模型)时同样按目标快照收敛**:目标支持思考就按会话档位重新下发一次,+否则保留现有档位——历史实现的「无意图就不动」会让这类切换静默丢思考通道(2026-10-06 实报:Orca lead+切到 `commandcode/deepseek-v4.1-flash` 后 `usage.reasoning` 归零、推理整段写进正文,Pi 侧无任何+`set_thinking_level` 记录,直到用户手动改一次档位才恢复)。实现见+`packages/maker-core/src/agents/pi/index.ts` 的 `switchModel` 末尾,+回归见 `pi-provider-routing.test.ts` 的 thinking-level 用例。跨引擎切换提交时还会把这次选择写进+本机偏好镜像(普通 send 走 lazy-create 只读镜像、不经过 bootstrap),避免远端推送未回流时新建会话+用旧值。**仍未覆盖**:Bot 设置保存、agent/scheduler/IM 回滚等**旁路入口**热切 Pi 模型时没有 thinking+载体(`SessionRuntimeProfile` 不含该字段)。按目标快照收敛保证推理模型不丢通道;用户明确关过的+思考(`setThinkingEnabled(false)` / 显式 `thinkingEnabled:false` / 启动关闭)由运行期意图标记+保护,无载体切换不会重新开启。剩下的是本机偏好镜像里的 per-model 开关意图(记忆里关了、运行期+从未显式下发过)仍无法携带,要完全对齐需给这些入口补载体(镜像已有 `getThinkingEnabledFromMemory`,+目前只在会话启动钩子接入)。+Pi 原生负责 threshold 与 overflow 压缩;Cindy 消费 compaction 事件做 UI、usage、digest 投影,并只在本机原生自动压缩确定性失败后锁存下一次发送前换窗。设置页的 Pi 百分比默认 90%(已有显式 override 保留),在每次启动或恢复Pi 任务时冻结,并写入该任务 `settings.json` 的 `compaction.reserveTokens`