Worktree 隔離的跨模型代理編排
具備盲審分歧驗證與自動學習
curl -fsSL https://raw.githubusercontent.com/project820/be-my-butler/main/install.sh | bash
每個架構決策都可追溯至這些不可妥協的原則。
git worktree。無共享狀態、無 index.lock 衝突,實現真正的檔案系統級隔離。.bmb/ 和 CLAUDE.md,絕不碰程式碼。上下文保護至關重要 — Lead 是瓶頸。session-prep.md 為下一個 session 捕捉狀態。跨 session 上下文得以保留,任何工作都不會真正遺失。council 和 verify 為唯讀模式。不再到處使用 --full-auto。9 個專業代理,各有明確角色和嚴格邊界。從腦力激盪到生產就緒的程式碼。
graph TB User["👤 User"] Lead["🎯 Lead
Opus · Orchestrator"] Consultant["💬 Consultant
Sonnet · Persistent"] Architect["📐 Architect
Opus · Council"] Executor["⚙️ Executor
Opus · Backend"] Frontend["🎨 Frontend
Opus · UI"] Tester["🧪 Tester
Opus · Blind"] Verifier["✅ Verifier
Opus · Blind"] Simplifier["🧹 Simplifier
Opus · Cleanup"] Writer["📝 Writer
Sonnet · Docs"] BMB[".bmb/
Handoffs · Artifacts"] CrossModel["🌐 Cross-Model
Codex / Gemini"] User <-->|"brainstorm
approve"| Lead Lead <-->|"SendMessage
bidirectional"| Consultant Lead -->|"briefing"| Architect Architect <-->|"council
debate"| CrossModel Lead -->|"plan-to-exec"| Executor Lead -->|"plan-to-exec"| Frontend Lead -->|"test request"| Tester Tester -.->|"blind wall"| CrossModel Lead -->|"verify request"| Verifier Verifier -.->|"blind wall"| CrossModel Lead -->|"simplify"| Simplifier Lead -->|"write docs"| Writer Architect -->|"writes"| BMB Executor -->|"writes"| BMB Frontend -->|"writes"| BMB Tester -->|"writes"| BMB Verifier -->|"writes"| BMB Lead -->|"reads only"| BMB classDef opus fill:#1a1030,stroke:#7c3aed,stroke-width:2px,color:#a78bfa classDef sonnet fill:#0a2015,stroke:#16a34a,stroke-width:2px,color:#22c55e classDef cross fill:#1a1500,stroke:#d97706,stroke-width:2px,color:#f59e0b classDef user fill:#0a1628,stroke:#3b82f6,stroke-width:2px,color:#60a5fa classDef storage fill:#111827,stroke:#1e3a5f,stroke-width:2px,color:#8494a7 class Lead,Architect,Executor,Frontend,Tester,Verifier,Simplifier opus class Consultant,Writer sonnet class CrossModel cross class User user class BMB storage
.bmb/,絕不寫入程式碼。輕量指揮者。analytics.db,依 Bird’s Law 嚴重性分類事件(critical/warn/info),找出 pattern_counts 晉升候選人。從使用者意圖到生產就緒的程式碼。點擊每個步驟查看詳情。
bmb_learn PRAISE。MODIFY → bmb_learn CORRECTION + 更新。NO → 取消。
bmb_learn MISTAKE + 上報使用者。
plan-to-exec.md。Cross-Model Tester 讀取 briefing.md。不同的框架、獨立的 worktree、獨立的逾時設定。雙方皆不讀取對方的結果。
bmb_learn MISTAKE + 分類式迴圈。
bmb_learn MISTAKE + 還原 + 使用原始版本繼續。
analytics.db。依 Bird’s Law 嚴重性分類事件(critical / warn / info)。交叉比對 pattern_counts 找出反覆出現的故障(≥2 次)以作為 CLAUDE.md 晉升候選。撰寫 analyst-report.md(3–5 分鐘逾時;逾時則管線繼續)。
bmb_learn PRAISE。檢查重複次數 ≥2 → 提議 CLAUDE.md 晉升。Git commit/push。FTS5 索引。為下個 session 產生 session-prep.md。
flowchart TD S1["1. Setup
tmux, session, learnings"] S2["2. Brainstorm + Consultant
min 2 rounds"] S3{"3. User Approval"} S4["4. Architecture Council
2-4 debate rounds"] S5["5. Execution
worktree-isolated"] S55["5.5 Merge Worktrees"] S6["6. Blind Testing
divergent framing"] S7["7. Blind Verification
divergent framing"] S8{"8. Reconciliation"} S9["9. Simplify + Re-verify"] S10["10. Docs Update"] S105["10.5 Retrospective Analysis
Bird's Law severity"] S11["11. Cleanup + Session Prep"] S1 --> S2 S2 --> S3 S3 -->|"YES"| S4 S3 -->|"MODIFY"| S2 S3 -->|"NO"| CANCEL["Cancel"] S4 -->|"skip: bugfix/infra"| S5 S4 --> S5 subgraph parallel ["Parallel Worktrees"] direction LR EX["Executor"] FE["Frontend
if detected"] end S5 --> parallel parallel --> S55 S55 --> S6 S6 --> S7 S7 --> S8 S8 -->|"PASS"| S9 S8 -->|"IMPL fail"| S5 S8 -->|"ARCH fail"| S4 S8 -->|"REQ fail"| S2 S8 -->|"ENV fail"| S1 S8 -->|"TEST fail"| S6 S9 --> S10 S10 --> S105 S105 --> S11 classDef decision fill:#1a1500,stroke:#d97706,color:#f59e0b classDef cancel fill:#2a0a0a,stroke:#ef4444,color:#ef4444 classDef step fill:#111827,stroke:#1e3a5f,color:#e8edf5 classDef parallel fill:#0a1628,stroke:#3b82f6,color:#60a5fa classDef analyst fill:#0a2010,stroke:#22c55e,color:#4ade80 class S3,S8 decision class CANCEL cancel class S1,S2,S4,S5,S55,S6,S7,S9,S10,S11 step class EX,FE parallel class S105 analyst
產出物如何透過 .bmb/ 目錄在代理之間流轉。Lead 絕不碰程式碼 — 僅讀取摘要。
flowchart LR User["👤 User"] Lead["🎯 Lead"] Brief["📋 briefing.md"] Arch["📐 Architect"] Plan["📄 plan-to-exec.md"] ExFe["⚙️ Executor
🎨 Frontend"] Merge["🔀 Merge"] Test["🧪 Tester
blind"] Verify["✅ Verifier
blind"] Recon["⚖️ Reconcile"] Simp["🧹 Simplifier"] Write["📝 Writer"] Output["✨ Output"] User -->|"intent"| Lead Lead -->|"brainstorm"| Brief Brief -->|"briefing"| Arch Arch -->|"council"| Plan Plan -->|"instructions"| ExFe ExFe -->|"worktrees"| Merge Merge -->|"merged code"| Test Merge -->|"merged code"| Verify Test -->|"test-summary"| Recon Verify -->|"verify-summary"| Recon Recon -->|"PASS"| Simp Simp -->|"cleaned"| Write Write --> Output classDef artifact fill:#1a2234,stroke:#3b82f6,color:#60a5fa classDef agent fill:#111827,stroke:#1e3a5f,color:#e8edf5 class Brief,Plan artifact class User,Lead,Arch,ExFe,Merge,Test,Verify,Recon,Simp,Write,Output agent
gantt
title Consultant Monitoring (Steps 2–11)
dateFormat X
axisFormat %s
section Brainstorm
Bidirectional with Lead :active, 0, 2
section Approval
Monitor user decision :1, 3
section Council
Observe debate rounds :2, 4
section Execution
Track progress via feed file :3, 6
section Testing
Monitor blind test results :5, 7
section Verification
Monitor blind verify results :6, 8
section Reconciliation
Observe failure classification :7, 9
section Simplify
Track re-verify outcome :8, 10
section Docs
Validate doc consistency :9, 11
section Cleanup
Final session summary :10, 12
不僅在結果上盲審 — 在問題框架上就存在分歧。工作區層級的盲審跨模型驗證。
每個平行代理都擁有獨立的 git worktree。無共享狀態、無 index.lock 衝突,實現真正的檔案系統隔離。
gantt
title Worktree Lifecycle per Pipeline Run
dateFormat X
axisFormat Step %s
section Executor
Create worktree :e1, 4, 5
Work in worktree :e2, 5, 6
Merge to main :crit, e3, 6, 7
section Frontend
Create worktree :f1, 4, 5
Work in worktree :f2, 5, 6
Merge to main :crit, f3, 6, 7
section Tester-Claude
Create worktree :tc1, 6, 7
Run tests :tc2, 7, 8
Cleanup :tc3, 8, 9
section Tester-Cross
Create worktree :tx1, 6, 7
Run tests :tx2, 7, 8
Cleanup :tx3, 8, 9
section Verifier-Claude
Create worktree :vc1, 7, 8
Verify :vc2, 8, 9
Cleanup :vc3, 9, 10
section Verifier-Cross
Create worktree :vx1, 7, 8
Verify :vx2, 8, 9
Cleanup :vx3, 9, 10
Council 辯論使用 Claude ↔ Codex/Gemini 檔案交換。基於設定檔的權限確保在需要時保持唯讀。
sequenceDiagram participant A as Architect
(Claude Opus) participant F as Council Files
(.bmb/council/) participant X as Cross-Model
(Codex / Gemini) Note over A,X: Round 1 — Initial Proposals A->>F: Write claude-proposal.md X->>F: Write cross-proposal.md Note over A,X: Round 2 — Critique A->>F: Read cross-proposal.md A->>F: Write claude-critique.md X->>F: Read claude-proposal.md X->>F: Write cross-critique.md Note over A,X: Round 3 — Synthesis (optional) A->>F: Read cross-critique.md A->>F: Write claude-synthesis.md X->>F: Read claude-critique.md X->>F: Write cross-synthesis.md Note over A,X: Round 4 — Final Decision A->>F: Read all files A->>F: Write plan-to-exec.md ✅ Note right of X: Cross-Model uses
--profile read-only
council 和 verify 設定檔:跨模型只能讀取程式碼並寫入 .bmb/。不允許生產環境寫入。test 和 exec-assist 設定檔:跨模型可在 worktree 範圍內撰寫測試和輔助程式碼。bmb-config.sh 設定。獨立的截止時間追蹤。Lead 的上下文視窗是共享資源。三個壓縮層確保其永不超過 50% 容量。
.compressed/*.summary.md(最多 300 token)。原始產出物僅在爭議時才存取。.tool-cache/。僅保留摘要:"Modified: auth.ts (47 lines)"、"PASS: 12, FAIL: 0"。錯誤、修正和成功都會自動記錄。過去的陷阱會注入所有專案的未來 session 中。
.bmb/learnings.md — 每行一筆學習紀錄,依時間順序追加。在步驟 1 為此專案載入。~/.claude/bmb-system/learnings-global.md — 相同格式加上 [project_name] 標籤。在所有 BMB 專案間共享。六種任務類型,每種都有各自優化的管線路徑。不論配方為何,Consultant 始終存在。
4 個斜線指令以不同規模呈現 BMB 的功能 — 從完整管線到專注的腦力激盪。
flowchart LR
Setup["/BMB-setup\n⚙️ Config"]
BMB["/BMB\n🔧 Full Pipeline"]
Brainstorm["/BMB-brainstorm\n💡 Ideation"]
Refactoring["/BMB-refactoring\n🔄 Code Quality"]
Setup -->|"prerequisite"| BMB
Setup -->|"prerequisite"| Brainstorm
Setup -->|"prerequisite"| Refactoring
Brainstorm -.->|"feeds into"| BMB
Refactoring -.->|"standalone"| BMB
style Setup fill:#111827,stroke:#22c55e,color:#e8edf5
style BMB fill:#111827,stroke:#3b82f6,color:#e8edf5,stroke-width:3px
style Brainstorm fill:#111827,stroke:#22d3ee,color:#e8edf5
style Refactoring fill:#111827,stroke:#a78bfa,color:#e8edf5
| 階段 | /BMB | /BMB-brainstorm | /BMB-refactoring |
|---|---|---|---|
| 初始設定 / 設定 | ✓ | ✓ | — |
| Consultant Session | ✓ | ✓ | — |
| 腦力激盪 / 分析 | ✓ | ✓ | ✓ 平行 |
| Council 辯論 | ✓ | — | ✓ 綜合 |
| 架構計畫 | ✓ | — | — |
| 執行(Worktree) | ✓ | — | ✓ |
| 測試 | ✓ | — | — |
| 驗證(盲審) | ✓ | — | ✓ 審查 |
| 修復循環 | ✓ | — | ✓ |
| 簡化 | ✓ | — | — |
| 合併 / 清理 | ✓ | ✓ 摘要 | ✓ |
管線絕不阻塞。每種故障模式都有定義好的降級方案。
| 情境 | 行為 |
|---|---|
| 跨模型不可用(Council) | 單獨設計(僅 Claude),記錄於 session log |
| 跨模型不可用(測試) | 僅 Claude 的測試結果,記錄於協調階段 |
| 跨模型不可用(驗證) | 僅 Claude 的驗證結果,記錄於協調階段 |
| Claude 測試者逾時 | 記錄逾時,以跨模型結果繼續 |
| 跨模型逾時 | 以僅 Claude 的結果繼續 |
| 合併衝突 | bmb_learn MISTAKE + 上報使用者 |
| Simplifier 破壞測試 | bmb_learn MISTAKE + 還原 + 使用原始版本繼續 |
| Telegram 環境變數未設定 | 靜默跳過通知 |
| knowledge.db 遺失 | 跳過索引/搜尋 |
| 未偵測到前端 | 跳過 Frontend 代理,僅使用 Executor |
.bmb/ 目錄是所有管線產出物的唯一真實來源。