Skip to content

TUI architecture

ainb is a Cargo workspace rooted at ainb-tui/. The TUI application and CLI live in the ainb-core crate; the rest of the workspace is the v2 plugin platform (runtime, SDK, reference plugins, conformance + test tooling).

Workspace crates

34 members, declared in ainb-tui/Cargo.toml. default-members is ["crates/ainb-core", "crates/ainb-hangar-daemon"], so a bare cargo build produces the TUI and the Hangar daemon.

The host

CrateRole
ainb-coreThe TUI app and the ainb binary: screens, event loop, session, git, tmux and provider integration.
ainb-cliThe skill-manager CLI (ainb skill, source, search), routed before the async runtime starts.
ainb-webRead-only SSE web dashboard over the fleet.
xtaskWorkspace automation: builds canary plugins and release helpers.

Plugin platform

CrateRole
ainb-plugin-protocolWire types: JSON-RPC 2.0 envelopes, Content-Length framing, error codes.
ainb-plugin-runtimeHost side: subprocess spawn, lifecycle FSM, snapshot and action bus, capability gate.
ainb-plugin-sdk-rustRust SDK for writing a plugin.
ainb-plugin-testkitIn-process harness so a plugin author can test without a subprocess.
ainb-plugin-cts-v2Conformance suite: 18 numbered axes plus 3 canaries, 21 in total.
ainb-plugin-types-sessionsShared session schema exposed across the wire.

In-tree plugins

Six, staged into dist/plugins/<id>/ by scripts/build-plugins.sh.

CratePlugin idRole
ainb-plugin-burndownburndownUsage and cost analytics; owns the Stats screen and ainb usage.
ainb-plugin-session-readersession-readerSilent publisher: walks provider logs, feeds burndown.
ainb-plugin-witrwitrProcess-causality tracing; wraps the external witr binary.
ainb-plugin-abtopabtopLive agent-process monitor; wraps the external abtop binary.
ainb-plugin-learningslearningsBrowse, search and graph the knowledge base.
ainb-plugin-hangarhangar-tuiThe Hangar screen; a client of the Hangar daemon.

ainb-plugin-notifyd is not a plugin despite the crate name. It builds the ainb-notifyd daemon, which listens on a Unix socket and writes to SQLite; the Inbox screen reads that store. It has no plugin manifest and speaks no plugin ABI.

Hangar

Seven crates behind the managed-agents control plane.

CrateRole
ainb-hangar-coreIO-free domain types: actors, ids, task status, clock.
ainb-hangar-protoThe daemon’s JSON-RPC surface; ALL_METHODS is the registry.
ainb-hangar-storeSQLite pool, embedded migrations, repository wrappers.
ainb-hangar-clientThe one client onto the daemon’s socket.
ainb-hangar-daemonThe control plane itself: scheduler, task FSM, agent runner.
ainb-hangar-sandboxFilesystem-confined spawn wrapper (Seatbelt on macOS).
ainb-hangar-secretsRead/write bridge onto the OS keychain.

Fleet, skills and support

CrateRole
ainb-fleet-coreSession discovery, needs classification, verified tmux delivery.
ainb-fleet-toolsPal’s MCP tool server.
ainb-acpAgent Client Protocol client, transcript reducer, store writer.
ainb-skill-coreManifest-driven install, sync and removal of skills and agents.
ainb-adapters-sourceWhere units come from: git, local, marketplace.
ainb-adapters-toolWhere units go: the nine tool homes.
ainb-diffConfirm-diff rendering for the skill installer.
ainb-fetchShared HTTP fetch with caching.
ainb-usageUsage and cost primitives shared by burndown and fleet cost.
ainb-model-ratesPer-model pricing tables.

Rust edition 2021, unsafe_code forbidden. Regenerate the counts above with cargo metadata --no-deps.

ainb-core module tree

App code lives under ainb-tui/crates/ainb-core/src/:

crates/ainb-core/src/
├── main.rs # Entry point, CLI parsing, TUI loop
├── lib.rs # Crate exports
├── app/ # App state machine + event handling (state.rs, events.rs)
├── components/ # TUI screens (session_list, git_view, logs_viewer, home_screen, …)
├── widgets/ # Reusable UI widgets
├── cli/ # Non-interactive subcommand implementations
├── fleet/ # `ainb fleet` orchestration (standup/broadcast/sequence/needs/daemon)
├── providers/ # Multi-provider (claude/codex/gemini/copilot) abstractions
├── claude/ # Claude API client
├── docker/ # Container management
├── tmux/ # Tmux / PTY integration
├── git/ # Git + worktree operations
├── config/ # Configuration loading
├── models/ # Data models
├── agents/ # Agent registry
├── agent_parsers/ # Parse agent output
├── interactive/ # Interactive-mode helpers
├── usage_cache/ # Persistent usage-analytics cache
├── audit.rs # Audit helpers
├── credentials.rs # Credential storage
├── editors.rs # Editor integration
└── plugins.rs # Plugin install/management CLI surface

Plugin runtime

ainb-plugin-runtime is the host-side supervisor that loads v2 plugins as native subprocess binaries speaking JSON-RPC over stdio (the ainb-plugin-protocol types). Authors build against ainb-plugin-sdk-rust and validate with ainb-plugin-testkit and the ainb-plugin-cts-v2 conformance suite. The three in-tree reference plugins: burndown (analytics), notifyd (notifications), and session-reader (data backend): double as worked examples. Install and inspect plugins via ainb plugin install|list|lint|watch|tail (see the CLI reference).

Style guide

Components follow the shared palette in .claude/skills/tui-screen/SKILL.md: cornflower-blue borders (Rgb(100,149,237)), gold titles/CTAs (Rgb(255,215,0)), green active state (Rgb(100,200,100)), BorderType::Rounded on all panels, a ▶ selection indicator, and a gold-keys / muted-descriptions bottom help bar.

Testing surface

Tests live under crates/ainb-core/tests/:

  • Unit + model tests: test_app_state.rs, test_events.rs, test_session_model.rs, etc.
  • Behavioral: behavioral.rs and the behavioral/ suite.
  • E2E PTY: e2e_pty_tests.rs, interactive_mode_tests.rs (real PTY drive).
  • Tripwires: tripwire_*.rs tmux-driven end-to-end screen assertions (burndown, inbox, crash recovery, new-session, …).

See also