# V4 协议命令 ↔ 桌面 Renderer 入口映射(④) > 只读调查。每条带 `文件:行号`。本文档回答:**协议定义了什么、桌面端真正用了什么、哪些定义没有入口。** --- ## 0. 结论摘要 | 指标 | 值 | | --- | --- | | V4 命令总数 | **34** | | 桌面 Renderer / 服务侧**有发送方** | **30** | | **协议已定义但全仓库无发送方(孤儿命令)** | **4**:`editQueueItem`、`discardSharedContext`、`toggleWorkspaceHookReviewItem`、`revokeWorkspaceHookTrust` | | 发送漏斗数量 | **2**(渲染端统一 transport + 服务适配器) | 命令全集:`packages/shared/src/zcode-protocol-v4/command.ts:43-244`。 信封不变式:`commandId` = uuid v7(时间有序、重试不变)、`clientId` = 每客户端实例稳定并持久化(`packages/ui/src/v4/commandFactory.ts:1-3`、`:21-39`)、CAS 命令缺 `baseRevision` **构造期直接抛**(`:54-56`)、row-targeting 命令缺 `baseLogEpoch` 同样抛(`:57-59`)。 --- ## 1. 两个发送漏斗 | 漏斗 | 位置 | 说明 | | --- | --- | --- | | **渲染端统一 transport** | `packages/ui/src/v4/agentConversationTransport.ts:365` | 所有 UI 直发命令的**唯一出口**(`agentService.sendConversationCommandV4({ ...workspace, envelope })`);`:61` 声明能力名 | | **服务适配器** | `packages/services/src/zcode-agent/zcodeTaskServiceAdapter.ts` | 经 `zcodeTaskService` 暴露给 UI 的业务方法;6 个 `sendConversationCommandV4` 调用点:`:442`、`:1173`、`:2041`、`:2182`、`:2209`、`:2910` | | 连接作用域包装 | `packages/services/src/zcode-agent/zcodeAgentConnectionScope.ts:682-695` | 按 workspace 作用域路由到对应 host 的 base service | **为什么必须区分**:`session-flow` / `queue` / `interaction` 这类命令走渲染端直发(`SessionPane` 内 `dispatchCommand`),而 `renameSession` / `switchModelConfig` / `resolveInteraction`(permission/elicitation) / `stop` / `sendText` 走**业务服务方法**——即同一条协议命令可能有两个上游,改动时不能只改一侧。 --- ## 2. 完整映射表 图例:✅ 有发送方 | ❌ 全仓库无发送方 ### 2.1 session-flow / 会话流 | 命令 | 发送方 | 证据 | | --- | --- | --- | | `sendText` | ✅ SessionPane 直发 + 服务适配器 | `SessionPane.tsx:2743`、`:2839`、`:2864`;`zcodeTaskServiceAdapter.ts:448` | | `stop` | ✅ SessionPane 直发 + 服务适配器 | `SessionPane.tsx:3568`;`zcodeTaskServiceAdapter.ts:2045` | ### 2.2 session-mgmt / 会话管理 | 命令 | 发送方 | 证据 | | --- | --- | --- | | `createSession` | ✅ 4 处 | `SessionPane.tsx:2712`、`:2794`、`:2826`;`v4/composer/useDraftSessionPrewarm.ts:83`;`settings/saved-workflows/useSavedWorkflowLauncher.ts:160`;`useSavedWorkflowPromote.ts:77` | | `renameSession` | ✅ 仅服务侧 | `zcodeTaskServiceAdapter.ts:2914` | | `deleteSession` | ✅ 2 处 | `v4/composer/useDraftSessionPrewarm.ts:54`;`useSavedWorkflowLauncher.ts:140` | | `discardSharedContext` | ❌ **无发送方** | 仅 `command.ts:243` 定义(schema);全 `packages/` 无第二次出现 | ### 2.3 queue / 队列 | 命令 | 发送方 | 证据 | | --- | --- | --- | | `deleteQueueItem` | ✅ | `SessionPane.tsx:3150`、`:3181` | | `reorderQueueItem` | ✅ | `SessionPane.tsx:3249` | | `sendQueuedNow` | ✅ | `SessionPane.tsx:3233` | | `setAutoDrain` | ✅ | `SessionPane.tsx:3268` | | `setFollowupMode` | ✅ | `SessionPane.tsx:3372`、`:3399` | | `editQueueItem` | ❌ **无发送方** | 仅 `command.ts:164`(schema)与 `:300`(CAS 集合);全 `packages/` 无第三次出现 | > ⚠️ **注意这个不对称**:队列 6 条命令里 5 条有发送方,只有 `editQueueItem` 没有。它的同族兄弟 `deleteQueueItem` / `reorderQueueItem` / `sendQueuedNow` 都在 `SessionPane.tsx:3140-3270` 同一段代码里——即**队列项的「重排/删除/立即发送」都有入口,「编辑内容」没有**。 ### 2.4 selection-side-session | 命令 | 发送方 | 证据 | | --- | --- | --- | | `createSelectionSideSession` | ✅ | `SessionPane.tsx:1922`、`:1985`(对应「辅助对话」侧面板入口) | ### 2.5 goal-compact / 目标与压缩 | 命令 | 发送方 | 证据 | | --- | --- | --- | | `compact` | ✅ | `SessionPane.tsx:2458`(`case "compact"`) | | `sendGoalCommand` | ✅ | `SessionPane.tsx:2461` | | `pauseGoal` | ✅ | `SessionPane.tsx:3581` | | `resumeGoal` | ✅ | `SessionPane.tsx:3591` | ### 2.6 model-config | 命令 | 发送方 | 证据 | | --- | --- | --- | | `switchModelConfig` | ✅ 仅服务侧(3 处) | `zcodeTaskServiceAdapter.ts:2703`、`:2749`、`:2763` | | `switchCollaborationMode` | ✅ 仅服务侧 | `zcodeTaskServiceAdapter.ts:1206`(经 CAS 辅助函数 `sendConfigCasCommandV4`,`:1165`) | ### 2.7 interaction-background / 交互与后台工作 | 命令 | 发送方 | 证据 | | --- | --- | --- | | `resolveInteraction` | ✅ 渲染端 + 服务侧(permission / elicitation 两条) | `v4/V4InteractionDialogs.tsx:186`;`zcodeTaskServiceAdapter.ts:2186`(permission)、`:2213`(elicitation) | | `snoozeInteractionAutoResolution` | ✅ | `v4/interactionAutoResolutionCommand.ts:17` | | `cancelBackgroundWork` | ✅ 2 处 | `SessionPane.tsx:2118`;`app-shell/WorkflowRunSidePane.tsx:216` | | `resumeWorkflowRun` | ✅ 2 处 | `SessionPane.tsx:2139`;`WorkflowRunSidePane.tsx:247` | | `amendWorkflowRunSettings` | ✅ 2 处 | `SessionPane.tsx:2154`;`app-shell/useWorkflowRunPaneSettings.ts:75` | | `startSavedWorkflow` | ✅ | `settings/saved-workflows/useSavedWorkflowLauncher.ts:185` | | `requestWorkspaceHookReview` | ✅ 2 处 | `settings/workspaceHookReviewCommands.ts:118`(经泛型 `sendWorkspaceHookCommand`,`:17-35`);`v4/WorkspaceHookPendingBanner.tsx:99` | | `respondWorkspaceHookReview` | ✅ | `workspaceHookReviewCommands.ts:155` | | `toggleWorkspaceHookReviewItem` | ❌ **无发送方** | 仅 `command.ts:189`(schema)与 `v4/pendingCommandReplay.ts:15`、`:45`(重放白名单) | | `revokeWorkspaceHookTrust` | ❌ **无发送方** | 仅 `command.ts:193`(schema)与 `pendingCommandReplay.ts:16`、`:46`(重放白名单) | ### 2.8 fork-edit-retry / 分叉、编辑、重试 | 命令 | 发送方 | 证据 | | --- | --- | --- | | `forkAssistant` | ✅ | `SessionPane.tsx:3029` | | `editUserQuery` | ✅ | `SessionPane.tsx:3062` | | `retryTurn` | ✅ | `SessionPane.tsx:3093` | ### 2.9 其他 | 命令 | 发送方 | 证据 | | --- | --- | --- | | `applyFileRewind` | ✅ | `SessionPane.tsx:1697` | | `setAssistantFeedback` | ✅ | `SessionPane.tsx:3128` | --- ## 3. 孤儿命令详情(④ 的核心发现) | 命令 | 定义 | 其它出现 | 判定 | | --- | --- | --- | --- | | `editQueueItem` | `command.ts:164` (schema) | `command.ts:300`(`COMMANDS_REQUIRING_BASE_REVISION` CAS 集合) | **协议 + CAS 声明齐备,零发送方**。同族 5 条都有入口,唯独「编辑队列项内容」没有 | | `discardSharedContext` | `command.ts:243` (schema) | **无** | **最彻底的孤儿**:连 CAS/row-target 集合都没进,重放白名单也没有 | | `toggleWorkspaceHookReviewItem` | `command.ts:189` (schema) | `pendingCommandReplay.ts:15`、`:45` | 协议 + **渲染端重放白名单**齐备,但无发送方 | | `revokeWorkspaceHookTrust` | `command.ts:193` (schema) | `pendingCommandReplay.ts:16`、`:46` | 同上 | ### 3.1 为什么后两条特别值得注意 `pendingCommandReplay.ts:13-16` 把 `resolveInteraction` / `respondWorkspaceHookReview` / `toggleWorkspaceHookReviewItem` / `revokeWorkspaceHookTrust` 四者放在**同一个重放白名单联合类型**里(`:43-46` 逐条判断)。其中两条有发送方、两条没有——**白名单比实际能力宽**。 即:重放逻辑为这两条命令准备了完整分支,但**永远不会被触发**。这是一处「下游比上游齐备」的残留:如果将来接上入口,重放路径已经就绪;如果不打算接,这条白名单分支是死代码。 > 交叉参考:③ 文档 §6.1 中 `revokeWorkspaceHookTrust` 也在 `hooks` 分区的「未接线」候选里(`HooksList` 无「拒绝/撤销信任」控件)——两处证据互相印证。 ### 3.2 `discardSharedContext` 的独立风险 它既不在 CAS 集合、也不在 row-target 集合、也不在重放白名单,**唯一存在形式就是一行 schema**。这类「纯 schema 残留」最容易被误认为「功能已在协议里预留」,实际没有任何实现面。 --- ## 4. 映射中发现的其它不对称 | 现象 | 细节 | 证据 | | --- | --- | --- | | 同一条命令双上游 | `sendText` / `stop` / `resolveInteraction` 既有渲染端直发,也有服务适配器路径 | `SessionPane.tsx` vs `zcodeTaskServiceAdapter.ts` | | 仅服务侧可达 | `renameSession`、`switchModelConfig`、`switchCollaborationMode` **没有**渲染端直发路径 | `zcodeTaskServiceAdapter.ts:2914`、`:2703`、`:1206` | | 分发集中在单文件 | 30 条有入口的命令里,**大量集中在 `SessionPane.tsx`**(一个 207KB 的文件)——`:1424`-`:3591` 区间内可见 `createSession`/`sendText`/`stop`/队列 5 条/`forkAssistant`/`editUserQuery`/`retryTurn`/`setAssistantFeedback`/`applyFileRewind`/`pauseGoal`/`resumeGoal`/`cancelBackgroundWork`/`resumeWorkflowRun`/`amendWorkflowRunSettings` | `SessionPane.tsx` 同性 | | CAS 命令构造期校验 | 15 条 CAS 命令(`command.ts:293-309`)缺 `baseRevision` 会在 `createCommandEnvelope` 直接抛,属**客户端编程错误就地暴露**的设计 | `commandFactory.ts:54-56` | --- ## 5. 待确认 / 未覆盖 1. **4 条孤儿命令是有意保留还是漏接**:`editQueueItem`(同族齐全,最可疑)、`discardSharedContext`(纯 schema)、两条 Hook 命令(重放白名单已备)。需产品确认。 2. 本表「发送方」以**字面类型名**为准。经泛型函数传递的类型名(如 `sendWorkspaceHookCommand`)不会被字面搜索命中——已对 `sendWorkspaceHookCommand` 的 3 个调用点逐一核对(`workspaceHookReviewCommands.ts:118`、`:155`、`WorkspaceHookPendingBanner.tsx:99`),确认没有遗漏的 Hook 命令发送方。 3. 本表**未**逐一核对每条命令对应的「用户可见触发入口」(按钮/快捷键),只到「发送方代码位置」。若要列 UI 入口,需再接一层。 4. **CLI/TUI 侧的发送方未纳入本表**(本表口径是「桌面 Renderer」)。CLI 侧 34 条命令全部由原生 handler 实现,见 `docs/analysis/zcode-entrypoint-map.md` §8.2。 5. `zcode-protocol-v4/transport.ts` 的 RPC 方法与下行通知未纳入(仅覆盖 command 面)。 --- ## 6. 执行记录(如实说明) - 本轮只读,未修改任何源码。 - 未运行 `typecheck` / `lint` / 测试(无源码改动;本仓库无可执行 test 脚本)。 - 34 条命令清单来自 `command.ts` 与 CLI 侧 `handlers/index.ts` 注册表的交叉核对;发送方结论全部为 grep 实测,非推断。 - 本轮曾尝试用并行分支补齐 ③ 的四个扫描项(零引用组件 / 显式下线标记 / 零消费者 API / 恒假门禁),**四个分支均长时间无产出后被终止**;相关章节在 ③ 文档中仍标为待补。