ravi.bot 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,222 @@
1
+ # Ravi Bot
2
+
3
+ A Claude-powered conversational bot with WhatsApp and Matrix integration, session routing, and message queuing.
4
+
5
+ ## Features
6
+
7
+ - **WhatsApp Integration** - Connect via Baileys (no API keys needed)
8
+ - **Matrix Integration** - Connect to any Matrix homeserver
9
+ - **Session Routing** - Route conversations to different agents based on rules
10
+ - **Message Queue** - Smart interruption handling when tools are running
11
+ - **Debounce** - Group rapid messages before processing
12
+ - **Multi-Agent** - Configure multiple agents with different capabilities
13
+ - **Daemon Mode** - Run as a system service (launchd/systemd)
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ git clone https://github.com/filipelabs/ravi.bot
19
+ cd ravi.bot
20
+ bun install
21
+ bun run build
22
+ bun link # Makes `ravi` command available globally
23
+ ```
24
+
25
+ ## Quick Start
26
+
27
+ ### 1. Configure Environment
28
+
29
+ ```bash
30
+ ravi daemon env
31
+ ```
32
+
33
+ Add your API keys to `~/.ravi/.env`:
34
+
35
+ ```bash
36
+ NOTIF_API_KEY=nsh_xxx # Get from notif.sh
37
+ CLAUDE_CODE_OAUTH_TOKEN=sk-ant-oat01-xxx # From claude auth
38
+ ```
39
+
40
+ ### 2. Start the Daemon
41
+
42
+ ```bash
43
+ ravi daemon start
44
+ ```
45
+
46
+ This starts both the bot server and WhatsApp gateway as a background service.
47
+
48
+ ### 3. Connect WhatsApp
49
+
50
+ On first run, scan the QR code in the terminal to link your WhatsApp.
51
+
52
+ ### 4. Monitor
53
+
54
+ ```bash
55
+ ravi daemon status # Check if running
56
+ ravi daemon logs # View logs
57
+ ```
58
+
59
+ ## CLI Reference
60
+
61
+ ### Daemon Management
62
+
63
+ ```bash
64
+ ravi daemon start # Start bot + gateway
65
+ ravi daemon stop # Stop daemon
66
+ ravi daemon restart # Restart daemon
67
+ ravi daemon status # Show status
68
+ ravi daemon logs # Follow logs
69
+ ravi daemon env # Edit environment
70
+ ravi daemon install # Install system service
71
+ ravi daemon uninstall # Remove system service
72
+ ```
73
+
74
+ ### Agent Configuration
75
+
76
+ ```bash
77
+ ravi agents list # List all agents
78
+ ravi agents show main # Show agent details
79
+ ravi agents create mybot ~/ravi/mybot # Create new agent
80
+ ravi agents set main model opus # Set model
81
+ ravi agents debounce main 2000 # Set 2s debounce
82
+ ravi agents tools main # Manage tool whitelist
83
+ ```
84
+
85
+ ### Contacts (WhatsApp)
86
+
87
+ ```bash
88
+ ravi contacts list # List approved contacts
89
+ ravi contacts add +5511999999999
90
+ ravi contacts pending # Show pending requests
91
+ ```
92
+
93
+ ## Configuration
94
+
95
+ ### Router (`~/ravi/ravi.db`)
96
+
97
+ Configuration is stored in SQLite and managed via CLI:
98
+
99
+ ```bash
100
+ # Agents
101
+ ravi agents list
102
+ ravi agents create assistant ~/ravi/assistant
103
+ ravi agents set main model sonnet
104
+ ravi agents set main dmScope main
105
+ ravi agents debounce main 2000
106
+
107
+ # Routes
108
+ ravi routes list
109
+ ravi routes add "+5511*" assistant
110
+ ravi routes set "+5511*" priority 10
111
+
112
+ # Settings
113
+ ravi settings list
114
+ ravi settings set defaultAgent main
115
+ ravi settings set defaultDmScope per-peer
116
+ ```
117
+
118
+ ### Agent Options
119
+
120
+ | Option | Description |
121
+ |--------|-------------|
122
+ | `cwd` | Working directory with CLAUDE.md and tools |
123
+ | `model` | Model to use (sonnet, opus, haiku) |
124
+ | `dmScope` | How to group DM sessions |
125
+ | `debounceMs` | Message grouping window in ms |
126
+ | `allowedTools` | Whitelist of allowed tools |
127
+
128
+ ### DM Scopes
129
+
130
+ | Scope | Session Key | Use Case |
131
+ |-------|-------------|----------|
132
+ | `main` | `agent:X:main` | Shared context for all DMs |
133
+ | `per-peer` | `agent:X:dm:PHONE` | Isolated per contact |
134
+ | `per-channel-peer` | `agent:X:wa:dm:PHONE` | Isolated per channel+contact |
135
+
136
+ ## Architecture
137
+
138
+ ```
139
+ ┌─────────────┐ ┌───────────────────────┐
140
+ │ TUI │──────────────────────────────│ notif.sh │
141
+ └─────────────┘ │ ravi.{sessionKey}.* │
142
+ └───────────┬───────────┘
143
+ ┌─────────────┐ ┌─────────────┐ │
144
+ │ WhatsApp │────▶│ Gateway │──────────────────────┤
145
+ │ Plugin │ │ (router) │ │
146
+ └─────────────┘ └─────────────┘ ▼
147
+ ┌───────────────────────┐
148
+ │ RaviBot │
149
+ │ Claude Agent SDK │
150
+ │ cwd: ~/ravi/{agent} │
151
+ └───────────────────────┘
152
+ ```
153
+
154
+ ### Message Flow
155
+
156
+ 1. **Inbound**: WhatsApp → Gateway → notif.sh → Bot
157
+ 2. **Processing**: Bot uses Claude SDK with agent's working directory
158
+ 3. **Outbound**: Bot → notif.sh → Gateway → WhatsApp
159
+
160
+ ### Message Queue
161
+
162
+ When messages arrive while processing:
163
+
164
+ - **Tool running**: Queue message, wait for tool to finish, then interrupt
165
+ - **No tool running**: Interrupt immediately
166
+ - **Debounce active**: Group messages within time window
167
+
168
+ ## File Structure
169
+
170
+ ```
171
+ ~/ravi/ # Ravi data directory
172
+ ├── ravi.db # All config: agents, routes, sessions, contacts (SQLite)
173
+ └── main/ # Agent working directory
174
+ ├── CLAUDE.md # Agent instructions
175
+ └── ... # Agent-specific files
176
+
177
+ ~/.ravi/ # Ravi config directory
178
+ ├── .env # Environment variables
179
+ ├── matrix/ # Matrix SDK storage
180
+ └── logs/
181
+ └── daemon.log # Daemon logs
182
+ ```
183
+
184
+ ## Development
185
+
186
+ ```bash
187
+ bun run build # Compile TypeScript
188
+ bun run dev # Watch mode
189
+ make quality # Run lint + typecheck
190
+ ```
191
+
192
+ ## Troubleshooting
193
+
194
+ ### Daemon won't start
195
+
196
+ ```bash
197
+ ravi daemon logs # Check for errors
198
+ ravi daemon env # Verify API keys are set
199
+ ```
200
+
201
+ ### WhatsApp not connecting
202
+
203
+ Delete the auth folder and restart to get a new QR code:
204
+
205
+ ```bash
206
+ rm -rf ~/.ravi/whatsapp-auth
207
+ ravi daemon restart
208
+ ```
209
+
210
+ ### Messages not being processed
211
+
212
+ ```bash
213
+ # Check bot is running
214
+ ravi daemon status
215
+
216
+ # Check notif.sh connection
217
+ RAVI_LOG_LEVEL=debug ravi daemon restart
218
+ ```
219
+
220
+ ## License
221
+
222
+ MIT
package/bin/ravi ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env bash
2
+ # Ravi CLI wrapper - runs the TypeScript CLI with bun
3
+
4
+ # Resolve the actual script location (following symlinks)
5
+ SOURCE="${BASH_SOURCE[0]}"
6
+ while [ -L "$SOURCE" ]; do
7
+ DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
8
+ SOURCE="$(readlink "$SOURCE")"
9
+ [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE"
10
+ done
11
+ SCRIPT_DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
12
+ PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
13
+
14
+ exec bun "$PROJECT_DIR/dist/bundle/index.js" "$@"