8 tình huống thực tế
8 real-world scenarios

Dùng harness-kit trong thực tế như thế nào?

How to use harness-kit in real projects

Mỗi tình huống bắt đầu bằng nỗi đau cụ thể, đi qua các bước copy-paste được, kết thúc bằng kết quả nhìn thấy được. Không lý thuyết thừa.

Each scenario starts with a concrete pain, walks through copy-paste-ready steps, and ends with a visible outcome. No filler theory.

GOV  Case 1–4: governance-only — cài mặc định, mọi ngôn ngữ Cases 1–4: governance-only — default install, any language FULL  Case 5–8: cần --full (Python runtime) Cases 5–8: require --full (Python runtime)
1Khởi tạo project mớiCold-start a new projectGOV 2Audit project đang lộn xộnAudit a messy projectGOV 3Gate CI theo điểm harnessGate CI on harness scoreGOV 4Đổi AGENTS.md ↔ CLAUDE.mdSwitch AGENTS.md ↔ CLAUDE.mdGOV 5Khôi phục sau crashResume after a crashFULL 6Thêm tool tuỳ chỉnhAdd a custom toolFULL 7Wire LLM thật (Claude/OpenAI)Wire a real LLM adapterFULL 8Spawn sub-agent cho task conSpawn a focused sub-agentFULL
01

Khởi tạo harness cho project mới

Cold-start a new project

cold-start · scaffold · 2 minutes GOV
PAIN
Bạn vừa mở một repo trống. Claude Code / Cursor đoán mò file, sửa lung tung, không biết khi nào "xong". Bạn cần governance tối thiểu trước khi gọi agent. You just opened an empty repo. Claude Code / Cursor are guessing at files, drifting, with no "done" gate. You need minimal governance before letting an agent run.
  1. Chạy lệnh cài đặt tại thư mục gốc project

    Run the install command from your project root

    Không cần npm/pip — chỉ cần Python 3.8+ và git. Lệnh tự clone, scaffold, rồi tự dọn sạch.

    No npm/pip — just Python 3.8+ and git. The script clones, scaffolds, then cleans up automatically.

    # macOS / Linux
    curl -fsSL https://raw.githubusercontent.com/nguyenanh92/harness-kit/main/install.sh | sh
    
    # Windows (PowerShell)
    irm https://raw.githubusercontent.com/nguyenanh92/harness-kit/main/install.ps1 | iex
  2. Điền 1 feature đầu tiên vào feature_list.json

    Fill in the first feature in feature_list.json

    Đặt active_featurestatus: "in_progress" cho duy nhất 1 feature.

    Set active_feature and status: "in_progress" for exactly one feature.

    feature_list.jsonjson
    {
      "active_feature": "F-001",
      "features": [
        {
          "id": "F-001",
          "name": "Auth login flow",
          "description": "Email + password, no OAuth yet",
          "status": "in_progress",
          "dependencies": []
        }
      ]
    }
  3. Chạy verification entrypoint

    Run the verification entrypoint

    ./init.sh      # POSIX
    ./init.ps1     # Windows
  4. Mở Claude Code / Cursor và bắt đầu

    Open Claude Code / Cursor and start

    Agent đọc AGENTS.md trước, biết cách restart, biết khi nào dừng.

    The agent reads AGENTS.md first — it now knows how to restart and when to stop.

RESULT
Một harness 100/100 ngay từ commit đầu tiên. Agent không lạc scope; có Definition of Done rõ ràng và progress.md đầy đủ để bàn giao giữa các phiên. A 100/100 harness from the first commit. The agent stays in scope, has a clear Definition of Done, and a populated progress.md for session-to-session handoff.
02

Audit project đang lộn xộn

Audit an existing chaotic project

