Metadata-Version: 2.4
Name: camosur
Version: 0.1.0a1
Summary: An IRC chat persona and game master backed by a language model
License-Expression: Apache-2.0
Project-URL: Homepage, https://camosur.com
Project-URL: Repository, https://github.com/kjiwa/camosur
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Communications :: Chat :: Internet Relay Chat
Requires-Python: >=3.13
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Provides-Extra: bedrock
Requires-Dist: pydantic-ai-slim[bedrock]==2.75.0; extra == "bedrock"
Provides-Extra: anthropic
Requires-Dist: pydantic-ai-slim[anthropic]==2.75.0; extra == "anthropic"
Provides-Extra: openai
Requires-Dist: pydantic-ai-slim[openai]==2.75.0; extra == "openai"
Provides-Extra: all
Requires-Dist: pydantic-ai-slim[anthropic,bedrock,openai]==2.75.0; extra == "all"
Dynamic: license-file

<p align="center"><img src="logo.svg" width="96" alt=""></p>

# camosur

An IRC chat persona and West Marches D&D game master backed by a language model.

`camosur` connects to one or more IRC networks, keeps a shared WAL-mode SQLite database between its IRC relay and LLM brain, participates in channel banter on a schedule with presence windows and spend caps, reflects nightly on conversations, and runs West Marches D&D 5e (SRD 5.1) expeditions via `!dnd`.

## Quick start

`camosur` requires Python 3.13 or later and declares no base dependencies — install the provider extra you need (`openai`, `anthropic`, `bedrock`, or `all`).

### Local with Ollama (free)

Ollama's OpenAI-compatible API uses the `openai` extra:

```sh
pip install 'camosur[openai]'
ollama pull qwen2.5:7b
camosur run ircs://irc.example.org/#channel
```

`camosur run` with an IRC URL seeds the channel and an always-on schedule in `camosur.db`, turns disclosure on (`AI bot - https://camosur.com`), auto-detects Ollama on `http://127.0.0.1:11434`, and prints a one-time `/msg <nick> claim <code>` instruction to stderr so you can claim ownership on IRC.

### Cloud providers

```sh
# Anthropic (uses ANTHROPIC_API_KEY)
pip install 'camosur[anthropic]'
camosur run ircs://irc.example.org/#channel

# OpenAI (uses OPENAI_API_KEY)
pip install 'camosur[openai]'
camosur run ircs://irc.example.org/#channel

# Amazon Bedrock (uses ambient AWS credentials)
pip install 'camosur[bedrock]'
camosur run ircs://irc.example.org/#channel
```

Pass `--model PROVIDER:MODEL` (e.g. `--model anthropic:claude-haiku-4-5`) to override auto-detection, or `--nick NICK` to override the persona's default nick.

### Configuration file

```sh
camosur init
# Edit camosur.toml and persona.toml
camosur run
```

`camosur init` writes a starter `camosur.toml` and `persona.toml` (copied from `brain/persona.example.toml`). Without a URL, `camosur run` reads `camosur.toml`, or falls back to `relay.json` and `brain.json`. Pass `--only relay` or `--only brain` to run the two sides in separate processes sharing `--db`.

## Models and evals

`camosur` routes each job to a named model slot (`banter`, `guard`, `reflection`, and `game`). Small models handle the non-GM routes well; the West Marches GM route is more demanding.

Results from the fictional public eval suite (`brain/evals/results/2026-12-03.md`, 3 runs per case, projected at 100 calls/day):

| Route | Model | Limit cases (strict) | Limit cases (2/3 runs) | Contract | Est. USD/month |
|---|---|---|---|---|---:|
| `guard` | `us.amazon.nova-lite-v1:0` | 10/10 | 10/10 | 30/30 | 0.07 |
| `banter` | `global.anthropic.claude-haiku-4-5-20251001-v1:0` | 9/10 | 10/10 | 36/36 | 2.34 |
| `reflection` | `us.amazon.nova-pro-v1:0` | 6/6 | 6/6 | 18/18 | 3.12 |
| `game` | `global.anthropic.claude-haiku-4-5-20251001-v1:0` | 4/8 | 4/8 | 24/24 | 17.58 |

