feat(dsh): add CAD verification recovery diff and issue broker

This commit is contained in:
阿白叔 committed 2026-10-31 10:17:26 +08:00
1 parent eee4e6bde9
commit 27334fef81
23 files changed
+553 -12

No files matched your search

@@ -0,0 +1,102 @@
# DSH 生产闭环增强实施计划
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
**Goal:** Add real CAD verification visibility, safe failure classification, resume diffs, and a deployable fixed-target issue broker contract.
**Architecture:** Reuse the existing TaskCenterService and private CAD identity as the only execution authority. Add bounded Qt-free analyzers, then expose their read-only results through existing preflight, incident, resume confirmation, health, and issue transport paths.
**Tech Stack:** Python 3.12, PySide6, stdlib HTTP server/client, existing SQLite/JSON evidence stores, pytest, Node and Qt/CDP acceptance.
**Spec:** `docs/superpowers/specs/2026-10-31-dsh-production-chain.md`
## Global Constraints
- Work only in `.worktrees/codex-dsh` on branch `codex/dsh`.
- Never print, stage, or commit provider keys, Git tokens, broker secrets, or ignored bootstrap files.
- Keep native confirmation, safe pause, original queue identity, and automatic snapshot-only admission unchanged.
- Controlled fixtures must not start real CAD or write user projects.
---
### Task 1: Real CAD verification adapter
**Files:**
- Create: `src/dx_productivity/dsh/cad_verification.py`
- Create: `tests/dsh/test_cad_verification.py`
- Modify: `src/dx_productivity/dsh/task_lifecycle.py`
**Interfaces:**
- `CadVerificationAdapter(service).preflight(task_ids) -> dict` returns `mode`, `status`, `projects`, `blockers`, and `evidence_refs`.
- `CadVerificationAdapter(service).after_run(task_ids) -> dict` returns readback status and actual progress counters.
- [x] Write tests for ready fixture, missing probe, identity mismatch, uncertain result and exact counter preservation.
- [x] Run the focused tests and observe the missing-module failure.
- [x] Implement read-only checks using `task_context`, `expected_probe_path`, project file identity and existing evidence; never invent component counts.
- [x] Include adapter result in DSH preflight and execution impact context.
- [x] Run focused adapter and lifecycle tests.
### Task 2: Failure classification and safe retry policy
**Files:**
- Create: `src/dx_productivity/dsh/failure_policy.py`
- Create: `tests/dsh/test_failure_policy.py`
- Modify: `src/dx_productivity/dsh/incidents.py`
- Modify: `src/dx_productivity/dsh/rules.py`
**Interfaces:**
- `classify_failure(issue_code, status, *, interrupted=False, authorized=False) -> dict` returns `category`, `retry_allowed`, `reason`, `backoff_seconds`, and `max_attempts`.
- [x] Write tests for transient, deterministic, uncertain, paused and unknown errors.
- [x] Run focused tests and observe expected failure.
- [x] Implement conservative classification; only transient authorized runs with clean evidence can retry once.
- [x] Replace raw `RETRYABLE_CODES` checks in automatic incident flow with the policy result and append it to decision gates.
- [x] Run incident, decision-log and policy tests.
### Task 3: Resume difference report
**Files:**
- Create: `src/dx_productivity/dsh/resume_diff.py`
- Create: `tests/dsh/test_resume_diff.py`
- Modify: `src/dx_productivity/dsh/run_journal.py`
- Modify: `src/dx_productivity/trial_task_center/ui/dsh_task_lifecycle.py`
- Modify: `integration/dsh/task-plugin/model_results.mjs`
**Interfaces:**
- `resume_diff(service, inspected_run) -> dict` returns `safe`, `changed`, `completed`, `remaining`, `plan_changes`, `evidence_changes`, and bounded `blockers`.
- [x] Write tests for unchanged scope, completed items, plan change, missing checkpoint and uncertain evidence.
- [x] Run focused tests and observe expected failure.
- [x] Implement deterministic diff from saved hashes, current plan hashes, queue entries and task evidence.
- [x] Add diff to resume inspection and native confirmation text; block automatic resume when `safe` is false.
- [x] Project bounded diff fields to model results and run lifecycle/UI tests.
### Task 4: Broker reference service and client hardening
**Files:**
- Create: `tools/dsh_issue_broker.py`
- Create: `src/dx_productivity/dsh/issue_broker.py`
- Create: `tests/dsh/test_issue_broker.py`
- Modify: `src/dx_productivity/dsh/issue_transport.py`
- Modify: `docs/user/dsh-ai-supervision.md`
**Interfaces:**
- `IssueBrokerConfig.from_environment()`, `IssueBroker.exchange(payload) -> dict`, and `IssueTransport.credentials(...)` with `instance_proof`, `idempotency_key`, `expires_in`.
- Reference HTTP endpoints: `GET /healthz`, `POST /v1/issue-token`.
- [x] Write tests for fixed target, HMAC instance proof, idempotency, short expiry, invalid scope, and no secret in response logs.
- [x] Run focused tests and observe expected failure.
- [x] Implement the broker with stdlib `ThreadingHTTPServer`, fixed target configuration, environment-only secret/token, bounded requests and no redirects.
- [x] Require broker exchange metadata in the client and reject responses with missing expiry or wrong target.
- [x] Document deployment variables and explicitly label the local server as a reference implementation.
- [x] Run broker, transport, ticket, and health tests.
### Task 5: Full verification and commit
**Files:**
- Modify: `docs/testing/2026-10-31-dsh-production-chain.md`
- [x] Run focused and relevant regression tests, Node checks, credential scan and `git diff --check`.
- [x] Run two-process Qt/CDP acceptance with the adapter enabled in controlled mode.
- [x] Record exact artifacts and limits; no real CAD or remote issue creation claims.
- [x] Commit only intended files on `codex/dsh` and verify clean status.
@@ -0,0 +1,30 @@
# DSH 生产闭环增强设计
## 目标
把 DSH 从“能监管受控执行”推进到“能解释真实 CAD 验证状态、按错误类别安全处理、在恢复前展示差异、并通过生产工单中转提交证据”。
## 四个阶段
### 1. CAD 验证适配器
`dsh/cad_verification.py` 封装现有 TaskCenterService、私有桌面 CAD 身份和前后探针。适配器只返回工程身份、探针基线、读回状态和证据引用,不接受模型传入的进程、路径或 COM 参数。预检只读;真实执行继续由现有原生确认和私有 CAD 会话负责。
### 2. 错误分类与受控重试
`dsh/failure_policy.py` 将错误归类为 `transient`、`deterministic`、`uncertain`、`paused` 或 `observe`,返回重试理由、等待时间和最大次数。自动介入只能对明确的 transient 且原执行已授权、无不确定证据的场景执行一次;deterministic 进入人工修正,uncertain 禁止重放。所有判定写入决策记录。
### 3. 恢复差异对比
`dsh/resume_diff.py` 对原始冻结范围、当前任务计划、队列检查点和已有证据生成有界差异。恢复确认窗口显示已完成、待执行、计划哈希、工程文件身份和阻断原因;差异存在时不得自动恢复。
### 4. 生产工单中转
`dsh/issue_transport.py` 的 broker 模式扩展为可部署的固定目标中转协议:服务端校验安装实例签名、仓库和事件幂等键,签发短期 issue-only token;客户端不缓存 token。新增 stdlib broker 参考服务和协议测试,生产部署仍需由运维配置服务端 secret 与 Git 凭据。
## 约束
- 模型不能直接获得 CAD 进程、COM、文件写入或任意工单 URL 权限。
- 错误分类不能把“模型建议”当成可重试授权。
- 恢复差异只读,差异未解决不得扩大执行范围。
- broker 只允许固定服务器、固定仓库、固定事件标记和幂等写入。
@@ -0,0 +1,18 @@
# DSH 生产闭环增强验证记录
本轮按“真实 CAD 验证适配器 → 错误分类与受控重试 → 恢复差异 → 工单中转”顺序实现,继续沿用原生确认、私有 CAD 身份和受控 fixture 边界。
## 已完成验证
- CAD 适配器:读取真实任务上下文、工程路径和既有探针基线;缺失工程、缺失探针、任务异常和中断结果均保留阻断或待核验状态,元件数量未知时保持 `null`。
- 错误策略:临时错误最多一次且必须已有执行授权;确定性错误要求人工修正;不确定和暂停状态禁止自动重放。
- 恢复差异:对比冻结计划、当前计划、队列检查点和任务中断证据;差异未解决时恢复请求被阻断,确认窗口显示已完成和待执行范围。
- 工单中转:固定仓库、实例 HMAC 证明、事件幂等键和短期过期时间通过;参考服务不打印 secret/token,客户端不缓存 token。
相关回归通过 **296 项**:212 项 DSH/UI/队列/打包回归、82 项存储与监管回归、2 项执行反馈回归;本轮四阶段定向测试另有 61 项通过(与上述回归有覆盖重叠)。
两进程真实 Qt/CDP 验收报告:[report.json](../../build/dsh-production-chain-verified/20261031-101218/report.json)。两个进程正常退出,原队列重启续跑和授权排期执行一次均通过,受控执行器调用 3 次,`realCadStarted=false`、`remoteIssuesCreated=false`、fixture 哈希未变化。
## 限制
参考 broker 只完成协议和安全边界验证,尚未部署到生产 HTTPS 服务;生产环境仍需运维配置 Git issue-only 凭据、实例注册、吊销和轮换。CAD 适配器复用现有私有桌面和前后探针,验收仍使用隔离 fixture,不代表真实用户工程已经写入成功。
+3 -1
View File
@@ -103,12 +103,14 @@ Harness 使用任务中心数据目录下独立的 `dsh/harness-home` 保存会
每次自动介入在数据目录 `dsh/incidents/<事件编号>/` 保存:前后任务快照、脱敏诊断包、事件时间线、规则门禁明细、模型可见会话、尝试动作、实际核验结果、工单草稿和带 SHA256 清单的 `evidence.zip`。保留可审阅的诊断说明,不要求模型输出隐藏思维过程;“取证”只收集本工具已有的日志与运行记录,不扫描无关网络流量、工程源文件或用户文件。
工单默认提交到 `https://git.simgreek.com/Skyworth_Digital_Hardware/dxdesigner-part-replacement`。生产环境优先配置固定仓库的中转地址:客户端使用安装实例标识换取短期 `write:issue` 凭据,令牌只在内存中使用,不进入模型、缓存、日志或工单正文。中转不可用时才进入本机 Git credential 或预置令牌兼容路径,概览健康会标记“需要轮换凭据”。预置账户必须是非管理员、仅绑定本仓库的 `write:issue` 权限,并支持服务端吊销和轮换。
工单默认提交到 `https://git.simgreek.com/Skyworth_Digital_Hardware/dxdesigner-part-replacement`。生产环境优先配置固定仓库的中转地址、安装实例标识、实例证明和事件幂等键:客户端使用这些信息换取短期 `write:issue` 凭据,令牌只在内存中使用,不进入模型、缓存、日志或工单正文。中转不可用时才进入本机 Git credential 或预置令牌兼容路径,概览健康会标记“需要轮换凭据”。预置账户必须是非管理员、仅绑定本仓库的 `write:issue` 权限,并支持服务端吊销和轮换。
开发/验收预填资源为 `integration/dsh/issue-bootstrap.json`,已加入 Git 忽略;生产打包不应依赖它,而应配置中转地址和实例注册流程。管理员侧的账户密码和令牌恢复资料单独保存在本机 DPAPI 文件,不能随包分发。没有中转或明确兼容凭据时,工单保留本地证据并显示待提交状态。
`dsh/issue-config.json` 可覆盖启用状态与目标。预填令牌仅用于其绑定的服务器和仓库;自定义其他目标不会携带该令牌,而沿用该目标的本机 Git 凭据。受限共享令牌可在 Git 服务端吊销;吊销后保留证据待补交,并需更新分发资源。
参考中转服务使用环境变量 `DSH_ISSUE_SERVER`、`DSH_ISSUE_REPOSITORY`、`DSH_ISSUE_TOKEN`、`DSH_BROKER_SECRET` 启动 `python tools/dsh_issue_broker.py`,提供 `GET /healthz` 和 `POST /v1/issue-token`。这是服务端参考实现,正式部署应放在受控 HTTPS 服务后并配置实例注册、密钥轮换、访问日志脱敏和网络限流。
提交前按事件标记查重,成功后上传脱敏证据附件并在任务监管显示工单链接;提交、权限或上传失败时保留为“工单待完整提交”。可以点击 **打开证据目录** 或 **重新提交工单**;重试工单不会重新执行 CAD。重启后恢复待提交记录,已中断的处理也不自动重放。附件是提交前封存的证据快照,提交回执另存在 `ticket.json` 和后续时间线中。
## 安装与验证