# elleryfamilia/mix2 architecture

> Architecture diagram of the GitHub repository elleryfamilia/mix2, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/elleryfamilia/mix2
- Repository: https://github.com/elleryfamilia/mix2

## Overview

#### 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: [`crates/mix2-core/src/runtime.rs`](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/runtime.rs) (Runtime orchestration), [`apps/tui/src/cli.tsx`](https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/cli.tsx) (TUI CLI entrypoint), [`crates/mix2-core/src/collaboration/consult.rs`](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/collaboration/consult.rs) (Consult coordination), [`crates/mix2-core/src/agents/runner.rs`](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/agents/runner.rs) (Agent stream runner)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_tui["Terminal TUI"]
  node_tui_cli["TUI CLI entrypoint<br/>TypeScript/Ink<br/>[cli.tsx]"]
  node_app["App composition<br/>Ink UI<br/>[App.tsx]"]
  node_ui_store["UI event state<br/>state store<br/>[store.ts]"]
  node_rendering["Terminal rendering<br/>renderer<br/>[conversation.ts]"]
  node_ipc_client["Core JSONL client<br/>process IPC<br/>[client.ts]"]
end

subgraph group_core["Rust Core"]
  node_core_main["Core entrypoint<br/>Rust binary<br/>[main.rs]"]
  node_runtime["Runtime orchestration<br/>session runtime<br/>[runtime.rs]"]
  node_session_state[("Session and turn state<br/>authoritative state<br/>[state.rs]")]
  node_ipc_contract["TUI-core contract<br/>JSONL commands/events<br/>[commands.rs]"]
  node_config["Configuration resolution<br/>[config.rs]"]
  node_sandbox["Provider sandboxing<br/>execution boundary<br/>[sandbox.rs]"]
end

subgraph group_agents["Agent Harnesses"]
  node_harness_registry["Harness selection<br/>agent registry<br/>[registry.rs]"]
  node_discovery["CLI discovery<br/>provider probe<br/>[discovery.rs]"]
  node_agent_runner["Agent stream runner<br/>process runner<br/>[runner.rs]"]
end

subgraph group_collab["Consultation"]
  node_consult["Consult coordination<br/>collaboration pipeline<br/>[consult.rs]"]
  node_consult_helper["Consult helper binary<br/>Rust binary<br/>[mix2_consult.rs]"]
  node_consult_guards["Consult limits and token auth<br/>security controls<br/>[limits.rs]"]
  node_consult_ipc["Consult IPC transport<br/>Unix socket/mailbox<br/>[mod.rs]"]
end

subgraph group_external["Local &amp; Release Dependencies"]
  node_agent_clis{{"Provider CLIs<br/>local executables"}}
  node_github_updates{{"GitHub release updates<br/>release service<br/>[github.ts]"}}
end

node_user(("User terminal<br/>actor"))

node_user -->|"launches"| node_tui_cli
node_tui_cli -->|"renders"| node_app
node_app -->|"reads state"| node_ui_store
node_ui_store -->|"streams content"| node_rendering
node_tui_cli -->|"sends prompts"| node_ipc_client
node_ipc_client -->|"JSONL process I/O"| node_core_main
node_core_main -->|"starts"| node_runtime
node_runtime -->|"emits events"| node_ipc_contract
node_ipc_contract -->|"JSONL events"| node_ui_store
node_runtime -->|"owns"| node_session_state
node_runtime -->|"resolves setup"| node_config
node_runtime -->|"probes at startup"| node_discovery
node_runtime -->|"selects roles"| node_harness_registry
node_harness_registry -->|"provides harness"| node_agent_runner
node_agent_runner -->|"constrains execution"| node_sandbox
node_agent_runner -->|"spawns and decodes"| node_agent_clis
node_runtime -->|"substantive turns"| node_consult
node_consult -->|"checks quota and token"| node_consult_guards
node_consult -->|"invokes teammate"| node_consult_helper
node_consult_helper -->|"consult request"| node_consult_ipc
node_consult_ipc -->|"independent agent work"| node_agent_runner
node_consult -->|"results for reconciliation"| node_runtime
node_tui_cli -.->|"checks updates"| node_github_updates

