Repository navigation
Description
Hide v1/v2 HTTP dialect dispatch inside protocol-selected remotes so Screen Models and repository ports stay on product language. No user-facing change.
Parent
OPE-146 — Server API v2 Compatibility
Post-ship follow-up from the dual-stack architecture review. P0–P6 already put protocol behind existing repository interfaces; this ticket only deepens that implementation. Do not block the epic merge on this work.
Why
Repositories currently re-ask isV2() on almost every method (~30 branches per platform; isV2() copied across Session, Message, Command, Agent, Model, Filesystem, Project). Screen Models do not leak protocol — they read ServerCapabilities. The repository port is the right seam; the bodies are a shallow dispatcher.
ServerProtocol is infrastructure (HTTP generation). Product language is sessions, diffs, permissions, and capabilities (e.g. supportsSessionMessageDiff). Keep that split.
Target shape
Keep the external port forever. Add an internal remote seam inside each repository module:
SessionRepository ← port (product; Screen Models unchanged)
DefaultSessionRepository ← application: error map, model-selection cleanup
SessionRemote ← internal seam (not injected into UI)
V1SessionRemote ← legacy HTTP + SessionDomainAdapter
V2SessionRemote ← /api/* + same adapter + v2 compensation
A thin facade holds both remotes and does remote = protocol == v2 ? v2 : v1 once per call, not once per method. Same shape for Command, Filesystem, Model, Agent, Project. Lift MessageProtocolRouter into the same remote pair. Event projection stays in EventDomainAdapter (payload sniffing). SSE path pick stays in the event client.
Protocol is still chosen on connect and cached on ActiveConnectionManager. Callers never see it.
What not to do
- Protocol flags or
isV2in ViewModels / SwiftUI / Compose (capability flags only). - Regenerating OpenAPI into UI or forking Screen Models per protocol.
- Swapping
V1SessionRepository/V2SessionRepositoryin Hilt/Factory on connect. Protocol is unknown at singleton construction, updates in place viaupdateProtocol, and LiveStores already hold the bound instance. - One
OpencodeServergod facade for session+message+event+command. - Per-method strategy objects (
ListSessionsStrategy). - Persisting protocol on
ConnectionProfilewithout a separate decision (stale dialect after server upgrade). - Treating
ServerProtocolas ubiquitous language.
Implementation steps
Do this after feature/ope-146-server-api-v2 is on main (or at least after P6 lands). Both platforms in the same change.
- Centralize probe fallback. One
ActiveConnectionManager.currentProtocolOrProbe()(cache → elseprobeServer()→ default v1). Delete the seven copiedisV2()helpers. Today a failed/missing probe silently means v1; parallel first calls can stampede probes (Android mutex is per repository). This is the real footgun; splitting remotes does not fix it unless probe is shared. - Proof: Session. Extract
SessionRemote+V1/V2fromDefaultSessionRepositoryonly. KeepDefaultSessionRepositoryas the port adapter that also owns delete → model-selection cleanup. ExistingSessionProtocolRepositoryTestsshould survive if they already speak product operations. - Messages. Lift
MessageProtocolRouterinto the same remote pair (it is already the closest to this shape). Keep v2 prompt extras (agent/model POST thenPOST .../prompt) insideV2MessageRemote. - Repeat for Command, Filesystem, Model, Agent, Project only when those files are next edited — not a big-bang rewrite.
- Keep Screen Models on
ServerCapabilities, repositories/remotes on protocol (or remotes selected by protocol).
Hotspots
ios/.../Domain/Session/SessionRepository.swift(~20if await isV2())android/.../domain/session/DefaultSessionRepository.kt(~22if (isV2()))- Same helper in Command, Filesystem, Model, Agent, Project on both platforms
MessageProtocolRouter(iOS + Android)- SSE:
EventsAPIClient.subscribePath/DefaultForegroundEventStream(path pick only; leave there) - DI:
AppContainer.sessionRepository, HiltSessionModule— keep one bound implementation; do not protocol-select at construction
Remaining
- Centralize protocol-or-probe; remove duplicated
isV2()helpers on iOS and Android - Extract
V1SessionRemote/V2SessionRemotebehindSessionRepositoryon both platforms - Lift
MessageProtocolRouterinto v1/v2 message remotes - Extract remotes for Command, Filesystem, Model, Agent, Project when those files are next edited
Docs: docs/features/server-api-v2/
Imported from Linear OPE-155. Linear status: Done. Priority: Low. Created 2026-08-13. Completed 2026-08-13.
Parent: OPE-146.
Activity