Note: `game` is currently below gate on Haiku 4.5 (4/8 cases); evaluate a stronger model before relying on it for West Marches sessions.

Run the eval suite against any candidate model:

```sh
python -m brain.evals --route banter --models <model-id> --guard-model <guard-id>
```

## Deploying on AWS

For a self-hosted AWS deployment (single Spot EC2 instance over IPv6, Litestream SQLite replication to S3, Bedrock Converse proxy Lambda, status page, and optional D&D hex map publishing), use the [terraform-aws-camosur](https://github.com/kjiwa/terraform-aws-camosur) Terraform module.

## Design and activities

See [docs/architecture.md](docs/architecture.md) for process topology, message dispatch, and deployment diagrams.

- **Chat** (`brain/chat/`): Presence windows, measured channel rhythm, burst holding, thread-aware addressing, catch-up remarks, conversation openers, link title fetching, outbound safety guard (`KEEP`/`DROP`), daily and monthly spend caps, and nightly reflection (`brain/reflect/`). Turn rules evaluate in order (`away`, `hard`, `summon`, `answer`, `quiet`, `held`, `queued`, `other`, `engaged`, `unprompted`), and periodic ticks evaluate `backlog`, `catchup`, and `opener`.
- **West Marches** (`brain/game/`): SRD 5.1 rules core (Fighter, Rogue, Cleric, Wizard to level 5; four races; spells to 3rd level; ~20 monsters), seeded hex map with SVG/HTML rendering, expeditions, and shared journal. Players interact in-channel via `!dnd`.
- **Slap** (`brain/slap/`): `!slap <nick>` and `!slap <nick> with <item>` with configurable trout chance and cooldown.
- **Help** (`brain/help/`): `!help` lists public activity commands via NOTICE.
- **Activities plugin API** (`brain/activity.py`): Additional activities register via the `camosur.activities` entry point group.

### Owner commands

Private messages from configured owner masks or IRCv3 accounts are commands answered via NOTICE with no model call; non-owner DMs are ignored (except the one-time `claim <code>` bootstrap when unowned). Send `/msg <nick> help` to list `Core`, `Chat`, and `Activities` commands (`status`, `budget`, `schedule`, `presence`, `channel`, `person`, `mask`, `directive`, `campaign`, `flag`).

## Development

```sh
pip install -r requirements-dev.txt
pytest
pre-commit run --all-files
```

Layout:

- `camosur/irc/`: Standard-library-only IRC client (IRCv3 capabilities, SASL PLAIN, TLS certificate pinning, CTCP, rate limiting).
- `relay/`: Multi-network IRC bridge, `!botlist`/`!rollcall`, ident server, and SQLite event/outbox loop.
- `brain/`: Activity dispatch, chat presence/rhythm/guard/budget, nightly reflection, West Marches GM, owner commands, and evals.
- `shared/`: Shared SQLite store, key encoding, event helpers, and package version lookup.
- `runner/`: CLI (`camosur`), `camosur.toml`/URL config, CloudWatch/status/map wiring.
- `scripts/`: Utility scripts (`models.py`, `transcript.py`, `corpus.py`, `migrate_state.py`, `denylist.sh`).

## License

Licensed under the [Apache License 2.0](LICENSE). See [NOTICE](NOTICE) for third-party attributions.

This work includes material taken from the System Reference Document 5.1 ("SRD 5.1") by Wizards of the Coast LLC and available at https://dnd.wizards.com/resources/systems-reference-document. The SRD 5.1 is licensed under the Creative Commons Attribution 4.0 International License available at https://creativecommons.org/licenses/by/4.0/legalcode.
