AliAgentic — System Flow Diagrams
18 skills • 100+ sub-commands • 11 gates • Interactive Mermaid diagrams
Diagrams cover 13 skills. Utility/automation skills ali-pause, ali-monitor, ali-set-profile, ali-cross-review, ali-reconcile are documented in CLAUDE.md.
🗺️ Main Workflow — Full Pipeline
Luồng chính từ ý tưởng → ship production. Mỗi phase có gate blocking.
flowchart TB
subgraph ENTRY["🎯 Entry Point"]
A["💬 /ali\n(Natural Language)"]
end
subgraph PHASE1["📋 Phase 1: Requirements"]
B["🗣️ /ali-discuss\nbrief | deep | research\nassumptions | redflags | summary"]
end
subgraph GATE1["🚧 Gate 1"]
G1{"Discussion Summary\nexists in .claude/memory/?"}
end
subgraph PHASE2["📄 Phase 2: Specification"]
C["📝 /ali-spec\nquick | edit | approve\nreject | scope change"]
end
subgraph GATE2["🚧 Gate 2"]
G2{"approved: true\nin spec frontmatter?"}
end
subgraph PHASE25["🎨 Phase 2.5: Design (UI only)"]
D["🎨 /ali-design\nsystem | screen | html\nreview | figma | iterate"]
end
subgraph GATE3["🚧 Gates 3-4"]
G3{"Design system exists?\nScreens approved?\nReview passed?"}
end
subgraph PHASE3["📐 Phase 3: Planning"]
E["📐 /ali-plan\npreflight 9-dim | waves\nbudget | intel | deps"]
end
subgraph GATE5["🚧 Gate 5"]
G5{"Pre-flight 8/8 pass?\n(dim 9 = analysis only)"}
end
subgraph PHASE4["⚡ Phase 4: Execution"]
F["⚡ /ali-do\nRED → GREEN → REFACTOR\nwave | yolo | batch | ship"]
end
subgraph GATE67["🚧 Gates 6-8"]
G67{"Env verified?\nWave gate pass?\nAll waves done?"}
end
subgraph PHASE5["🔍 Phase 5: Review"]
H["🔍 /ali-review\nspec | quality | security\nperf | regression | uat"]
end
subgraph GATE9["🚧 Gate 9"]
G9{"Spec + Security +\nRegression PASS?"}
end
SHIP["🚀 Ship!\n/ali-do ship → PR"]
A --> B
B --> G1
G1 -->|"✅ Yes"| C
G1 -->|"❌ No"| B
C --> G2
G2 -->|"✅ Approved"| D
G2 -->|"❌ Not approved"| C
D --> G3
G3 -->|"✅ Pass"| E
G3 -->|"❌ Fail"| D
E --> G5
G5 -->|"✅ 8/8 Pass"| F
G5 -->|"❌ Fail"| E
F --> G67
G67 -->|"✅ All gates pass"| H
G67 -->|"❌ Fail"| F
H --> G9
G9 -->|"✅ 3/3 Pass"| SHIP
G9 -->|"❌ Changes requested"| F
C -.->|"scope change"| B
D -.->|"iterate → spec change"| C
H -.->|"fix findings"| F
style ENTRY fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style PHASE1 fill:#1a1f29,stroke:#bc8cff,color:#e6edf3
style PHASE2 fill:#1a1f29,stroke:#d29922,color:#e6edf3
style PHASE25 fill:#1a1f29,stroke:#f778ba,color:#e6edf3
style PHASE3 fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style PHASE4 fill:#1a1f29,stroke:#3fb950,color:#e6edf3
style PHASE5 fill:#1a1f29,stroke:#f85149,color:#e6edf3
style SHIP fill:#238636,stroke:#3fb950,color:#fff
style GATE1 fill:#0d1117,stroke:#d29922,color:#e6edf3
style GATE2 fill:#0d1117,stroke:#d29922,color:#e6edf3
style GATE3 fill:#0d1117,stroke:#d29922,color:#e6edf3
style GATE5 fill:#0d1117,stroke:#d29922,color:#e6edf3
style GATE67 fill:#0d1117,stroke:#d29922,color:#e6edf3
style GATE9 fill:#0d1117,stroke:#d29922,color:#e6edf3
🚧 Gates & Checkpoints
9 gates blocking — không thể skip. Backend-only features skip gates 3, 4.
flowchart LR
G1["🚧 Gate 1\nDiscussion Summary\ndiscuss → spec"] --> G2["🚧 Gate 2\nSpec Approval\nspec → plan"]
G2 --> G3["🚧 Gate 3\nDesign System\n(UI only)"]
G3 --> G4["🚧 Gate 4\nDesign Consistency\n(UI only)"]
G4 --> G5["🚧 Gate 5\nPre-flight 9-dim\n(1-8 blocking)"]
G5 --> G6["🚧 Gate 6\nEnv Verify\n(first run)"]
G6 --> G7["🚧 Gate 7\nWave Gate\n(between waves)"]
G7 --> G8["🚧 Gate 8\nCompletion Gate\n(before ship)"]
G8 --> G9["🚧 Gate 9\nReview Gate\n(3/5 must pass)"]
style G1 fill:#2d1600,stroke:#d29922,color:#e6edf3
style G2 fill:#2d1600,stroke:#d29922,color:#e6edf3
style G3 fill:#2d1600,stroke:#f778ba,color:#e6edf3
style G4 fill:#2d1600,stroke:#f778ba,color:#e6edf3
style G5 fill:#2d1600,stroke:#d29922,color:#e6edf3
style G6 fill:#2d1600,stroke:#d29922,color:#e6edf3
style G7 fill:#2d1600,stroke:#d29922,color:#e6edf3
style G8 fill:#2d1600,stroke:#d29922,color:#e6edf3
style G9 fill:#2d1600,stroke:#f85149,color:#e6edf3
🎮 3-Tier UX
3 cách sử dụng: từ mới dùng → power user.
flowchart LR
subgraph T1["Tier 1: Natural Language"]
U1["User gõ:\n/ali tạm dừng"] --> R1["Router (Haiku)\nclassify intent"]
R1 --> S1["→ /ali-do pause"]
end
subgraph T2["Tier 2: Smart Menu"]
U2["User gõ:\n/ali-do"] --> M2["Smart Menu\ncontext-aware"]
M2 --> S2["User chọn số\n→ execute"]
end
subgraph T3["Tier 3: Direct Flag"]
U3["User gõ:\n/ali-do wave 2"] --> S3["Execute\nngay lập tức"]
end
style T1 fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style T2 fill:#1a1f29,stroke:#3fb950,color:#e6edf3
style T3 fill:#1a1f29,stroke:#bc8cff,color:#e6edf3
🧠 /ali — Natural Language Router
Entry point: phân loại intent bằng Haiku LLM, route đến đúng skill.
flowchart TB
INPUT["User input\n(tiếng Việt / Anh)"] --> CONTEXT["Collect context:\npending specs, handoff,\nuncommitted, scope lock"]
CONTEXT --> CLASSIFY["Haiku LLM Classifier\n→ {skill, subcommand, confidence}"]
CLASSIFY --> CHECK{Confidence?}
CHECK -->|"≥ 0.8"| ROUTE["Route trực tiếp\n→ target skill"]
CHECK -->|"0.5 - 0.8"| CONFIRM["Hỏi user xác nhận:\nBạn muốn chạy X?"]
CHECK -->|"< 0.5"| MENU["Show SMART MENU\n18 skills + descriptions"]
CONFIRM -->|"✅ Yes"| ROUTE
CONFIRM -->|"❌ No"| MENU
MENU --> SELECT["User chọn skill"] --> ROUTE
ROUTE --> MODEL{"Model routing"}
MODEL -->|"Opus"| EXEC_O["discuss deep, spec,\nplan, do, debug,\nsecurity review"]
MODEL -->|"Sonnet"| EXEC_S["review quality/perf,\nintel refresh, html,\nrefactor, test gen"]
MODEL -->|"Haiku"| EXEC_H["status, doctor,\nnext, test smoke,\ncompact, figma"]
style INPUT fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style CLASSIFY fill:#2d1600,stroke:#d29922,color:#e6edf3
style MENU fill:#1a1f29,stroke:#bc8cff,color:#e6edf3
style ROUTE fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
🗣️ /ali-discuss — Requirements Elicitation
Thu thập requirements bằng Socratic questioning, BMAD techniques.
flowchart TB
START["User: mô tả feature"] --> ROUTE{Sub-command?}
ROUTE -->|"(default)"| SOCRATIC["5-Level Socratic\n1. WHAT: mục tiêu?\n2. WHO: user nào?\n3. HOW: cách implement?\n4. EDGE: rủi ro gì?\n5. VALIDATE: confirm all"]
ROUTE -->|"brief"| BRIEF["Quick Product Brief\nProblem → Solution → Audience"]
ROUTE -->|"deep"| DEEP["Deep Analysis (BMAD)\nPre-mortem + Red Team\n+ Inversion + 5 Whys"]
ROUTE -->|"research"| RESEARCH["Market / Competitive\n/ Technical Research"]
ROUTE -->|"assumptions"| ASSUME["Codebase-First Analysis\nScan code → confirm assumptions"]
ROUTE -->|"redflags"| RED["Conflict Scan\nSpec vs spec, tech debt,\nbreaking changes"]
SOCRATIC --> COLLECT["Thu thập vào memory"]
BRIEF --> COLLECT
DEEP --> COLLECT
RESEARCH --> COLLECT
ASSUME --> COLLECT
RED --> COLLECT
COLLECT --> ROUTE2{"/ali-discuss summary?"}
ROUTE2 -->|"Yes"| SUMMARY["Generate Summary\n→ .claude/memory/\ndiscuss-summary-{feature}.md"]
ROUTE2 -->|"Not yet"| MORE["Tiếp tục hỏi\n(loop back)"]
MORE --> ROUTE
SUMMARY --> GATE["✅ Gate 1 Ready\n→ /ali-spec"]
style START fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style DEEP fill:#2d1600,stroke:#d29922,color:#e6edf3
style SUMMARY fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
style GATE fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
📝 /ali-spec — Specification
Tạo spec 6 sections, blast radius analysis, scope management.
flowchart TB
START["Parse input"] --> CHECK{"Discussion summary\nexists?"}
CHECK -->|"❌ No"| BLOCK["🚧 STOP\n→ /ali-discuss first"]
CHECK -->|"✅ Yes"| ROUTE{Sub-command?}
ROUTE -->|"(default)"| FULL["Create Full Spec:\n1. Context & Goals\n2. Scope (scope_files)\n3. Technical Design + Blast Radius\n4. Test Criteria\n5. Implementation Plan (XML)\n6. Open Questions"]
ROUTE -->|"quick"| QUICK["Micro-spec\n(≤3 files, simple fix)"]
ROUTE -->|"edit"| EDIT["Edit existing spec\n→ preserve frontmatter"]
ROUTE -->|"scope change"| SC["🔄 Scope Change:\n1. STOP execution\n2. Archive old plan\n3. Reset approved: false\n4. → /ali-discuss"]
ROUTE -->|"approve"| APR["Set approved: true\n+ timestamp"]
ROUTE -->|"reject"| REJ["Set approved: false\n+ rejection reason"]
ROUTE -->|"list"| LIST["Show all specs\n+ status"]
ROUTE -->|"diff"| DIFF["Compare spec versions"]
FULL --> SAVE["Save to\n.claude/specs/SPEC-{NNN}-{name}.md\napproved: false"]
QUICK --> SAVE
SAVE --> REVIEW["Present to user\nfor review"]
REVIEW --> DECIDE{User decision?}
DECIDE -->|"Approve"| APR
DECIDE -->|"Edit"| EDIT
DECIDE -->|"Reject"| REJ
APR --> GATE["✅ Gate 2 Ready\n→ /ali-design or /ali-plan"]
style BLOCK fill:#3d0c0c,stroke:#f85149,color:#e6edf3
style SC fill:#2d1600,stroke:#d29922,color:#e6edf3
style GATE fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
style FULL fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
🎨 /ali-design — UI/UX Design
Design system → screens → HTML prototype → review → iterate. Bắt buộc cho UI features.
flowchart TB
START["Spec approved ✅"] --> ROUTE{Sub-command?}
ROUTE -->|"system"| SYS["🎨 Design System\n1. Hỏi 4 câu (product, platform, style, brand)\n2. Generate tokens (colors, fonts, spacing)\n3. Platform tokens (CSS/SwiftUI/Compose)\n4. User review → approve"]
ROUTE -->|"screen <name>"| SCR["📱 Screen Design\n1. Read design system + spec\n2. Component tree\n3. States (default/loading/empty/error)\n4. Interactions\n5. Responsive breakpoints"]
ROUTE -->|"html"| HTML["🌐 HTML Prototype\n1. Read design tokens + screen docs\n2. Generate self-contained HTML\n3. Inline CSS/JS, all states\n4. Navigation between screens\n5. Index page"]
ROUTE -->|"review"| REV["🔍 UX Review\nA: Accessibility (WCAG 2.2)\nB: UX Patterns (8 checks)\nC: Anti-patterns (23 checks)\n→ pass/warn/fail report"]
ROUTE -->|"figma pull"| FPULL["Import từ Figma\n→ generate docs + tokens"]
ROUTE -->|"figma sync"| FSYNC["Compare code vs Figma\n→ diff report"]
ROUTE -->|"iterate"| ITER["Vòng lặp chỉnh sửa"]
SYS --> SYSOUT["design-system-{spec-id}.md\napproved: false"]
SCR --> SCROUT["screens/{name}.md\n+ prototypes/{name}.html"]
HTML --> HTMLOUT["prototypes/*.html\n+ prototypes/index.html"]
REV --> REVOUT{"Blockers?"}
REVOUT -->|"❌ Yes"| FIX["Fix blockers\n→ re-review"]
REVOUT -->|"✅ No"| APPROVE["User approve design\napproved: true + timestamp"]
ITER --> CLASSIFY{Change type?}
CLASSIFY -->|"Design only"| UPDVIS["Update visual\n→ re-review"]
CLASSIFY -->|"Design system"| UPDSYS["Update tokens\n+ all screens"]
CLASSIFY -->|"Spec change"| SPECCH["→ /ali-spec edit\n→ redesign"]
APPROVE --> GATE["✅ Design Gate Ready\n→ /ali-plan"]
FIX --> REV
UPDVIS --> REV
UPDSYS --> REV
style SYS fill:#2d1a29,stroke:#f778ba,color:#e6edf3
style HTML fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style REV fill:#2d1600,stroke:#d29922,color:#e6edf3
style GATE fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
style SPECCH fill:#3d0c0c,stroke:#f85149,color:#e6edf3
📐 /ali-plan — Planning
Pre-flight 9 dimensions, wave grouping, context budget, codebase intelligence.
flowchart TB
START["Spec approved + Design done"] --> PRE{"Prerequisites"}
PRE -->|"Spec not approved"| STOP1["🚧 STOP → /ali-spec"]
PRE -->|"No scope_files"| STOP2["🚧 STOP → fix spec"]
PRE -->|"UI: no design"| STOP3["🚧 STOP → /ali-design"]
PRE -->|"✅ All pass"| PREFLIGHT["Pre-flight 9 Dimensions"]
PREFLIGHT --> D1["1. Spec Clarity ✓"]
PREFLIGHT --> D2["2. Scope Boundaries ✓"]
PREFLIGHT --> D3["3. Dependency Check ✓"]
PREFLIGHT --> D4["4. Test Infrastructure ✓"]
PREFLIGHT --> D5["5. Risk Assessment ✓"]
PREFLIGHT --> D6["6. Context Budget ✓"]
PREFLIGHT --> D7["7. Design Consistency ✓"]
PREFLIGHT --> D8["8. Integration Points ✓"]
PREFLIGHT --> D9["9. Environment (analysis only)"]
D1 & D2 & D3 & D4 & D5 & D6 & D7 & D8 --> GATE5{"Dim 1-8\nall pass?"}
GATE5 -->|"❌ Any fail"| FIXPRE["Fix → re-run preflight"]
GATE5 -->|"✅ 8/8 Pass"| PLAN["Generate Plan"]
PLAN --> BLAST["Blast Radius Analysis\nimport graph + risk matrix"]
BLAST --> WAVES["Wave Grouping\nTask → Wave 1..N\n(dependency order)"]
WAVES --> BUDGET["Context Budget\n(estimated tokens per wave)"]
BUDGET --> OUTPUT["📄 Plan Output\n.claude/plans/SPEC-{id}/plan.xml\n+ env-requirements.md"]
ROUTE{Sub-command?}
ROUTE -->|"deps"| DEPS["Dependency analysis"]
ROUTE -->|"waves"| WAVES
ROUTE -->|"budget"| BUDGET
ROUTE -->|"intel"| INTEL["Codebase Intelligence\nrefresh | query | diff"]
ROUTE -->|"add/insert/remove\nsplit/reorder"| DYN["Dynamic Phase\nManagement"]
style PREFLIGHT fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style GATE5 fill:#2d1600,stroke:#d29922,color:#e6edf3
style OUTPUT fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
style STOP1 fill:#3d0c0c,stroke:#f85149,color:#e6edf3
style STOP2 fill:#3d0c0c,stroke:#f85149,color:#e6edf3
style STOP3 fill:#3d0c0c,stroke:#f85149,color:#e6edf3
⚡ /ali-do — TDD Execution Engine
Core TDD loop: RED → GREEN → REFACTOR. Wave gates, YOLO mode, ship flow.
flowchart TB
START["Plan ready"] --> ENVCHECK{"First run?\nEnv verified?"}
ENVCHECK -->|"Not verified"| ENV["🔧 env-verify\nServices, env vars, tools\nAuto-fix safe issues"]
ENVCHECK -->|"✅ Verified"| PICK
ENV --> PICK["Pick next task\nfrom plan"]
PICK --> RED["🔴 RED Phase\nWrite failing test\n→ verify test FAILS"]
RED --> GREEN["🟢 GREEN Phase\nMinimal implementation\n→ test PASSES\n→ full suite PASSES"]
GREEN --> REFACTOR["🔵 REFACTOR Phase\nStructural cleanup\n→ tests still PASS"]
REFACTOR --> STUB{"Stub check\nTODO/FIXME/\nPLACEHOLDER?"}
STUB -->|"❌ Found"| FIXSTUB["Remove stubs\n→ implement properly"]
STUB -->|"✅ Clean"| COMMIT["Atomic commit\ntype(scope): desc"]
FIXSTUB --> GREEN
COMMIT --> MORETASK{"More tasks\nin wave?"}
MORETASK -->|"Yes"| PICK
MORETASK -->|"No"| WAVEGATE{"🚧 Wave Gate\nFull suite pass?\nNo stubs?"}
WAVEGATE -->|"✅ Pass"| MOREWAVE{"More waves?"}
WAVEGATE -->|"❌ Fail"| FIXWAVE["Fix failures\n→ re-check"]
FIXWAVE --> WAVEGATE
MOREWAVE -->|"Yes"| COMPACT["Compact? → Next wave"]
MOREWAVE -->|"No"| COMPLETE{"🚧 Completion Gate\nAll waves + suite +\nno stubs + review?"}
COMPACT --> PICK
COMPLETE -->|"✅ Pass"| SHIP["🚀 /ali-do ship\nCreate PR → milestone\n→ docs → retro"]
COMPLETE -->|"❌ Fail"| FIXCOMP["Fix → re-check"]
subgraph SPECIAL["Special Modes"]
YOLO["🤖 YOLO mode\nAuto-pilot, scope-locked\n≤10 files, ≤5 waves\nauto-compact per wave"]
QUICK["⚡ Quick mode\nAd-hoc, ≤3 files\nbypass full plan"]
BATCH["📦 Batch N\nDo N tasks → pause\nfor review"]
PAUSE["⏸️ Pause\nSave handoff JSON\n→ /ali-resume later"]
end
subgraph STRIKE["3-Strike Escalation"]
S1["Strike 1: retry\ndifferent approach"]
S1 --> S2["Strike 2: try\nsplitting task"]
S2 --> S3["Strike 3: STOP\n→ ask user options"]
end
style RED fill:#3d0c0c,stroke:#f85149,color:#e6edf3
style GREEN fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
style REFACTOR fill:#0c1a3d,stroke:#58a6ff,color:#e6edf3
style SHIP fill:#238636,stroke:#3fb950,color:#fff
style WAVEGATE fill:#2d1600,stroke:#d29922,color:#e6edf3
style COMPLETE fill:#2d1600,stroke:#d29922,color:#e6edf3
style YOLO fill:#2d1a29,stroke:#bc8cff,color:#e6edf3
🔍 /ali-review — 5-Perspective Review
5 reviewers độc lập. 3/5 phải pass (spec, security, regression) = blocking.
flowchart TB
START["Code implementation done"] --> R1["👤 Reviewer 1: SPEC COMPLIANCE\n🚧 BLOCKING\nEvery requirement implemented?\nNo extras? Blast radius matches?"]
START --> R2["👤 Reviewer 2: CODE QUALITY\nFunctions <50 lines?\nFiles <300 lines?\nNo duplication? Error handling?"]
START --> R3["👤 Reviewer 3: SECURITY\n🚧 BLOCKING\nInput validation? SQL injection?\nXSS? Auth/Authz? Secrets?"]
START --> R4["👤 Reviewer 4: PERFORMANCE\nNo N+1? Indexes?\nPagination? Caching?\nNo blocking async?"]
START --> R5["👤 Reviewer 5: REGRESSION\n🚧 BLOCKING\nFull suite pass? No skipped?\nCoverage maintained? No stubs?"]
R1 --> REPORT
R2 --> REPORT
R3 --> REPORT
R4 --> REPORT
R5 --> REPORT["📊 Review Report\npass / warn / fail per perspective"]
REPORT --> GATE{"Blocking 3/5\nall pass?"}
GATE -->|"✅ All 3 pass"| APPROVED["✅ APPROVED\n→ ready to ship"]
GATE -->|"❌ Any fail"| CHANGES["❌ CHANGES REQUESTED"]
CHANGES --> FIX{"Fix mode?"}
FIX -->|"--auto"| AUTOFIX["Auto-fix → re-review\n(loop until clean)"]
FIX -->|"--dry-run"| DRY["Preview changes\n(don't apply)"]
FIX -->|"manual"| MANUAL["Developer fixes\n→ re-review"]
AUTOFIX --> REPORT
MANUAL --> REPORT
subgraph MORE["Additional Reviews"]
AUDIT["🔎 audit\nFull codebase audit"]
COV["📈 coverage\nTest coverage gap analysis"]
UAT["🧪 uat\nUser acceptance testing"]
end
style R1 fill:#2d1600,stroke:#d29922,color:#e6edf3
style R3 fill:#2d1600,stroke:#d29922,color:#e6edf3
style R5 fill:#2d1600,stroke:#d29922,color:#e6edf3
style APPROVED fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
style CHANGES fill:#3d0c0c,stroke:#f85149,color:#e6edf3
🐛 /ali-debug — Structured Debugging
4 phase + 3-strike escalation. 1 hypothesis, 1 variable at a time.
flowchart TB
ERROR["🐛 Error / Failing test"] --> P1["Phase 1: ROOT CAUSE\nRead error completely\nReproduce (steps → result → expected)\nEvidence at component boundaries\nTimeline (git log)"]
P1 --> P2["Phase 2: PATTERN ANALYSIS\nFind working code\nCompare char-by-char\nDependency check\n(packages, env, schema)"]
P2 --> P3["Phase 3: HYPOTHESIS\nForm 1 hypothesis\nChange 1 variable only\nVerify"]
P3 --> TEST{"Hypothesis\ncorrect?"}
TEST -->|"❌ Wrong"| STRIKE{"Strike count?"}
STRIKE -->|"Strike 1"| RETRY["Retry:\ndifferent approach"] --> P1
STRIKE -->|"Strike 2"| SPLIT["Split task:\nnarrow scope"] --> P1
STRIKE -->|"Strike 3"| STOP["🛑 STOP\nPresent options to user:\n1. Split further\n2. Revise spec\n3. Architecture issue\n4. Need more info\n5. Skip"]
TEST -->|"✅ Correct"| P4["Phase 4: IMPLEMENTATION\n1. Write regression test (must FAIL)\n2. Implement fix\n3. Test passes + all old tests pass\n4. Commit"]
P4 --> FORENSICS["📝 Forensics\nforensics-{date}.md\nRoot cause, fix, prevention"]
style P1 fill:#3d0c0c,stroke:#f85149,color:#e6edf3
style P2 fill:#2d1600,stroke:#d29922,color:#e6edf3
style P3 fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style P4 fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
style STOP fill:#3d0c0c,stroke:#f85149,color:#e6edf3
🧭 /ali-next — Smart Advisor
Thu thập 10 tín hiệu → đánh giá priority P0-P5 → gợi ý next action.
flowchart TB
START["Collect 10 Signals\n(parallel)"] --> S1["Git state\nbranch, uncommitted,\nconflicts"]
START --> S2["Spec state\ndraft/approved/done"]
START --> S3["Plan state\ncurrent wave/task"]
START --> S4["Test state\npass/fail count"]
START --> S5["Handoff state\npaused/in_progress"]
START --> S6["Design state\nsystem/screens/approved"]
START --> S7["Guard state\nfrozen/scope lock"]
START --> S8["Discussion state\norphaned discussions"]
START --> S9["Review state\nunresolved findings"]
START --> S10["Context state\nusage %"]
S1 & S2 & S3 & S4 & S5 & S6 & S7 & S8 & S9 & S10 --> EVAL["Evaluate Priority Matrix"]
EVAL --> P0["🔴 P0 (Critical)\nMerge conflicts\nTests failing (no task)\nContext > 85%"]
EVAL --> P1["🟠 P1 (Urgent)\nHandoff paused\nContext > 85%"]
EVAL --> P2["🟡 P2 (Active Work)\nCurrent task\nWave gate\nReview before ship"]
EVAL --> P3["🔵 P3 (Ready)\nSpec approved, no plan\nMissing design"]
EVAL --> P4["⚪ P4 (Prepare)\nSummary without spec\nNo discussions"]
EVAL --> P5["⬜ P5 (Maintenance)\nContext > 50%\nUncommitted changes"]
P0 & P1 & P2 & P3 & P4 & P5 --> OUTPUT["📋 Recommendation\nTop action + alternatives\n+ reasoning"]
style P0 fill:#3d0c0c,stroke:#f85149,color:#e6edf3
style P1 fill:#2d1600,stroke:#d29922,color:#e6edf3
style P2 fill:#2d2d00,stroke:#d29922,color:#e6edf3
style P3 fill:#0c1a3d,stroke:#58a6ff,color:#e6edf3
style OUTPUT fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
🔄 /ali-resume — Unified Smart Resume
Auto-detect interrupt type → strategy phục hồi phù hợp.
flowchart TB
START["Detect ALL interrupt signals\n(parallel)"] --> DETECT["Check:\nHandoff files, compact files,\ngit state, plan state,\ntest state, guard state"]
DETECT --> CLASS{Classify interrupt}
CLASS -->|"PAUSED"| RES1["Load handoff\n→ continue TDD\nwhere left off"]
CLASS -->|"CRASHED_MID_TASK"| RES2["Load handoff\n→ verify branch SHA\n→ verify tests\n→ ask user: continue/revert?"]
CLASS -->|"EMERGENCY_COMPACT"| RES3["Load compact carry-forward\n→ verify branch\n→ verify tests\n→ continue"]
CLASS -->|"STALE_SESSION"| RES4["⚠️ Warn about age\n→ offer re-verify\n→ user decides"]
CLASS -->|"FAILED_TASK"| RES5["Show strike count\n→ offer options:\n1. Different approach\n2. Split task\n3. Revise spec\n4. Skip"]
CLASS -->|"WAVE_GATE_FAIL"| RES6["Show failures\n→ fix → re-gate"]
CLASS -->|"CLEAN_PAUSE"| RES7["Reconstruct from git\n→ offer resume"]
CLASS -->|"FRESH"| RES8["No resume needed\n→ /ali-next"]
MULTI{"Multiple states\ndetected?"} -->|"Yes"| ASK["Ask user\nwhich to resume"]
MULTI -->|"No"| EXEC["Execute strategy"]
RES1 & RES2 & RES3 & RES4 & RES5 & RES6 & RES7 --> EXEC
EXEC --> CONTINUE["✅ Context restored\n→ continue work"]
style DETECT fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style RES2 fill:#2d1600,stroke:#d29922,color:#e6edf3
style RES5 fill:#3d0c0c,stroke:#f85149,color:#e6edf3
style CONTINUE fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
🛡️ /ali-guard — Safety & Drift Detection
Freeze files, scope lock, 6-dimension drift, audit, undo.
flowchart TB
subgraph ALWAYS["Always-on Protections"]
P1["Protected files\nCLAUDE.md, hooks,\nsettings, guard-state"]
P2["Pre-commit hook\nStub detection\nSecret detection"]
P3["Pre-tool-use hook\nBlock writes to\nfrozen/out-of-scope files"]
end
ROUTE{Sub-command?}
ROUTE -->|"freeze <path>"| FREEZE["Add to frozen list\n→ hook blocks writes"]
ROUTE -->|"unfreeze <path>"| UNFREEZE["Remove from frozen\n(after confirmation)"]
ROUTE -->|"careful"| CAREFUL["Toggle careful mode\nEvery change needs\nuser confirmation"]
ROUTE -->|"scope <SPEC-id>"| SCOPE["Read spec.scope_files\n→ lock guard-state\n→ deny writes outside scope"]
ROUTE -->|"drift"| DRIFT["6-Dimension Drift Check"]
ROUTE -->|"audit"| AUDIT["Full Safety Audit"]
ROUTE -->|"undo"| UNDO["Show recent changes\n→ ask which to revert\n→ revert + log"]
DRIFT --> DD1["1. Spec drift\ncode vs spec"]
DRIFT --> DD2["2. Decision drift\nvs memory decisions"]
DRIFT --> DD3["3. Ownership drift\nfile responsibility"]
DRIFT --> DD4["4. Test drift\ncoverage decay"]
DRIFT --> DD5["5. Usage drift\nAPI contracts"]
DRIFT --> DD6["6. Dependency drift\npackage changes"]
DD1 & DD2 & DD3 & DD4 & DD5 & DD6 --> REPORT["📊 Drift Report\nmatches / mismatches"]
AUDIT --> A1["Protected files check"]
AUDIT --> A2["Frozen files check"]
AUDIT --> A3["Stub detection"]
AUDIT --> A4["Secret detection"]
AUDIT --> A5["6-dim drift"]
AUDIT --> A6["Test health"]
AUDIT --> A7["Git hygiene"]
AUDIT --> A8["Scope compliance"]
style ALWAYS fill:#1a1f29,stroke:#f85149,color:#e6edf3
style FREEZE fill:#3d0c0c,stroke:#f85149,color:#e6edf3
style SCOPE fill:#2d1600,stroke:#d29922,color:#e6edf3
style DRIFT fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style AUDIT fill:#1a1f29,stroke:#bc8cff,color:#e6edf3
📊 /ali-status — Session Monitor
Progress tracking, handoff, compact memory, doctor/repair, backlog.
flowchart TB
ROUTE{Sub-command?}
ROUTE -->|"progress"| PROG["📊 Show status:\nSpec, wave, task,\ntest results"]
ROUTE -->|"handoff"| HAND["💾 Save handoff\n→ .claude/memory/\nhandoff-{spec-id}-{ISO}.json"]
ROUTE -->|"compact"| COMP["📦 Compact Memory\nClassify: HIGH/MED/LOW\n→ compact-{spec-id}-{wave}.md"]
ROUTE -->|"doctor"| DOC["🩺 Doctor Check\n7 categories:\nfiles, skills, hooks,\npermissions, deps,\ndesign, CLAUDE.md"]
ROUTE -->|"repair"| REP["🔧 Auto-fix safe issues\nCreate dirs, chmod hooks,\nsymlink git hooks,\nmerge settings"]
ROUTE -->|"backlog"| BL["📝 Backlog\nadd | review | seed\nnote | explore"]
ROUTE -->|"workspace"| WS["📁 Workspace\nlist | switch | close"]
ROUTE -->|"init"| INIT["🗺️ Map codebase\n→ .claude/intel/"]
ROUTE -->|"thread"| THR["🧵 Cross-session\nthread management"]
ROUTE -->|"memory"| MEM["🧠 Memory\nsave | load"]
ROUTE -->|"learn"| LEARN["📚 Learn from\nproject patterns"]
ROUTE -->|"next"| NEXT["→ delegate to\n/ali-next"]
ROUTE -->|"resume"| RES["→ delegate to\n/ali-resume"]
ROUTE -->|"update"| UPD["→ delegate to\n/ali-update"]
subgraph CTX["Context Thresholds"]
C50["🟡 > 50%: suggest compact"]
C70["🟠 > 70%: default Yes"]
C85["🔴 > 85%: auto compact"]
end
style COMP fill:#2d1600,stroke:#d29922,color:#e6edf3
style DOC fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style REP fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
style CTX fill:#1a1f29,stroke:#f85149,color:#e6edf3
📦 /ali-update — Package Manager
Install, update, rollback, version bump. NPM distribution.
flowchart TB
ROUTE{Mode?}
ROUTE -->|"init"| INIT["🆕 First Install\n1. Validate env\n2. Check git\n3. Copy template files\n4. Setup hooks\n5. Update .gitignore\n6. Run doctor"]
ROUTE -->|"check"| CHECK["🔍 Version Check\nInstalled vs latest\n→ STOP (info only)"]
ROUTE -->|"update"| UPDATE["📦 Update Flow"]
UPDATE --> U1["1. Pre-flight\nCompare versions"]
U1 --> U2["2. Backup\n→ .claude/backups/\nv{old}-{timestamp}/"]
U2 --> U3["3. Diff preview"]
U3 --> U4{"--dry-run?"}
U4 -->|"Yes"| STOP2["Show diff only\n→ STOP"]
U4 -->|"No"| U5["4. Apply changes"]
U5 --> FW["FRAMEWORK: overwrite\nskills/, hooks/, scripts/"]
U5 --> CF["CONFIG: merge\nCLAUDE.md.new\nsettings.json union"]
U5 --> UD["USER DATA: skip\nspecs/, memory/, design/"]
U5 --> MT["META: update\nali-version.json"]
FW & CF & UD & MT --> U6["5. Post-update\nRun doctor + report"]
ROUTE -->|"rollback"| ROLL["⏪ Rollback\n1. List backups\n2. Safety backup first\n3. Restore from backup\n4. Preserve guard-state"]
ROUTE -->|"uninstall"| UNIN["🗑️ Uninstall\nDelete framework\nAsk about config\nPreserve user data always"]
ROUTE -->|"bump"| BUMP["🔢 Version Bump\nfix → patch (1.1.0→1.1.1)\nfeat → minor (1.1.1→1.2.0)\nmajor → manual only"]
style INIT fill:#0c2d0c,stroke:#3fb950,color:#e6edf3
style UPDATE fill:#1a1f29,stroke:#58a6ff,color:#e6edf3
style ROLL fill:#2d1600,stroke:#d29922,color:#e6edf3
style BUMP fill:#1a1f29,stroke:#bc8cff,color:#e6edf3
style UD fill:#2d1a29,stroke:#f778ba,color:#e6edf3