# b-nnett/grok-bot-0.18-reconstructed architecture

> Architecture diagram of the GitHub repository b-nnett/grok-bot-0.18-reconstructed, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/b-nnett/grok-bot-0.18-reconstructed
- Repository: https://github.com/b-nnett/grok-bot-0.18-reconstructed

## Overview

#### Purpose and delivery model
Unofficial reconstruction of Grok Bot 0.18.0 for macOS/Apple Silicon. It rebuilds desktop/runtime control planes from TypeScript while preserving a checksum-pinned upstream renderer and applying a narrow Router-settings patch. Packaging produces a separately identified, ad-hoc-signed app.
- `scripts/bootstrap-runtime.mjs`
- `scripts/package-macos.mjs`
- `scripts/lib/router-renderer-patch.mjs`

#### Runtime entry points
Electron main owns application lifecycle and desktop services; preload exposes constrained renderer bridges; the coordinator and host run the agent/control plane. A separate daemon supports local execution.
- `source/electron-main/main.ts`
- `source/electron-preload/preload.ts`
- `source/node-agent-coordinator/main.ts`
- `source/host/main.ts`
- `source/local-exec-daemon/main.ts`

#### Desktop boundary and control plane
Renderer calls cross the Electron trust boundary through preload RPC/port bridges into Electron main. Main wires settings, auth/secrets, update policy, box connectivity, coordinator lifecycle, and native integrations; it should remain the authority for privileged OS access.
- `source/electron-preload/main-rpc-runtime.ts`
- `source/electron-preload/coordinator-port-bridge.ts`
- `source/electron-main/main-edge-wiring.ts`
- `source/electron-main/coordinator/coordinator-launcher.ts`

#### Renderer surfaces
The shipped renderer is production baseline; `frontend/` is a readable partial React/TypeScript reconstruction. Its production bootstrap renders conversation, roster/sidebar, command palette, and Router-related settings through coordinator-facing models.
- `frontend/src/main.tsx`
- `frontend/src/production/bootstrap.tsx`
- `frontend/src/production/ProductionRenderer.tsx`
- `frontend/src/recovered/features/conversation/workspace/view.tsx`
- `frontend/src/recovered/features/settings/overlay/router.ts`

#### Coordinator, gateway, and streaming
The coordinator mediates renderer traffic, host supervision, remote gateway requests/SSE, routed MCP calls, local-exec supervision, and inference dispatch. It is the transport boundary between desktop processes and host execution.
- `source/node-agent-coordinator/renderer-port-server.ts`
- `source/node-agent-coordinator/gateway/gateway-request-dispatcher.ts`
- `source/node-agent-coordinator/inference-router.ts`
- `source/node-agent-coordinator/routed-mcp-bridge.ts`

#### Host: durable agent state and turn execution
The host composes extensions around persisted sessions/transcripts, then turns accepted messages into scheduled agent runs. The runner assembles prompts, selects tools, invokes model inference, and emits transcript/tool-result events back through the coordinator. SQLite/blob-backed storage and worker isolation support local durability.
- `source/host/host-runner-composition.ts`
- `source/host/extensions/session/session-materialization.ts`
- `source/host/extensions/transcript/send-pipeline.ts`
- `source/host/runner/turn-agent-composition.ts`
- `source/host/storage/store-db.ts`

#### Inference, tools, sandbox, and external services
Inference can route to Cursor, Claude Code, Codex, or OpenRouter; tool execution supports Grok Bot tools, MCP plugins, shell/files, subagents, and computer use. The default box path is remote; an optional Docker-backed local box runs a host and execution daemon on loopback. OAuth/account sessions, MCP servers/marketplace, provider APIs, Docker, VNC, telemetry/Sentry, and OS notifications are material integrations.
- `source/shared/node/inference-router-local.ts`
- `source/host/extensions/inference/inference-service.ts`
- `source/host/extensions/mcp/mcp-service.ts`
- `source/electron-main/box/local-docker-host-connector.ts`
- `source/host/box/loopback-sand-box.ts`
- `source/packages/shell-exec/sandbox/sandbox.ts`

