fix: 权限模式改为按 session 持久化,隔离多 tab 状态#365
Merged
ErlichLiu merged 2 commits intoErlichLiu:mainfrom May 4, 2026
Merged
Conversation
- 每次 send 带 permissionModeOverride,渲染进程成为权威源 - session 初始化时从 workspace config 读回持久化模式,只写入当前 session,避免跨会话污染 - 新增 UPDATE_SESSION_PERMISSION_MODE IPC,cycleMode 在持久化之外热切换当前 session,保留中途切模式即时生效 - 初始模式为 plan 时主进程主动 emit enter_plan_mode,修复 plan 横幅不展示 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- AgentSessionMeta 新增 permissionMode 字段,随 session index 落盘 - UPDATE_SESSION_PERMISSION_MODE handler:先写 session meta,active 时再热切换;session 不存在时抛明确错误 - EXIT_PLAN_MODE_RESPOND 补写 session meta,保持 meta 优先语义一致(之前只写 workspace config,ExitPlanMode 切换的模式重启后会丢) - PermissionModeSelector 读回优先级:session meta → workspace config → 全局 default;用 useMemo 把 effect 依赖收窄到 permissionMode 字段本身,避免流式中无关字段变化触发重跑 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
重构权限模式(自动 / 完全自动 / 计划)的存储与切换模型,解决两个现存问题:
改造后:每个 session 独立持久化自己的权限模式到
AgentSessionMeta.permissionMode;workspace config 字段降级为"该工作区新 session 的默认值";UI 侧每次发送消息都带permissionModeOverride,渲染进程成为权威源。Changes
commit 1 —
c1aa356 fix: 权限模式隔离到 session 维度,兼顾持久化与中途热切换apps/electron/src/main/ipc.tsSET_PERMISSION_MODEhandler 删除广播逻辑(不再强制同步同工作区其他 active session)UPDATE_SESSION_PERMISSION_MODEhandler:只更新指定 sessionId 的运行时权限模式apps/electron/src/main/lib/agent-orchestrator.tspermissionModeOverride ?? appSettings.defaultplan时主动 emitenter_plan_mode事件,修复冷启动就是 plan 时横幅不展示的问题apps/electron/src/preload/index.ts— 新增updateSessionPermissionMode(sessionId, mode)方法apps/electron/src/renderer/components/agent/AgentView.tsx— 五个发送路径(auto-send / handleSend / /compact / retry / retryInNewSession)都带上permissionModeOverride: permissionModeapps/electron/src/renderer/components/agent/PermissionModeSelector.tsxcycleMode在持久化之外调用新 IPC 做运行时热切换(仅影响当前 session)packages/shared/src/types/agent.ts— 新增UPDATE_SESSION_PERMISSION_MODEIPC 常量commit 2 —
ea8e123 fix: 权限模式按 session 持久化,重启后各 tab 独立恢复packages/shared/src/types/agent.ts—AgentSessionMeta新增permissionMode?: PromaPermissionMode字段apps/electron/src/main/lib/agent-session-manager.ts—updateAgentSessionMetaPick 白名单加入permissionModeapps/electron/src/main/ipc.tsUPDATE_SESSION_PERMISSION_MODEhandler:先写 session meta 持久化,active 时再热切换;session 不存在时直接抛错EXIT_PLAN_MODE_RESPONDhandler 补写 session meta,避免通过 ExitPlanMode 切到的模式重启后丢失apps/electron/src/renderer/components/agent/PermissionModeSelector.tsxuseMemo派生persistedSessionMode/sessionExistsInList,effect 依赖收窄到 permissionMode 字段值,避免流式中无关字段变化触发重跑sessions列表尚未加载时暂不 seed,加载完成后自动重跑How to Test
canUseTool立刻使用新模式(不影响同工作区其他 session)sessionPermissionModesMap 和 SDK 侧都立即生效Notes
permissionMode字段保留,含义从"全工作区共享状态"降级为"新 session 的默认模板",对老数据向前兼容bypassPermissions通过外部 override 进入的场景(bridge-command-handler、feishu-bridge)不受影响,override 仍然优先permission_mode_changed事件和enter_plan_mode事件的渲染端 listener 本次未改动,延用现有实现🤖 Generated with Claude Code