6.4 KiB
OpenClaw-Style Gateway-First TUI Runtime Unification Plan
Date: 2026-02-24
Branch: feature/openclaw-gateway-first-tui-runtime-unification
Summary
Unify Flynn command/runtime behavior so TUI, Telegram, and gateway/web chat all execute through the same daemon command/control path (OpenClaw-style control plane), while preserving local model backend switching via /backend for llamacpp and ollama.
Key policy:
/runtime ...is global runtime mode control (config_default,force_native,force_pi_embedded) via daemon command services./backend [provider]remains TUI-local backend selection for local tier only.- TUI command execution should use gateway/daemon command services, not a separate local-only command path.
Goals and Success Criteria
- TUI
/runtimebehavior matches Telegram/gateway behavior exactly. - TUI no longer has a divergent runtime-control command path.
- TUI keeps local
/backendswitching forollamaandllamacpp. flynn tuiauto-starts/attaches daemon+gateway when needed.- Tests validate parity and no regressions.
Scope
In scope:
- Command-path unification for runtime controls.
- TUI bootstrap/attach behavior aligned with gateway runtime.
- Parser/help/tooltip updates for clear
/runtimevs/backendsemantics. - Docs + Mermaid diagram updates.
docs/plans/state.jsonupdate for this feature entry once implementation completes.
Out of scope:
- New backend modes beyond current three values.
- Protocol redesign unrelated to command routing.
- Broad TUI UX redesign outside command/runtime parity.
Public Interfaces and Behavioral Contract
flynn tui
- Primary behavior: connect to gateway-backed session.
- If unavailable: auto-start local daemon+gateway, retry connect, then proceed.
- Failure path: deterministic, actionable error message.
- Slash commands in TUI
/runtime status|activate pi|deactivate pi|use config: forwarded to daemon command service./backend: local-tier backend command only.- No
/backendalias for global runtime mode in TUI.
- Runtime mode persistence
- Existing preference persistence remains source of truth.
- No schema change unless required by implementation details.
Architecture Changes
- Extract/reuse command service execution surface from daemon routing so it can be consumed uniformly by:
- Channel adapters.
- Gateway/web chat sessions.
- TUI sessions.
- Wire TUI through gateway command path:
- Remove TUI-only runtime guard message path.
- Invoke same backend command service used by channel/gateway.
- Keep local backend switching logic isolated:
/backendremains local-tier (llamacpp/ollama) and does not mutate global runtime mode.
Implementation Phases
Phase 1: Branch + Baseline
- Create branch
feature/openclaw-gateway-first-tui-runtime-unification. - Capture baseline behavior with focused tests:
src/frontends/tui/commands.test.tssrc/frontends/tui/minimal.test.tssrc/daemon/routing.test.ts- relevant gateway agent handler tests.
- Commit baseline harness updates (if any).
Phase 2: Command Service Unification
- Refactor daemon runtime command handling into reusable service function(s).
- Replace duplicated logic paths with shared invocation entry points.
- Preserve command output text contract unless intentionally changed.
- Add tests for parity across command surfaces.
Phase 3: Gateway-First TUI Runtime Path
- Update
src/cli/tui.tsstartup flow to attach through gateway-backed runtime path. - Add daemon/gateway auto-start + reconnect sequence with bounded timeout.
- Ensure minimal/fullscreen paths both use unified command execution.
- Keep existing
onTools,onResearch,onCouncilbehavior compatible.
Phase 4: /runtime and /backend Semantics in TUI
- Update parser/help/tooltip text in
src/frontends/tui/commands.ts. - Implement
/runtimeforwarding in:
src/frontends/tui/minimal.tssrc/frontends/tui/components/App.tsx
- Keep
/backendlocal-only behavior; remove any global alias behavior in TUI. - Add tests for both commands and edge cases.
Phase 5: Docs and State
- Update docs:
README.mddocs/architecture/AGENT_DIAGRAM.mddocs/architecture/GATEWAY_SESSIONS_AND_QUEUE.mddocs/api/PROTOCOL.md
- Include Mermaid diagram updates or explicit “no diagram change required” note.
- Update
docs/plans/state.jsonwith new feature entry and test status.
Phase 6: Validation and Merge
- Run focused test suites +
pnpm typecheck. - Fix regressions.
- Rebase branch onto
main. - Fast-forward merge and branch cleanup.
Test Plan
/runtime statusin TUI returns same normalized mode/output as Telegram path./runtime activate pisets persisted mode toforce_pi_embedded./runtime deactivate pisets persisted mode toforce_native./runtime use configrestoresconfig_default./backend llamacppand/backend ollamastill work for local tier in TUI./backend status|activate pi|...in TUI does not control global runtime mode.- TUI auto-start path works when daemon/gateway are not already running.
- TUI attach path works when daemon/gateway are already running.
- Telegram/gateway
/runtimebehavior remains unchanged.
Subagent Model Assignment Plan
claude-haiku-4.5(fast/mechanical)
- Parser/help/tooltip updates.
- Small test fixture updates.
- Docs wording and consistency checks.
claude-sonnet-4.6(default implementation)
- TUI startup/runtime path refactor.
- Command service integration wiring.
- Main test additions and fixes.
claude-opus-4.6(complex reasoning/architecture)
- Control-plane boundary validation.
- Failure-mode handling for auto-start/attach behavior.
- Final architecture/doc consistency review.
Risks and Mitigations
-
Risk: Regressing local
/backendbehavior while unifying runtime path.
Mitigation: explicit tests for local-tier backend commands before/after refactor. -
Risk: Startup race conditions during auto-start attach.
Mitigation: bounded retry loop, deterministic backoff, explicit timeout errors. -
Risk: Command-output drift across channels.
Mitigation: golden-style assertions for runtime command outputs.
Defaults Locked
- Architecture: gateway-first control plane (OpenClaw-style).
- TUI behavior:
/runtimeglobal control via daemon service. - Compatibility: keep
/backendlocal-only in TUI forllamacpp/ollama. - Delivery: staged atomic commits; final report after full implementation.