Files
solution-erp/.claude/workflows
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
..

.claude/workflows/ — Workflow fan-out + run-trace convention (Harness-10)

Mục đích: convention cho HMW workflow fan-out + run-trace folder (mỗi workflow run → 1 thư mục runs/<run-id>/ git TRACKED, gom plan + per-sub + synthesis + ledger 2-nhịp). Adopt AI_INFRA Harness-10 (anh 06-18) — kế thừa wave-folder memory-isolation Harness-2 nhưng đổi từ transient-gitignored sang tracked-run-folder để audit trực-tiếp qua git-diff. 🆕 Cấu trúc PHẲNG (h10-refine 06-18): file phẳng cùng cấp trong run-folder (phân biệt RAW vs VERIFIED bằng TÊN), KHÔNG subfolder. Canonical rule: AI_INFRA CANONICAL-RULES.md §J4 (return-delta default) + §J6 (run-trace + agent-team) — pull qua cross_project_search, KHÔNG copy. Tailor SE 9-role roster + S1 scope.

Files (tracked)

  • hmw.js — HMW P2 fan-out script. 2 mode: DEFAULT return-delta-only (§J4) · RUN-TRACE mode (§J6, args.run).
  • README.md — file này (convention).
  • runs/git TRACKED (qua negation .gitignore:83 !.claude/**), không gitignore. Mỗi workflow run = 1 sub-folder runs/<run-id>/. Xem runs/README.md cho cấu trúc chi-tiết (FLAT) + ledger 2-nhịp + 3-layer anti-miss + C8 migration + detector-tailored-out.

Run-trace = mỗi workflow run → runs/<run-id>/ TRACKED (FLAT)

Mỗi lần chạy workflow fan-out (RUN-TRACE mode) → 1 thư mục run git theo dõi, file phẳng cùng cấp:

.claude/workflows/runs/<run-id>/         ← TRACKED · FLAT h10-refine (hiện trong git-diff = audit trực-tiếp)
├── run.md                               ← Run-MD chính — EM MAIN ghi @P1 (plan + agents-table + spec + guards + status OPEN→CLOSE)
├── sub-<role>-<i>.md                    ← per-sub RAW (prefix `sub-`) — full detail (write-sub ghi @P2 · read-only sub → em main scribe @P3)
└── <stage>-synthesis.md                 ← gom/VERIFIED (suffix `-synthesis.md`) — EM MAIN ghi NGAY sau mỗi fan-out turn (C4 per-turn primary)

Phân biệt RAW (prefix sub-) vs VERIFIED (suffix -synthesis.md) bằng TÊN file, KHÔNG subfolder. C8: 5 run cũ S71 (h10-investh910-curate) giữ sub-md/+harvest/ (đừng rewrite history); close-gate chấp nhận CẢ HAI dạng.

  • runs/_ledger.md🧊 RETIRED H18-B S100 (sổ 2-nhịp nghỉ-hưu — đo bắt-thật: true-orphan-catch 0/15 lifetime + mode-A coverage 0/8 workflow từ S93; 15 row lịch-sử GIỮ NGUYÊN, đảo-ngược = gỡ marker). Orphan-authority = folder-scan: runs/<id>/run.md*-synthesis.md VẮNG/0-byte. Chi-tiết runs/README.md.

2 MODE memory (anh 06-07, KHÔNG thay return-delta)

DEFAULT return-delta-only (§J4) RUN-TRACE mode (§J6)
Khi dùng fan-out NHỎ (<3 task ước ≤5 phút; read/analyze — vd recon) workflow DÀI / sinh nhiều detail / cần audit-trail
Bắt buộc? (sàn H22 S111) mode-A hợp lệ cho fan-out NHỎ BẮT BUỘC khi run ≥3 task HOẶC ước chạy >5 phút (args.run → per-agent-file sub-<role>-<i>.md)
Sub ghi file? KHÔNG — chỉ return memoryDelta + findings write-sub GHI full-detail vào runs/<run-id>/sub-<role>-<i>.md (phẳng); read-only sub → findings + subMdPath → em main scribe
Lead làm VERIFY + APPEND @P3 (B3) đọc sub-<role>-<i>.md on-demand + ghi <stage>-synthesis.md per-turn (C4) + H2 gom @session-end (B5, backstop)
Rủi ro mất detail có (delta lossy) — chấp nhận cho việc nhẹ KHÔNG (full-detail giữ trong run-folder tracked)

Sàn H22 (S111) — FLIP policy: mode-A return-delta-only VẪN hợp lệ cho fan-out NHỎ, NHƯNG run ≥3 task HOẶC ước chạy >5 phút = BẮT BUỘC RUN-TRACE mode (args.run → per-agent-file sub-<role>-<i>.md trong run-folder). Lý-do: chết giữa run vẫn còn vật-liệu trên đĩa để /tiep nối lại — per-TURN ≠ per-TASK: returns mất khi chết giữa turn, nhưng file trên disk còn. Fan-out NHỎ dưới ngưỡng → DEFAULT return-delta-only vẫn OK (KHÔNG bắt MỌI fan-out tạo run-folder).

Quy trình RUN-TRACE (B1B6)

  1. B3 SCAFFOLD TRƯỚC (em main @P1): tạo runs/<run-id>/ + run.md (FLAT — KHÔNG cần sub-md//harvest/ subfolder hay .gitkeep; file sub-*/*-synthesis.md sinh phẳng cùng cấp khi fan-out chạy). (🧊 bước "ghi OPEN-beat vào runs/_ledger.md" retired H18-B S100 — orphan-authority = folder-scan.) ⚠️ hmw.js chạy JS-sandbox no-filesystem → KHÔNG tự tạo folder; em main Write @P1 TRƯỚC khi invoke Workflow. (Đây là fragile-point — quên scaffold = run mất dấu-vết âm-thầm; xem runs/README.md §C7.)
  2. B1 spawn-from-real-sub: mỗi task role ∈ VALID_ROLES (12 sub — đủ roster từ S110, +2 monitor anh-directed) → workflow-agent = sub THẬT (agentType inherit memory-pack slice + skill identity), KHÔNG agent vô-danh.
  3. B4 phân-quyền TOOL-AWARE: hmw.js inject vào prompt mỗi sub đường-dẫn runs/<run-id>/sub-<role>-<i>.md (phẳng) + lệnh ghi ĐÚNG file đó.
    • Write sub (CÓ Write/Edit): implementer-backend · implementer-frontend · test-specialist · frontend-designer → ghi-direct sub-MD via Write/Edit.
    • Read-only sub (CHỉ Bash): investigator-codebase · investigator-api · reviewer · cicd-monitor → 🔴 KHÔNG Bash-write MD (mojibake) → full-detail vào findings + subMdPathem main scribe @P3 (single-writer).
  4. B6 ISOLATION (AUDIT cẩn-thận): sub CHỈ ghi trong runs/<run-id>/ (file sub-<role>-<i>.md phẳng của mình) + code-file-disjoint nếu giao. 🔴 KHÔNG ghi agent-memory/* chính · KHÔNG MD canonical (CLAUDE/README/STATUS/agents) · KHÔNG sub-MD agent khác. Em main git status/git diff + chunk-count sau P2run-folder TRACKED → mọi write trong run-folder HIỆN trong diff = audit trực-tiếp; tracked-change NGOÀI runs/<run-id>/ VÀ NGOÀI code-disjoint đã giao = vi-phạm (thay model Harness-2 B6 "mọi tracked-change = vi-phạm"). Verify pattern bằng git check-ignore -v (test match thật, đừng tin .gitignore text — bẫy exit-code: dùng && IGNORED || NOT).
  5. B5 HARVEST (per-turn primary C4 + close-gate backstop): em main ghi <stage>-synthesis.md (phẳng) NGAY sau mỗi fan-out turn (đọc sub-<role>-<i>.md + findings → 5-trục integrity → consolidate). @session-end harvest-curator H2 §L.b(f) VERIFY per-turn harvest đã xong cho mọi runs/<id>/ (idempotent — KHÔNG re-APPEND, chống DUPLICATE-HARVEST) + giữ 5-trục GATE làm backstop, rồi đề-xuất em main APPEND vào agent-memory/<role> sub tương-ứng.

Agent-team (.claude/agent-teams/<tên>/ — gitignored .gitignore:94)

  • Cùng nguyên-lý isolation: teammate KHÔNG có memory-dir built-in (khác subagent) → folder riêng cho teammate ghi MD-session (A1, tránh overwrite memory chuẩn).
  • Team spawn TỪ sub-agent chính có memory dự-án rõ-ràng (A2 — mang identity/skill sub thật trong 9 roster).
  • H2 harvest-curator gom .claude/agent-teams/<tên>/ → agent-memory tương-ứng (giống run-trace).
  • ⚠️ Caveat: Agent-Team experimental + Windows 11 in-process only (no split-pane) → SE CHƯA dùng team thật → A = convention-ready (n-a runtime), cơ-chế isolation chung qua workflow.

Guard

  • S1: Workflow CHỈ repo SOLUTION_ERP — KHÔNG fan-out repo/corpus khác (cross_project_search = READ reference only).
  • S2/S3: chỉ chạy khi HMW-mode ON (/ultra-on → marker .claude/hmw-mode.on) + checkpoint INFORM (hmw.js throw nếu checkpointApproved≠true) + sub KHÔNG spawn sub.
  • Anti-bypass detector (h10-refine b): SE TAILORED-OUT — SE chạy workflow qua Anthropic Workflow tool (KHÔNG có CLI-launcher để lách như node-CLI) → bypass-surface ~N/A; containment = git-diff + run-folder TRACKED + folder-scan orphan (🧊 _ledger retired H18-B S100) (G-015). 3 nguyên-tắc detector (whitelist launcher · path-variant match · anchor launch-key + nghiệm-thu quan-hệ) đã cân-nhắc, N/A cho threat-model SE. Chi-tiết runs/README.md.
  • G-015 accuracy (no-overclaim): run-folder TRACKED ≠ read-only-ENFORCED — sub vẫn giữ Bash (write-channel mở: ghi-ngoài-repo git-diff mù / curl Qdrant). Containment THẬT = em-main single-writer + git-diff (in-repo, run-folder tracked nên hiện) + chunk-count (RAG), defense-in-depth, KHÔNG sandbox cứng. KHÔNG claim "ENFORCED", KHÔNG bỏ chunk-count.