Skip to content

fix(core): 修复多工作区模式下 /mode 未作用到当前 workspace agent 的问题#363

Open
JrDw0 wants to merge 2 commits intochenhg5:mainfrom
JrDw0:fix/multi-workspace-mode-switch
Open

fix(core): 修复多工作区模式下 /mode 未作用到当前 workspace agent 的问题#363
JrDw0 wants to merge 2 commits intochenhg5:mainfrom
JrDw0:fix/multi-workspace-mode-switch

Conversation

@JrDw0
Copy link
Copy Markdown

@JrDw0 JrDw0 commented Mar 29, 2026

关联 issue #233

变更说明

修复多工作区模式下 /mode 只更新全局 agent、没有更新当前 workspace agent 的问题。

multi-workspace 模式下,普通消息会路由到当前工作区对应的 workspace agent。
但原来的 /mode yolo 和卡片动作 act:/mode ... 实际修改的是全局 e.agent
导致界面上看起来已经切到 YOLO,当前工作区会话却仍然按旧模式运行。

这会表现为:

  • /mode yolo 后日志显示切换成功
  • 但当前 workspace 的实际会话仍然像 full-auto
  • 一些需要真正无沙箱执行的操作仍然无法按预期生效

修改内容

  • cmdMode 改为通过 commandContext() 获取当前会话对应的 agent 和 session manager
  • 卡片动作 /mode 改为通过 sessionContextForKey() 获取当前 workspace agent
  • /mode 卡片渲染改为显示当前 workspace agent 的真实模式
  • 增加多工作区回归测试,覆盖:
    • /mode 更新 workspace agent
    • 卡片动作更新 workspace agent

为什么 #240 还不够

#240 修复了模式切换后需要重置 session 才能生效的问题,但它仍然操作的是全局
e.agent / e.sessions

在多工作区模式下,真正处理消息的是按工作区缓存的 workspace agent,因此仅修复 session
重置还不够,必须把 mode 切换应用到当前 workspace agent 上。

测试

已执行:

go test ./core -run 'TestCmdMode_MultiWorkspaceUpdatesWorkspaceAgent|TestExecuteCardAction_ModeUsesWorkspaceAgent|TestCmdMode_UsesInlineButtonsOnButtonOnlyPlatform|TestExecuteCardAction_ModeCleansUpWithInteractiveKey'

Copy link
Copy Markdown
Owner

@chenhg5 chenhg5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Correct fix for multi-workspace /mode issue.

Review notes:

  • ✅ CI passes
  • Properly uses commandContext() to get workspace-specific agent
  • Card actions also updated to use sessionContextForKey()
  • Good test coverage for multi-workspace scenarios
  • Fixes issue #233

Approved for merge.

@archerjty
Copy link
Copy Markdown

你这里修复的在codex下用不了skills命令,/quiet 目前也只有一个生效

@chenhg5
Copy link
Copy Markdown
Owner

chenhg5 commented Apr 2, 2026

⚠️ Merge Conflict + Unresolved Issue

This PR has merge conflicts with the main branch. Please resolve:

git fetch origin
git checkout your-branch
git merge origin/main
# Resolve conflicts, then:
git push

Also, there was a comment from @archerjty noting that:

  • Skills command doesn't work under codex
  • /quiet only has one effect

Please verify if these issues are addressed in this PR or need separate fixes.

@JrDw0 JrDw0 force-pushed the fix/multi-workspace-mode-switch branch from f2f087c to 0ae4d58 Compare April 2, 2026 12:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants