feat(dsh): harden health decisions and issue transport

This commit is contained in:
阿白叔 committed 2026-10-31 09:50:35 +08:00
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.