/remote 是现有 Hub 的远程 UI attachment,不独立创建 Node runtime。desktop-continuous 与 Browser / 手机 replayable 继续保持不同 delivery 语义;
目标态再把 Browser 与手机拆成不同的可信连接角色。| 层 | 本规划的变化 |
|---|---|
| option-source | 模型目录改为账户级期望配置;Skill / Plugin / Subagent 候选改为目标 Node 实际能力。 |
| draft-default | 新任务模型默认值来自账户级模型 Profile;已有 Session 继续使用自己的运行时配置。 |
| validation | 创建和发送前校验目标 Node 的模型与凭据 readiness;扩展操作校验目标 Node 能力。 |
| commit-effect | Task / Session 命令只路由到任务来源 Node;Hub 不执行业务命令。 |
| persistence | 引入稳定 Node / Workspace 身份、跨节点视图配置、Hub 目录缓存和迁移 ledger。 |
| recovery | 多 Node 游标、节点离线、拓扑变化、双数据库迁移和旧 identity alias 都需要恢复协议。 |
tasks-index.sqlite,Session runtime 和正文仍由 CLI
Session Store 权威持有。当前 UI 会把每个 endpoint 的 active / pinned / archived 全量拉回,
再在 renderer 合并、排序和裁剪。ZCodeTaskListQuery 只有 limit,没有 cursor;当前“显示更多”仍会重新读取完整前缀。tasks-index.sqlite 的
task_groups / task_group_members / task_group_view_node_orders,排序是用户显式顺序,
不是时间排序;当前 Grouped 视图明确不聚合 remote endpoint。~/.zcode/v2/config.json。当前 Provider metadata、Base URL 和
自定义 API Key 仍混在同一配置 / registry snapshot 中。~/.zcode/v2/tasks-index.sqlite~/.zcode/cli/db/db.sqlite旧 SSH workspace key 的格式为:
remote:ssh:<host>:<port>:<username>:<workspacePath>
同一目标机经不同 hostname、端口、用户名或 SSH alias 连接,会形成不同 key。
IRemoteBackend -> deployServer -> connectRemote -> zcode-server,进程复用和回收仍不一致:
zcode-server。它由 Desktop Host 持有生命周期,
不监听长期端口;连接 EOF 或 Host 退出会触发 Server 和 Agent 清理。entry-http.js 创建另一种长期 HTTP / WebSocket Server;它与 stdio Server
都调用 createLocalServices(),但入口、认证、连接复用和生命周期仍是两套。/remote 经 relay 附着 Desktop 窗口已有 Local / Remote Host;relay 和 Desktop main
只透传 rpc-frame 与 attachment 控制,不拥有 task / session / stream / queue / snapshot。全局 Task 身份不能再只用 taskId,至少使用:
GlobalTaskRef = { nodeId, workspaceId, taskId }
workspacePath 只用于目标 Node 上的 IO 和展示,不能继续承担跨机器永久身份。
已有 Session 的 provider / model / thought 仍由该 Session runtime 权威持有;账户模型配置只提供 目录、默认值和新 Session 种子,不能批量改写历史 Session。
Node 本地 Skill / Plugin / Subagent 不得被多个节点的候选并集伪装成“当前任务可用”。
手机 /remote 只看到已配对 Hub 已连接或已缓存的 Node;不能绕过 Hub attachment 直接创建
Node runtime。
UI 不得自行声明可信 clientMode;Desktop continuous、Browser / Mobile replayable 都必须由
Hub / Node attachment 依据已认证的连接角色注入。
SSH / WSL / Docker bootstrap 只负责“到达 Node”,不得拥有 workspace、Agent 或 conversation 生命周期。
Account Control Plane
┌────────────────────────────────┐
│ Model Profile │
│ Credential policy / bindings │
│ Federated Task View Profile │
└───────────────┬────────────────┘
│ revision sync
┌───────────────┴────────────────┐
│ │
Browser Web on A Desktop UI on C
│ │
Federated Hub A Federated Hub C
┌────┴────┐ ┌──────┼──────┐
│ │ │ │ │
Node A Node B Node A Node B Node C
▲
│ local/in-process
TUI on A
Mobile /remote
-> relay
-> Hub C attachment
-> 已连接的 Node A / B / C
约束:
Desktop / Browser / Mobile UI 只连接 Hub
TUI 只连接本机 Node
Hub 只连接 Node
Node 持有本机业务服务和 workspace runtime
Node 按 workspaceKey 懒启动 ZCode Agent
SSH / WSL / Docker 只是 bootstrap + tunnel adapter
目标不是把所有东西塞进一个进程,而是让不同部署形态复用同一组逻辑角色和协议合同。
| 角色 | 数量与位置 | 职责 | 明确不负责 |
|---|---|---|---|
| UI Client | Desktop Renderer、Browser Web、Mobile Web | 展示统一 Node / Workspace / Task 视图,提交用户意图 | 不持有业务权威,不直接 SSH,不直接启动 Agent |
| ZCode Hub | 每个 Desktop 实例一个;每个 Lite Web origin 一个 | Node registry、连接管理、Task Summary 聚合、离线目录缓存、账户 Profile 同步、UI attachment | 不执行文件命令,不拼 conversation,不拥有 queue / stream / snapshot |
| ZCode Node | 每台目标机器、WSL distro 或容器一个稳定实例 | Workspace Registry、file/git/terminal、Task Index、Resource Store、Agent manager、extension inventory | 不聚合其他 Node,不递归充当远端 Hub |
| ZCode Agent | 每个活跃 workspaceKey 最多一个主聊天 runtime | Session、V4 CommandInbox、projection、stream、permission、tool、model runtime | 不管理跨 Node 连接或 UI 布局 |
| Bootstrap / Tunnel Adapter | 每条 SSH / WSL / Docker 连接一个短生命周期 connector | 安装、升级、发现 Node,建立到 Node endpoint 的字节隧道 | 不创建第二套 ServiceCollection,不保存业务状态 |
| Relay | 外部可选基础设施 | 手机与 Hub 的鉴权、配对、心跳、opaque frame 透传 | 不解析 Node / task / session,不做 replayable snapshot |
| Account Control Plane | 账户服务、自托管服务或离线实现 | Model Profile、Credential policy、Federated View revision | 不承载实时 conversation |
Desktop machine C
┌─────────────────────────────────────────────────────────────────────┐
│ Electron Main │
│ - 窗口、native API、进程监督、MessagePort 分发 │
│ - 不拥有 Node registry / task / session │
│ │
│ ├─ Renderer Window 1 ─┐ │
│ ├─ Renderer Window 2 ─┼─ MessagePort ──> App-wide ZCode Hub Process │
│ └─ Mobile relay ──────┘ │ │
│ ├─ local connector │
│ ├─ direct WSS │
│ ├─ SSH tunnel │
│ ├─ WSL tunnel │
│ └─ Docker tunnel │
└────────────────────────────────────────────────┼────────────────────┘
│
┌───────────────────────┼──────────────────────┐
▼ ▼ ▼
Node A Node B Node C
目标态不再按窗口为每个 SSH / Docker workspace 创建一套业务 Remote Host。Desktop main 只监督一个 app-wide Hub;多个窗口和手机 attachment 都复用 Hub 的 Node connection pool。每个 UI attachment 仍有独立 connection / subscription scope,不能因物理连接复用而共享 delivery buffer。
Desktop 本机能力也通过同一个 Node 合同访问:
Desktop Hub
-> 发现已有 local Node daemon
-> 若不存在,则由 Main 监督启动 embedded Node Process
-> MessagePort / named pipe / loopback socket
-> Local Node Core
Node 数据目录必须有 single-owner lock。若用户已经通过 ZCode Lite 启动同一数据目录的 Node, Desktop 必须复用它,不能再启动第二个 SQLite / Agent owner。
zcode-lite serve
┌──────────────────────────────────────────────────────────────┐
│ Lite Supervisor │
│ ├─ Node Core / Node Process │
│ │ ├─ Workspace Registry / Task Index / Resource Store │
│ │ └─ Agent A / Agent B ... │
│ ├─ Hub Core / Hub Gateway │
│ │ ├─ local Node A connection │
│ │ └─ remote Node B / C connections │
│ └─ HTTP Gateway │
│ ├─ / Web 静态资源 │
│ ├─ UI <-> Hub endpoint │
│ └─ authenticated Hub <-> Node endpoint │
└──────────────────────────────────────────────────────────────┘
▲ ▲
│ same-origin WSS │ HTTPS/WSS
Browser Web on A Desktop Hub C
Lite 对外可以只暴露一个端口,但端口内必须按角色分开:
Browser UI role -> Hub endpoint
Remote Hub role -> Node endpoint
Admin/bootstrap -> 有限的 Node discovery / pairing endpoint
同一个 HTTP listener 不等于同一个权限。Browser session cookie 不能自动获得 Hub-to-Node 的可信权限; Desktop Hub 需要独立 token、mTLS 或一次性 capability。
MVP 可以让 Node Core、Hub Core 和 HTTP Gateway 同处一个 Node.js 进程以降低安装复杂度,但必须使用 独立 service collection、身份和生命周期接口。长期可以拆进程而不改变协议。
| 当前实现 | 当前语义 | 目标迁移 |
|---|---|---|
entry-http.ts -> createLocalServices() |
Lite HTTP 进程直接持有 Node services | 抽出 Node Core;同 listener 增加独立 Hub Gateway |
/ws |
Browser 直接连接 Node services,固定 replayable | Browser 改连 Hub endpoint;Hub 再路由 local / remote Node |
/ws/host |
Desktop Node Host 以一次性 capability 直连 Node | 保留为 Hub-to-Node trusted endpoint,并扩展稳定身份与重连 |
entry-stdio.ts -> createLocalServices() |
SSH / WSL / Docker 每次连接启动一套业务 Server | 迁为 bootstrap / tunnel shim;业务只在稳定 Node daemon |
| per-window Remote Host | 窗口级 SSH / WSL pool,Docker dedicated | app-wide Hub connector pool |
| Desktop Main mobile bridge | relay frame 接到某个窗口已有 Host | relay device transport 接到 Hub logical attachment |
当前 Browser Web 只读取一个 ZCODE_SERVER_WORKSPACE,不能管理动态 workspace catalog;普通 Web
也不能完整处理长文本临时附件。目标 Hub / Workspace Registry 和 Resource Store 必须先补齐这些合同,
再开放跨 Node Web 管理,不能只把 UI 入口显示出来。
TUI 是 Lite / Node 安装包的本机客户端,不参与跨 Node 聚合:
TUI on A
-> local socket / in-process adapter
-> Node A
-> workspace Agent
它可以复用 Node API 和 V4 conversation protocol,但不提供 SSH 管理入口,也不作为其他机器的 Hub。
建议最终发布同一套 runtime,以子命令区分角色:
zcode node serve # 长期 Node daemon
zcode node connect # 只做 stdio <-> local Node socket 字节桥
zcode hub serve # 可独立运行的 Hub Gateway
zcode lite serve # 监督 local Node + Hub + Web 静态入口
zcode tui # 本机 UI,直接连接 local Node
zcode node connect 不调用 createLocalServices(),也不启动 Agent;它只是 SSH / WSL / Docker
无法直接转发本地 socket 时的 transport shim。
ssh、direct URL 或 local socket 只说明如何到达 Node,不能继续隐式决定模型、凭据和设置的权威。
Transport:
local | direct-wss | ssh-tunnel | wsl-tunnel | docker-tunnel
Authority profile:
account-managed
hub-attached-compat
node-standalone
account-managed:账户 Model Profile 是期望配置,Node 使用自己的 credential binding / lease。hub-attached-compat:仅表示已经退出的历史 Desktop Registry 下发方案,不是当前兼容模式。node-standalone:离线或自托管 Node 使用本机 Profile / vault。同一个 Node 从 SSH tunnel 改为 direct WSS 后,不得因此换一套 task、workspace、model 或 extension 身份。
业务层
├─ Hub Protocol
│ ├─ Node registry / connection status
│ ├─ federated Task Summary query
│ ├─ account profile / view profile
│ └─ route(GlobalWorkspaceRef / GlobalTaskRef)
├─ Node Service Protocol
│ ├─ workspace / file / git / terminal / task index
│ ├─ extension inventory / readiness
│ └─ resource begin / chunk / commit
├─ ZCode Protocol V4
│ ├─ command ACK / query
│ ├─ conversation / sessions-index / workspace-config topic
│ └─ snapshot / delta / gap recovery
└─ Bootstrap Protocol
├─ install / upgrade / discover
└─ NodeId / version / capability / endpoint
统一 RPC / frame 层
└─ @zcode/rpc IMessagePassingProtocol + typed runtime schema
Transport adapter
├─ MessagePort
├─ local socket / named pipe
├─ HTTPS + WSS
├─ SSH direct-tcpip / stdio tunnel
├─ WSL stdio tunnel
├─ Docker exec stdio tunnel
└─ mobile relay acknowledged rpc-frame
“SSH 发送的内容和 WS 差不多”应落实为:两者承载完全相同的 Node RPC / V4 frame, 而不是在 SSH 代码里维护另一套 service 方法。WebSocket 是一种 carrier;SSH / Docker 的 stdio 也只是 carrier。业务 schema、connection scope、命令幂等、资源协议和恢复语义必须相同。
| 链路 | 物理 Transport | 逻辑协议 | 默认 delivery |
|---|---|---|---|
| Desktop Renderer -> Desktop Hub | Electron MessagePort | Hub RPC | desktop-continuous |
| Browser Web -> Lite Hub | same-origin WSS | Hub RPC | browser-replayable |
| Mobile -> Hub | WSS relay + acknowledged opaque rpc-frame |
Hub RPC | mobile-remote-replayable |
| Desktop / Lite Hub -> direct Node | authenticated WSS | Node RPC + multiplexed V4 | 由 logical attachment 决定 |
| Hub -> local embedded Node | MessagePort / named pipe / local socket | Node RPC + multiplexed V4 | 由 logical attachment 决定 |
| Hub -> SSH Node | SSH tunnel 中的 socket frames | 与 direct Node 完全相同 | 由 logical attachment 决定 |
| Hub -> WSL Node | stdio connector -> distro local socket | 与 direct Node 完全相同 | 由 logical attachment 决定 |
| Hub -> Docker Node | docker exec -i connector -> container local socket |
与 direct Node 完全相同 | 由 logical attachment 决定 |
| Node -> Agent | child-process stdio NDJSON | ZCode Protocol V4 | Node 内部连接 |
browser-replayable 和 mobile-remote-replayable 可以复用同一种 replayable 算法,但必须保留不同
client role,避免把手机 pairing、Hub attachment 和 Browser same-origin 权限混成一个模式。
迁移期可以映射到现有 web-remote-replayable。
Hub 与同一 Node 只需维护少量物理连接,但物理复用不能吞掉现有 connection 隔离:
Hub C == one authenticated physical link ==> Node A
│
├─ attachment d1
│ role=desktop
│ profile=continuous
│ connectionId=node-assigned-1
│
├─ attachment b1
│ role=browser
│ profile=replayable
│ connectionId=node-assigned-2
│
└─ attachment m1
role=mobile-remote
profile=replayable
connectionId=node-assigned-3
每个 logical attachment 必须独立拥有:
connectionIdNode 只接受已认证 Hub 打开的 attachment role;UI payload 不能直接指定 clientMode。MVP 可先为每个
attachment 打开独立 WebSocket,等合同稳定后再做物理 multiplex。
Hub 只路由 frame 和管理 connection;conversation 的 seq、snapshot、queue 和 command lookup 仍由来源 Node / Agent 权威持有。
Hub Connector Bootstrap Adapter Target Node
| | |
|-- detect/install ---->| |
| |-- install/upgrade --->|
| |-- ensure daemon ----->|
| |<-- bootstrap result --|
|<-- NodeId/endpoint ---| |
| |
|==== authenticated Node Protocol over tunnel ==|
|-- hello(nodeId, protocol range, role) -------->|
|<-- capability / bootId / workspace registry --|
|-- open logical attachment -------------------->|
|<== Node RPC / V4 / resource frames ===========>|
Bootstrap 返回至少包含:
interface NodeBootstrapResult {
nodeId: string;
bootId: string;
nodeVersion: string;
protocolRange: { min: number; max: number };
capabilities: string[];
endpoint: {
kind: "loopback-tcp" | "unix-socket" | "named-pipe" | "direct-url";
address: string;
};
connectionChallenge: string;
}
connectionChallenge 只能兑换短期 Hub-to-Node capability,不能成为长期明文凭据。
ssh2
1. 上传/升级统一 Node runtime
2. 启动或发现 zcode node serve
3. Node 仅监听远端 loopback
4. ssh2.forwardOut 建 direct-tcpip tunnel
5. tunnel 上运行与 direct WSS 相同的 Node frame
若目标环境无法使用 direct-tcpip,则执行 zcode node connect,把 SSH stdio 纯转发到 Node local
socket。旧 entry-stdio.ts -> createLocalServices() 只保留一个迁移周期,不作为长期架构。
wsl.exe ... zcode node connect
-> distro 内 Unix socket
-> persistent Node daemon
这样 Windows localhost forwarding 差异只影响 adapter,不影响 Node RPC。WSL distro 不因 Desktop 窗口关闭而被 terminate。
docker exec -i <container> zcode node connect
-> container 内 Unix socket
-> persistent Node daemon
如果容器已显式暴露并保护 Node HTTPS / WSS 端口,Hub 可以 direct URL 连接;否则默认使用 exec
tunnel,不要求用户重建容器增加 -p。Node 生命周期跟随容器,workspace / Agent 生命周期由统一
WorkspaceLeaseManager 决定,不再每个 UI session 重启整套 Server。
用户通过 zcode lite serve 或 zcode node serve 启动后:
连接 URL、SSH alias、Docker container name 和 WSL distro 只进入 ConnectionProfile,不进入 Node /
Workspace / Task 永久身份。
长文本自动转文件、拖入图片和任意外部资源必须走同一个目标 Node Resource Store:
Desktop / Browser / Mobile bytes
|
v
Hub route(GlobalWorkspaceRef)
|
v
Node resource/begin
-> resource/chunk*
-> resource/commit
|
v
ResourceRef { nodeId, workspaceId, resourceId, sha256, mediaType, size }
|
v
Prompt 只携带 ResourceRef
|
v
目标 Node materialize / stream 给 workspace Agent
规则:
commit 前校验长度、hash、配额和目标 workspace lease。nodeId + workspaceId,禁止在 Node 之间误复用。File 对象共享同一 API。因此 Browser A 管理 Node B 时,资源链路是
Browser A -> Hub A -> Node B Resource Store,不是把 Node A 的临时路径写进 prompt。
手机是 Hub 的远程 UI attachment:
Mobile Browser
-> external relay
-> selected Hub device transport
-> Hub node registry / router
-> existing Node logical attachment
-> source workspace Agent
目标态把 relay device transport 和 shared attachment manager 收敛到 Hub Gateway。Desktop main 只保留二维码、窗口和进程调度;Lite Hub 也可以在用户显式开启后注册 relay device role。
mobile-remote-replayable logical attachment。rpc-frame;replay / gap / snapshot 在 Node / Agent 与手机 UI 两端。CommandInbox;不新增 mobile queue。Browser Web:
same-origin WSS -> Lite Hub -> one or more Nodes
Mobile Remote:
relay WSS -> 已配对 Hub -> one or more Nodes
两者可以渲染同一套 UI 组件,也都使用 replayable delivery,但认证、入口和连接 owner 不同。
UI attachment lifetime = 页面 / 窗口 / 手机 bridge
Hub lifetime = Desktop App 或 Lite Hub service
Tunnel lifetime = Hub 到 Node 的一次物理连接
Node daemon lifetime = 节点级,独立于 UI 和 tunnel
Workspace lease lifetime = attachment + running task + policy / idle TTL
Agent lifetime = workspaceKey 级,由 Node WorkspaceLeaseManager 管理
Conversation lifetime = Agent session store,不等于任何进程连接
必须满足:
bootId 变化;Hub 必须使旧 attachment /
subscription / cursor 失效并重新握手。connectionId,并根据已认证 role 注入 delivery profile。| Scope | 权威数据 | 同步语义 |
|---|---|---|
| account | Provider / Model metadata、展示顺序、默认模型、全局最近显式模型元组、可选跨端分组视图 | revision 化,同一账户各 Hub / Node 收敛 |
| credential | API Key、OAuth token、Coding Plan key、runtime header | 与 metadata 分离;按策略使用 E2E 同步、Node 本地 vault 或短期 lease |
| hub/device | Node connection profile、连接状态、UI 布局、持久化离线目录缓存 | 设备本地;不能成为 Task / Session 权威 |
| node | Plugin 实际安装、user Skill / Subagent、工具链、Node capability、runtime cache | 每台机器独立,可显式复制,不自动求并或覆盖 |
| workspace | Repo 内 .zcode/* / .agents/*、workspace extension、项目设置 |
位于目标 Node 的 workspace;由 Git / 文件系统自然传播 |
| session | 当前 provider / model / thought / mode、消息、queue、owner、stream、permission | 只在执行该 Session 的 Node runtime |
历史 ZCodeProviderRegistrySnapshot 曾同时包含 metadata 和 raw secret;该快照链已经删除。多 Node
目标设计仍需把期望配置、Credential Binding 和执行时 Lease 保持为三条独立链:
Account Model Profile
ProviderCatalogSnapshot
- provider / model / capability / baseURL / order / defaults
- metadataRevision
│
▼
Node Runtime Binding
- providerId / modelId / metadataRevision
- credentialBindingId
│
▼
Credential Plane
- encrypted Node secret 或短期 credential lease
- audience = nodeId + workspaceId + sessionId
- credentialRevision / expiry / revocation
建议类型:
interface ModelProfile {
profileId: string;
revision: string;
providers: ProviderMetadata[];
defaultModelRef?: string;
lastExplicitSelection?: {
modelRef: string;
thoughtLevel?: string;
};
}
interface NodeModelReadiness {
nodeId: string;
profileRevision: string;
providers: Array<{
providerId: string;
status: "ready" | "missing-credential" | "unsupported" | "stale";
reason?: string;
}>;
}
规则:
ModelProfile。nodeId + workspaceId 查询,不能使用所有 Node 的并集作为当前任务候选。workspace 字段当前还没有形成完整的 workspace 隔离语义,不能直接当作目标设计已完成。Hub 只聚合 Task Summary;用户打开任务后才从来源 Node 读取 snapshot / conversation page。
Node A sorted TaskSummary page ─┐
Node B sorted TaskSummary page ─┼─ Hub k-way merge ── unified task list
Node C sorted TaskSummary page ─┘
select {nodeId, workspaceId, taskId}
-> route to origin Node
-> subscribe continuous / replayable
-> on-demand session snapshot and rows
interface FederatedTaskQuery {
kind: "timeline" | "workspace" | "pinned" | "archived";
sortBy: "created" | "updated";
search?: string;
workspaceIds?: string[];
pageSize: number;
cursor?: string;
}
interface NodeTaskSummaryPage {
nodeId: string;
taskIndexRevision: string;
sessionIndexRevision: {
logEpoch: string;
seq: number;
};
items: TaskSummary[];
nextCursor?: string;
}
协议要求每个 Node 使用完全相同的 total order。全局 tie-break 必须包含
nodeId + workspaceId + taskId,不能继续假设 taskId 跨 endpoint 不冲突。
推荐把易变的 running task 从历史 cursor 中拆出:
有界、实时、全量的 running overlay
+
稳定 keyset 分页的 terminal / history rows
当前排序语义保持:
createdAt DESC,再按全局 Task ref;createdAt DESC, updatedAt DESC, GlobalTaskRefupdatedAt DESC, createdAt DESC, GlobalTaskRef历史页 cursor 至少绑定:
queryHash
topologyEpoch
nodeId -> taskIndexRevision / sessionIndexRevision / shardCursor
after -> primaryTime / secondaryTime / GlobalTaskRef
节点集合或 revision 变化时返回 cursor-stale 并刷新,不静默跳项。
MVP 可以沿用 createdAt / updatedAt,并以全局 Task ref 做稳定 tie-break;这只能保证确定性,
不能消除机器时钟漂移。
长期建议增加:
ActivityStamp = { physicalMs, logical, nodeId }
旧数据迁移为 { updatedAt, 0, nodeId }。Node 握手时交换时钟诊断,严重漂移时在 UI 标记,
不能用 Hub 收到消息的时间篡改历史创建时间。
当前 renderer cache 不持久化。Federated Hub 需要一个只读 materialized catalog:
GlobalTaskRefGlobalWorkspaceRef 派生,任务仍按时间分页。sortOrder,不是 Task 时间。跨 Node 的自定义分组不能把每个 Node 的 task_groups 直接求并。推荐由账户级
FederatedTaskViewProfile 单一持有:
interface FederatedTaskViewProfile {
revision: string;
groups: Array<{
groupId: string;
title: string;
color: string;
sortOrder: number;
}>;
members: Array<{
groupId: string;
task: GlobalTaskRef;
sortOrder: number;
}>;
topLevel: Array<
| { type: "group"; groupId: string; sortOrder: number }
| { type: "task"; task: GlobalTaskRef; sortOrder: number }
>;
}
所有成员和顶层节点必须持久化显式顺序;新架构不能再依赖客户端扫描全量后用
max + 1000 补序。
因此:
GlobalTaskRef 向对应 Node 批量取 Summary。viewRevision + groupId + sortOrder + GlobalTaskRef。NodeId = Node 数据目录中一次生成并持久化的 UUID
WorkspaceId = Node Workspace Registry 中的稳定 UUID
GlobalWorkspaceRef = { nodeId, workspaceId }
GlobalTaskRef = { nodeId, workspaceId, taskId }
workspacePath 是 Workspace Registry 的可变属性,不是 WorkspaceId。remoteSessionId 仍是某个 Hub attachment 的短期句柄,不进入全局身份。workspaceIdentity 翻译成
Node-local WorkspaceId;Node 数据库不应因为访问方式不同产生多套 Task。渐进式 MVP 可以先用 Node 内规范化路径作为 canonical workspace key,但 RPC 必须先引入
WorkspaceRef,给稳定 WorkspaceId 留出升级位置。
当前 HTTP serverId 可能回退 hostname,SSH stdio hello 也没有 serverId。迁移前必须:
目标 Node
├─ ~/.zcode/v2/tasks-index.sqlite
│ ├─ tasks
│ ├─ task_group_members
│ ├─ task_group_view_node_orders
│ ├─ task_group_workspace_bootstraps
│ ├─ automations
│ └─ automation_runs
├─ ~/.zcode/cli/db/db.sqlite
│ └─ session.workspace_id
├─ ~/.zcode/v2/sessions/<legacyWorkspaceHash>/
├─ workspace config / provider isolation hash directories
└─ Hub / Desktop lastWorkspaceSession 与 connection credentials
messages / parts / todos / targets 等通过 session_id 关联,无需改 workspace key。
先上兼容层,再搬数据:
workspace_registry(
workspace_id,
canonical_path,
...
)
workspace_alias(
alias_key,
workspace_id,
source_kind,
verified_node_id,
created_at
)
migration_run(
migration_id,
source_alias,
workspace_id,
phase,
error,
updated_at
)
旧客户端继续传 remote:ssh:* 时,ingress alias 必须先把它解析到 canonical workspace;
否则迁移后旧客户端会再次写出旧 key。
两个 SQLite 不能跨库事务,迁移必须可恢复:
prepared
-> task_index_done
-> session_store_done
-> files_and_settings_done
-> verified
prepared
task_index_done
tasks,同步改标量列与 meta_json;node_key 的新旧格式;group_id、标题、颜色和顺序;session_store_done
session.id;directory == canonicalPath 和 old workspace_id == source alias;files_and_settings_done
lastWorkspaceSession 改为 GlobalWorkspaceRef;verified
同一 canonical workspace 下出现相同 taskId 时:
createdAt 取最早;updatedAt / unreadAt 取最新;各 Hub / Node 可能已经有不同的本地 Group 布局。推荐:
legacyViewOrigin 导入;entry-http / entry-stdio 抽出唯一 Node Core 组合根。zcode node connect 到 local socket。WorkspaceLeaseManager,消除三种不同 Host / Agent 回收语义。entry-stdio -> createLocalServices() 远端主路径。| 维度 | 代表值 |
|---|---|
| UI | Browser Web / Desktop / Mobile remote |
| Node | local / direct server / SSH bootstrap / offline |
| delivery | desktop-continuous / browser-replayable / mobile-remote-replayable |
| transport | MessagePort / direct WSS / SSH tunnel / WSL connector / Docker connector / relay |
| config | Profile current / Node stale / missing credential |
| task state | running / terminal / archived / deleted |
| list | timeline / workspace / pinned / grouped |
| resource | long-paste file / image / browser File / mobile attachment |
| migration | clean / duplicate alias / same task same content / same task divergent |
| ID | Setup | Action | Assertion | 状态 |
|---|---|---|---|---|
| FED-01 | A Web 连接 Node A/B,C Desktop 连接 A/B/C | 各 Node 创建 Task | 两个 UI 都以 GlobalTaskRef 展示,不因 taskId / path 相同去重错误 | accepted |
| FED-02 | 三个 Node 各有多页 terminal Task 和 running Task | 滚动 timeline | running overlay 置顶;历史 k-way merge 不重不漏;不拉正文 | proposed |
| FED-03 | Node B 离线,Hub 有旧目录缓存 | 打开统一列表 | B 的 Task 显示 stale/offline;命令被阻止;A/C 可正常操作 | proposed |
| FED-04 | Account Profile revision N,Node B 仍是 N-1 | 在 B 新建 Task | 先同步到 N;缺 credential 时明确阻止,不静默换模型 | proposed |
| FED-05 | A/B 的 Skill / Plugin / Subagent 不同 | 在 B 的 Task 打开候选菜单 | 只展示 B workspace + B node inventory;全局矩阵不参与执行 | accepted |
| FED-06 | Account Group 跨 A/B Task | A Web 拖拽排序,C Desktop 刷新 | 两端按同一 View Profile revision 收敛 | pending-decision |
| FED-07 | 旧 SSH alias 与新 Node WorkspaceRef 指向同一数据 | 运行迁移并冷启动 | Task、Session、Group、automation 可对账;旧 alias 不再产生新行 | proposed |
| FED-08 | 两个旧 alias 有同 taskId、不同 Session 内容 | 运行迁移 | 不覆盖;生成 conflict,原数据和备份均保留 | proposed |
| FED-09 | 手机附着 C Desktop Hub | 切换查看 A/B/C Task | 只使用已有 attachment;不新建 Node runtime;replayable 恢复边界不变 | accepted |
| FED-10 | Node B 已由 Lite 启动,Desktop 又通过 SSH 发现 B | Desktop 连接同一 workspace | 复用同一 NodeId / WorkspaceId;不创建第二个 Server、Task Index 或 Agent owner | proposed |
| FED-11 | Desktop 与 Browser 同时操作 Node A 的同一 Task | 两端订阅并发送 | logical connection 隔离;continuous / replayable 各自恢复;命令进入同一 CLI inbox | proposed |
| FED-12 | Node B running task,SSH tunnel 断开 | Hub 重连 tunnel | Node / Agent 不因 tunnel 断开退出;按新 bootId / logEpoch 恢复或明确失败 | proposed |
| FED-13 | Docker 未暴露端口 | Desktop 连接容器 | docker exec connector 只转发 local socket;业务 RPC 与 direct WSS 同 schema |
proposed |
| FED-14 | Desktop 长文本转文件、Browser 拖图片到 Node B | 发送 prompt | 资源先 commit 到 B Resource Store;prompt 只含 B 的 ResourceRef;Agent 可读 | proposed |
| FED-15 | 手机连接 Hub C,Node B 离线 | 打开 B 历史 Task | 只展示 stale summary;不由手机触发 SSH / Docker bootstrap | accepted |
| FED-16 | Lite Node 与 Desktop embedded Node 竞争同一 data dir | 两端并发启动 | single-owner lock 保证一个 Node owner,另一端发现并连接或明确失败 | proposed |
| FED-17 | 普通 Browser 伪造 desktop clientMode | 建立 Node 连接 | Node 忽略客户端自报值,按认证 role 注入 replayable profile | accepted |
packages/shared/src/remote-workspace-identity.tspackages/shared/src/remoteTarget.tspackages/shared/src/zcode-protocol/index.tspackages/services/src/session/taskIndexRepo.tspackages/services/src/session/automationRepo.tsapps/zcode-cli/packages/adapters/src/storage/session-store/packages/ui/src/hooks/useWorkspaceTaskLists.tspackages/ui/src/hooks/useGlobalTaskList.tspackages/ui/src/hooks/useGroupedTaskView.tspackages/ui/src/lib/buildGroupedTaskViewFromSessions.tspackages/ui/src/lib/taskListMembershipSets.tspackages/desktop/src/host/remoteWorkspaceServiceCollection.tspackages/desktop/src/main/desktopRemoteSessions.tspackages/desktop/src/main/desktopHostProcess.tspackages/desktop/src/main/webRemoteControlSharedHostAttachments.tspackages/desktop/src/host/serverRemoteConnection.tspackages/server/src/entry-http.tspackages/server/src/entry-stdio.tspackages/server/src/http.tspackages/server/src/remote/connect.tspackages/server/src/remote/create-backend.tspackages/server/src/remote/ssh-backend.tspackages/server/src/remote/wsl-backend.tspackages/server/src/remote/docker-backend.tspackages/services/src/node.tspackages/services/src/zcode-agent/zcodeAgentProcessManager.tsscripts/build-zcode-lite.mjslastWorkspaceSession 与 Connection Profile persistence在产品语义确认后再更新 feature graph,建议新增:
capability.federated-node-hubcapability.unified-node-runtimestate.account-model-profilestate.node-capability-manifeststate.federated-task-view-profileservice.hub-coreservice.node-coreservice.node-bootstrapservice.node-resource-storeservice.logical-attachment-multiplexerservice.node-workspace-registryservice.federated-task-querypersistence.workspace-alias-ledgerpersistence.hub-task-summary-catalogboundary.browser-replayableboundary.mobile-remote-replayableinvariant.global-task-refdeleted > archived > pinned > normal
的保守优先级?