# Session 29 — 2026-05-22 — Plan CA + Plan B Contract V2 wire end-to-end > **TL;DR:** 20 commits cumulative S29 push 4 CI Runs PASS deploy production. Plan CA (Move "Cấu hình danh mục" admin → eoffice) + Plan B Contract V2 wire (mirror PE Mig 22-26). Smart Friend Reviewer + CICD Monitor cumulative 4× catches MAJOR/CRITICAL bugs pre/post deploy. 8 patterns reusable NEW. ## 🎯 Session goals (anh chốt 2026-05-22 startup S29) 1. ✅ Re-bootstrap RAG SOLUTION_ERP S27+S28 NEW content (60.9s, 2,794 chunks) 2. ✅ **Plan CA** — Move "Cấu hình danh mục dùng chung" (9 menu Master + Catalogs) từ fe-admin → fe-user/eoffice + role mới `CatalogManager` 3. ✅ **Plan B** — Contract V2 wire mirror PE Mig 22-26 (COEXIST V1+V2) 4. ✅ Add MCP RAG tools cho 4 sub-agent definitions (pending CLI restart S30) 5. ✅ End-to-end demo cross-project RAG search (NAMGROUP HRM 10 info samples) ## 📦 Commits cumulative S29 — 20 commits push `3cb54e0..38f1c4d` ### Plan CA — 7 commits | # | SHA | Chunk | Owner | |---|---|---|---| | 1 | `06a441c` | B FE move 4 master pages (948 LOC byte-identical) | 🟨 Implementer | | 2 | `80d39a0` | A BE Role CatalogManager + Seed permissions | 👤 Em main | | 3 | `c995f42` | C Sidebar filter 2 app | 👤 Em main | | 4 | `4a592cf` | D Seed demo user catalog.manager | 👤 Em main | | 5 | `68bcedd` | D2 Hotfix password ≥12 chars S22+2 policy (Reviewer catch) | 👤 Em main | | 6 | `e55d96b` | **Hotfix 1** resolvePath staticMap silent sidebar drop (anh UAT catch) | 👤 Em main | | 7 | `6eec8d7` | Docs wrap (gotcha #50 + Pattern 16-bis + STATUS) | 👤 Em main | ### MCP RAG add — 1 commit | # | SHA | Description | |---|---|---| | 8 | `b51fc94` | Add `mcp__rag-unified__search_memory + cross_project_search` cho 4 agent definitions (pending CLI restart hot-reload S30+) | ### Plan B Contract V2 wire — 11 commits + 1 docs wrap | # | SHA | Chunk | Owner | |---|---|---|---| | 9 | `58898e8` | A1 Entity Contract +2 V2 fields | 👤 Em main | | 10 | `a85e437` | A2 Mig 32 + Configuration + Seed sample (4,094 LOC EF auto-gen) | 🟨 Implementer | | 11 | `138469d` | B Service ApproveV2Async branch + gen mã HĐ adapt | 👤 Em main | | 12 | `26c98d3` | C Mig 33 ContractLevelOpinions cookie-cutter (4,265 LOC) | 🟨 Implementer | | 13 | `1f199b0` | B2 UPSERT block + ResolveActorFullName helper | 👤 Em main | | 14 | `ef23308` | E1 CreateContractCommand +ApprovalWorkflowId V2 | 👤 Em main | | 15 | `62b50d1` | D FE Workspace V2 Select dropdown × 2 app | 🟨 Implementer | | 16 | `48f6d22` | E2 ContractDetailDto + populate LevelOpinions[] | 👤 Em main | | 17 | `14feb69` | E3 FE Section 5 LevelOpinionsV2 × 2 app (em main solo, Implementer stopped mid-task) | 👤 Em main | | 18 | `3e92584` | **Hotfix Reviewer** ApplicableType=Contract validation guard (Reviewer MAJOR catch) | 👤 Em main | | 19 | `38f1c4d` | **Hotfix CICD** SeedSampleContractWorkflowV2 OUT of DemoSeed gate (CICD CRITICAL catch — gotcha #51 NEW) | 👤 Em main | | 20 | (this session log) | Docs wrap S29 + session log + flush 4 MEMORY | 👤 Em main | ## 🎯 Multi-agent ROI explosive S29 | Agent | Spawns | Tokens | Major catches | |---|---:|---:|---| | 🟦 **Investigator** | 2 | ~40K | Plan CA terrain map 9 menu + GOTCHA tree-inherit; Plan B audit Contract V1 + recommend 6→9 chunk re-split + 3 surprise (zero ApplicableType=3 prod, RejectedAtStepIndex drift, ContractType variants generic) | | 🟨 **Implementer Case 2** | 5 | ~82K | Plan CA Chunk B 4 master pages mirror byte-identical; Plan B A2 Mig 32 + C Mig 33 + D FE Workspace V2 cookie-cutter; **E3 stopped mid-task** (complex FE judgment, em main solo finish) | | 🟥 **Reviewer** | 4 | ~355K | **MAJOR Plan CA Hotfix D2:** Password ≥12 chars policy S22+2 catch BEFORE prod 401; **MAJOR Plan B Hotfix:** ApplicableType=Contract validation guard catch BEFORE security gap exploit | | 🟩 **CICD Monitor** | 3 | ~90K | 2 fail 529 Anthropic transient → em main fallback manual smoke; **1 CRITICAL Plan B Hotfix:** SeedSampleContractWorkflowV2 gated by DemoSeed → V2 path BLOCKED prod → gotcha #51 NEW | | 👤 **Em main Solo** | — | ~150K | Coordinate 4 agents + Chunk B/B2 cross-stack reasoning + E3 finish + 3 hotfix re-edit + 2 docs wrap | | **TOTAL** | 14 spawn | ~715K | 4× Smart Friend cumulative wins | ## 🛡️ Smart Friend pattern proven 4× cumulative | # | Session | Catch | Severity | Owner | |---|---|---|---|---| | 1 | S22 | Class-level `[Authorize(Policy)]` silent 403 (gotcha #44) | MAJOR | 🟥 Reviewer | | 2 | S25 | Multi-Changelog SQLite tie-break test discriminator (gotcha #48) | MAJOR | 🟩 CICD Monitor | | 3 | **S29** | Password ≥12 chars policy + ApplicableType=Contract validation | MAJOR | 🟥 Reviewer | | 4 | **S29** | INFRASTRUCTURE vs DEMO seed gate confusion (gotcha #51) | CRITICAL | 🟩 CICD Monitor | ## 🆕 Patterns reusable NEW saved S29 (8 patterns) 1. **9-menu permission terrain map pattern** (Investigator) — inventory file paths + LOC + component parity check trước delegate chunk 2. **V1+V2 coexist boundary** (Investigator) — KHÔNG drop V1 nếu prod data pinned. Plan F precedent S22 (ABORT khi định drop V1) 3. **Reference template paths cross-module mirror** (Investigator) — cite EXACT line ranges PE → Contract V2 (Mig 23:14-31, Mig 24:14-17, ApproveV2Async 446-634, UPSERT 519-546, ResolveActor 774-783) → saving 30%+ time 4. **Pattern 12-bis cross-module entity cookie-cutter mirror** (Implementer) — entity + Mig + Config + DbSet 4-file mirror cho cross-module clone scenarios 5. **Pattern 16-bis 4-place mirror cross-app** (Implementer) — reinforced 2× Plan CA + Plan B Workspace 6. **Cross-module security validation mirror Cat 3** (Reviewer) — khi mirror entity/command cross-module, MUST mirror validation guards (ApplicableType + FK + idempotent). Easy miss 7. **INFRASTRUCTURE vs DEMO seed classification** (CICD #51) — decision tree: production cần để work end-to-end? YES → INFRASTRUCTURE ungate 8. **Race condition em main + Implementer parallel BE → stash workaround** (Implementer Plan B A2+B) — Implementer auto-stash em main WIP cho clean build. Forward: SEQUENTIAL chunks A→B→C khi cùng touch BE, NOT parallel ## 📊 State chốt S29 | Metric | Before S29 | After S29 | Δ | |---|---:|---:|---| | Migrations | 31 | **33** | +2 (Mig 32 Contract V2 + Mig 33 LevelOpinions) | | DB tables | 59 | **60** | +1 (ContractLevelOpinions) | | API endpoints | ~146 | **~148** | +1 (V2 contract create) | | FE pages | 35 | **38** | +3 (4 master moved to fe-user — net +3 sau remove fe-admin) | | Tests | 111 | **111** | unchanged (UAT mode skip; V2 logic NO test cover defer) | | Gotchas | 49 | **51** | +2 (#50 staticMap silent drop + #51 INFRASTRUCTURE vs DEMO seed) | | Memory user-level | 25 | **25** | unchanged | | Skills | 6 | **6** | unchanged | | Sub-agents | 4 | **4** | unchanged (MCP RAG added pending CLI restart) | | AppRoles | 13 | **14** | +1 (CatalogManager) | | Active prod users | 33 | **34** | +1 (catalog.manager@solutions.com.vn) | | V1 contracts prod | 7 | **7** | preserved (no V2 contract yet) | | RAG chunks SOLUTION_ERP | 3,462 | **2,794** | -668 (re-bootstrap clean indexing, dedup improvement) | | Bundle hash rotate | — | **4×** | fe-admin: `BvcWrq2z→leEMWFLU→BBADl46y`, fe-user: `Bg2FNeIz→DVBLmZlt→Dgn1iU9E→DA_VI3zO` | ## 🚀 NEW capability prod end-to-end **1. Catalog management user role:** - Login `catalog.manager@solutions.com.vn / CatalogMgr@2026` - fe-user sidebar: Master + 4 leaf (Suppliers + Projects + Departments) + Catalogs root + 4 sub (Units/Materials/Services/WorkItems) - Full CRUD 9 menu, KHÔNG access fe-admin tools **2. Contract V2 workflow path:** - Login Drafter (vd `qs.hoang@solutions.com.vn`) - `/contracts/new?type=1` → Workspace dropdown "Quy trình duyệt V2" có `QT-HD-V2-001` - Pick V2 + create → contract pin `ApprovalWorkflowId` - Submit ChoDuyet → workflow advance Step 1 Cấp 1 - Login `binh.le@solutions.com.vn` (CCM approver) → Approve - Service `ApproveV2Async` UPSERT opinion + advance → terminal Phase=DaPhatHanh + gen mã HĐ RG-001 - Detail page Section 5 LevelOpinionsV2 render dynamic với opinion data ## ⚠️ Pending S30+ follow-up 1. **Anh restart Claude Code CLI** để 4 sub-agents pick up MCP RAG tools (commit `b51fc94`) 2. **Anh UAT verify V2 contract end-to-end** flow (Drafter → CCM approve → DaPhatHanh) 3. **Test bundle Plan B**: regression test ApproveV2Async (~150 LOC) + ApplicableType validation guard (xUnit Domain policy + Infra service test) 4. **Curate dedicated session 4 MEMORY** (Implementer 35.4KB > hard threshold) 5. **Anh UAT verify catalog manager** end-to-end (login + CRUD 9 menu) ## 📝 Files touched S29 ### BE (~715 LOC actual + ~7,970 EF Designer = ~8,685) - `src/Backend/SolutionErp.Domain/Identity/AppRoles.cs` (+6 CatalogManager) - `src/Backend/SolutionErp.Domain/Contracts/Contract.cs` (+12 V2 fields + LevelOpinions nav) - `src/Backend/SolutionErp.Domain/Contracts/ContractLevelOpinion.cs` (NEW 36) - `src/Backend/SolutionErp.Application/Contracts/Services/IContractWorkflowService.cs` (+10 skipToFinal) - `src/Backend/SolutionErp.Application/Contracts/ContractFeatures.cs` (+96 V2 + Hotfix Reviewer) - `src/Backend/SolutionErp.Application/Contracts/Dtos/ContractDtos.cs` (+28 V2 DTO + LevelOpinion) - `src/Backend/SolutionErp.Application/Common/Interfaces/IApplicationDbContext.cs` (+3 ContractLevelOpinions DbSet) - `src/Backend/SolutionErp.Infrastructure/Persistence/ApplicationDbContext.cs` (+2 DbSet) - `src/Backend/SolutionErp.Infrastructure/Persistence/Configurations/ContractConfiguration.cs` (+15 FK + Index) - `src/Backend/SolutionErp.Infrastructure/Persistence/Configurations/ContractLevelOpinionConfiguration.cs` (NEW 37) - `src/Backend/SolutionErp.Infrastructure/Persistence/DbInitializer.cs` (+~120 CatalogManager seed + SampleContractWorkflowV2 + ungate Hotfix CICD) - `src/Backend/SolutionErp.Infrastructure/Services/ContractWorkflowService.cs` (+200 V2 branch + ApproveV2Async + UPSERT + ResolveActor) - `src/Backend/SolutionErp.Infrastructure/Persistence/Migrations/20260522051059_AddApprovalWorkflowToContract.cs` (NEW Mig 32) - `src/Backend/SolutionErp.Infrastructure/Persistence/Migrations/20260522052240_AddContractLevelOpinions.cs` (NEW Mig 33) ### FE (~1,050 LOC × 2 app sometimes byte-identical) - `fe-user/src/pages/master/{Suppliers,Projects,Departments,Catalogs}Page.tsx` (NEW 948 byte-identical mirror admin) - `fe-user/src/lib/menuKeys.ts` (+5 Catalogs sub-keys) - `fe-user/src/App.tsx` (+5 master routes) - `fe-admin/src/components/Layout.tsx` (+ADMIN_HIDDEN_MASTER_KEYS 9 keys hide) - `fe-user/src/components/Layout.tsx` (-4 USER_HIDDEN_KEYS + 7 resolvePath staticMap Hotfix 1) - `fe-admin/src/pages/contracts/ContractCreatePage.tsx` (+44 V2 Workspace dropdown) - `fe-user/src/pages/contracts/ContractCreatePage.tsx` (+44 V2 Workspace mirror) - `fe-admin/src/types/contracts.ts` (+22 V2 fields + ContractLevelOpinion) - `fe-user/src/types/contracts.ts` (+22 V2 fields mirror) - `fe-admin/src/components/contracts/ContractDetailContent.tsx` (+40 Section 5 V2) - `fe-user/src/components/contracts/ContractDetailContent.tsx` (+40 Section 5 V2 mirror) ### Docs + scripts + agent setup - `docs/STATUS.md` (S29 wrap header) - `docs/HANDOFF.md` (S29 wrap header) - `docs/gotchas.md` (+gotcha #50 staticMap + #51 INFRASTRUCTURE vs DEMO seed) - `docs/changelog/sessions/2026-05-22-s29-plan-ca-plan-b-contract-v2-wire.md` (NEW this session log) - `.claude/agents/{investigator,implementer,reviewer,cicd-monitor}.md` (+MCP RAG tools) - `.claude/agent-memory/{investigator,implementer,reviewer,cicd-monitor}/MEMORY.md` (S29 wrap entry FIFO each agent perspective) - `.claude/agent-memory/implementer/pattern_master_page_mirror.md` (NEW Pattern 16-bis cross-app from Plan CA Chunk B) - `scripts/plan-ca-verify-menu.{sql,ps1}` + `plan-ca-verify-perms.{sql,ps1}` + `plan-ca-run-perms.ps1` + `plan-b-verify-prod.{sql,ps1}` + `plan-b-run-verify.ps1` (NEW verify scripts)