Main entry points: [`source/node-agent-coordinator/main.ts`](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/node-agent-coordinator/main.ts) (Agent coordinator), [`frontend/src/production/ProductionRenderer.tsx`](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/frontend/src/production/ProductionRenderer.tsx) (Production renderer), [`source/host/runner/turn-agent-composition.ts`](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/runner/turn-agent-composition.ts) (Turn agent runner), [`source/electron-main/main-edge-wiring.ts`](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-main/main-edge-wiring.ts) (Main edge wiring)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_build["Build &amp; Packaging"]
  node_bootstrap["Runtime bootstrap<br/>build script"]
  node_package["macOS packager<br/>build script<br/>[package-macos.mjs]"]
end

subgraph group_desktop["Desktop Runtime"]
  node_electron_main["Electron main<br/>desktop authority<br/>[main.ts]"]
  node_main_wiring["Main edge wiring<br/>control-plane wiring"]
  node_preload["Preload bridge<br/>trust boundary<br/>[preload.ts]"]
  node_renderer_rpc["Renderer RPC runtime<br/>preload RPC"]
  node_port_bridge["Coordinator port bridge<br/>preload port bridge"]
end

subgraph group_renderer["Renderer"]
  node_production_renderer["Production renderer<br/>renderer UI"]
  node_recovered_conversation["Conversation workspace<br/>recovered React surface<br/>[view.tsx]"]
  node_router_settings["Router settings<br/>recovered React surface<br/>[router.ts]"]
end

subgraph group_control["Coordinator &amp; Host"]
  node_coordinator["Agent coordinator<br/>desktop transport boundary<br/>[main.ts]"]
  node_renderer_port_server["Renderer port server<br/>coordinator transport"]
  node_gateway["Remote gateway dispatcher<br/>gateway / SSE"]
  node_host["Agent host<br/>durable agent runtime<br/>[main.ts]"]
  node_send_pipeline["Message send pipeline<br/>transcript pipeline<br/>[send-pipeline.ts]"]
  node_turn_runner["Turn agent runner<br/>agent execution"]
  node_durable_store[("Session &amp; transcript store<br/>SQLite/blob storage<br/>[store-db.ts]")]
end

subgraph group_execution["Execution &amp; Integrations"]
  node_inference["Inference routing<br/>provider dispatch"]
  node_mcp_tools["MCP &amp; tool service<br/>tool integration<br/>[mcp-service.ts]"]
  node_local_box["Local Docker box<br/>optional sandbox path"]
  node_local_daemon["Local execution daemon<br/>[main.ts]"]
  node_sandbox["Shell execution sandbox<br/>sandbox runtime<br/>[sandbox.ts]"]
end

node_bootstrap -->|"pins and patches"| node_production_renderer
node_bootstrap -->|"prepares runtime"| node_package
node_package -->|"packages"| node_electron_main
node_production_renderer -->|"renders"| node_recovered_conversation
node_production_renderer -->|"renders"| node_router_settings
node_production_renderer -->|"privileged calls"| node_preload
node_preload -->|"main RPC"| node_renderer_rpc
node_renderer_rpc -->|"crosses trust boundary"| node_electron_main
node_preload -->|"coordinator port"| node_port_bridge
node_port_bridge -->|"connects"| node_renderer_port_server
node_renderer_port_server -->|"renderer traffic"| node_coordinator
node_electron_main -->|"wires services"| node_main_wiring
node_main_wiring -->|"supervises lifecycle"| node_coordinator
node_coordinator -->|"remote requests and SSE"| node_gateway
node_coordinator -->|"supervises"| node_host
node_host -->|"accepted messages"| node_send_pipeline
node_send_pipeline -->|"schedules turns"| node_turn_runner
node_host -->|"persists state"| node_durable_store
node_turn_runner -->|"invokes models"| node_inference
node_turn_runner -->|"selects tools"| node_mcp_tools
node_turn_runner -->|"transcript and tool events"| node_coordinator
node_main_wiring -.->|"optional local path"| node_local_box
node_local_box -->|"loopback execution"| node_local_daemon
node_local_daemon -->|"runs commands"| node_sandbox

