|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +discli is a Discord CLI for AI agents and humans — a Python command-line tool for managing Discord servers, messages, reactions, threads, DMs, and events from the terminal. Published on PyPI as `discord-cli-agent`. |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Install (editable, with dev deps) |
| 13 | +pip install -e ".[dev]" |
| 14 | + |
| 15 | +# Run tests |
| 16 | +pytest tests/ -v |
| 17 | + |
| 18 | +# Run a single test |
| 19 | +pytest tests/test_utils.py -v |
| 20 | + |
| 21 | +# Build package |
| 22 | +python -m build |
| 23 | +``` |
| 24 | + |
| 25 | +No linter is configured. Commit style: conventional commits (`feat:`, `fix:`, `docs:`, `chore:`). |
| 26 | + |
| 27 | +## Architecture |
| 28 | + |
| 29 | +**Entry point:** `src/discli/cli.py` → Click root group → registers all command groups. |
| 30 | + |
| 31 | +**Core flow:** Click CLI → permission/audit check (security.py) → `run_discord()` (client.py) → async discord.py action → `output()` (utils.py). |
| 32 | + |
| 33 | +**Key modules:** |
| 34 | +- `client.py` — Token resolution (flag → env var → config file), `run_discord()` sync wrapper around async Discord actions |
| 35 | +- `security.py` — Permission profiles (full/chat/readonly/moderation), audit logging to `~/.discli/audit.log` (JSONL), token-bucket rate limiter |
| 36 | +- `utils.py` — Output formatting (text/JSON via `--json` flag), channel/guild resolvers |
| 37 | +- `config.py` — Token storage at `~/.discli/config.json` |
| 38 | + |
| 39 | +**Command pattern:** Each module in `commands/` defines Click commands, takes an async action function, and calls `run_discord(ctx, action)`. Follow existing modules when adding new commands. |
| 40 | + |
| 41 | +**`serve` command (commands/serve.py):** The largest module (~1100 lines). Runs a persistent bot with bidirectional JSONL over stdin/stdout. Features: event forwarding, action dispatch (send/reply/edit/delete/stream/typing/reactions/threads/polls/channels/members/roles/DMs), slash command registration, streaming message edits with periodic flush, Windows-compatible stdin reading via threading. |
| 42 | + |
| 43 | +## Adding a New Command |
| 44 | + |
| 45 | +1. Create file in `src/discli/commands/` |
| 46 | +2. Define Click group/command following existing patterns |
| 47 | +3. Register in `src/discli/cli.py` |
| 48 | +4. Add tests in `tests/` |
| 49 | +5. Update `agents/discord-agent.md` with command reference |
| 50 | + |
| 51 | +## Docs Development |
| 52 | + |
| 53 | +```bash |
| 54 | +# Start docs dev server (Lito, Astro-based) |
| 55 | +npx @litodocs/cli dev -i ./docs |
| 56 | + |
| 57 | +# Build docs for production |
| 58 | +npx @litodocs/cli build -i ./docs -o ./docs/dist |
| 59 | +``` |
| 60 | + |
| 61 | +Docs live in `docs/` — Lito framework with `docs-config.json` for sidebar/theme. Custom landing page in `docs/_landing/`. |
| 62 | + |
| 63 | +## Release Process |
| 64 | + |
| 65 | +Bump version in `pyproject.toml` → commit → `git tag vX.Y.Z && git push origin vX.Y.Z` → CI runs tests (Python 3.10–3.13), builds, creates GitHub Release, publishes to PyPI. |
0 commit comments