feat(harness): implement Plan-20 transparent agentic client bridge

Wave 0 + Wave 1 core of the transparent agentic-client integration: a
developer types prompts normally in Claude Code / Codex while every
certified turn still carries a full H1->H7 trace and an H6 record.

- agentic_bridge.py: stdlib-only lifecycle state machine (begin/pre-tool/
  post-tool/telemetry/finalize/abort + report/doctor). Single-model
  invariant (never calls a model), fail-closed at the side-effect point,
  admission TTL + canonical-project/session binding, atomic state under
  .specify/state/agentic-sessions/, secret redaction, null-not-zero H6.
- agentic-lifecycle.schema.json: client-agnostic JSON contract.
- adapters/claude-code + adapters/codex: thin hook renderers + config
  templates that call the core bridge.
- phase-agentic-bridge-tests.sh: C1-C12 acceptance + threat suite (30/30).
- devkit templates/{claude,codex} + windows/install-agentic.ps1
  (install/doctor/uninstall with manifest, path-safe).
- docs/casan Windows + security/bypass guides; plan status -> IMPLEMENTED.
- harden generate-agentops-dashboard.py aggregation against null H6 costs.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
thanhnv
2026-07-23 20:44:07 +07:00
co-authored by Claude Opus 4.8
parent 0cc43d94d3
commit 4bb184b935
18 changed files with 2647 additions and 6 deletions
@@ -1,10 +1,12 @@
# CASAN Plan-20 — Transparent Agentic Client Integration
> Ngày lập: 2026-07-22
> Trạng thái: **PLAN — thực hiện sau khi Spike-20 đạt exit gate**
> Cập nhật: 2026-07-23
> Trạng thái: **IMPLEMENTED (Wave 0 + Wave 1 core) — bridge, adapters, tests, devkit, docs đã ship và xanh; Codex/VS Code black-box trên client thật còn CONDITIONAL**
> Thứ tự bắt buộc: **Claude Code → Codex → Claude/Codex trên VS Code**
Kết quả khảo sát và test matrix: [CASAN Spike-20](../spikes/CASAN_SPIKE_20_AGENTIC_CLIENT_HOOKS.md).
Trạng thái triển khai chi tiết: [§11 Implementation status](#11-implementation-status).
## 1. Mục tiêu
@@ -293,3 +295,47 @@ docs/spikes/
Tên/file cụ thể có thể điều chỉnh sau Spike-20, nhưng lifecycle contract, single-model
invariant và certification strength là quyết định kiến trúc bắt buộc.
## 11. Implementation status
Cập nhật 2026-07-23. Ba quyết định kiến trúc bắt buộc đều được hiện thực và có test bao phủ:
**lifecycle contract**, **single-model invariant** (bridge không gọi model — có test grep
nguồn), **certification strength** (bốn mức, không gộp).
### Deliverable đã ship
| Deliverable | File | Trạng thái |
|---|---|---|
| Lifecycle JSON contract (20.0.1) | `packages/casan-harness/schemas/agentic-lifecycle.schema.json` | ✅ |
| Bridge state machine (20.0.2/0.3/0.4) | `packages/casan-harness/scripts/python/agentic_bridge.py` (stdlib-only, Py3.9+) | ✅ |
| Claude Code adapter (20.1.1–20.1.3) | `packages/casan-harness/adapters/claude-code/` (`claude_hook.py`, `settings.template.json`) | ✅ |
| Codex adapter (20.3.1/0.2) | `packages/casan-harness/adapters/codex/` (`codex_hook.py`, `hooks.template.json`, `config.template.toml`) | ✅ mapping defensive, chờ pin trên client thật |
| Threat + acceptance suite (20.0.5/1.6) | `packages/casan-harness/tests/phase-agentic-bridge-tests.sh` | ✅ **30/30 PASS** (C1–C12 + threat) |
| DevKit templates + Windows installer (Wave 5) | `packages/casan-devkit/templates/{claude,codex}/`, `packages/casan-devkit/windows/install-agentic.ps1` | ✅ (install/doctor/uninstall + manifest) |
| Docs Windows + Security/bypass | `docs/casan/CASAN_AGENTIC_CLIENTS_WINDOWS.md`, `docs/casan/CASAN_AGENTIC_CLIENT_SECURITY.md` | ✅ |
| H6 provenance + report filter (20.0.4) | superset record trong bridge + `agentic_bridge.py report --client/--integration-mode/--trace-id/--project-id` | ✅ null-not-zero, filter được |
### Ánh xạ exit gate (mục 8)
- ✅ 100% test lifecycle fixtures pass (30/30).
- ✅ 100% side-effect test bị deny khi thiếu admission (C4, cross-project, expired, traversal).
- ✅ Không có double model execution (invariant test trên nguồn bridge).
- ✅ Timeout/hook failure tạo non-certified + H6 failure (C6, abort).
- ⏳ Windows smoke: installer PowerShell viết theo path-safe + doctor; **cần chạy trên máy
Windows thật** (host phát triển không có `pwsh`). macOS/Linux smoke: ✅ qua suite.
- ✅ H6 JSON thể hiện `project_hook`/`observed_only` + telemetry quality.
### Còn CONDITIONAL (đúng theo phạm vi Spike-20, chưa đóng)
- **Codex payload keys**: adapter đọc nhiều alias phòng thủ; cần pin trên Codex thật (Wave 3.1).
- **VS Code / extension**: chưa black-box trên client thật; `@casan` Chat Participant (Wave 4)
chưa hiện thực — vẫn giữ badge `unsupported` cho tới khi có evidence độc lập.
- **Windows exit-gate smoke**: cần chạy `install-agentic.ps1` trên clean Windows clone.
### Quyết định thiết kế cần lưu
- H2 tool-registry gate là **opt-in** (`CASAN_AGENTIC_H2_REGISTRY=1`) cho managed deployment
có agent identity; gate side-effect luôn-bật của luồng transparent là **admission gate**
(side-effect thiếu admission hợp lệ → deny). Xem `CASAN_AGENTIC_CLIENT_SECURITY.md`.
- Certified có thể đi kèm `telemetry_quality=insufficient`: certification dựa trên
admission/evidence/coverage; chất lượng telemetry được báo cáo riêng, không bịa số.