click node_tui_cli "https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/cli.tsx"
click node_app "https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/components/App.tsx"
click node_ui_store "https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/state/store.ts"
click node_rendering "https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/render/conversation.ts"
click node_ipc_client "https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/ipc/client.ts"
click node_core_main "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/main.rs"
click node_runtime "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/runtime.rs"
click node_session_state "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/session/state.rs"
click node_ipc_contract "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/ipc/commands.rs"
click node_config "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/config.rs"
click node_harness_registry "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/agents/registry.rs"
click node_discovery "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/agents/discovery.rs"
click node_agent_runner "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/agents/runner.rs"
click node_consult "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/collaboration/consult.rs"
click node_consult_helper "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/bin/mix2_consult.rs"
click node_consult_guards "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/collaboration/limits.rs"
click node_consult_ipc "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/ipc/mod.rs"
click node_sandbox "https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/sandbox.rs"
click node_github_updates "https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/update/github.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_tui_cli,node_app,node_ui_store,node_rendering,node_ipc_client toneBlue
class node_core_main,node_runtime,node_session_state,node_ipc_contract,node_config,node_sandbox toneAmber
class node_harness_registry,node_discovery,node_agent_runner toneMint
class node_consult,node_consult_helper,node_consult_guards,node_consult_ipc toneRose
class node_agent_clis,node_github_updates toneIndigo
class node_user toneNeutral
```

## Components

### Terminal TUI

- [TUI CLI entrypoint](https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/cli.tsx): TypeScript/Ink · `apps/tui/src/cli.tsx`
- [App composition](https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/components/App.tsx): Ink UI · Composes conversation, composer, header, status, and team views. · `apps/tui/src/components/App.tsx`
- [UI event state](https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/state/store.ts): state store · `apps/tui/src/state/store.ts`
- [Terminal rendering](https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/render/conversation.ts): renderer · Converts streamed conversation and Markdown into terminal lines. · `apps/tui/src/render/conversation.ts`
- [Core JSONL client](https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/ipc/client.ts): process IPC · `apps/tui/src/ipc/client.ts`

### Rust Core

- [Core entrypoint](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/main.rs): Rust binary · `crates/mix2-core/src/main.rs`
- [Runtime orchestration](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/runtime.rs): session runtime · Owns startup, turn execution, processes, cancellation, and temporary IPC. · `crates/mix2-core/src/runtime.rs`
- [Session and turn state](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/session/state.rs): authoritative state · `crates/mix2-core/src/session/state.rs`
- [TUI-core contract](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/ipc/commands.rs): JSONL commands/events · `crates/mix2-core/src/ipc/commands.rs`
- [Configuration resolution](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/config.rs): config · Resolves flags, TOML, models, command overrides, and coordinator. · `crates/mix2-core/src/config.rs`
- [Provider sandboxing](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/sandbox.rs): execution boundary · Applies Seatbelt or bubblewrap when provider controls are insufficient. · `crates/mix2-core/src/sandbox.rs`

### Agent Harnesses

- [Harness selection](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/agents/registry.rs): agent registry · Validates roles and selects registered provider harnesses. · `crates/mix2-core/src/agents/registry.rs`
- [CLI discovery](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/agents/discovery.rs): provider probe · Checks installed and authenticated provider CLIs at startup. · `crates/mix2-core/src/agents/discovery.rs`
- [Agent stream runner](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/agents/runner.rs): process runner · Normalizes provider streams into agent events. · `crates/mix2-core/src/agents/runner.rs`

### Consultation

- [Consult coordination](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/collaboration/consult.rs): collaboration pipeline · Creates an independent brief, runs teammate work, and returns it for reconciliation. · `crates/mix2-core/src/collaboration/consult.rs`
- [Consult helper binary](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/bin/mix2_consult.rs): Rust binary · `crates/mix2-core/src/bin/mix2_consult.rs`
- [Consult limits and token auth](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/collaboration/limits.rs): security controls · Enforces quotas, blocks recursion, and authorizes per-turn requests. · `crates/mix2-core/src/collaboration/limits.rs`
- [Consult IPC transport](https://github.com/elleryfamilia/mix2/blob/main/crates/mix2-core/src/ipc/mod.rs): Unix socket/mailbox · Uses a Unix socket with a file-mailbox fallback. · `crates/mix2-core/src/ipc/mod.rs`

### Local & Release Dependencies

- **Provider CLIs**: local executables · Claude, Codex, Cursor, OpenCode, or Copilot with existing authentication.
- [GitHub release updates](https://github.com/elleryfamilia/mix2/blob/main/apps/tui/src/update/github.ts): release service · TUI checks releases and drives installation updates. · `apps/tui/src/update/github.ts`

### Other components

- **User terminal**: actor

## Connections

- 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
