|
| 1 | +# Phase A: Provider Infrastructure (Implementation Kickoff) |
| 2 | + |
| 3 | +**Scope:** Formalize multi-provider routing and declarative config architecture. Critical path for Phases B-F. |
| 4 | + |
| 5 | +**Pinpoints in scope:** #245, #246, #285 |
| 6 | +**Blocked by:** Phase 0 merge (GitHub OAuth, cargo fmt, clawcode-human approval) |
| 7 | +**Estimated effort:** 2-3 cycles |
| 8 | +**Target:** Merge-ready immediately post-Phase 0 |
| 9 | + |
| 10 | +## #245 — Providers are hard-coded enum; no backend-swap capability |
| 11 | + |
| 12 | +**Acceptance Criteria:** |
| 13 | +- [ ] Providers defined as trait (not enum) |
| 14 | +- [ ] Factory/registry pattern allows runtime provider selection |
| 15 | +- [ ] Existing providers (Anthropic, OpenAI) are re-implemented as trait impls |
| 16 | +- [ ] Tests pass for all existing behavior |
| 17 | +- [ ] Zero breaking changes to public API |
| 18 | + |
| 19 | +**Implementation sequence:** |
| 20 | +1. Define `Provider` trait with core methods (chat completion, streaming, model listing) |
| 21 | +2. Implement trait for existing providers |
| 22 | +3. Add provider registry/factory |
| 23 | +4. Update CLI to accept `--provider` flag |
| 24 | +5. Regression tests |
| 25 | + |
| 26 | +## #246 — Provider selection logic is CLI-parsing only; no config source integration |
| 27 | + |
| 28 | +**Acceptance Criteria:** |
| 29 | +- [ ] Provider selection checks: 1) CLI flag, 2) env var, 3) settings.json, 4) default |
| 30 | +- [ ] settings.json schema includes `provider` field with subconfig |
| 31 | +- [ ] Env vars like `OPENAI_API_KEY` trigger automatic provider selection |
| 32 | +- [ ] Conflict resolution documented (CLI > env > config file > default) |
| 33 | +- [ ] Config merging tested |
| 34 | + |
| 35 | +**Implementation sequence:** |
| 36 | +1. Extend settings.json schema (add provider field, subconfig structure) |
| 37 | +2. Implement config-merge logic (priority order) |
| 38 | +3. Update `claw doctor` to validate provider config (#293 prerequisite) |
| 39 | +4. Integration tests |
| 40 | + |
| 41 | +## #285 — No declarative provider fallback; can't swap backends mid-session |
| 42 | + |
| 43 | +**Acceptance Criteria:** |
| 44 | +- [ ] `settings.json` supports `providers: [primary, secondary, fallback]` array |
| 45 | +- [ ] Streaming failures trigger automatic fallback to next provider |
| 46 | +- [ ] Session state is preserved across provider swap |
| 47 | +- [ ] User is notified of fallback event |
| 48 | +- [ ] `claw doctor --providers` shows fallback chain health |
| 49 | + |
| 50 | +**Implementation sequence:** |
| 51 | +1. Extend settings.json schema (providers array) |
| 52 | +2. Implement fallback logic in streaming handler |
| 53 | +3. Add state-preservation during swap |
| 54 | +4. User notification (log + maybe `--verbose` output) |
| 55 | +5. Integration tests with dual-provider setup |
| 56 | + |
| 57 | +## Dependency Graph |
| 58 | + |
| 59 | +``` |
| 60 | +Phase 0 merge ──→ #245 (trait + registry) ──→ #246 (config integration) ──→ #285 (fallback) |
| 61 | + │ │ |
| 62 | + └────────────────────────┘ |
| 63 | + (parallel possible) |
| 64 | +``` |
| 65 | + |
| 66 | +## Success Criteria (Phase A complete) |
| 67 | + |
| 68 | +- [ ] All three pinpoints (#245, #246, #285) have passing tests |
| 69 | +- [ ] `claw --provider openai` works |
| 70 | +- [ ] `claw --provider openai --fallback anthropic` works |
| 71 | +- [ ] settings.json with `{ "provider": "openai", ... }` is read correctly |
| 72 | +- [ ] `claw doctor --providers` validates all configured backends |
| 73 | +- [ ] Zero regression on existing Anthropic-only workflows |
| 74 | +- [ ] PR merges with zero cargo fmt warnings |
| 75 | +- [ ] clawcode-human approval granted |
| 76 | + |
| 77 | +## Next: Phase B (transport-layer + resilience) |
| 78 | + |
| 79 | +Once Phase A merges, Phase B begins with auto-compaction (#287, #288, #289) and streaming resilience (#223, #225, #229, #230, #232, #283, #287, #288, #289, #290, #291, #292). |
0 commit comments