audit · score · bottleneck GOV
PAIN
Đội đã dùng AI agent 3 tháng nhưng output ngày càng lỗi, scope rộng, sửa fix-fix-fix. Bạn nghi ngờ harness yếu nhưng không biết yếu chỗ nào. Your team has used AI agents for 3 months but quality is degrading, scope creeps, fixes pile on fixes. You suspect harness drift but don't know where.
  1. Chấm điểm cấu trúc

    Score the structure

    py skills/scripts/validate_harness.py --target /path/to/project
  2. Đọc Bottleneck trước tiên

    Read the Bottleneck first

    Output mẫu:

    Sample output:

    Overall: 64/100
    Bottleneck: verification
    
    instructions: 4/5 (4/5)
      PASS Agent instruction file exists
      PASS Startup workflow documented
      FAIL Verification commands discoverable    <-- AGENTS.md thiếu init.sh
    
    verification: 1/5 (1/5)
      PASS Verification entrypoint exists
      FAIL Verification fails fast               <-- thiếu set -e
      FAIL Test command documented
      FAIL Static / build check documented
      FAIL Verification evidence is recorded
  3. Sinh report HTML để share team

    Render an HTML report to share with the team

    py skills/scripts/render_assessment_html.py \
        --target /path/to/project \
        --output harness-audit-$(date +%Y%m%d).html
  4. Sửa subsystem yếu nhất TRƯỚC — đừng rải rác

    Fix the lowest subsystem FIRST — don't spread the work

    Mỗi check FAIL là một ticket. Đừng cố lên 100 ngay — kéo bottleneck từ 1→4 đã tạo khác biệt lớn nhất.

    Each FAIL line is a ticketable sentence. Don't aim for 100 immediately — pulling the bottleneck from 1→4 makes the biggest real-world difference.

  5. Re-score sau khi sửa

    Re-score after the fix

    py skills/scripts/validate_harness.py --target . --json | jq '.overall'
RESULT
Một con số trước/sau có thể bảo vệ trước lead. Bottleneck rõ, ticket cụ thể. Score là cấu trúc — kết hợp với 1-2 phiên agent thật trước/sau là đủ để biết harness có thực sự khoẻ hơn. A before/after number you can defend to your lead. Clear bottleneck, ticketable checks. The score is structural; pair with 1-2 real before/after agent sessions to confirm the harness is genuinely healthier.
03

Gate CI theo điểm harness (chống drift)

Gate CI on the harness score (anti-drift)

ci · github-actions · regression GOV
PAIN
Sau vài tuần, ai đó xoá Definition of Done trong AGENTS.md, ai khác xoá set -e trong init.sh. Harness âm thầm trôi. CI hiện tại không phát hiện được. After a few weeks, someone deletes Definition of Done from AGENTS.md and another removes set -e from init.sh. The harness silently drifts. Your CI catches none of it.
  1. Vendor scripts vào repo

    Vendor the scripts into your repo

    Clone harness-kit vào thư mục .harness-scripts/ rồi commit. CI sẽ dùng scripts từ đó thay vì cần clone lại mỗi lần chạy.

    Clone harness-kit into .harness-scripts/ then commit. CI uses those vendored scripts instead of cloning on every run.

    git clone --depth 1 https://github.com/nguyenanh92/harness-kit.git .harness-scripts
    git add .harness-scripts
    git commit -m "vendor harness validation scripts"
  2. Thêm workflow GitHub Actions

    Add a GitHub Actions workflow

    .github/workflows/harness.ymlyaml
    name: Harness regression gate
    on: [push, pull_request]
    jobs:
      audit:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - uses: actions/setup-python@v5
            with: { python-version: "3.12" }
          - run: python .harness-scripts/validate_harness.py --target . --min-score 90
  3. Cài --min-score theo độ chín của project

    Calibrate --min-score to project maturity

    Project mới: 70. Stable: 85. Production: 90+. Đừng pin 100 — một edit nhỏ cũng làm fail CI vì lý do không quan trọng.

    New project: 70. Stable: 85. Production: 90+. Don't pin 100 — trivial edits will fail CI for the wrong reasons.

  4. (Tuỳ chọn) Upload HTML report làm artifact

    (Optional) Upload the HTML report as an artifact

          - run: python .harness-scripts/render_assessment_html.py --target . --output audit.html
            if: always()
          - uses: actions/upload-artifact@v4
            with: { name: harness-audit, path: audit.html }
RESULT
PR nào kéo điểm xuống dưới ngưỡng sẽ đỏ. Reviewer thấy ngay check nào fail, không phải đoán "AGENTS.md có còn ổn không." Any PR that drops the score below the threshold goes red. Reviewers see which checks failed immediately, no guessing whether "AGENTS.md still looks OK."
Các case dưới đây cần cài --full Cases below require the --full install
Thêm Python runtime: vòng lặp agent, JSONL persistence, tool registry, sub-agent spawning.
Adds the Python runtime: agent loop, JSONL persistence, tool registry, sub-agent spawning.
# macOS / Linux
curl -fsSL https://raw.githubusercontent.com/nguyenanh92/harness-kit/main/install.sh | sh -s -- --full

