# BMO

BMO connects your local OpenCode instance to Telegram, an interactive terminal TUI, and a webchat interface, all sharing a single SQLite database and session history. 

BMO is designed to build and expand itself. If you need a new feature, a new subcommand, or a custom integration, you can ask BMO directly in the chat. It will write the code, run tests, install any necessary dependencies, and update its own live environment on your system.

It handles its own dependencies out of the box, packaging a minimal embedded Python runtime, pip dependencies, and cloudflared for secure tunneling.

## Installation

Install BMO globally via npm:

```bash
npm install -g @aliwey/bmo
```

## Setup

Run the configuration wizard to link your Telegram bot token and define your settings:

```bash
bmo init
```

This creates a configuration file in `~/.bmo/.env`.

## Quick Start

### Start Bot and CLI TUI
```bash
bmo
```
If your local OpenCode server is not running, BMO will attempt to start it automatically.

### Start Webchat and Tunnel
```bash
bmo web
```
This launches the Node/Express webchat server and opens a secure public Cloudflare Tunnel, allowing you to access your chat session from any device.

### Start BFP Relay (Optional)
To make your agent discoverable by other BMO peers on the registry:
```bash
bmo relay
```
Options:
- `--private`: Run the relay and tunnel locally without registering on the public directory.
- `--stop`: Terminate the background relay and tunnel processes.

## Command Reference

- `bmo` - Launches the Telegram bot and the CLI TUI.
- `bmo init` - Runs the interactive configuration wizard.
- `bmo web` - Starts the webchat server and Cloudflare tunnel.
- `bmo relay` - Controls the peer-to-peer relay.
- `bmo --version` - Prints the installed version.
- `bmo --update` - Checks for and pulls the latest updates.

## Storage and Configuration

All configuration, logs, and database files are kept in the user home directory:

- `~/.bmo/.env` - Your API tokens, ports, and default model configuration.
- `~/.bmo/data/bot.db` - The shared SQLite database (WAL mode) containing session history, memory, and custom agents.
- `~/.bmo/logs/` - Logs for the bot, CLI, webchat, and tunnel.

## License

MIT
