feat(harness): Git Bash + graceful degradation for Windows agentic bridge

Wide-deployment Windows path without WSL2. The agentic bridge already runs
on native Python + PowerShell; the only bash dependency is the H4/H2 gate
scripts, which run under Git Bash (Git for Windows) — much lighter than WSL2.

- h4_scan now returns a status (ok|blocked|timeout|unavailable). Timeout stays
  FAIL-CLOSED (block/deny). "unavailable" (no bash / gate missing) DEGRADES the
  turn to observed_only and does NOT block the developer — never silently
  certifies without a working gate.
- bash interpreter is configurable via CASAN_AGENTIC_BASH; gates use it.
- doctor reports bash_available / gates_runnable + a remediation warning, and
  stays green (degraded, not failed) when bash is absent.
- tests: +4 no-bash cases (degrade to observed_only, tool still allowed,
  non-certified finalize, injection still blocked when bash present). 34/34.
- docs: Windows guide + security guide now point to Git Bash, not WSL2, and
  document the timeout-vs-unavailable distinction.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
thanhnv
2026-07-23 20:52:02 +07:00
co-authored by Claude Opus 4.8
parent 4bb184b935
commit f6d28a3163
4 changed files with 141 additions and 23 deletions
@@ -21,17 +21,37 @@ Liên quan:
## 2. Yêu cầu nền
**KHÔNG cần WSL2 cho luồng agentic client.** Bridge là Python stdlib + PowerShell
thuần. Chỉ cần:
- Windows PowerShell 5.1 trở lên (hoặc PowerShell 7+/`pwsh`).
- Python 3 trên PATH (`python3`, `python`, hoặc `py`). Bridge chỉ dùng stdlib —
không cài thư viện mới.
- **`bash` trên PATH để chạy security gate H4/H2** — khuyến nghị **Git for
Windows (Git Bash)**, nhẹ hơn WSL2 nhiều và đa số máy dev đã có. Đây là điều
kiện để turn được **certified**.
- Repo dự án đã adopt CASAN core (`packages/casan-harness` tồn tại). Nếu chưa,
xem [CASAN_ADOPTION_WINDOWS.md](CASAN_ADOPTION_WINDOWS.md).
> **Graceful degradation:** nếu máy **không có bash**, bridge vẫn chạy —
> admission/telemetry/redaction bằng Python thuần — nhưng H4/H2 gate không chạy
> được nên turn bị **hạ cấp `observed_only`** (không certified) và **không chặn**
> developer. Cài Git Bash để bật lại certification. Không bao giờ certify âm thầm
> khi thiếu gate.
Nếu Git Bash cài ở đường dẫn không chuẩn, trỏ trực tiếp:
```powershell
$Env:CASAN_AGENTIC_BASH = "C:\Program Files\Git\bin\bash.exe"
```
Kiểm tra nhanh:
```powershell
python3 --version
Test-Path .\packages\casan-harness\scripts\python\agentic_bridge.py
# Xác nhận gate chạy được (bash_available / gates_runnable = true)
python3 .\packages\casan-harness\scripts\python\agentic_bridge.py doctor
```
## 3. Cài đặt từ clone sạch (không copy file thủ công)
@@ -129,3 +149,4 @@ Uninstall chỉ xóa file do CASAN tạo (theo manifest) và khôi phục bản
| Turn hiện `observed_only` | Đang ở observe mode hoặc client ngoài allowlist | Đặt `-Mode enforce`, thêm client vào allowlist |
| Token/cost là `null` | Client chưa cấp nguồn usage đáng tin | Đúng theo thiết kế — không bịa số; `telemetry_quality=partial` |
| `bridge doctor` báo gate missing | Repo chưa adopt core đầy đủ | Chạy lại DevKit install core |
| Mọi turn hiện `observed_only` trên Windows | Không có `bash` (thiếu Git Bash) → gate H4/H2 không chạy | Cài Git for Windows hoặc set `CASAN_AGENTIC_BASH`; `doctor` sẽ báo `gates_runnable=true` |
@@ -35,6 +35,16 @@ UI và export H6 **không** được gộp bốn mức trên thành một nhãn
Nếu bất kỳ điều kiện nào thiếu → turn là **non-certified**. Bridge fail-closed:
khi không quyết định được trong internal timeout → block/deny.
**Phân biệt timeout vs gate-unavailable (graceful degradation):**
- **Timeout** (gate tồn tại nhưng không trả lời kịp) → **fail-closed**: block prompt
/ deny tool. Coi như có thể có rủi ro.
- **Gate không chạy được** (ví dụ Windows không có `bash`/Git Bash) → **degrade**:
turn bị hạ cấp `observed_only`, **không certify**, nhưng **không chặn** developer.
Đây là thực tế triển khai, không phải tấn công. CASAN không bao giờ certify âm
thầm khi H4/H2 không chạy, và cũng không biến việc thiếu bash thành lý do chặn
mọi prompt. Cài Git Bash để bật lại certification.
## 3. Những gì CASAN KHÔNG hứa
- **Không** chặn được mọi prompt trong mọi AI extension bên thứ ba.