Files
deepseek-harness/docs/subsystems/web-client.zh.md
T
a39d44b5dc feat(session): add host reading status to SessionStatus (#6858)
* ✨ feat(session): persist and synchronize read state

* 🌐 fix(client): complete Japanese labels after base update

* 📝 docs: refresh session read-state dependency graph

* 🧪 test(web): align session menu and read-state snapshots

* 🌐 fix(session): complete Japanese plugin metadata

* 🧪 test(web): distinguish unread from pending user input

* 🐛 修复会话阅读状态的故障隔离与生命周期

* 🐛 修复阅读状态依赖检查并补齐自动已读覆盖

* 🐛 恢复会话绿点并移除未读标题加粗

* ♻️ Keep shared session reading state in Host memory

* 🌐 Complete reading-state metadata for supported locales

* 📝 Refresh module graph after removing storage dependency

* 🧹 Move storage dependency policy out of memory-only reading

* 🐛 Wait for sidebar catalog before replay navigation

* 🔧 Give Host TypeScript checks 8 GiB of heap

* ✅ Align Host heap checks and Windows diagnostics

* ♻️ Keep CI repairs outside the session reading PR

* 🐛 Show failed unread turns with an error indicator

* 🔧 Adjust npm layout budget for the reading package

* 🧪 Scope projection stream assertions to observed units

* 🧪 Scope permission and title assertions to their projections

* ♻️ Simplify session reading updates to explicit positions

* 🐛 Align session reading package with release version

* 🧪 Load reading state in LiveShare viewer fixtures

* 🧹 Remove persistence-only type link from memory PR

* 🧪 Align context menu expectations with reading actions

* 🐛 Sync reading package with the release version

* 🧪 Include turn boundaries in session summary expectations

* ♻️ Derive reading failure facts from Host events instead of a projection

The reading service took each completion from the Agent turn-boundary
projection, which forced a stateVersion bump and put that projection's whole
internal state on the wire for every Session list row. The service now records
`turn/end` itself, so `core/agent` and the persisted projection schema are
untouched.

History that ended before the service started raises no reminder, which keeps
"existing history reads as read" without a startup scan. The failure flag
therefore describes only turns this Host observed: marking a Session whose last
turn failed before a restart shows the ordinary unread reminder.

* 🐛 Preserve manual unread until explicit Session interaction

* 🧪 Align cold Session reading snapshot with unloaded title

* 🔖 chore(session): align session-read-state with 0.2.2-rc.2

Master moved the root and every released manifest to 0.2.2-rc.2, but the
new dsh-session-read-state package still declared 0.2.2-rc.1, failing
constraints, verify-version-sync, verify-npm-install-layout, and
release:verify after the master merge.

* ♻️ refactor(gateway): recognize Remote stream carrier loss by error code

RemoteStream now decides whether a generation end or failure is a
retryable carrier loss by the stable code 'gateway/carrier-lost' instead
of `instanceof RemoteStreamCarrierError`. RemoteStreamCarrierError keeps
working and carries that code, so existing callers are unchanged, while a
Client feature package can return a coded Error from `ended` without
importing the class. The new RemoteStreamCarrierFailure type describes
such errors; terminal-controller classifies disconnects the same way.

* ♻️ refactor(session): move Session reading into ui-session-status

Fold the reading feature into the single package
packages/client/ui-session-status and delete session-read-state.

- Host face: SessionStatusService keeps in-memory reading records and
  serves the sessionStatus Remote namespace (mark, follow) with
  session-status/* error codes; its service key is registered only for
  Gateway discovery and is not declared on Context.
- Client face: a package-internal reading model follows the Host stream
  through RemoteSnapshotStream; ctx.uiSession.sessionStatus folds the
  records into completionUnread and completionFailed and exposes mark and
  readingReady; main-view acknowledgement and the
  session-status/read-intent event live here. No reading service or type
  is exported.
- verify-client-packages lets a packages/client feature package request
  packages/api rows through dsh.client.external; feature-to-feature
  requests stay rejected.
- ui-workspace, ui-conversation, bundles, remotes, LiveShare, the client
  test runtime, docs, Agent Notes, and the upgrade guide follow.

* ♻️ refactor(session): clear manual unread only when the main view switches to the Session

Remove the session-status/read-intent event. ui-session-status now clears an
existing manual unread mark when the main view switches to a different
Session, including the first selection after a page load, once the reading
baseline is ready and the body arrives. Window focus, visibility changes,
a replaced binding for the same Session, and activity in the open Session
preserve manual unread.

ui-conversation returns to master (only the ui-session-status client
tsconfig reference remains), and ui-workspace navigation no longer emits
the event. Tests, the session-reading Web e2e case, READMEs, and the
reading Agent Note follow the new rule.

* 🐛 fix(session): address the Session status review findings

- Open the reading stream only while ctx.remoteAccess allows
  sessionStatus/follow, so a LiveShare viewer opens no owner-only stream,
  keeps readingReady false, and logs no synchronization failure; access
  changes start or stop the stream.
- Hide the unacknowledged completion of the Session the visible, focused
  main view retains; manual marks stay visible, completionFailed follows
  completionUnread, and the reminder returns on blur, hiding, or a switch.
- Declare ctx.sessionStatus on Context and restore its SERVICE_PAGE and
  SERVICE_ROLES entries; the service and SessionRead* types document on
  docs/subsystems/web-client.md, which now owns the reading section with
  the failed field.
- Document that a Host plugin reload can leave the Client with a terminal
  error until a page reload; drop the redundant types import and the
  unused publish() result.
- Archived Sessions read as read and offer no reading mark in the row
  menu or the toggle-read shortcut.
- session.toggleRead names the open dialog, open panel, or archived
  Session that blocks it instead of asking to select a Session.
- isRemoteStreamCarrierFailure rejects a RemoteError from the Host even
  when it carries gateway/carrier-lost; the code is Client-local.
- ./types is types-only like ui-trajectory, and files no longer ship
  lib/types JavaScript.

* 🐛 fix(session): close the remaining Session status review gaps

- The Gateway Client exports isRemoteStreamCarrierFailure, and the
  terminal view uses it, so a Host RemoteError carrying the carrier code
  shows as failed rather than disconnected.
- Each access grant's reading stream carries a token: frames a revoked
  or superseded stream still delivers are discarded, and cleanup waits
  for disposal before leaving reading unavailable unless a newer grant
  is active.
- The status table hides the viewed Session's natural reminder only
  while that Session is open; the panel case is a documented limitation.
- The README limitation and the upgrade guide state that only the
  main-view switch rule, including a reload restore, clears manual
  unread automatically.
- Add the missing blank line before the next heading in the web-client
  reading section.

* ♻️ refactor(session): install reading under the Session status table

- apply returns to master's form plus one line: UiSessionStatus is the
  root, published as the useSessionStatus source, and installReading()
  from the new src/client/read.ts follows Host reading records into it.
  UiSessionStatus takes master's three constructor parameters and
  creates its own SessionReadModel as the package-internal `reading`
  member; installSessionStatus is removed and acknowledge.ts stays a
  separate file.
- The viewed Session's snapshot subscription republishes the table only
  when its openState changes, so streamed events do not rebuild it.
- Remove the obsolete Dev Note sentence about failure outcomes.
- session.toggleRead passes when the Peer may not mark reading, matching
  the row menu, and reports readingUnavailable only while unsynchronized.

---------

Co-authored-by: imccyu <[email protected]>
Co-authored-by: imccyu <[email protected]>
2026-11-12 05:35:57 +00:00

17 KiB
Raw Blame History

Web Client 架构

English | 中文

Web Client 是由独立加载插件组装而成的浏览器侧 Cordis 应用。它有四个可复用底座:Client Modules 加载插件图,API Gateway 提供类型化 Host 通信,Slots 组合 React UI,Conversation 把 Session 历史窗口变成各 target 自有的视图。本文串联这些系统,并规定 Client model 与功能包各自所在的位置。

快捷键负责窗口内命令注册和物理键分发;快捷键速查展示可用命令及局部输入操作。命令 owner 声明各运行端/平台的默认键位,并与鼠标控件共用既有操作。共用模态组件裁决顶层 Esc 并恢复焦点。

分层与所有权

层 主要 owner 职责
Host 应用 业务 service 与 packages/api/*-controller Host entry 拥有权威状态、持久化、mutation 顺序、访问策略与 stream 生产。
传输与 API assembly client/connection、api/gateway、api/remotes 建立 Client generation,公开生成的 ctx.remote method 与 stream,转发选定的 Cordis event,并承载取消和结果。
Client model api/session-controller/client、api/workspace-controller/client 维护不依赖 React 的 Host 状态镜像,处理 stream/unary 竞态,拥有对象 identity 与订阅,并公开收窄的 command service。
UI adapter client/ui-session、client/ui-workspace 把 model observable 转换为 root 或 Provider 绑定的 Session Slot source,并拥有视图级导航与状态策略。
Conversation 数据 client/ui-conversation、ui-chat 与 ui-trajectory 等 target package 把标准 event 与紧凑的 Assistant 历史批次组装成相互独立的 target snapshot,并拥有共享的 Conversation shell 与输入流程。
组合与渲染 client/ui-slots、client/ui-renderer、client/ui-layout、各 UI 功能包 声明扩展位置、推导组件 props、把 observable 绑定成 React hook,并挂载最终组件树。

依赖方向是 Host 状态 → Remote 传输 → Client model → UI adapter → Conversation 或 presentation → Slots → React。用户操作通过 callback 反向进入注入的 Client service 或生成的 Remote namespace。Presentation component 绝不接收 Cordis ctx、transport object 或其他功能插件的实现。

浏览器启动

Host 把组合后的 WebBootGraph 写入 window.__DSH_BOOT__,并在 parser-preloaded script 执行前安装浏览器 module-loader facade。模块系统是一张 lazy CommonJS 表:加载 bundle 只注册 factory;materialize entry 时才以同步 require 运行 factory,并解析 platform module 和已声明的动态依赖。

Web boot kernel 创建模块系统、预取 immediately entry、挂载 vendored Cordis Loader,再创建图中的每个 entry。Cordis service injection 决定激活顺序;module graph 顺序只决定同步 import 能否被 materialize。完整 roster 到达 settled 状态且启动审计通过后(浏览器必需名单中的 entry 未激活会拒绝启动;其他未激活 entry 输出一条控制台警告),ui-renderer hydrate 不依赖框架的 boot DOM,并调用唯一一次 context 级 renderSlot('root')。Client Modules负责 graph、bundle route、cache revision 与 loader 细节。

Remote 通信

Host 业务 service 使用 Typert Remote decorator 标记可调用 method。Host generation 产出严格 descriptor、runtime codec、declaration merge 与 source map。Client 侧 api-remotes assembly 选择这些生成贡献,并把具体 method 挂到 ctx.remote.<namespace> 与 Session scope 的 agentCtx.remote.<namespace>。功能包依赖生成的 service face,而不依赖 Gateway 实现或 Host 包的运行时 entry。

Connection 拥有请求 URL 解析、request correlation、/api carrier、trust check、精确 Fetch 路由与 connection generation。API Gateway 拥有 Remote dispatch、取消、logical stream 与选定 Host event 的转发。Controller 操作应进入生成的 Remote method 或显式 Remote stream;功能自有的下载则注册精确 Fetch 路由。API Gateway 参考定义 generation 与调用,Connection README定义物理 carrier 与信任策略。

内部 $events logical stream 是 Connection generation source。它的 opening ready frame 携带用于路径显示的 Host home,并在 Host listener 已挂载、任何 controller 开始 baseline read 之前建立 generation。ctx.remote.$on() 把 allowlist 内的普通 event 交付给 root Client Context,并把 scoped waterfall event 交付给已解析的 Session Context;waterfall listener 可以返回结果、调用 next() 或拒绝。

Client models

每个 API controller 包都拥有配对的 Host face 与 Client face。Host 侧拥有权威 mutation 与 stream 生产;Client 侧基于相同的生成 wire type 维护 identity 稳定、与 React 无关的 model,并公开 observable snapshot 与 command。UI 包消费这些 Client service,不在 component store 中复制 transport state。

Sessions

api/session-controller公开 Session list、search、creation、prompt、queue、cancellation、pagination 及 follow/control stream 等 Host command。其 Client 侧按 ClientSessions → SessionManager → Session 组织:

  • ClientSessions 提供 ctx.sessions,拥有 reference、source count、Session scope 与稳定的 SessionBinding object,并投影不含全局 current Session 选择的 catalog state。
  • SessionManager 拥有 list baseline、实时 list/control update、惰性 Session instance、projection store、subagent catalog,以及 pull 与后到 update 之间的冲突顺序。
  • 每个 Session 拥有一段由 SessionEventLikeEntry value 表示的连续逻辑 event window、pagination、follow、prompt/control state 与供 adapter 消费的 observable snapshot。

持久 event 路径打开 follow(),其首帧包含当前 header、tail page、cursor 与完整 projection baseline。历史 record 带有显式 event 或 chunks 判别字段和字段对齐的内部 event;journal 先校验每条 record 的逻辑 seq 闭区间,Client 再直接把这些 record 保留为 SessionEventLikeEntry,无需逐 record 转换。每个物理 generation 都根据该 snapshot 原子替换保留窗口,随后按 seq append 标准实时 event。page() 只用于更早历史与 gap repair。瞬态 control stream 每代以完整 baseline 开始,随后应用 projection update。

Workspaces

api/workspace-controller把 Workspace 变更策略与权威 follow feed 留在 Host。ClientWorkspaceModel 拥有浏览器行、Workspace 顺序、归档与置顶 Session id 数组、命令回显,以及流与一元调用的竞态合并。每代 stream 先给出完整 baseline,再给出 upsert、remove、order、archived 和 pinned increment;重连时以新 baseline 替换 model。WorkspaceController 把该 model 作为 ctx.workspaces 公开,ui-workspace 则提供 useWorkspaces 与导航回调。侧边栏的 ArchivedFilter 控制列表与搜索中的默认隐藏、显示已归档或仅显示已归档。归档行保留排序位置、置灰展示,必须通过行菜单或搜索结果的取消归档操作恢复后才能打开。恢复调用 workspace.unarchiveSession,完整归档集合通过一元响应及 archived increment 到达 Client。Session 显示顺序保存在浏览器本地,包含隐藏归档项;置顶在该完整顺序内移动 Session,取消置顶不恢复先前位置。

这种配对不会产生第二份业务真相。Host controller 决定持久状态与 mutation outcome;Client model 维护最新可用的本地 projection,在有利于渲染时保持 object identity,并明确 delayed response 与 replacement baseline 的合并规则。

Conversation 与 presentation

Web 和桌面端共享代码工作工具偏好。它控制诊断 View、可用的预设选项、改动文件卡片和内置 HTML 预览策略,不改变 Session 记录。

ui-session 安装 Session scope adapter,并在 remote-access Client 服务之上提供 useSessions、useSessionRetainInfo、useSessionAccess、useSession、sessionId、useProjection 和会话作用域的 useAccess。SessionProvider 可以继承外围 binding,也可以绑定显式 SessionReference,因此并存子树可以指向不同 Session。ui-session-status 从 ctx.uiSession.sessionStatus 状态表提供 useSessionStatus,该表汇总运行状态、生效的待交互请求,以及其宿主面为同一宿主各前端保存的阅读提醒。领域 adapter 可以继续添加标准 source,但不会把 React hook 放进 model object。

ui-conversation 对每个 SessionBinding.eventSource 只绑定一次。它的 event registry 把持久 Session event 与 Client-only assistant/live-chunk update 关联成稳定的业务 Context,view registry 则 materialize target snapshot。Chat Assistant、Trajectory Assistant 与 Turn Tail 同时解释 live chunk 和持久 settlement 中嵌入的紧凑 stream,因此重连与分页历史无需持久 token 行即可复现相同 Assistant 状态。ui-chat 与 ui-trajectory 分别注册自己的 Definition 和 builder:它们可以解释同一 event family,但不会导入或共享彼此的最终 display model。Shell 选择一个已注册 view,再通过标准 hook 与 Slot 交付其 snapshot。Conversation定义 Context identity、replay、Location data、target builder 与 keyed renderer。

ui-slots 提供类型化 registry 与 lifecycle ledger;ui-renderer 是唯一通过 useSyncExternalStore 绑定裸 observable、拥有 React context 并渲染 root tree 的包。功能 component 通过推导出的 props 接收 framework hook、owner prop、store action 与显式 injection。Web Client Slots列出这些输入、扩展 API 与当前 Slot 层级。

数据通路

路径 顺序
持久 Session 展示 Host Session log → packed Remote follow/page 历史 → Client SessionEventLikeEntry window → Conversation Context → target snapshot(chat、trajectory 或其他已注册 target)→ Slot view → React
瞬态 Session control Host control baseline → Remote snapshot stream → SessionManager projection store → Session 与 list snapshot → 标准 hook → component
后台任务 Host job 注册表 → job.list / job.follow → ClientJobs 名册与输出视图 → 任务列表和面板
Workspace 状态 Host Workspace baseline 与 increment → ClientWorkspaceModel → ctx.workspaces.list → useWorkspaces → sidebar、hero 与 navigation entry
scoped interaction Host Cordis waterfall → API Remotes $events → Session Context 上的 ctx.remote.$on() → 所属 UI 包 → result 或 next()
用户 command component callback → 注册项 inject face 或 Slot owner → ctx.sessions、ctx.workspaces 或生成的 scoped Remote → Host Controller → 权威 update → stream 或 event projection 回到 Client

重连

物理恢复与逻辑恢复彼此独立。Gateway mux 恢复物理 WebSocket;Connection 发布可用 generation 后,每个 RemoteStream 分别重开自己的 logical source。Carrier failure 可以重试;business error、非法 opening item 或 protocol violation 会令所属 logical stream 终止。

恢复方式由数据语义决定:

  • 持久 Session journal 校验逻辑 seq range,并根据每个 generation 的 opening snapshot 替换窗口;page() 提供更早历史并修复后续 range gap。
  • Session control 与 Workspace stream 在断开期间保留最后一次发布的值,再用新的 opening baseline 原子替换。
  • 普通 forwarded notification 不会 replay。需要可靠恢复的 stateful domain 必须提供 baseline、cursor 或显式 query;scoped waterfall 保留自身的 request lifetime。

架构中没有统一的 Client Runtime、HostFrame、events.mux、events.host 或通用 resync() API。Connection 公开 generation state,Gateway 管理 logical stream,Client model 则按自身数据定义 replacement 或 resume 语义。

阅读提醒

会话状态在宿主内存中保存使用者的阅读确认和手动未读标记。其宿主 Remote 服务发送重连快照和已保存的更新;其前端插件把这些记录汇入 ctx.uiSession.sessionStatus 状态表,并在可见且聚焦的主视图中确认已加载的完成内容。阅读状态不改变模型历史。

SessionReadState

完整阅读记录包含 sessionId、最近结束的 completedTurn、该轮是否以本宿主观察到的执行错误结束的 failed、已确认的 readTurn 和 manualUnread 标记。设置了手动标记,或最近结束的轮次大于已确认轮次时,会话为未读。

mark(sessionId, action) 按宿主处理顺序更新会话。前端只通过有序订阅流更新记录。该服务自己记录 turn/end 事件,包括该轮是否失败。

SessionReadAction

unread 操作设置手动标记。read 操作清除标记,并将阅读位置推进至它的 throughTurn;acknowledge 操作只推进位置,不改变标记。位置不会回退,也不越过宿主最近完成的轮次。修改回复仅表示成功或失败,不回传记录。

SessionReadFrame

每次同步先发送 type: 'baseline',在 items 中包含所有可访问的记录。后续每个 type: 'changed' 都携带一条已保存的完整 state。重连会替换上一代同步流的记录。

包边界

功能插件包可以通过 import type 共享声明;不得运行时导入或转发另一个功能插件的值。跨包行为使用注入的 Cordis service,跨包 UI 使用 Slots。特定 target 的 Conversation Definition、projection helper 与最终 view data 留在所属 target 包中,即使 Chat 和 Trajectory 有意实现平行逻辑。

共享运行时值需要一个职责收窄、没有功能生命周期的静态 owner,例如 client/store、ui-primitives 或浏览器安全的 util 包。Transport 与生成 API assembly 可以导入运行时 contribution,因为组装同一个 protocol 正是它们的显式职责。功能包可以通过 dsh.client.external 请求 packages/api/ 下某一行的运行时值,但不能请求另一个功能插件的行。

根据所添加的扩展查阅四篇详细参考:

  • Client Modules:package discovery、loading、共享 module identity 与 boot order。
  • API Gateway:Host method、生成的 Remote contribution、stream 与 forwarded event。
  • Web Client Slots:component、hook、store、injection 与 placement。
  • Conversation:持久 event correlation、target snapshot,以及 Chat 或 Trajectory view contribution。

Cordis API

Generated from source by scripts/gen-cordis-catalog.ts (verified fresh by pnpm run verify-cordis-catalog in doc-sync; regenerate with pnpm run gen-cordis-catalog) — the language sides differ only in locale-specific paired document paths. Signature blocks use a ts cordis-catalog fence and keep the original source JSDoc; dispatch modes are defined in the primer, and the framework-inherited ctx API lives in cordis-api/inherited.md.

ctx.sessionStatus — SessionStatusService

Shared owner reading records; no reading operation changes model history.

/**
 * Update one Session; read positions advance only through Client-observed completions.
 * @param sessionId - Session identity.
 * @param action - Explicit reminder change or automatic read-position acknowledgement.
 * @throws RemoteError when closing, the Session is missing, or its metadata cannot be read.
 */
@Remote async mark(sessionId: SessionId, action: SessionReadAction): Promise<void>

/**
 * Follow accessible reading records; every connection starts with a complete baseline.
 * @param signal - generation cancellation.
 * @returns the baseline and whole-record changes, filtered by Session access.
 * @throws RemoteError when the service is closing.
 */
@Remote({ mode: 'stream' }) async *follow(signal: AbortSignal): AsyncIterable<SessionReadFrame>

Types: SessionId

Source: packages/client/ui-session-status/src/index.ts