Skip to content

refactor(harmonyos): split the app shell into MVVM layers - #2160

Open
wgqqqqq wants to merge 2 commits into
GCWing:mainfrom
wgqqqqq:feat/mobile-agent-chat
Open

refactor(harmonyos): split the app shell into MVVM layers#2160
wgqqqqq wants to merge 2 commits into
GCWing:mainfrom
wgqqqqq:feat/mobile-agent-chat

Conversation

@wgqqqqq

@wgqqqqq wgqqqqq commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

背景

AppRoot 已经膨胀成一个同时负责路由、远程传输、会话状态与展示的运行时对象,任何一个改动都要横跨全部职责。这个 PR 把它按边界拆开,并顺带修掉了拆分过程中暴露出来的几个行为问题。

结构调整

  • pages/runtime —— 组合根与生命周期
  • pages/viewmodel —— 控制器与 ViewModel
  • pages/policy —— 纯决策函数
  • pages/actions —— 交给组件的 intent / action 类型化接口
  • pages/navigationpages/layout —— 路由与几何契约

组件不再直接访问 ViewModel,而是接收类型化的 action 对象,因此 Local 与 Remote 可以共用同一套会话外壳(紧凑布局用 ConversationRouteSurface,宽屏用 WideConversationHost)。

行为修复

  • 新建会话时选「聊天」,现在会先绑定桌面端的 assistant 工作区。桌面端对 Claw 会话会忽略 workspace_path 并强制使用 assistant 工作区,所以之前 App 仍停留在原来的代码工作区,而会话其实建在了别处——新会话在列表里根本看不到。
  • 创建面板里选中的工作区现在与 code agent 配对,选择会被真正生效,而不是被静默丢弃。
  • 紧凑布局下的远程会话改为通过菜单按钮把侧边栏覆盖在聊天之上,与本地会话一致,不再直接退出会话页。系统返回手势仍然是离开会话并展开抽屉。

配套检查

新增 pnpm run harmony:architecture,在 services 反向导入 pages、components 导入 viewmodel、页面依赖成环、action/hook 接口不是类型化对象字面量时报错。

验证

  • pnpm run harmony:architecture
  • HarmonyOS 单元测试(entry/src/test
  • 真机构建安装后手测:新建聊天/代码会话、紧凑与宽屏布局切换、远程会话侧边栏与返回手势

🤖 Generated with Claude Code

wgqqqqq and others added 2 commits August 7, 2026 17:22
AppRoot had grown into a single runtime object that owned routing, remote
transport, conversation state and presentation at once, so every feature
change reached across all of them. Split it along explicit boundaries:

- pages/runtime for the composition root and lifecycle
- pages/viewmodel for controllers and view models
- pages/policy for pure decision helpers
- pages/actions for the typed intent/action surface handed to components
- pages/navigation and pages/layout for route and geometry contracts

Components now receive typed action objects instead of reaching into view
models, which lets Local and Remote share one conversation shell
(ConversationRouteSurface on compact, WideConversationHost on wide).

Behaviour changes that came out of the split:

- Creating a chat from the "chat" option binds the desktop's assistant
  workspace first. The desktop ignores workspace_path for Claw sessions and
  always uses its assistant workspace, so the app used to keep showing the
  code workspace it was on while the session was actually created
  elsewhere - the new chat never appeared in the list.
- Picking a workspace in the create sheet now pairs it with the code agent,
  so the picker is honoured instead of being silently dropped.
- Compact remote conversations open the sidebar over the chat from a menu
  button, matching local chats, instead of popping back out of the
  conversation. The system back gesture still leaves the chat and reveals
  the drawer.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The MVVM split only holds if the import direction is enforced. Add
`pnpm run harmony:architecture`, which fails when services import pages,
when components import view models, when the page graph gains a cycle, or
when action and hook interfaces are passed as anything but typed object
literals.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

1 participant