Files
solution-erp/.claude/hooks/wal-flush.ps1
pqhuy1987 92de58f329 [CLAUDE] Infra: W0 pre-flight - gitattributes EOL san-chung + hook rebase-interlock + FIX #3-bis 4-ca
W0.1 .gitattributes theo CLASS (khong va theo duoi-file-vua-can):
- `* text=auto eol=lf` = san chung. core.autocrlf=true @system lat LF->CRLF luc checkout;
  attr nay ep blob LF + worktree LF, DOC-LAP autocrlf.
- Khai binary TUONG-MINH 13 duoi (zip/exe/dll/docx/xlsx/pptx/pdf/png/jpg/jpeg/ico/woff/woff2)
  thay vi pho-thac heuristic NUL-byte-8000-dau: .docx "gay" co the lot thanh text -> mangle
  OOXML -> hong file KHONG cuu duoc. Do that: repo co 19 binary (12 docx + 6 png + 1 xlsx).
- .svg = XML -> CO Y giu text. Giu 2 rule cu (broadcasts/** + *.sh) tuong-minh.
- Fault-inject chung rule CO RANG: go `*.docx binary` -> git coi .docx la `text: auto` (nguy
  hiem that); khoi phuc -> `text: unset`. 19/19 binary co attr/-text.
- Acceptance PASS: agents/reviewer.md unspecified -> text:auto eol:lf.

W0.2 scoped-only (vacuous, KHAI THAT):
- scope-gate (agents+commands+skills) = 0 DA XANH SAN truoc khi lam gi -> KHONG tinh la thanh-tuu.
- repo-wide 188 (131 Migrations + 57 con lai) = INFORM-only. CAM mass rm+checkout phien nay.
- `git add --renormalize --dry-run .` = 0 file dirty; `git diff --cached --stat` = rong.

W0.3 hook rebase-interlock (anh ky S119 fix#8b = TRONG KHUNG, khong can adap-request):
- wal-flush.ps1: `if (Test-Path .git/rebase-merge -or .git/rebase-apply) { exit 0 }`.
- Dat SAU Set-Location $root, KHONG phai dau file: dat truoc thi Test-Path soi nham CWD.
- Chung RANG 2 CHIEU tren cay tam: (a) khong rebase-state -> hook VAN commit (guard khong
  over-fire, WAL persist con song); (b) co rebase-state -> 0 commit, exit 0, worktree GIU dirty.
- Pure-ASCII giu nguyen (gotcha #30). Do lai bang tr sau khi phat hien `grep -P` false-pass
  (loi locale -> output rong -> wc -l dem 0 = grep CHET, khong phai sach).

FIX #3-bis (MOI, ghi vao v3-PATCH) - dieu-kien re nhanh W0.3 test SAI THU:
- v2:92 re nhanh bang `NONWAL==0`; luat fix#3(c) noi phai test "wal: o DAY range". Hai thu khac nhau.
- Fault-inject 4 cay tam chung diem re o ca2 (shape base|wal:|[CLAUDE], NONWAL=1, day=wal:):
  v2 -> nhanh-B REBASE; v3bis -> reset--soft. Chay that nhanh-B tren ca2: REBASE-EXIT=0 KHONG
  crash, nhung commit gop THUA KE message "wal: flush 1" -> push-guard n=1 -> chan push ->
  re-squash cung logic -> van "wal:" -> STOP VINH VIEN. Deadlock XAC NHAN bang thuc nghiem.
- +ca(0) MOI v2/v3 khong liet: K=0 range RONG (S119 da push 4727d16) -> NO-OP commit thang.
- 4 ca: (0) K=0 NO-OP · (1) day=wal: NONWAL=0 · (2) day=wal: NONWAL>0 -> (1)+(2) CUNG xu-ly
  reset--soft origin/main CAM rebase · (3) day=commit-thuong -> rebase+fixup OK.
- Ca fire hom nay = ca(0). Commit-chot nay dat day range = commit thuong -> moi wal: sinh sau
  deu roi vao ca(3) an-toan. Dung y do fix#3(a).

WAL reconcile (/tiep S120): ground-truth thang WAL 3 cho - (1) 7 broadcast "UNTRACKED co y"
da tracked+pushed trong 4727d16, W0.3 khong con viec gop; (2) "K troi 10->11" -> thuc te K=0
range RONG; (3) fix#8 tick mau-thuan -> owner-decisions xac nhan DA KY, gate-blocker=0.

0 prod-code, 0 migration, 0 FE, 0 test-change.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-15 11:41:33 +07:00

26 lines
1.3 KiB
PowerShell

# wal-flush.ps1 - WAL persist-only Stop hook (H22 S111). KHONG sinh noi dung, KHONG push, KHONG block.
# Fail-open MOI nhanh: exit 0 ke ca loi (Stop-hook exit!=0 co hanh vi rieng - CAM).
# Per-path add + CAND commit (X3: add/commit da-pathspec = all-or-nothing khi 1 path vang).
try {
$root = if ($env:CLAUDE_PROJECT_DIR) { $env:CLAUDE_PROJECT_DIR } else { "." }
Set-Location $root
# INTERLOCK rebase-state (S120 W0.3). Dang rebase/mid-surgery => HEAD co the DETACHED.
# Commit len detached HEAD = mo-coi commit khi `rebase --abort` => MAT VIEC (R3 fault-inject chung minh).
# Guard nay THU HEP hook, KHONG them hanh-vi: no chan hook TU-HUY chinh floor N.2 ma no phuc-vu
# (anh ky S119 fix#8b = TRONG KHUNG, khong can adap-request).
# !! Dat SAU Set-Location: dat truoc thi Test-Path soi nham CWD (hook chay tu thu-muc bat-ky).
if ((Test-Path ".git/rebase-merge") -or (Test-Path ".git/rebase-apply")) { exit 0 }
$paths = @(".claude/WAL.md", ".claude/agent-memory/", ".claude/workflows/runs/")
$cand = @()
foreach ($p in $paths) {
git add -- $p 2>$null
git diff --cached --quiet -- $p 2>$null
if ($LASTEXITCODE -ne 0) { $cand += $p }
}
if ($cand.Count -gt 0) {
$ts = Get-Date -Format "yyyyMMddTHHmm"
git commit -q -m "wal: flush $ts" -- $cand 2>$null | Out-Null
}
} catch { }
exit 0