Summary
- Adds a Zig HTTP server (
src/server.zig, src/main.zig) that serves an embedded vanilla JS/CSS chat UI from a single binary.
- Chat agent (
src/chat.zig) answers in plain language using two tools, describe_tables and run_sql, backed by an Anthropic-format model client (src/llm.zig) for Divine or the Anthropic API.
- Each request opens a private in-memory DuckDB (
src/duckdb.zig, src/session.zig) attached read-only to the Deadlock DuckLake catalog over HTTPS, with a 1 GB memory cap, 30 s query timeout, and 4 concurrent chats.
- SQL is never built from user text; every query passes an AST parser check, a lake-only table rule, table-function and scalar-function denials, a statement-kind check, and a locked-down read-only session (
src/sql_guard.zig).
- Adds Discord support (
src/discord.zig, src/gateway.zig): signed /discord/interactions for the /ask slash command, plus a Gateway connection for @-mentions and DMs, with reconnect backoff and a stop on fatal close codes.
- Adds once/Docker packaging: port 80,
GET /up health check, /storage volume, docs/DEPLOY.md, mise tasks, and a DuckDB library fetch script.
Testing
mise run test — 10 unit tests pass, covering the SQL guard, mention stripping and detection, Discord content clipping, signature rejection, and fatal close codes.
zig fmt --check build.zig src/ — clean.
- Local smoke test: server boots with DuckDB 2.0.0 and
GET /up returns ok on port 8080.
- Discord Gateway handshake checked against the real service with an invalid token: TLS, WebSocket upgrade, hello, and identify all succeed, and Discord replies with close code 4004 (authentication failed), which the client treats as fatal.
- Not run: end-to-end model answers and live Discord replies, which need a valid bot token and (for
/ask) a public HTTPS interactions URL.
Sign in to comment on this pull request.