Metadata-Version: 2.4
Name: jchat
Version: 0.2.1
Summary: Single-file, single-process localhost signal and @tag notification bus for AI agents.
License-Expression: MIT
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# jchat

Single-file, single-process localhost signal and `@tag` notification bus for AI agents. Standard library only, SQLite WAL backed, zero runtime dependencies.

## Install

Requires Python >= 3.11.

```bash
pip install jchat
```

Verify with the built-in self-test:

```bash
jchat doctor
```

## Quick Start

Any command auto-starts the **single** localhost process (`127.0.0.1:8765`, guarded by `fcntl.flock`) on demand. No separate MCP server, ping server, or polling cron is used.

```bash
# Event-driven wait (marks agy online while waiting; wakes immediately on send or @agy tag)
jchat wait agy

# Send direct + @tag notifications (auto-starts the bus if not already running)
jchat send agy "@claude review ready" --sender codex --ref git:HEAD --kind verify

# Turn-boundary hook (silent exit 0 when empty; prints untrusted-wrapped data and acks when queued)
jchat hook --agent agy

# Inspect the single running process, online agents, and queue depth
jchat status
```

### Harness Hooks

```bash
jchat install-hooks claude --agent claude
jchat install-hooks agy --agent agy
```

### Python API

```python
from jchat import LocalBus, wait_messages, wrap_untrusted

with LocalBus("/tmp/jchat.db", port=0) as bus:
    bus.store.send(sender="claude", recipient="agy", body="@agy check this", ref="git:HEAD")
    for msg in wait_messages("agy", url=bus.url, timeout=2.0):
        print(wrap_untrusted(msg))
```

## Contract

- **Localhost only (`127.0.0.1`):** wildcard binds are rejected; `ensure_running` uses `flock` so concurrent cold starts spawn exactly one daemon PID.
- **Inbox + `@tag` routing:** `send` delivers once to the explicit recipient plus every unique `@agent` mention in `body`.
- **Event-driven wakeups (`wait`):** per-agent `threading.Condition` wakes waiting agents immediately when messages land; connected waiters appear in `online_agents`.
- **1,000-char pointer envelope & delete-on-read:** `body <= 1000` chars, `ref <= 512` chars without embedded secrets; `ack` hard-deletes rows and leaves only a 1 h in-memory receipt (`queued` / `delivered` / `read` / `failed`).
