feat(dsh): harden health decisions and issue transport
This commit is contained in:
1 parent
736b582bc1
commit
eee4e6bde9
18 files changed
+592
-11
No files matched your search
@@ -0,0 +1,107 @@
|
||||
# DSH 生产化加固实施计划
|
||||
|
||||
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.
|
||||
|
||||
**Goal:** Add local health visibility, append-only incident decision records, and fixed-target issue credential rotation without weakening DSH execution gates.
|
||||
|
||||
**Architecture:** Add three Qt-free bounded stores/services, then expose read-only health and decision data through the existing operations context and right dock. Issue publishing obtains credentials through a fixed-target transport abstraction and retains the current direct Git credential path only as an explicitly reported compatibility fallback.
|
||||
|
||||
**Tech Stack:** Python 3.12, SQLite/atomic JSON, PySide6, existing Harness 0.2.1-rc.5 plugin protocol, pytest and Node verification scripts.
|
||||
|
||||
**Spec:** `docs/superpowers/specs/2026-10-31-dsh-production-hardening.md`
|
||||
|
||||
## Global Constraints
|
||||
|
||||
- Work only in `.worktrees/codex-dsh` on branch `codex/dsh`.
|
||||
- Do not print, stage, or commit provider keys, issue tokens, or ignored bootstrap files.
|
||||
- Do not change automatic-session snapshot-only admission, native confirmations, safe pause semantics, schedule idle requirement, or original queue resume rules.
|
||||
- Every new operation must be bounded, fixed-target, auditable, and read-only unless it is an existing confirmed issue submission.
|
||||
- Use controlled fixtures for tests; never write a real user CAD project.
|
||||
|
||||
---
|
||||
|
||||
### Task 1: Health snapshot service
|
||||
|
||||
**Files:**
|
||||
- Create: `src/dx_productivity/dsh/health.py`
|
||||
- Create: `tests/dsh/test_health.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Produces `HealthStore.snapshot(service, *, now=None) -> dict` with `status`, `checked_utc`, and bounded `checks`.
|
||||
- Each check has `name`, `status` (`ok|degraded|blocked`), `code`, `message`, and optional `updated_utc`.
|
||||
|
||||
- [x] Write tests for no provider, healthy local stores, stale ticket cache, active worker, and credential rotation warning.
|
||||
- [x] Run the focused tests and confirm the new module is missing or tests fail.
|
||||
- [x] Implement deterministic local checks without network or CAD calls; provider availability is based on configured metadata, not a live model request.
|
||||
- [x] Bound all messages and scrub secrets before returning values.
|
||||
- [x] Run `pytest -q tests/dsh/test_health.py` and confirm all pass.
|
||||
|
||||
### Task 2: Append-only decision log
|
||||
|
||||
**Files:**
|
||||
- Create: `src/dx_productivity/dsh/decision_log.py`
|
||||
- Create: `tests/dsh/test_decision_log.py`
|
||||
- Modify: `src/dx_productivity/dsh/incidents.py`
|
||||
- Modify: `src/dx_productivity/trial_task_center/ui/dsh_operations.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Produces `DecisionLog(data_root).append(record) -> dict`, `.list(limit=20) -> list[dict]`, and `.verify(sequence=None) -> dict`.
|
||||
- `append` stores a SHA256-linked JSON line with `sequence`, `previous_hash`, `record_hash`, `incident_id`, `trigger`, `evidence_refs`, `gates`, `candidate_action`, `authorized_scope`, `outcome`, and `human_takeover`.
|
||||
|
||||
- [x] Write tests proving append order, hash verification, restart recovery, bounded output, and tamper detection.
|
||||
- [x] Run focused tests and observe expected failure.
|
||||
- [x] Implement append-only atomic writes; reject malformed identifiers and scrub all free text.
|
||||
- [x] Record diagnosis gates and actual result after each automatic intervention; never record model prose as verification.
|
||||
- [x] Add recent decision rows to operations context and experience view.
|
||||
- [x] Run focused tests and existing incident/UI tests.
|
||||
|
||||
### Task 3: Fixed-target issue transport
|
||||
|
||||
**Files:**
|
||||
- Create: `src/dx_productivity/dsh/issue_transport.py`
|
||||
- Create: `tests/dsh/test_issue_transport.py`
|
||||
- Modify: `src/dx_productivity/dsh/issue_credentials.py`
|
||||
- Modify: `src/dx_productivity/dsh/git_issues.py`
|
||||
- Modify: `src/dx_productivity/dsh/ticket_tracking.py`
|
||||
|
||||
**Interfaces:**
|
||||
- Produces `IssueTransport(config_path).credentials(target, *, now=None) -> dict` with only in-memory `headers`, `source`, `expires_utc`, and `rotation_required`.
|
||||
- Supports `broker_url` plus instance ID and a short-lived exchange response; direct bootstrap/Git credential fallback is tagged and never cached as a token.
|
||||
|
||||
- [x] Write tests for fixed target validation before credentials, broker success, broker expiry, direct fallback warning, and no-token cache/log output.
|
||||
- [x] Run focused tests and observe expected failure.
|
||||
- [x] Implement strict HTTPS host/path validation and bounded broker request with no redirects; hash or omit instance identifiers in logs.
|
||||
- [x] Make Git issue publishing request fresh transport credentials for each submission and preserve existing idempotency marker behavior.
|
||||
- [x] Keep read-only ticket tracking compatible with the transport and expose credential source/expiry only.
|
||||
- [x] Run focused issue, ticket, and credential tests.
|
||||
|
||||
### Task 4: Health and decisions in the Harness dock
|
||||
|
||||
**Files:**
|
||||
- Modify: `src/dx_productivity/trial_task_center/ui/dsh_operations.py`
|
||||
- Modify: `src/dx_productivity/dsh/native_runtime.py`
|
||||
- Modify: `integration/dsh/task-plugin/model_results.mjs`
|
||||
- Modify: `integration/dsh/task-plugin/client.js`
|
||||
- Modify: `tests/ui/test_dsh_operations.py`
|
||||
- Modify: `tools/verify_dsh_model_results.mjs`
|
||||
|
||||
**Interfaces:**
|
||||
- Operations context adds `health` and `decisions` arrays with bounded rows.
|
||||
- Existing operations actions gain `health` and `decisions` read operations; no new write capability is registered.
|
||||
|
||||
- [x] Add failing UI/model projection tests for bounded health and decision data.
|
||||
- [x] Implement read operations through the existing background observation lane and refresh button.
|
||||
- [x] Add overview cards and a compact decision timeline without remounting the dock or changing the selected task.
|
||||
- [x] Verify model output keeps IDs, hashes, and unknown values explicit and omits credentials.
|
||||
- [x] Run Node projection, dock startup, UI, and runtime guard checks.
|
||||
|
||||
### Task 5: Full verification and documentation
|
||||
|
||||
**Files:**
|
||||
- Modify: `docs/user/dsh-ai-supervision.md`
|
||||
- Modify: `docs/testing/2026-10-31-dsh-production-hardening.md`
|
||||
|
||||
- [x] Run focused DSH tests, existing relevant UI/lifecycle tests, Node checks, `git diff --check`, and credential scan.
|
||||
- [x] Run real two-process Qt/CDP acceptance using controlled fixtures.
|
||||
- [x] Record exact artifact paths, limits, and whether a broker was available.
|
||||
- [x] Commit only intended files on `codex/dsh`; verify clean status and commit ID.
|
||||
@@ -0,0 +1,47 @@
|
||||
# DSH 生产化加固设计
|
||||
|
||||
## 目标
|
||||
|
||||
在现有 DSH 七项能力和原生确认边界之上,补齐运行健康、自动处理决策审计和工单凭据生命周期,降低上线后的不可观测、误判和凭据泄露风险。
|
||||
|
||||
## 设计边界
|
||||
|
||||
- 模型仍不能直接写 CAD、绕过原生确认、扩大重试额度或提交任意 URL。
|
||||
- 排期仍要求任务中心打开且空闲;异常处理仍只使用已授权的原执行上下文。
|
||||
- 健康信息只读;不向远端发送工程源文件、模型隐藏思维或凭据。
|
||||
- 工单提交保持固定仓库和事件标记去重;优先使用中转服务短期令牌,直连凭据只作为明确配置的兼容路径。
|
||||
|
||||
## 组件
|
||||
|
||||
### 运行健康中心
|
||||
|
||||
新增 `dsh/health.py`,收集模型提供方、Harness 子进程、任务中心工作线程、运行队列、排期、证据目录和工单同步的本地状态。每项返回 `ok`、`degraded` 或 `blocked`、更新时间、错误码和可执行建议;不得把异常文本中的凭据带入结果。健康读取为只读快照,不能触发模型请求、CAD 操作或工单写入。
|
||||
|
||||
右侧概览增加健康卡片和“重新检查”按钮。检查使用现有后台读取通道,活动执行期间不阻塞执行器;展示“模型未配置”“等待原生确认”“队列待核验”等真实边界。
|
||||
|
||||
### 异常决策记录
|
||||
|
||||
新增 `dsh/decision_log.py`,对每次自动介入保存不可变的决策记录:事件编号、触发来源、证据引用、门禁结果、候选动作、实际授权范围、结果和人工接管状态。保存结构化摘要,不保存隐藏思维;每条记录有 SHA256 链接和序号,追加失败不得覆盖旧记录。
|
||||
|
||||
自动诊断和 DSH 右侧经验页展示最近记录。模型建议、工单关闭和“已解决”文字仍不能单独把记录标为已验证;验证必须来自持久化执行证据。
|
||||
|
||||
### 工单凭据生命周期
|
||||
|
||||
新增 `dsh/issue_transport.py`,支持固定仓库的中转模式:客户端只保存中转地址和安装实例标识,通过一次性或短期令牌换取服务端签发的 issue-only 访问凭据;令牌只用于固定服务器、仓库、事件标记和工单创建/附件上传。缓存只保存凭据来源、过期时间和错误码,不保存访问令牌。
|
||||
|
||||
兼容模式继续读取本机 Git credential,但预置静态令牌只作为开发/验收 fallback,并在健康中心标记为 `credential_rotation_required`。任何目标校验都必须在获取凭据前完成。
|
||||
|
||||
## 错误处理
|
||||
|
||||
- 健康检查失败返回脱敏错误码和最近一次成功时间,不能让后台轮询打断执行。
|
||||
- 决策记录写入失败时保留内存结果,禁止把“未记录”显示为“已完成”;结束后补写并提示人工导出证据。
|
||||
- 中转服务超时只进入待提交队列,不能自动重复 CAD 执行;使用事件编号和请求幂等键去重。
|
||||
- 令牌过期、仓库身份不匹配和附件失败分别呈现,均保留本地证据包。
|
||||
|
||||
## 验收标准
|
||||
|
||||
1. 健康接口和右侧概览能在无模型、运行中、排期阻断、工单离线四种状态下给出正确状态。
|
||||
2. 自动介入至少生成一条追加式决策记录,重启后可恢复并校验哈希,旧记录不可被覆盖。
|
||||
3. 中转凭据不进入模型上下文、日志、缓存和工单正文;过期后只读健康状态变为降级。
|
||||
4. 固定目标校验失败时不读取任何凭据、不发起网络请求。
|
||||
5. 既有 DSH 回归和两进程 Qt/CDP 验收保持通过。
|
||||
@@ -0,0 +1,21 @@
|
||||
# DSH 生产化加固验证记录
|
||||
|
||||
本轮在 `codex/dsh` 继续加固健康检查、自动处理决策审计和固定目标工单凭据传输。所有验证使用临时状态目录、受控任务服务和无写入 CAD fixture。
|
||||
|
||||
## 已完成的验证
|
||||
|
||||
- 健康快照:未配置模型、后台工作线程、状态目录、工单缓存和预置凭据轮换提示均有对应状态;输出不包含令牌。
|
||||
- 决策日志:追加记录、重启读取、SHA256 链校验、篡改检测和有界输出通过。
|
||||
- 工单传输:固定目标在凭据读取前校验;中转短期凭据不落盘;中转失败标记降级;预置凭据仅作为兼容 fallback。
|
||||
- UI:概览显示健康摘要和最近决策,刷新走既有后台观察通道,不改变选中任务和执行器占用。
|
||||
- 原有事件诊断、工单只读同步、DSH 操作页和 Qt UI 回归保持通过。
|
||||
|
||||
完整相关回归通过 **287 项**:203 项 DSH/UI/队列/打包回归、82 项存储与监管回归、2 项执行反馈回归;另有 50 项本轮定向测试通过(其中包含上述回归的重叠覆盖)。
|
||||
|
||||
真实模型与两进程 Qt/CDP 验收报告:[report.json](../../build/dsh-operations-hardening-verified/20261031-093920/report.json)。两次应用进程均正常退出,原队列重启续跑、排期授权执行一次、工单只读同步、健康概览和七页签点击均通过;受控执行器共 3 次,`realCadStarted=false`、`remoteIssuesCreated=false`、源 fixture 哈希未变化。
|
||||
|
||||
截图:[初始运行页](../../build/dsh-operations-hardening-verified/20261031-093920/initial-desktop.png)、[重启后工单页](../../build/dsh-operations-hardening-verified/20261031-093920/after-restart-operations.png)。
|
||||
|
||||
## 当前验收边界
|
||||
|
||||
本轮没有部署真实中转服务,因此 broker 只用受控 HTTP 响应验证协议和凭据不落盘行为;生产部署仍需配置固定服务器、实例注册、短期令牌过期和吊销策略。没有改变真实 CAD 写入门禁,也没有构建新 EXE。
|
||||
@@ -57,6 +57,8 @@ Harness 使用任务中心数据目录下独立的 `dsh/harness-home` 保存会
|
||||
|
||||
右侧保留官方三栏界面,在“任务监管”内部提供 **概览、运行、影响、排期、经验、工单、用量** 七个页签。默认进入概览。各页按钮直接请求任务中心,原生窗口负责需要确认的操作;不需要发送特定模型提示或记忆工具名。
|
||||
|
||||
概览页还显示 DSH 运行健康和最近自动处理决策。健康状态只检查本地配置、任务中心后台工作线程、状态目录、工单缓存和凭据来源,不会为了探活调用模型、CAD 或远端写接口。决策记录包含事件、证据引用、门禁、授权范围、实际结果和人工接管标记,并通过追加式 SHA256 链保存;模型文字、工单关闭和“已解决”描述都不会单独成为修复证明。
|
||||
|
||||
### 运行与重启恢复
|
||||
|
||||
**运行**页显示实际执行所属任务、运行编号、阶段、耗时、当前进度、已保存/失败/未命中数量及安全暂停请求。即使左侧选中其他任务,活动执行仍显示真实所有者。请求暂停后,执行器在当前项安全收尾后停止;等待期间仍显示执行中。
|
||||
@@ -101,9 +103,9 @@ Harness 使用任务中心数据目录下独立的 `dsh/harness-home` 保存会
|
||||
|
||||
每次自动介入在数据目录 `dsh/incidents/<事件编号>/` 保存:前后任务快照、脱敏诊断包、事件时间线、规则门禁明细、模型可见会话、尝试动作、实际核验结果、工单草稿和带 SHA256 清单的 `evidence.zip`。保留可审阅的诊断说明,不要求模型输出隐藏思维过程;“取证”只收集本工具已有的日志与运行记录,不扫描无关网络流量、工程源文件或用户文件。
|
||||
|
||||
工单默认提交到 `https://git.simgreek.com/Skyworth_Digital_Hardware/dxdesigner-part-replacement`。随客户端预填专用上报账户 `dsh-issue-reporter` 的 `write:issue` 令牌,其他电脑无需安装 Git、登录或提供个人凭据。该账户为非管理员受限账户,专用团队仅包含本仓库,只有工单写权限;代码、拉取请求、发布、组织、包和 Actions 权限均未授予。令牌不交给模型或网页。
|
||||
工单默认提交到 `https://git.simgreek.com/Skyworth_Digital_Hardware/dxdesigner-part-replacement`。生产环境优先配置固定仓库的中转地址:客户端使用安装实例标识换取短期 `write:issue` 凭据,令牌只在内存中使用,不进入模型、缓存、日志或工单正文。中转不可用时才进入本机 Git credential 或预置令牌兼容路径,概览健康会标记“需要轮换凭据”。预置账户必须是非管理员、仅绑定本仓库的 `write:issue` 权限,并支持服务端吊销和轮换。
|
||||
|
||||
预填资源为 `integration/dsh/issue-bootstrap.json`,已加入 Git 忽略;打包时放入 `dsh-runtime/issue-bootstrap.json`,可跨电脑使用,不依赖开发电脑的 DPAPI。管理员侧的账户密码和令牌恢复资料单独保存在本机 DPAPI 文件,不能随包分发。没有预填资源时,DSH 发布打包会明确报错,避免生成缺少上报身份的安装包。
|
||||
开发/验收预填资源为 `integration/dsh/issue-bootstrap.json`,已加入 Git 忽略;生产打包不应依赖它,而应配置中转地址和实例注册流程。管理员侧的账户密码和令牌恢复资料单独保存在本机 DPAPI 文件,不能随包分发。没有中转或明确兼容凭据时,工单保留本地证据并显示待提交状态。
|
||||
|
||||
`dsh/issue-config.json` 可覆盖启用状态与目标。预填令牌仅用于其绑定的服务器和仓库;自定义其他目标不会携带该令牌,而沿用该目标的本机 Git 凭据。受限共享令牌可在 Git 服务端吊销;吊销后保留证据待补交,并需更新分发资源。
|
||||
|
||||
|
||||
Reference in new issue
Block a user