click node_bootstrap "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/scripts/bootstrap-runtime.mjs"
click node_package "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/scripts/package-macos.mjs"
click node_electron_main "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-main/main.ts"
click node_main_wiring "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-main/main-edge-wiring.ts"
click node_preload "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-preload/preload.ts"
click node_renderer_rpc "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-preload/main-rpc-runtime.ts"
click node_port_bridge "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-preload/coordinator-port-bridge.ts"
click node_production_renderer "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/frontend/src/production/ProductionRenderer.tsx"
click node_recovered_conversation "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/frontend/src/recovered/features/conversation/workspace/view.tsx"
click node_router_settings "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/frontend/src/recovered/features/settings/overlay/router.ts"
click node_coordinator "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/node-agent-coordinator/main.ts"
click node_renderer_port_server "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/node-agent-coordinator/renderer-port-server.ts"
click node_gateway "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/node-agent-coordinator/gateway/gateway-request-dispatcher.ts"
click node_host "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/main.ts"
click node_send_pipeline "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/extensions/transcript/send-pipeline.ts"
click node_turn_runner "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/runner/turn-agent-composition.ts"
click node_durable_store "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/storage/store-db.ts"
click node_inference "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/extensions/inference/inference-service.ts"
click node_mcp_tools "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/extensions/mcp/mcp-service.ts"
click node_local_box "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-main/box/local-docker-host-connector.ts"
click node_local_daemon "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/local-exec-daemon/main.ts"
click node_sandbox "https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/packages/shell-exec/sandbox/sandbox.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_bootstrap,node_package toneBlue
class node_electron_main,node_main_wiring,node_preload,node_renderer_rpc,node_port_bridge toneAmber
class node_production_renderer,node_recovered_conversation,node_router_settings toneMint
class node_coordinator,node_renderer_port_server,node_gateway,node_host,node_send_pipeline,node_turn_runner,node_durable_store toneRose
class node_inference,node_mcp_tools,node_local_box,node_local_daemon,node_sandbox toneIndigo
```

## Components

### Build & Packaging

- [Runtime bootstrap](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/scripts/bootstrap-runtime.mjs): build script · Pins the upstream renderer and applies the Router settings patch. · `scripts/bootstrap-runtime.mjs`
- [macOS packager](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/scripts/package-macos.mjs): build script · Produces the separately identified ad-hoc-signed app. · `scripts/package-macos.mjs`

### Desktop Runtime

- [Electron main](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-main/main.ts): desktop authority · Owns lifecycle, privileged OS access, desktop services, and control-plane wiring. · `source/electron-main/main.ts`
- [Main edge wiring](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-main/main-edge-wiring.ts): control-plane wiring · Connects settings, auth, updates, box connectivity, and native integrations. · `source/electron-main/main-edge-wiring.ts`
- [Preload bridge](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-preload/preload.ts): trust boundary · Exposes constrained renderer RPC and port bridges. · `source/electron-preload/preload.ts`
- [Renderer RPC runtime](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-preload/main-rpc-runtime.ts): preload RPC · `source/electron-preload/main-rpc-runtime.ts`
- [Coordinator port bridge](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-preload/coordinator-port-bridge.ts): preload port bridge · `source/electron-preload/coordinator-port-bridge.ts`

### Renderer

- [Production renderer](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/frontend/src/production/ProductionRenderer.tsx): renderer UI · Production bootstrap for conversation, roster, commands, and settings. · `frontend/src/production/ProductionRenderer.tsx`
- [Conversation workspace](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/frontend/src/recovered/features/conversation/workspace/view.tsx): recovered React surface · `frontend/src/recovered/features/conversation/workspace/view.tsx`
- [Router settings](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/frontend/src/recovered/features/settings/overlay/router.ts): recovered React surface · Narrowly patched settings surface. · `frontend/src/recovered/features/settings/overlay/router.ts`

### Coordinator & Host

- [Agent coordinator](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/node-agent-coordinator/main.ts): desktop transport boundary · Mediates renderer traffic, host supervision, gateway, MCP, local execution, and inference. · `source/node-agent-coordinator/main.ts`
- [Renderer port server](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/node-agent-coordinator/renderer-port-server.ts): coordinator transport · `source/node-agent-coordinator/renderer-port-server.ts`
- [Remote gateway dispatcher](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/node-agent-coordinator/gateway/gateway-request-dispatcher.ts): gateway / SSE · `source/node-agent-coordinator/gateway/gateway-request-dispatcher.ts`
- [Agent host](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/main.ts): durable agent runtime · Composes session, transcript, inference, and tool extensions. · `source/host/main.ts`
- [Message send pipeline](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/extensions/transcript/send-pipeline.ts): transcript pipeline · Turns accepted messages into scheduled agent runs. · `source/host/extensions/transcript/send-pipeline.ts`
- [Turn agent runner](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/runner/turn-agent-composition.ts): agent execution · Builds prompts, selects tools, invokes inference, and emits events. · `source/host/runner/turn-agent-composition.ts`
- [Session & transcript store](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/storage/store-db.ts): SQLite/blob storage · Persists sessions and transcripts for local durability. · `source/host/storage/store-db.ts`

### Execution & Integrations

- [Inference routing](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/extensions/inference/inference-service.ts): provider dispatch · Routes to Cursor, Claude Code, Codex, or OpenRouter. · `source/host/extensions/inference/inference-service.ts`
- [MCP & tool service](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/host/extensions/mcp/mcp-service.ts): tool integration · Supports MCP plugins alongside agent tool execution. · `source/host/extensions/mcp/mcp-service.ts`
- [Local Docker box](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/electron-main/box/local-docker-host-connector.ts): optional sandbox path · Connects a loopback host and execution daemon through Docker. · `source/electron-main/box/local-docker-host-connector.ts`
- [Local execution daemon](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/local-exec-daemon/main.ts): execution daemon · `source/local-exec-daemon/main.ts`
- [Shell execution sandbox](https://github.com/b-nnett/grok-bot-0.18-reconstructed/blob/main/source/packages/shell-exec/sandbox/sandbox.ts): sandbox runtime · `source/packages/shell-exec/sandbox/sandbox.ts`

## Connections

- Runtime bootstrap → Production renderer: pins and patches
- Runtime bootstrap → macOS packager: prepares runtime
- macOS packager → Electron main: packages
- Production renderer → Conversation workspace: renders
- Production renderer → Router settings: renders
- Production renderer → Preload bridge: privileged calls
- Preload bridge → Renderer RPC runtime: main RPC
- Renderer RPC runtime → Electron main: crosses trust boundary
- Preload bridge → Coordinator port bridge: coordinator port
- Coordinator port bridge → Renderer port server: connects
- Renderer port server → Agent coordinator: renderer traffic
- Electron main → Main edge wiring: wires services
- Main edge wiring → Agent coordinator: supervises lifecycle
- Agent coordinator → Remote gateway dispatcher: remote requests and SSE
- Agent coordinator → Agent host: supervises
- Agent host → Message send pipeline: accepted messages
- Message send pipeline → Turn agent runner: schedules turns
- Agent host → Session & transcript store: persists state
- Turn agent runner → Inference routing: invokes models
- Turn agent runner → MCP & tool service: selects tools
- Turn agent runner → Agent coordinator: transcript and tool events
- Main edge wiring → Local Docker box: optional local path
- Local Docker box → Local execution daemon: loopback execution
- Local execution daemon → Shell execution sandbox: runs commands
