|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Commands |
| 6 | + |
| 7 | +```bash |
| 8 | +bun run dev # Start server (apps/server) |
| 9 | +bun run cli status # Admin CLI |
| 10 | +bun test # Run all tests (bun test runner) |
| 11 | +bun test packages/gateway/src/commands.test.ts # Run a single test file |
| 12 | +bun tsc --noEmit # Type check |
| 13 | +bun run lint # Biome lint |
| 14 | +bun run lint:fix # Biome lint + auto-fix |
| 15 | +bun run format # Biome format |
| 16 | +``` |
| 17 | + |
| 18 | +## Architecture |
| 19 | + |
| 20 | +Homie is an async Telegram agent that wraps the local `claude` CLI. Users send messages via Telegram, Homie routes them through a gateway to Claude Code, and returns results. |
| 21 | + |
| 22 | +### Data flow |
| 23 | + |
| 24 | +``` |
| 25 | +Telegram message → TelegramAdapter → Gateway.handleEvent() |
| 26 | + ├─ Command (/new, /use, etc.) → CommandHandler → reply |
| 27 | + └─ Chat message → AgentRunner.start() (background, interruptible) |
| 28 | + → SessionManager (history) + MemoryStore (context) |
| 29 | + → Agent.run() → buildMessages() → ClaudeCodeProvider.generate() |
| 30 | + → spawns `claude` CLI with stream-json output |
| 31 | + → parse response, extract <memory> tags, save usage |
| 32 | + → reply to user |
| 33 | +``` |
| 34 | + |
| 35 | +### Package dependency graph |
| 36 | + |
| 37 | +``` |
| 38 | +core (types, interfaces, errors) ← everything depends on this |
| 39 | +config (YAML loader) ← server |
| 40 | +observability (logger) ← most packages |
| 41 | +persistence (SQLite stores) ← sessions, gateway, server |
| 42 | +sessions (session manager) ← gateway, server |
| 43 | +providers (claude CLI wrapper) ← agent, server |
| 44 | +agent (context + provider orchestration) ← gateway, server |
| 45 | +gateway (routing, commands, agent-runner) ← server, telegram |
| 46 | +channels/telegram (grammy adapter) ← server |
| 47 | +``` |
| 48 | + |
| 49 | +### Key patterns |
| 50 | + |
| 51 | +- **No classes.** All modules use factory functions returning interfaces (e.g., `createSessionManager(store): SessionManager`). |
| 52 | +- **No build step.** Bun resolves `.ts` workspace imports directly via `tsconfig.json` path aliases (`@homie/core` → `./packages/core/src`). |
| 53 | +- **SQLite via `bun:sqlite`** with WAL mode. Inline migrations run on `openDatabase()`. Stores are synchronous under the hood but expose async interfaces. |
| 54 | +- **Provider resilience:** Session resume via `--resume`, fallback to full history replay, 1 crash retry with 3s backoff. |
| 55 | +- **Preflight checks:** Server startup validates Telegram bot token (`getMe` API) and Claude Code auth (minimal prompt) in parallel before booting. |
| 56 | + |
| 57 | +### Conventions |
| 58 | + |
| 59 | +- Commit messages: `type: description` (e.g., `feat:`, `fix:`, `chore:`) |
| 60 | +- Formatting: Biome — 2-space indent, single quotes, semicolons, 100 char line width |
| 61 | +- TypeScript strict mode with `noUncheckedIndexedAccess` |
| 62 | +- Channel adapters build their own `ReplyFn` and `ProgressHandler` internally, then pass them to the gateway's `EventHandler` |
| 63 | +- `EventHandler` from core is the contract between channels and the gateway — channels never import gateway directly |
0 commit comments