crabtalk-client
Starter template for building a client service with crabtalk-command.
This example provides a minimal Discord bot that connects to the crabtalk daemon over a Unix domain socket and forwards messages to an agent.
Structure
src/
bin/main.rs CLI entry point (clap App)
lib.rs Module declarations
cmd.rs Service definition (#[command] + Discord bot)
Key concepts
#[command(kind = "client")] generates service management subcommands
(start, stop, run, logs) and a DiscordCommand::start() entry point.
The struct implements an inherent async fn run(&self) method which the macro
calls on run — this is the client's main loop.
Setup
- Create a Discord bot at https://discord.com/developers/applications
- Enable the Message Content intent
- Set the
DISCORD_TOKENenvironment variable
Usage
Make sure the crabtalk daemon is running, then:
# Run directly
DISCORD_TOKEN=your-token
# Install as a launchd/systemd service
DISCORD_TOKEN=your-token
# View logs
# Stop
How it works
The bot:
- Listens for messages that mention it or are sent in DMs
- Opens a UDS connection to
~/.crabtalk/run/crabtalk.sock - Sends a
StreamMsgto the default agent - Accumulates text chunks from the streamed response
- Sends the full reply back to Discord
Building your own
- Clone this repo
- Rename the package in
Cargo.toml - Replace the Discord bot logic in
Discord::run()with your own client - Update the
#[command]name