feat(install): Plan-21 hybrid global install + casan init (pin+verify)

Adopt CASAN like a normal tool (codegraph-style): install the harness ONCE
per machine, then `casan init` per project writes CONFIG ONLY — the harness
is no longer copied into every repo.

- install.sh / install.ps1: global bootstrap (curl|sh / irm|iex or local
  source). Installs harness to $CASAN_HOME/versions/<ver>, writes a `casan`
  launcher that resolves the shared harness + the current project's .specify,
  and records a gate-code integrity hash. CASAN_NO_PATH_LINK for tests.
- harness_hash.py: deterministic content hash over gate code (scripts/bash,
  scripts/python, security, level5) — the pin+verify anchor.
- casan-init.py: `casan init` writes .casan/{config,version.lock,agentic.env},
  .specify/ marker, and the Plan-20 client hooks — no harness copy. `verify`
  recomputes the harness hash LIVE and compares to the project pin (drift/
  tamper -> rc 3), preserving the Plan-16 trusted-gates guarantee off-repo.
- bin/casan: new `init` and `verify-harness` commands.
- hybrid-install-tests.sh: 21/21 (install, config-only init, no-copy, pin,
  verify ok, tamper drift, bridge runs against project state via global harness).
- docs: CASAN_INSTALL_HYBRID.md + Plan-21.

The path model (casan-paths.sh) already separated harness/state/domain roots,
so this is installer + init, not a core rewrite. Remote dist tarball, real
Windows run, and signed .harness-hash are the documented next steps.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
thanhnv
2026-07-23 21:26:54 +07:00
co-authored by Claude Opus 4.8
parent f6d28a3163
commit 8450f8ca1a
8 changed files with 904 additions and 0 deletions
@@ -0,0 +1,65 @@
# CASAN Plan-21 — Hybrid Global Install + `casan init`
> Ngày lập: 2026-07-23
> Trạng thái: **IMPLEMENTED (MVP) — global install + `casan init` + pin/verify xanh (21/21 test)**
> Liên quan: [Plan-20](CASAN_PLAN_20_AGENTIC_CLIENT_INTEGRATION.md) (adapter/hook là base phổ quát), [CASAN_INSTALL_HYBRID.md](../casan/CASAN_INSTALL_HYBRID.md)
## 1. Mục tiêu
Cài CASAN như một tool bình thường (giống codegraph): cài **một lần** lên máy,
rồi trong dự án chỉ chạy `casan init`. Không còn copy toàn bộ harness vào từng
repo. Đây là câu trả lời cho "làm sao dựng 1 base chung nhất cho dự án muôn hình
vạn trạng": **harness = phần chung (agnostic), config per-project = phần biến
thể**, và entry phổ quát nhất là agentic bridge Plan-20 (chỉ cần Python + bash).
## 2. Kiến trúc
Tận dụng sẵn `casan-paths.sh` đã tách 3 root độc lập:
- `CASAN_HARNESS_ROOT` = **code** → cài global (`$CASAN_HOME/versions/<ver>`).
- `CASAN_STATE_ROOT` (`.specify/`) = **state runtime** → trong repo.
- `CASAN_DOMAIN_ROOT` = **dữ liệu dự án** → trong repo (optional).
Launcher global set `CASAN_HARNESS_ROOT`/`CASAN_DEVKIT_ROOT` về bản cài, và tìm
`CASAN_APP_ROOT` bằng cách đi lên từ CWD tới marker `.casan`/`.specify`. Nhờ vậy
harness global thao tác đúng trên state của dự án hiện tại.
## 3. Pin + Verify (giữ đảm bảo Plan-16 khi harness ở ngoài repo)
- Installer tính **hash toàn vẹn gate-code** (`scripts/bash`, `scripts/python`,
`security`, `level5`) và ghi `.harness-hash`.
- `casan init` **pin** version + hash vào `.casan/version.lock`.
- `casan verify-harness` **tính lại live** từ file thật và so với pin → phát hiện
drift/tamper (rc 3). Không tin hash cache.
- Làm mạnh sau: ký `.harness-hash` bằng khóa tổ chức (tái dùng hạ tầng ký Plan-16).
## 4. Deliverable đã ship
| Deliverable | File |
|---|---|
| Global installer (macOS/Linux) | `install.sh` |
| Global installer (Windows) | `install.ps1` |
| Integrity hash primitive | `packages/casan-harness/scripts/python/harness_hash.py` |
| `casan init` / `verify` | `packages/casan-devkit/casan-init.py` |
| CLI wiring | `bin/casan` (`init`, `verify-harness`) |
| Acceptance suite | `packages/casan-devkit/tests/hybrid-install-tests.sh` — **21/21 PASS** |
| Adoption doc | `docs/casan/CASAN_INSTALL_HYBRID.md` |
## 5. Definition of Done
- ✅ `install.sh` cài harness + launcher + integrity hash từ checkout cục bộ.
- ✅ `casan init` ghi CHỈ config per-project; **không** copy harness.
- ✅ `version.lock` pin đúng hash; `verify-harness` ok khi sạch, drift (rc 3) khi tamper.
- ✅ Bridge Plan-20 chạy qua harness global, state ghi vào `.specify` của dự án.
- ✅ Project id mặc định theo tên thư mục, được sanitize.
## 6. Còn lại / bước tiếp
- **Remote bootstrap**: `install.sh`/`install.ps1` đã hỗ trợ `CASAN_DIST_URL`
nhưng chưa có release tarball + URL Gitea công bố; cần publish artifact.
- **Windows thực**: `install.ps1` viết path-safe nhưng chưa chạy trên máy Windows
thật (host dev không có `pwsh`).
- **Ký `.harness-hash`**: verify hiện theo nội dung; thêm chữ ký để chống thay cả
hash lẫn code.
- **`casan init` domain pack**: hiện init tối giản (config + hook Plan-20); có thể
thêm `--with-domain` để scaffold domain-pack khi dự án cần traceability đầy đủ.