# Windows (PowerShell)
& ([ScriptBlock]::Create((irm https://raw.githubusercontent.com/nguyenanh92/harness-kit/main/install.ps1))) --full
04

Khôi phục agent sau khi crash giữa chừng

Resume an agent that crashed mid-feature

durability · jsonl · replay FULL
PAIN
Agent đang chạy iteration 18/30, terminal tắt đột ngột. Lịch sử chat trong IDE biến mất. Bạn không muốn bắt đầu lại từ đầu. An agent was on iteration 18/30 when the terminal died. The IDE's chat history is gone. You don't want to restart from scratch.
  1. Kiểm tra JSONL còn nguyên

    Check the JSONL log survived

    ls .harness/
    # main_session.jsonl  <-- mỗi dòng = 1 event được flush ngay xuống đĩa
    tail -3 .harness/main_session.jsonl
  2. Mở progress.md để có trạng thái human-readable

    Open progress.md for the human-readable state

    JSONL là cho replay máy. progress.md là cho mắt người.

    JSONL is for machine replay. progress.md is for human eyes.

  3. Chạy lại harness với cùng session-id

    Re-run the harness with the same session-id

    py harness/harness.py \
        --session-id main_session \
        --adapter my_app.adapters:claude_turn \
        --goal "continue F-001"

    Harness replay JSONL, dựng lại history, đếm iteration đã dùng. Side-effect (file đã ghi, lệnh đã chạy) không chạy lại.

    The harness replays the JSONL, reconstructs history, and counts iterations spent. Side effects (files written, commands run) are not re-executed.

  4. Luôn cập nhật session-handoff.md trước khi tắt máy

    Always update session-handoff.md before shutting down

    Lần crash sau, đó là thứ giúp bạn (hoặc đồng đội) khởi động trong 30 giây thay vì 30 phút.

    Next crash, that's what gets you (or a teammate) restarted in 30 seconds instead of 30 minutes.

RESULT
Phiên mới bắt đầu từ iteration 19, không phải iteration 1. Không phải gõ lại "ngữ cảnh hôm qua chúng ta đang sửa..." — đã có sẵn trong log và markdown. The new session starts at iteration 19, not iteration 1. No need to retype "yesterday we were fixing…" — it's all in the log and the markdown.
08

Đổi AGENTS.md ↔ CLAUDE.md

Switch AGENTS.md ↔ CLAUDE.md

cross-tool · compatibility · governance GOV
  1. Scaffold lại với cờ --agent-file

    Re-scaffold with the --agent-file flag

    # Đặt CLAUDE.md là file canonical:
    py skills/scripts/scaffold_harness.py \
        --target . \
        --agent-file CLAUDE.md \
        --governance-only
  2. Thêm symlink (POSIX) hoặc symbolic link (Windows admin)

    Add a symlink (POSIX) or symbolic link (Windows admin)

    # POSIX
    ln -s CLAUDE.md AGENTS.md
    git add AGENTS.md && git commit -m "alias AGENTS.md -> CLAUDE.md"
    
    # Windows (PowerShell, admin)
    New-Item -ItemType SymbolicLink -Path AGENTS.md -Target CLAUDE.md
  3. Nếu không dùng symlink: stub 3 dòng

    If symlinks aren't viable: a 3-line stub

    AGENTS.mdmarkdown
    # Agent Instructions
    
    This project's instructions live in [CLAUDE.md](./CLAUDE.md).
    Read that file end-to-end before writing any code.
  4. Validate vẫn chấm đúng — scorer hiểu cả hai

    Validate still scores correctly — the scorer accepts either

    py skills/scripts/validate_harness.py --target .
    # instructions: 5/5  PASS Agent instruction file exists
RESULT
Một document canonical, hai tên file. Cả Claude Code và Cursor đều tìm được instructions. Không có drift giữa hai bản — đó là symlink, hoặc stub trỏ về source duy nhất. One canonical document, two filenames. Both Claude Code and Cursor find the instructions. No drift between copies — it's a symlink, or a stub that points to the single source.