How elleryfamilia/mix2 works
Purpose and Entrypoints
mix2 is a Unix terminal collaboration app: one coordinating coding-agent session produces a team answer after consulting a second, independent agent. The user command launches a TypeScript/Ink TUI which starts and communicates with a Rust runtime over JSONL. Primary runtime entrypoints are apps/tui/src/cli.tsx, crates/mix2-core/src/main.rs, and the consultation helper binary crates/mix2-core/src/bin/mix2_consult.rs.
TUI, Interaction, and Presentation
The Node.js 22+ TUI owns terminal input, rendering, navigation, slash commands, local display state, and update prompting; it does not manage providers directly. apps/tui/src/components/App.tsx composes conversation, composer, header, status, and activity/team views. apps/tui/src/state/store.ts consumes core events into UI state, while apps/tui/src/render/conversation.ts and apps/tui/src/render/markdown.ts convert streamed content to terminal lines. apps/tui/src/ipc/client.ts is the JSONL process client boundary to Rust.
Rust Runtime and Session Ownership
The Rust core owns all authoritative execution state: configured team, session identity, turn lifecycle, agent process handles, cancellation, consultation budgets, and temporary IPC state. crates/mix2-core/src/runtime.rs orchestrates startup and turn execution; crates/mix2-core/src/session/state.rs tracks session/turn state; crates/mix2-core/src/ipc/commands.rs and crates/mix2-core/src/ipc/events.rs define the TUI-core contract. Runtime state is transient under /tmp/mix2/<session>/; prompts and agent streams cross the TUI boundary as JSONL.
Agent Harness Layer
Providers are pluggable descriptors plus stream decoders and command builders. crates/mix2-core/src/agents/registry.rs selects registered harnesses and validates role capabilities, while crates/mix2-core/src/agents/discovery.rs probes installed/authenticated CLIs at startup. Provider-specific integration lives in crates/mix2-core/src/agents/claude.rs, crates/mix2-core/src/agents/codex.rs, with parallel adapters for Cursor, OpenCode, and Copilot. This boundary normalizes heterogeneous CLI output into agent events without exposing provider protocol details upstream.
Collaboration Pipeline
For substantive turns, the coordinator receives the user prompt and invokes the consult helper. The core creates an independent, unanchored brief for the teammate, starts work concurrently, then returns results for reconciliation into one attributed answer. crates/mix2-core/src/collaboration/consult.rs implements start/wait coordination; crates/mix2-core/src/collaboration/prompts.rs defines collaboration instructions; crates/mix2-core/src/collaboration/disagreement.rs captures disclosed disagreement. crates/mix2-core/src/collaboration/limits.rs atomically enforces per-turn consult quotas and prevents recursive consultation.
Process, IPC, and Security Boundaries
Agent CLIs are child processes with streaming output and process-group cancellation, managed by crates/mix2-core/src/process/child.rs and crates/mix2-core/src/agents/runner.rs. The consult service uses a Unix socket, with a file-mailbox fallback for sandboxed Codex environments, implemented under crates/mix2-core/src/ipc/mod.rs. Per-turn capability tokens authorize consultation requests. crates/mix2-core/src/sandbox.rs applies macOS Seatbelt or Linux bubblewrap where native provider controls cannot constrain writes/read-only consultation.
Configuration, Delivery, and External Dependencies
crates/mix2-core/src/config.rs resolves CLI flags, slot-based and legacy TOML configuration, provider command overrides, models, and coordinator selection. The system relies on locally installed Claude, Codex, Cursor, OpenCode, or Copilot CLIs and their existing authentication; no hosted mix2 backend is implied. Release installation is shell-based via install.sh; TUI self-update logic uses GitHub release access in apps/tui/src/update/github.ts and installation flow in apps/tui/src/update/flow.ts.
Main entry points: runtime.rs Runtime orchestration · cli.tsx TUI CLI entrypoint · consult.rs Consult coordination · runner.rs Agent stream runner
Components 21
Terminal TUI
- TUI CLI entrypoint
apps/tui/src/cli.tsx - App composition · Composes conversation, composer, header, status, and team views.
apps/tui/src/components/App.tsx - UI event state
apps/tui/src/state/store.ts - Terminal rendering · Converts streamed conversation and Markdown into terminal lines.
apps/tui/src/render/conversation.ts - Core JSONL client
apps/tui/src/ipc/client.ts
Rust Core
- Core entrypoint
crates/mix2-core/src/main.rs - Runtime orchestration · Owns startup, turn execution, processes, cancellation, and temporary IPC.
crates/mix2-core/src/runtime.rs - Session and turn state
crates/mix2-core/src/session/state.rs - TUI-core contract
crates/mix2-core/src/ipc/commands.rs - Configuration resolution · Resolves flags, TOML, models, command overrides, and coordinator.
crates/mix2-core/src/config.rs - Provider sandboxing · Applies Seatbelt or bubblewrap when provider controls are insufficient.
crates/mix2-core/src/sandbox.rs
Agent Harnesses
- Harness selection · Validates roles and selects registered provider harnesses.
crates/mix2-core/src/agents/registry.rs - CLI discovery · Checks installed and authenticated provider CLIs at startup.
crates/mix2-core/src/agents/discovery.rs - Agent stream runner · Normalizes provider streams into agent events.
crates/mix2-core/src/agents/runner.rs
Consultation
- Consult coordination · Creates an independent brief, runs teammate work, and returns it for reconciliation.
crates/mix2-core/src/collaboration/consult.rs - Consult helper binary
crates/mix2-core/src/bin/mix2_consult.rs - Consult limits and token auth · Enforces quotas, blocks recursion, and authorizes per-turn requests.
crates/mix2-core/src/collaboration/limits.rs - Consult IPC transport · Uses a Unix socket with a file-mailbox fallback.
crates/mix2-core/src/ipc/mod.rs
Local & Release Dependencies
- Provider CLIs · Claude, Codex, Cursor, OpenCode, or Copilot with existing authentication.
- GitHub release updates · TUI checks releases and drives installation updates.
apps/tui/src/update/github.ts
Other components
- User terminal
Connections 23
- User terminal → TUI CLI entrypoint: launches
- TUI CLI entrypoint → App composition: renders
- App composition → UI event state: reads state
- UI event state → Terminal rendering: streams content
- TUI CLI entrypoint → Core JSONL client: sends prompts
- Core JSONL client → Core entrypoint: JSONL process I/O
- Core entrypoint → Runtime orchestration: starts
- Runtime orchestration → TUI-core contract: emits events
- TUI-core contract → UI event state: JSONL events
- Runtime orchestration → Session and turn state: owns
- Runtime orchestration → Configuration resolution: resolves setup
- Runtime orchestration → CLI discovery: probes at startup
- Runtime orchestration → Harness selection: selects roles
- Harness selection → Agent stream runner: provides harness
- Agent stream runner → Provider sandboxing: constrains execution
- Agent stream runner → Provider CLIs: spawns and decodes
- Runtime orchestration → Consult coordination: substantive turns
- Consult coordination → Consult limits and token auth: checks quota and token
- Consult coordination → Consult helper binary: invokes teammate
- Consult helper binary → Consult IPC transport: consult request
- Consult IPC transport → Agent stream runner: independent agent work
- Consult coordination → Runtime orchestration: results for reconciliation
- TUI CLI entrypoint → GitHub release updates: checks updates