Files
solution-erp/.claude/commands/session-end.md
pqhuy1987 009dd94f22 [CLAUDE] Docs: S48 adap-* verify closure post-restart + Gov-v2 error-ledger + §L.b
- store_memory strip VERIFIED-runtime (registry 0/8 subs) — adap-report updated
- frontend-designer FD2 loop VERIFIED-RAN (first spawn) — adap-report updated
- Gov-v2 delta CLOSED: NEW docs/governance/error-ledger.md (blameless RCA + Active-Guards
  index + AS-1..AS-9 deterministic-detect + 3-ledger triad) + session-end.md Phase 1.5 §L.b 6-step
- STATUS/HANDOFF S48 + session log + frontend-designer MEMORY flush (FD2 rig + Tailwind-v4 fact)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-03 00:05:39 +07:00

135 lines
9.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
description: Đóng session SOLUTION_ERP — flush 7-agent memory, sync MD/RAG, commit + push, eval. Run cuối mỗi session.
---
# /session-end — Session closeout (FLUSH + WRITE + VERIFY + REPORT + COMMIT + EVAL)
> Trigger cuối session. Em main chủ trì, gọi lại sub-agent đã spawn.
> ⚠️ **Harness note:** SendMessage KHÔNG khả dụng → "flush con đã spawn" = agent đã tự update MEMORY khi return (BẮT BUỘC trong agent frontmatter). Em main đọc lại MEMORY on-disk để synthesize, KHÔNG cần re-spawn chỉ để flush.
## 📋 BƯỚC 0 — Show command body (visibility, no wait)
Em main PHẢI echo **TOÀN BỘ nội dung command body này** (đầy đủ Phase 1-6 + sub-section + guard rule) trong response đầu tiên ĐỂ ANH USER ĐỌC LẠI.
**Quy trình (KHÔNG wait confirm):**
1. Em echo full content command (raw markdown, KHÔNG tóm tắt, KHÔNG cắt)
2. Em proceed execute Phase 1 → 6 sequential ngay
3. Anh user điều chỉnh **cuối session** nếu cần thay đổi nội dung command (KHÔNG mid-flow interrupt)
## Phase 1 — FLUSH (sub-agent memory)
**Điều kiện:** Chỉ xử lý con đã spawn trong session. KHÔNG spawn mới chỉ để flush (agent đã update MEMORY khi return).
1. Đọc MEMORY.md update của sub-agent đã spawn (Tiered L1 HOT):
- 🟦 **investigator-codebase** — research findings + audit results + schema/count grounding
- 🟦 **investigator-api** — external docs/CVE/lib eval + cross-project port + RAG fleet
- 🟨 **implementer-backend** — BE patterns applied + scope refusals (ACCEPT vs REFUSE)
- 🟧 **implementer-frontend** — FE mirror SHA256 + Pattern 16-bis 4-place + KIND_CONFIG
- 🟪 **test-specialist** — test bundle added + coverage gap + spec drift detected
- 🟥 **reviewer** — anti-patterns observed + Smart Friend catches + claim verification
- 🟢 **cicd-monitor** — Run verdict + bundle hash rotate + Mig prod + corpus drift
2. Synthesize cross-agent learnings → integrate vào:
- User auto-memory `MEMORY.md` (index — append entry mới, KHÔNG rewrite)
- `docs/rules.md`, `docs/architecture.md`, `docs/gotchas.md`, `docs/database/`, `docs/flows/`
- rules, architecture, gotcha, skill, daily, hand-off (`docs/HANDOFF.md`), DB, luồng DB, session log (`docs/changelog/sessions/`)
## Phase 1.5 — §L AUTO-MAINTAIN (Gov-v2 keystone — deterministic, KHÔNG daemon)
> Artifact home = [`docs/governance/error-ledger.md`](../../docs/governance/error-ledger.md) (RCA + Active-Guards index + 3-ledger triad mapping). **G-015:** đây là **step lead chạy ở session-end**, KHÔNG phải daemon tự-động-vô-điều-kiện.
**§L.a — Deterministic detect (scan action-signature, KHÔNG để AI tự-phán):** quét session theo bảng **AS-1..AS-9** trong error-ledger. Mỗi hit → 1 RCA entry blameless (5-why + fix + guard). **Bug-production = lỗi KÉP → 2 fix** (vá code **VÀ** vá guard/eval-case). List AS mở — gặp class mới thì thêm.
**§L.b — 6-step auto-maintain (đủ 6, KHÔNG skip — thiếu = ledger thối):**
- **(a) summary-index** += 1 dòng/session vào `STATUS.md` Recently Done (pointer, KHÔNG full-log).
- **(b) Active-Guards** (error-ledger): promote guard **2-strike** (episodic→procedural) · mark `verified` nếu held qua session · retire theo **net-effect** (hại>lợi → gỡ).
- **(c) chore-flag:** agent L1 >~30KB → archive L2 · error-ledger open-entry quá ngưỡng · **0-byte memory check (AS-8)**.
- **(d) flush agent-memory** mỗi sub đã spawn session này — **spawn-record 4-field** `{agent · task · nấc(agreed/executed/verified) · evidence}`. (0 sub spawn → "n-a".)
- **(e) pending-request audit:** request anh CHƯA-thực-thi đã log SPECIFICS chưa (KHÔNG placeholder).
- **(f) harvest-integrity double-check:** verify spawn-record (d) đủ + đúng mọi sub (moved-not-cut).
## Phase 2 — WRITE (update MD/RAG)
### 2.1 UPDATE/Re-rank MD/RAG đã thay đổi
- `docs/STATUS.md` (In Progress → Recently Done) + `docs/HANDOFF.md` (tiering: giữ current+2-3 session, archive cũ → session logs per `feedback_status_handoff_tiering`)
- rules, architecture, gotcha, skill, hand-off, DB, luồng DB, session log
### 2.2 Skill registry
- Liệt kê 6 skill. Dùng skill khi task khớp (KHÔNG tự suy luận lại)
- Skill staleness audit chỉ chạy theo lịch định kỳ (cron 2026-06-01)
- Phân bổ skill mới phù hợp per agent (README matrix)
### 2.3 Memory entry mới
- Add memory entry NẾU phát hiện rule/gotcha/decision quan trọng chưa có (vd `feedback_*`)
- **KHÔNG rewrite toàn bộ memory** — chỉ append entry mới + update MEMORY.md index 1 dòng
### 2.4 Quy tắc consolidate MD/RAG (CRITICAL — đọc kỹ) [GENERIC — GIỮ NGUYÊN]
- **Thứ 1:** Rất quan trọng, đọc kỹ lại quy tắc consolidate đúng cách, những thứ quan trọng KHÔNG đc cắt, chỉ phân tầng cho gọn lại, và xóa double. Phân tầng để các session sau đọc lại đúng chính xác context, không bị over context, rất quan trọng đấy.
- **Thứ 2:** Nếu MD/RAG không có gì cần điều chỉnh thì KHÔNG cần phải cố gắng điều chỉnh, điều này cũng rất quan trọng.
## Phase 3 — VERIFY (test + state)
### 3.1 Unit test verify
- `dotnet test SolutionErp.slnx --nologo --verbosity minimal` — verify count tăng đúng (vd 130 → 132 nếu thêm 2 test). Update STATUS Recently Done.
- Phase 9 UAT mode: feature test-after (có thể skip per chunk), vẫn `npm run build` × 2 app. Nếu chỉ docs/infra → ghi "N/A".
### 3.2 Sub-agent state
- Kiểm tra trạng thái spawn sub-agent (7-agent)
- Task bất kỳ phải phân việc đầy đủ đúng vai trò split boundary (BE→backend, FE→frontend, test→test-specialist)
### 3.3 RAG + MCP state
- RAG corpus health (chunk count delta, `last_indexed_at`). Re-index full = AI_INFRA op (charter v2).
- MCP `rag-unified` stdio launch verify (5 tool)
- Re-rank coverage: prompts đã store + đánh dấu re-rank đầy đủ chưa
## Phase 4 — REPORT (plan status)
Đặt tên + tô màu cho Plan hiện tại, tiến độ + agent assignment:
```
Plan cha: [tên]
Plan con: [tên]
Task: [tên] — STATUS: 🟢 done | 🟡 in-progress | ⚪ pending
- 🟦 investigator-codebase — [a] - 🟦 investigator-api — [b]
- 🟨 implementer-backend — [c] - 🟧 implementer-frontend — [d]
- 🟪 test-specialist — [e] - 🟥 reviewer — [f]
- 🟩 cicd-monitor — [g] - 👤 chủ trì — [h]
```
### SOLUTION_ERP report (per-session)
- Tóm tắt việc done + commit SHA + CI Run verdict + bundle hash rotate + plan progress
- (SE KHÔNG copy phần "6 sister report" của AI_INFRA host)
## Phase 5 — COMMIT (release)
### 5.1 Release + commit
- Kiểm tra release, commit task vừa hoàn thành. ⚠️ Update `SolutionErp.slnx` nếu có `.cs/.csproj` mới.
- Format: `[CLAUDE] <scope>: <imperative message>` + `Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>`
- Scope: `Contract · PurchaseEvaluation · Budget · Form · Workflow · Supplier · Auth · Admin · Api · App · Domain · Infra · FE-Admin · FE-User · Tests · Docs · CICD · Scripts · Skill`
### 5.2 Push remote
- `git push origin main``git.baocaogiaoduc.vn/vietreport-admin/solution-erp`
- Docs-only commit → CI skip per gotcha #41 (paths-ignore `docs/**` + `**/*.md` + `.claude/skills/**`). Code commit → spawn 🟩 cicd-monitor verify deploy.
## Phase 6 — EVAL (chunk + RAG)
### 6.1 Chunk MD/RAG update
- Cập nhật chunk MD/RAG content mới (Proposal/WorkflowApps/Phase 11...). SE-side: `mcp__rag-unified__store_memory` key facts (stopgap content-gap).
### 6.2 RAG eval
- ⚠️ **Charter v2:** RAG eval + full re-index (`bootstrap.py`, golden set, recall@5) = **AI_INFRA op** (cần VOYAGE_API_KEY). SE KHÔNG tự chạy.
- SE-side closeout: (a) verify `store_memory` chunk retrievable (1 `search_memory` rerank check); (b) flag drift/staleness lên AI_INFRA nếu `last_indexed` lag nhiều; (c) báo cáo broadcast nếu adopt infra change.
### 6.3 INFRA-ADOPTION report (cadence #4 — self-sustaining, AI_INFRA bundle 2026-06-01)
- NẾU session này adopt bất kỳ infra/governance change từ AI_INFRA (RAG fix / session-cmd / hygiene / charter / Gov-v2) → **tự-sinh adoption-report §E** TRƯỚC khi đóng (KHÔNG cần anh nhắc):
- **SERVER-VERIFIABLE** (Gitea url): chain N commit sha (origin synced, tree clean)
- Per-§: §A RAG · §B Gov · §C Hygiene (X/7 agent-mem L1 ≤30KB · bloat>50KB=0 — đo byte thật) · §D session-cmd (KHUNG added `<sha>` / skip `<đã-có>`) · §E evidence (sha list + integrity moved-not-cut) · §F mirror ledger committed `<sha>`
- **NẤC:** agreed / executed / VERIFIED-self. Caveat by-design: L2 gitignored · CANONICAL-pull = trust.
- Surface report cho anh main relay AI_INFRA (1 lần báo = ACK+executed+evidence). Em main `/session-start` kế watch + double-check → cơ chế 2 chiều tự duy trì.
- Session KHÔNG adopt infra gì → ghi "N/A (no infra adoption this session)".
---
**Trigger sau Phase 6:** Session đóng. Working memory có thể `/clear` an toàn (persistent memory đã flush + commit + push).