Expand description
UI ↔ runtime contract.
Tracking: issue #274 of the workspace-refactor epic (#279).
The TUI today reaches deep into brain / coord / bus / rules internals. This
module defines the read-only boundary it should reach through instead,
so a future claudectl-tui crate (#275) can be extracted and iterated on
without recompiling brain or the bus.
§Why traits, why core-owned DTOs
Each view is a trait, not a concrete struct, so:
- The binary crate can hand the TUI a real implementation backed by SQLite / the engine / the bus DB. A future remote frontend can hand it an HTTP client. Tests hand it a fixture.
- Adding a method to a trait is a contract change reviewable in one PR; adding a method to a concrete struct ripples through every caller.
Each DTO (SessionSnapshot, LeaseSummary, …) is owned by core so the
traits don’t drag brain::DecisionRecord / coord::Lease upward into the
TUI’s dependency surface. Conversion happens once, in the wrapper.
§What’s in scope here
Read-only views only. Side-effecting paths (terminate_session,
inject_prompt, log_decision) deserve a separate Actions trait once
the TUI’s write surface is mapped. Adding it speculatively now would
violate the “only add methods existing call sites need” rule the epic
committed to.
§What’s NOT in scope
- The TUI doesn’t yet call through these traits — that’s #275.
- Brain’s review/scorecard surface — it’s heavier and worth its own trait once #275 stabilizes the basic shape.
- Pub/sub claim protocol — #283 builds on top of these traits, not the other way around.
Structs§
- Agent
Directory Entry - Decision
Summary - A single past brain decision, projected for display.
- Handoff
Summary - Hive
View Snapshot - Snapshot of local hive state the overlay reads to render the Hive tab.
- Interrupt
Summary - Lease
Summary - LogDecision
Input - What the TUI needs to record when the user resolves a brain suggestion. Carries the suggestion that was on screen at the time, plus what the user did and (optionally) why they overrode the brain.
- Mock
Runtime - In-memory runtime backed by
Vecs and interior-mutable counters. Used by tests in this crate to verify the trait shapes compile and roundtrip cleanly, and by the futureclaudectl-tuicrate’s tests to render the TUI against fixtures without dragging in brain / coord / bus. - Observation
Input - What the TUI needs to record alongside a user action. Core-owned so the
trait doesn’t drag
brain::decisions::log_observation’s argument list upward into the TUI surface. - Pending
Suggestion - One pending brain suggestion the user can accept or reject. Mirrors the
binary’s
brain::client::BrainSuggestionwithout exposing brain types. - Review
Item Summary - One entry in the Brain Review queue — a decision worth showing the operator for canonical-marking review, with a reason and a priority score.
- Role
Binding - Runtime
- Single struct the binary builds at startup and hands to the TUI.
- Session
Snapshot - One running Claude Code session, as observed by the runtime. Minimal
projection of the binary-crate
ClaudeSession; only fields the TUI renders.
Enums§
- Brain
Gate Mode - Mirrors the binary’s
brain::GateModewithout depending on the brain crate. Persisted as the lowercased label. - Decision
Scope - Whether a decision was about a session or about an orchestration task.
Mirrors
brain::decisions::DecisionTypewithout depending on it. - Mock
Action - Recorded
Actionscalls. Tests use this to assert side-effect ordering without needing a real terminal or filesystem.
Traits§
- Actions
- Side-effecting paths the TUI invokes when the user takes an action (terminating a session, sending a prompt, flipping the brain mode, recording an observation, marking a decision canonical for teaching).
- Brain
Driver - Stateful brain orchestration. Unlike the read-only views, this needs
&mutper tick — the engine accumulates pending suggestions, cleans up after exited sessions, and applies user accept/reject decisions. - Brain
Review View - Read access to the Brain Review surface — the full decision log plus the
review-queue projection. Separate trait from
BrainViewbecause: - Brain
View - Read access to the brain’s decision history and current mode.
- BusView
- Read access to the agent-bus roster + role table. Disabled implementations
(
busfeature off in the binary) return empty vectors so the TUI can render the panel as “no bus” without conditional compilation. - Coord
View - Read access to coordination state (leases, handoffs, interrupts).
Backed today by the
coordSQLite store; in tests, by a fixture. - Hive
Actions - Hive + relay surface the TUI needs to render the Skills and Hive panels.
- Orchestrator
- Tick the orchestration layer once per refresh: deliver pending mailbox messages, deliver pending coordination interrupts, and bookkeep stale rows in the underlying stores.
- Session
Source - Read access to the live session roster.