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 验收保持通过。
|
||||
Reference in new issue
Block a user