状态:已实施。 当前代码入口是
packages/ui/src/WebRemoteControlMobileShell.tsx、WebRemoteControlMobileTaskHome.tsx与hooks/useWebRemoteControlTaskOpen.ts;下文“推荐/实施顺序” 保留设计轨迹,不表示待实现状态。当前远控链路使用外部 relay 的
data.payloadapp payload。本文中涉及任务首页/切 workspace 的交互仍有效;旧 relay token、HTTP bootstrap、bridgeToken/wsUrl假设已废弃,不再作为实现依据。
产品与架构总览见 Web 远程控制概览。本文记录手机首页与 聊天页的交互契约;时间线、主题和宽屏列表等专题由总览统一导航。
改造前,手机端 Web 远程控制复用了桌面端 WorkspaceSidebar 和聊天区域:
WorkspaceShellLayout 改成上下结构。这个结构能快速复用已有逻辑,但不适合新的手机端信息架构。新的目标是让手机端变成两个明确页面:
核心变化是:手机端不再复用桌面端任务列表 UI,但任务点击、跨 workspace 切换、mobile view state 上报等业务逻辑继续复用现有桌面远控链路。
workspaceKey = workspaceIdentity?.trim() || workspacePath 的身份隔离规则。第一版不做:
为补齐手机端操作闭环,任务首页的每个 workspace card 右侧增加“新建任务”按钮,行为如下:
startDraft(workspacePath, workspaceIdentity) 进入草稿态。updateMobileViewState(workspaceKey)(不带 taskId),避免继续高亮旧 task。switchWorkspace(workspaceKey, { mobileNavigationIntent: "chat" }),且不传 taskId。initialTaskId=undefined 启动,进入该 workspace 的草稿态。switcher 增加可选 startDraft(workspaceKey, { mobileNavigationIntent }) 能力,
便于手机端统一调用;不支持该能力的实现仍可回退到 switchWorkspace + updateMobileViewState。该补充保持现有身份隔离规则:workspaceKey = workspaceIdentity?.trim() || workspacePath。
采用移动端专用 shell,而不是继续改造 WorkspaceSidebar。
推荐新增一层手机远控 UI:
WebRemoteControlMobileShell
├── home: WebRemoteControlMobileTaskHome
│ └── workspace card list
│ └── task rows
└── chat: existing chat header + V4 session chat surface
桌面端和宽屏 Web 远控继续走现有 WorkspaceShellLayout 的桌面布局。只有满足 webRemoteControlWorkspaceSwitcher 且小屏断点时,才进入移动端两页 shell。
这样做的好处:
首页用于浏览当前 desktop window 内已打开的 workspace 和 task。
信息结构:
ZCode Remote ControlupdatedAt 最大值派生;没有 task 时不展示2026-05-28 补充:手机首页顶部增加全局 pinned 分区。桌面 renderer 同步任务快照时会同时读取
kind: "pinned" 与 kind: "timeline" 两类 sqlite 列表;mobile 首页收到统一 task targets 后,
先按 pinned === true 拆出置顶分区,再把非置顶任务交给 workspace/timeline 普通列表。置顶任务
不再重复出现在普通 workspace card 或 timeline 列表中,但 active task 校验和选中态必须同时匹配
pinned 分区与普通分组。
首页自己拥有滚动区域,不能依赖桌面 sidebar 的滚动容器。
聊天页复用现有工作区主内容:
packages/ui/src/v4/SessionPane.tsx 承载会话)。手机远控聊天页复用桌面会话组件,并保持与桌面一致的浮层层级和操作方式;手机端只收紧
浮层尺寸,避免为了适配窄视口引入另一套模型选择行为。
在 web-remote-replayable 且粗指针手机视口下,交互浮层必须满足:
calc(100vw - 2rem);长模型名、分支名和中英文文案由浮层内部截断或滚动承接,不得让页面本身产生水平滚动。当前与修复后的呈现边界:
当前(手机)
provider root menu -> desktop-width model submenu -> viewport clip
status panel row -> forced left popover -> viewport clip
修复后(手机)
provider root menu -> narrow model submenu(保持二级交互)
-> min(desired width, Radix available width) -> viewport edge
status panel row -> bottom/top popover -> viewport collision handling
桌面 / 宽屏 Web
provider root menu -> desktop-width model submenu(保持现状)
status panel row -> left popover(保持现状)
该边界只属于 renderer presentation;不改变 mobile shell 导航、task/session 投影、
CommandInbox、owner/lease、relay 或 desktop-continuous / web-remote-replayable delivery 语义。
当前链路里,desktop main 会通过 initialViewState 返回扫码发起时的 workspace/task。
新行为:
mobileViewState -> initialViewState -> 第一个 workspace。home。activeWorkspaceKey 展开对应 workspace card。activeTaskId 把对应 task row 标为选中。initialTaskId 在这个阶段只表达“首页选中态”,不能触发 onNavigateToChat,也不能复用点击任务的打开流程。
这样用户扫码后首先看到当前设备上所有 workspace/task 的总览,同时能清楚知道桌面扫码时对应的 task 在哪个 workspace 下。
任务打开逻辑从现有 WebRemoteControlTaskIndex 中抽出,形成共享 hook:
useWebRemoteControlTaskOpen
input:
switcher
activeWorkspacePath
activeWorkspaceIdentity
activeTaskId
onSelectTask
onNavigateToChat
onSwitchingChange
output:
openTask(task)
switchingTaskKey
error
跨 workspace 后进入聊天页需要一份一次性导航意图,不能从 initialTaskId 反推:
type WebRemoteControlMobileNavigationIntent = "chat";
interface WebRemoteControlWorkspaceSwitchOptions {
taskId?: string;
mobileNavigationIntent?: WebRemoteControlMobileNavigationIntent;
markTaskReadExpectedUnreadAt?: number;
}
interface WebRemoteControlMobileShellProps {
initialNavigationIntent?: WebRemoteControlMobileNavigationIntent;
}
规则:
WebRemoteControlWorkspaceSwitcherApi.switchWorkspace() 的第二个参数扩展为 WebRemoteControlWorkspaceSwitchOptions,旧调用不传 mobileNavigationIntent 时行为不变。openWorkspaceBridge() 前把 mobileNavigationIntent 暂存为内存中的 pending intent。initialNavigationIntent 传入,MobileShell 首次 mount 后消费并清空。mobileViewState,也不传给 desktop main;它只解决当前浏览器页跨 Root remount 后的页面落点。initialTaskId 不设置 pending intent,因此只展开首页 card 和选中 task row。同 workspace task:
taskWorkspaceKey。activeWorkspaceKey。unreadAt,通过当前 Web 远控 bridge 的
switcher.markTaskRead(task) 显式调用 setTaskUnread(..., false);该动作不得依赖手机 Root
内部 task query cache 是否已经水合。onSelectTask(task.workspacePath, task.taskId, task.workspaceIdentity)。switcher.updateMobileViewState(taskWorkspaceKey, task.taskId)。chat 页面。跨 workspace task:
switcher.switchWorkspace(taskWorkspaceKey, { taskId: task.taskId,
mobileNavigationIntent: "chat", markTaskReadExpectedUnreadAt: task.unreadAt })。workspacePath/workspaceIdentity 和首页快照中的 unreadAt 调用
setTaskUnread(..., false, expectedUnreadAt);失败只记录日志,不得阻止任务打开。initialTaskId 并选中任务。chat 页面。logger.error,并停留首页显示错误。注意:扫码初始 task 只影响首页选中态,不调用这个点击流程。
手机任务首页的蓝点来自 desktop renderer 推送的 WebRemoteControlTaskTarget.unreadAt 快照;手机
Root 内的 task query cache 是另一个按当前 bridge 异步水合的数据面。点击任务时不得再用 query cache
是否命中 unreadAt 作为是否清除未读的前置条件,否则同一 task 已经 active、冷 cache 或跨 Root
remount 时会跳过持久化。
mobile home snapshot task.unreadAt
│
├─ same workspace -> current bridge markTaskRead(expectedUnreadAt)
│ -> tasks-index compare-and-clear
│
└─ cross workspace -> switch option markTaskReadExpectedUnreadAt
-> target bridge connected
-> target service compare-and-clears tasks-index unreadAt
desktop task selection -> existing query-cache optimistic clear(保持不变)
约束:
unreadAt 时发起写入;已读 task 不产生无意义 mutation。workspaceIdentity;路径执行语义继续使用 workspacePath。desktop-continuous 的 useWorkspaceTaskNavigation、query-cache overlay、排序与
lastActivityAt 逻辑不变;本动作只存在于手机 Web 远控 switcher。unreadAt 与 expectedUnreadAt。相等时清除;不相等时返回当前 meta 且不发变更事件,禁止迟到
的旧点击覆盖随后产生的后台完成或错误未读。建议新增或调整以下 UI 文件:
packages/ui/src/WebRemoteControlMobileShell.tsx
home/chat 页面状态。mobileNavigationIntent。packages/ui/src/WebRemoteControlMobileTaskHome.tsx
packages/ui/src/hooks/useWebRemoteControlTaskOpen.ts
WebRemoteControlTaskIndex 的 task 打开逻辑。packages/ui/src/lib/webRemoteControlTaskIndex.ts
packages/ui/src/app-shell/WorkspaceShellLayout.tsx
WebRemoteControlMobileShell。当前 WebRemoteControlTaskTarget 已包含首页所需的基础字段:
taskIdtitleworkspacePathworkspaceIdentityremoteSessionIdworkspaceLabelworkspaceKindcreatedAtupdatedAtproviderunreadAtpinned首页派生展示字段:
deviceLabel 协议字段,只展示当前远控连接状态。后续如果要展示真实设备名,需要显式扩展 WebRemoteControlWindowBootstrapResult / WebRemoteControlWorkspaceListResult 增加可选 deviceLabel,并提供连接状态文案作为 fallback。workspaceUpdatedAt 协议字段,由 mobile 首页按 workspace 分组后取该组 task 的最大 updatedAt。没有 task 的 workspace 不显示更新时间。为了支持截图里的状态 pill,建议补一个可选展示字段:
displayStatus?: "idle" | "running" | "completed" | "error";
// 2026-09-09 追记:会话是否挂着后台工作(动态工作流 run / 后台 bash / 分离子代理)。
// 只参与列表运行层排序,不影响 displayStatus;来源是 sessions-index sidecar 的 hasBackgroundWork。
hasBackgroundWork?: boolean;
// 2026-09-14 追记:工作流运行摘要(≤ 4 条 run:在跑优先,其后最近结束的),来源是 sidecar 的 workflowActivity。
// 手机行在标题下绘制 Workflow 图标 + 迷你轨道灯 + 当前 phase 名(24px,13px 文字);只绘制,不参与排序或状态 pill。
workflowActivity?: SessionWorkflowActivity;
字段来源按权威级别分层,不能把多个缓存当成同级事实:
phase 是当前展示状态的唯一权威:
prewarming / running → runningcompletedSuccess / completedInterrupted → completederror → errordraft 不产生持久 task 行;如果兼容数据意外带入 draft,不把它当成终态,继续走下一级 fallbackcreating / queued / streaming / waiting_permission / waiting_user_input 等 live status → runningfailed → errorcompleted → completedcompleted → completederror → errorstatus=running 只表示旧进程可能未正常收尾,不能证明当前 host 仍在运行,fallback 为
idle。这条优先级必须覆盖所有冲突方向,而不是只修 running:
| sessions-index activity | 旧 runtime / 持久缓存 | 手机展示 |
|---|---|---|
prewarming / running |
completed / failed / error |
running |
completedSuccess / completedInterrupted |
live / failed / running |
completed |
error |
live / completed / running |
error |
缺失或兼容 draft |
任意 | 保持现有 runtime → 持久终态 fallback |
因此 sessions-index 新帧既能把旧 completed/error cache 推进为 running,也能把旧 live cache 收口为
completed/error。手机首页不自行合并这些来源。
聚合边界:
displayStatus 由 desktop renderer 在构建 WebRemoteControlTaskTarget 快照时计算;
buildWebRemoteControlTaskTargets() 先读取 task 行携带的 sessions-index activity,再按上述顺序
fallback 到 Zustand task runtime state 和 ZCodeTaskMeta.status。WebRemoteControlTaskTarget.displayStatus,不能直接读取 ZCode runtime、Repo、Service 或持久化实现。syncWebRemoteControlTasks() -> desktop main -> relay -> mobile bootstrap/listWorkspaces,不新增 mobile 侧状态查询入口。running / completed / error pill 滞后到下一次 task list 刷新。idle。Desktop main 只对 renderer 已构建的 WebRemoteControlWorkspaceListResult 做传输去重,不拥有或重新
解释 task 业务状态。去重签名必须覆盖手机首页需要即时采用、但只在生命周期节点或用户操作时变化的
字段:
title、unreadAt、displayStatus、pinned、archived、remoteSessionId;kind、connectionState、remoteSessionId、lastConnectionError;字段按手机端展示语义归一化:缺失 displayStatus 等价于 idle,缺失 connectionState 等价于
connected,缺失可选字符串等价于空串,缺失布尔 membership 等价于 false。上述任一有效值变化都
必须发送新的 workspace-list-updated。
updatedAt 来自 sessions-index lastActivityAt,流式文本和工具事件期间会高频变化。本轮不把它加入
即时推送签名;如需实时刷新相对时间和时间排序,必须另行设计节流/合并策略,不能让每个流式事件推送
整份任务首页快照。
低频展示/连接字段变化 ──> main 快照签名变化 ──> workspace-list-updated ──> 手机立即采用
高频 updatedAt 变化 ────> 本轮不触发整表即时推送(保留后续节流/合并边界)
本次修复属于 presentation / state-source precedence,不改变会话 command、runtime、持久化或恢复协议。
sessions-index phase (实时 activity) ───────────────┐
├─> desktop renderer target projection
renderer runtime cache (仅 activity 缺失时 fallback) ┤ └─> relay payload ─> 手机状态 pill
tasks-index terminal status (最后 fallback) ─────────┘
desktop task list ── sessions-index continuous projection(保持原链路)
mobile /remote ───── renderer task snapshot + replayable delivery(只修正 payload 字段)
必须保持:
desktop-continuous 与手机 web-remote-replayable 的 snapshot/gap、owner、queue 语义不变。workspaceIdentity?.trim() || workspacePath、remoteSessionId 和 pinned/archived membership 不受状态
合并影响。displayStatus,因此 stale cache 不再把终态行错误置顶或把
真实运行行压回普通时间排序。Focused 回归覆盖所有 phase 与冲突 cache 的组合;本次不新增 conversation E2E,因为没有新增交互、 command 或 delivery 行为,运行时 NDJSON 已证明 sessions-index 在错误窗口持续发布正确 phase,缺陷位于 纯 renderer target projection。
为了支持 pinned 分区,WebRemoteControlTaskTarget 增加可选字段:
pinned?: boolean;
字段来源:
Root 中分别通过 useGlobalTaskList({ kind: "pinned" }) 和
useGlobalTaskList({ kind: "timeline" }) 读取任务。buildWebRemoteControlTaskTargets() 对 pinned 查询结果标记 pinned: true,timeline 查询结果不标记。workspace_task_list_changed 携带 task meta 的增量事件只表示标题、时间、状态等元数据变化,不表示
pinned/archived 成员关系变化。前端缓存更新必须保留现有列表归属,避免状态刷新把置顶任务移出 pinned 分区。第一版不需要引入真实 URL 路由,可以在 mobile shell 内部用 React state:
currentMobilePage: "home" | "chat"
进入聊天:
currentMobilePage = "chat"。{ zcodeMobilePage: "chat" },补一层 chat history state。返回首页:
{ zcodeMobilePage: "chat" },调用 history.back(),由 popstate 回到 home。currentMobilePage = "home" 作为兜底。浏览器返回键:
home 时不写 history,保留扫码入口原始历史栈。home 点击 task 并成功进入 chat 时,调用一次 history.pushState({ zcodeMobilePage: "chat" }, "")。chat state,不重复 push,避免同一个 task 多次点击堆叠历史。popstate 命中 { zcodeMobilePage: "chat" } 时设置 currentMobilePage = "chat";从 chat 点返回按钮时用 history.back() 回到 home,而不是直接改 state。popstate 回到非 zcodeMobilePage state 时设置 currentMobilePage = "home",并放行浏览器后续默认返回行为。chat state;这层 state 来自点击流程的一次性 mobileNavigationIntent,扫码初始 initialTaskId 不补这层 state。popstate listener。不要把 workspace/task 状态塞进 URL,避免和扫码入口及配对态互相耦合。
UI 必须遵守根目录 DESIGN.md:
bg-background、bg-card、border-card-border、text-foreground-subtle。rounded-lg,不要使用过大的圆角。Button 组件和 lucide 图标。涉及交互问题时需要打日志辅助定位,不猜测状态。
UI 层统一使用:
import { logger } from "@/logger.js";
建议日志点:
error。error。info。error。warn。高频渲染和普通 hover 不打日志。
必须执行:
pnpm typecheck
pnpm lint
当前测试入口:
packages/ui/test/webRemoteControlMobileTaskHome.test.ts
activeWorkspaceKey。activeTaskId 对应 task 显示 selected。packages/ui/test/useWebRemoteControlTaskOpen.test.ts
onSelectTask 和 updateMobileViewState。switchWorkspace 时带上 { taskId, mobileNavigationIntent: "chat" }。packages/ui/test/workspaceShellRemoteMobileLayout.test.ts
mobileNavigationIntent 进入 chat,并在消费后清空。packages/shared/test/webRemoteControl.test.ts
displayStatus,补 schema/类型兼容测试。packages/ui/test/webRemoteControlTaskIndex.test.ts
buildWebRemoteControlTaskTargets() 按 sessions-index activity → task runtime →
ZCodeTaskMeta.status 的优先级计算 displayStatus。draft 时保持原有 runtime/persisted fallback,持久 running 仍不得制造假
running。packages/desktop/test/webRemoteControlManagerExternalRelay.test.ts
title、unreadAt、displayStatus、pinned、archived 或
remoteSessionId 时必须推送 workspace-list-updated。connectionState、remoteSessionId 或 lastConnectionError 时必须推送;
完全相同的有效字段快照仍应去重。updatedAt 不属于本轮即时推送契约。建议按以下顺序落地:
useWebRemoteControlTaskOpen,保持现有 WebRemoteControlTaskIndex 行为不变。displayStatus 字段和状态 pill。pnpm typecheck 和 pnpm lint。docs/web-remote-control/web-remote-control-architecture.md 中当前手机端 UI 描述。workspaceIdentity 做 key,不能只用 workspacePath。WorkspaceShellLayout 已有远控手机布局历史逻辑较多,接入 mobile shell 时要小心保留桌面远控行为。remoteControlToken 和内部 task 页面状态混在一起。