ralph-cli-sandboxed 0.4.0 → 0.4.2

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.
Files changed (80) hide show
  1. package/README.md +30 -0
  2. package/dist/commands/action.js +47 -20
  3. package/dist/commands/chat.d.ts +1 -1
  4. package/dist/commands/chat.js +325 -62
  5. package/dist/commands/config.js +2 -1
  6. package/dist/commands/daemon.d.ts +2 -5
  7. package/dist/commands/daemon.js +118 -49
  8. package/dist/commands/docker.js +110 -73
  9. package/dist/commands/fix-config.js +2 -1
  10. package/dist/commands/fix-prd.js +2 -2
  11. package/dist/commands/help.js +19 -3
  12. package/dist/commands/init.js +78 -17
  13. package/dist/commands/listen.js +116 -5
  14. package/dist/commands/logo.d.ts +5 -0
  15. package/dist/commands/logo.js +41 -0
  16. package/dist/commands/notify.js +1 -1
  17. package/dist/commands/once.js +19 -9
  18. package/dist/commands/prd.js +20 -2
  19. package/dist/commands/run.js +111 -27
  20. package/dist/commands/slack.d.ts +10 -0
  21. package/dist/commands/slack.js +333 -0
  22. package/dist/config/responder-presets.json +69 -0
  23. package/dist/index.js +6 -1
  24. package/dist/providers/discord.d.ts +82 -0
  25. package/dist/providers/discord.js +697 -0
  26. package/dist/providers/slack.d.ts +79 -0
  27. package/dist/providers/slack.js +715 -0
  28. package/dist/providers/telegram.d.ts +30 -0
  29. package/dist/providers/telegram.js +190 -7
  30. package/dist/responders/claude-code-responder.d.ts +48 -0
  31. package/dist/responders/claude-code-responder.js +203 -0
  32. package/dist/responders/cli-responder.d.ts +62 -0
  33. package/dist/responders/cli-responder.js +298 -0
  34. package/dist/responders/llm-responder.d.ts +135 -0
  35. package/dist/responders/llm-responder.js +582 -0
  36. package/dist/templates/macos-scripts.js +2 -4
  37. package/dist/templates/prompts.js +4 -2
  38. package/dist/tui/ConfigEditor.js +42 -5
  39. package/dist/tui/components/ArrayEditor.js +1 -1
  40. package/dist/tui/components/EditorPanel.js +10 -6
  41. package/dist/tui/components/HelpPanel.d.ts +1 -1
  42. package/dist/tui/components/HelpPanel.js +1 -1
  43. package/dist/tui/components/JsonSnippetEditor.js +8 -5
  44. package/dist/tui/components/KeyValueEditor.js +69 -5
  45. package/dist/tui/components/LLMProvidersEditor.d.ts +22 -0
  46. package/dist/tui/components/LLMProvidersEditor.js +357 -0
  47. package/dist/tui/components/ObjectEditor.js +1 -1
  48. package/dist/tui/components/Preview.js +1 -1
  49. package/dist/tui/components/RespondersEditor.d.ts +22 -0
  50. package/dist/tui/components/RespondersEditor.js +437 -0
  51. package/dist/tui/components/SectionNav.js +27 -3
  52. package/dist/tui/utils/presets.js +15 -2
  53. package/dist/utils/chat-client.d.ts +33 -4
  54. package/dist/utils/chat-client.js +20 -1
  55. package/dist/utils/config.d.ts +100 -1
  56. package/dist/utils/config.js +78 -1
  57. package/dist/utils/daemon-actions.d.ts +19 -0
  58. package/dist/utils/daemon-actions.js +111 -0
  59. package/dist/utils/daemon-client.d.ts +21 -0
  60. package/dist/utils/daemon-client.js +28 -1
  61. package/dist/utils/llm-client.d.ts +82 -0
  62. package/dist/utils/llm-client.js +185 -0
  63. package/dist/utils/message-queue.js +6 -6
  64. package/dist/utils/notification.d.ts +10 -2
  65. package/dist/utils/notification.js +111 -4
  66. package/dist/utils/prd-validator.js +60 -19
  67. package/dist/utils/prompt.js +22 -12
  68. package/dist/utils/responder-logger.d.ts +47 -0
  69. package/dist/utils/responder-logger.js +129 -0
  70. package/dist/utils/responder-presets.d.ts +92 -0
  71. package/dist/utils/responder-presets.js +156 -0
  72. package/dist/utils/responder.d.ts +88 -0
  73. package/dist/utils/responder.js +207 -0
  74. package/dist/utils/stream-json.js +6 -6
  75. package/docs/CHAT-CLIENTS.md +520 -0
  76. package/docs/CHAT-RESPONDERS.md +785 -0
  77. package/docs/DEVELOPMENT.md +25 -0
  78. package/docs/USEFUL_ACTIONS.md +815 -0
  79. package/docs/chat-architecture.md +251 -0
  80. package/package.json +14 -1
@@ -0,0 +1,520 @@
1
+ # Chat Client Setup Guide
2
+
3
+ Ralph supports multiple chat providers for remote control and notifications. You can control your Ralph automation from Telegram, Slack, or Discord - running commands, checking status, and receiving notifications all from your phone or desktop chat client.
4
+
5
+ ## Supported Providers
6
+
7
+ | Provider | Status | Use Case |
8
+ |----------|--------|----------|
9
+ | Telegram | ✅ Supported | Personal use, simple setup |
10
+ | Slack | ✅ Supported | Team collaboration, workspace integration |
11
+ | Discord | ✅ Supported | Community servers, gaming-style interaction |
12
+
13
+ ## Quick Start
14
+
15
+ 1. Choose your chat provider
16
+ 2. Create a bot/app on that platform
17
+ 3. Add credentials to `.ralph/config.json`
18
+ 4. Start the chat daemon: `ralph chat start`
19
+
20
+ ---
21
+
22
+ ## Telegram Setup
23
+
24
+ Telegram is the simplest option for personal use with minimal setup.
25
+
26
+ ### Step 1: Create a Bot with BotFather
27
+
28
+ 1. Open Telegram and search for `@BotFather`
29
+ 2. Send `/newbot` command
30
+ 3. Choose a name (e.g., "Ralph Automation")
31
+ 4. Choose a username (must end in `bot`, e.g., `ralph_dev_bot`)
32
+ 5. Copy the **bot token** (looks like `123456789:ABCdefGHIjklMNOpqrSTUvwxYZ`)
33
+
34
+ ### Step 2: Get Your Chat ID
35
+
36
+ 1. Start a chat with your new bot
37
+ 2. Send any message to the bot
38
+ 3. Open this URL in your browser (replace `YOUR_BOT_TOKEN`):
39
+ ```
40
+ https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates
41
+ ```
42
+ 4. Look for `"chat":{"id":123456789}` - this is your chat ID
43
+ 5. For group chats, add the bot to the group first, then check getUpdates
44
+
45
+ ### Step 3: Configure Ralph
46
+
47
+ Add to `.ralph/config.json`:
48
+
49
+ ```json
50
+ {
51
+ "chat": {
52
+ "enabled": true,
53
+ "provider": "telegram",
54
+ "telegram": {
55
+ "botToken": "123456789:ABCdefGHIjklMNOpqrSTUvwxYZ",
56
+ "allowedChatIds": ["123456789"]
57
+ }
58
+ }
59
+ }
60
+ ```
61
+
62
+ ### Step 4: Start the Chat Daemon
63
+
64
+ ```bash
65
+ ralph chat start
66
+ ```
67
+
68
+ The bot will respond to commands in the allowed chats.
69
+
70
+ ### Telegram Commands
71
+
72
+ | Command | Description |
73
+ |---------|-------------|
74
+ | `/run` | Start ralph automation |
75
+ | `/run feature` | Run only feature tasks |
76
+ | `/status` | Show PRD progress |
77
+ | `/add Fix the login bug` | Add a new task |
78
+ | `/exec npm test` | Execute a shell command |
79
+ | `/stop` | Stop running ralph process |
80
+ | `/action build` | Execute a daemon action |
81
+ | `/claude Fix the CSS` | Run Claude Code with a prompt |
82
+ | `/help` | Show available commands |
83
+
84
+ ---
85
+
86
+ ## Slack Setup
87
+
88
+ Slack requires more setup but provides deeper workspace integration with slash commands.
89
+
90
+ ### Step 1: Create a Slack App
91
+
92
+ 1. Go to [api.slack.com/apps](https://api.slack.com/apps)
93
+ 2. Click **Create New App** → **From scratch**
94
+ 3. Name your app (e.g., "Ralph Automation")
95
+ 4. Select your workspace
96
+ 5. Click **Create App**
97
+
98
+ ### Step 2: Enable Socket Mode
99
+
100
+ Socket Mode allows the bot to receive events without a public URL.
101
+
102
+ 1. In your app settings, go to **Socket Mode**
103
+ 2. Toggle **Enable Socket Mode** to ON
104
+ 3. Click **Generate Token**
105
+ 4. Name it (e.g., "ralph-socket")
106
+ 5. Copy the **App-Level Token** (starts with `xapp-`)
107
+
108
+ ### Step 3: Configure Bot Token
109
+
110
+ 1. Go to **OAuth & Permissions**
111
+ 2. Under **Scopes** → **Bot Token Scopes**, add:
112
+ - `chat:write` - Send messages
113
+ - `channels:history` - Read channel messages
114
+ - `groups:history` - Read private channel messages
115
+ - `im:history` - Read DMs
116
+ - `commands` - Use slash commands
117
+ 3. Click **Install to Workspace** at the top
118
+ 4. Copy the **Bot User OAuth Token** (starts with `xoxb-`)
119
+
120
+ ### Step 4: Get Signing Secret
121
+
122
+ 1. Go to **Basic Information**
123
+ 2. Under **App Credentials**, copy the **Signing Secret**
124
+
125
+ ### Step 5: Configure Event Subscriptions
126
+
127
+ 1. Go to **Event Subscriptions**
128
+ 2. Toggle **Enable Events** to ON
129
+ 3. Under **Subscribe to bot events**, add:
130
+ - `message.channels` - Messages in public channels
131
+ - `message.groups` - Messages in private channels
132
+ - `message.im` - Direct messages
133
+ 4. Click **Save Changes**
134
+
135
+ ### Step 6: Create Slash Commands (Optional)
136
+
137
+ 1. Go to **Slash Commands**
138
+ 2. Click **Create New Command** for each:
139
+
140
+ | Command | Request URL | Description |
141
+ |---------|-------------|-------------|
142
+ | `/run` | (leave empty for Socket Mode) | Start ralph automation |
143
+ | `/status` | (leave empty for Socket Mode) | Show PRD progress |
144
+ | `/add` | (leave empty for Socket Mode) | Add new task |
145
+ | `/exec` | (leave empty for Socket Mode) | Execute shell command |
146
+ | `/stop` | (leave empty for Socket Mode) | Stop ralph process |
147
+ | `/action` | (leave empty for Socket Mode) | Execute daemon action |
148
+ | `/claude` | (leave empty for Socket Mode) | Run Claude Code |
149
+
150
+ ### Step 7: Get Channel IDs
151
+
152
+ 1. Right-click on a channel in Slack
153
+ 2. Select **View channel details** (or **Copy link**)
154
+ 3. The channel ID is the last part of the URL (e.g., `C0123456789`)
155
+
156
+ ### Step 8: Install Dependencies
157
+
158
+ ```bash
159
+ npm install @slack/bolt @slack/web-api
160
+ ```
161
+
162
+ ### Step 9: Configure Ralph
163
+
164
+ Add to `.ralph/config.json`:
165
+
166
+ ```json
167
+ {
168
+ "chat": {
169
+ "enabled": true,
170
+ "provider": "slack",
171
+ "slack": {
172
+ "botToken": "xoxb-your-bot-token",
173
+ "appToken": "xapp-your-app-token",
174
+ "signingSecret": "your-signing-secret",
175
+ "allowedChannelIds": ["C0123456789"]
176
+ }
177
+ }
178
+ }
179
+ ```
180
+
181
+ ### Step 10: Start the Chat Daemon
182
+
183
+ ```bash
184
+ ralph chat start
185
+ ```
186
+
187
+ ### Slack Commands
188
+
189
+ Use either slash commands (`/run`) or message the bot with commands:
190
+
191
+ | Command | Description |
192
+ |---------|-------------|
193
+ | `/run` or `/run feature` | Start automation |
194
+ | `/status` | Show PRD progress |
195
+ | `/add Fix the bug` | Add a task |
196
+ | `/exec npm test` | Execute command |
197
+ | `/stop` | Stop ralph |
198
+ | `/action build` | Execute action |
199
+ | `/claude Fix CSS` | Run Claude Code |
200
+
201
+ ---
202
+
203
+ ## Discord Setup
204
+
205
+ Discord provides bot integration with slash commands and button interactions.
206
+
207
+ ### Step 1: Create a Discord Application
208
+
209
+ 1. Go to [discord.com/developers/applications](https://discord.com/developers/applications)
210
+ 2. Click **New Application**
211
+ 3. Name your app (e.g., "Ralph Automation")
212
+ 4. Click **Create**
213
+
214
+ ### Step 2: Create a Bot
215
+
216
+ 1. Go to the **Bot** section in your app
217
+ 2. Click **Add Bot** → **Yes, do it!**
218
+ 3. Under **Privileged Gateway Intents**, enable:
219
+ - **Message Content Intent** (required to read message content)
220
+ 4. Under **Token**, click **Reset Token** and copy it
221
+
222
+ ### Step 3: Configure OAuth2 and Invite the Bot
223
+
224
+ 1. Go to **OAuth2** → **URL Generator**
225
+ 2. Under **Scopes**, select:
226
+ - `bot`
227
+ - `applications.commands`
228
+ 3. Under **Bot Permissions**, select:
229
+ - Send Messages
230
+ - Read Message History
231
+ - Use Slash Commands
232
+ 4. Copy the generated URL and open it in your browser
233
+ 5. Select your server and click **Authorize**
234
+
235
+ ### Step 4: Get Server and Channel IDs
236
+
237
+ 1. In Discord, enable Developer Mode:
238
+ - User Settings → App Settings → Advanced → Developer Mode
239
+ 2. Right-click on your server icon → **Copy Server ID** (this is the Guild ID)
240
+ 3. Right-click on a channel → **Copy Channel ID**
241
+
242
+ ### Step 5: Install Dependencies
243
+
244
+ ```bash
245
+ npm install discord.js
246
+ ```
247
+
248
+ ### Step 6: Configure Ralph
249
+
250
+ Add to `.ralph/config.json`:
251
+
252
+ ```json
253
+ {
254
+ "chat": {
255
+ "enabled": true,
256
+ "provider": "discord",
257
+ "discord": {
258
+ "botToken": "your-discord-bot-token",
259
+ "allowedGuildIds": ["123456789012345678"],
260
+ "allowedChannelIds": ["987654321098765432"]
261
+ }
262
+ }
263
+ }
264
+ ```
265
+
266
+ ### Step 7: Start the Chat Daemon
267
+
268
+ ```bash
269
+ ralph chat start
270
+ ```
271
+
272
+ The first time the bot connects, it will register slash commands with Discord. This may take a few minutes to propagate.
273
+
274
+ ### Discord Commands
275
+
276
+ Use slash commands (type `/` to see available commands):
277
+
278
+ | Command | Description |
279
+ |---------|-------------|
280
+ | `/run` | Start automation |
281
+ | `/run category:feature` | Run specific category |
282
+ | `/status` | Show PRD progress |
283
+ | `/add description:Fix the bug` | Add a task |
284
+ | `/exec command:npm test` | Execute command |
285
+ | `/stop` | Stop ralph |
286
+ | `/action name:build` | Execute action |
287
+ | `/claude prompt:Fix CSS` | Run Claude Code |
288
+
289
+ ---
290
+
291
+ ## Configuration Reference
292
+
293
+ ### Full Config Example
294
+
295
+ ```json
296
+ {
297
+ "chat": {
298
+ "enabled": true,
299
+ "provider": "telegram",
300
+ "telegram": {
301
+ "enabled": true,
302
+ "botToken": "123456789:ABCdefGHIjklMNOpqrSTUvwxYZ",
303
+ "allowedChatIds": ["123456789", "-987654321"]
304
+ },
305
+ "slack": {
306
+ "enabled": false,
307
+ "botToken": "xoxb-...",
308
+ "appToken": "xapp-...",
309
+ "signingSecret": "...",
310
+ "allowedChannelIds": ["C0123456789"]
311
+ },
312
+ "discord": {
313
+ "enabled": false,
314
+ "botToken": "...",
315
+ "allowedGuildIds": ["123456789012345678"],
316
+ "allowedChannelIds": ["987654321098765432"]
317
+ }
318
+ }
319
+ }
320
+ ```
321
+
322
+ ### Config Options
323
+
324
+ | Field | Type | Description |
325
+ |-------|------|-------------|
326
+ | `chat.enabled` | boolean | Enable/disable chat integration |
327
+ | `chat.provider` | string | Active provider: `"telegram"`, `"slack"`, or `"discord"` |
328
+
329
+ #### Telegram Settings
330
+
331
+ | Field | Type | Required | Description |
332
+ |-------|------|----------|-------------|
333
+ | `telegram.enabled` | boolean | No | Enable/disable (default: true if botToken set) |
334
+ | `telegram.botToken` | string | Yes | Bot API token from @BotFather |
335
+ | `telegram.allowedChatIds` | string[] | No | Restrict to specific chat IDs |
336
+
337
+ #### Slack Settings
338
+
339
+ | Field | Type | Required | Description |
340
+ |-------|------|----------|-------------|
341
+ | `slack.enabled` | boolean | No | Enable/disable (default: true if tokens set) |
342
+ | `slack.botToken` | string | Yes | Bot User OAuth Token (xoxb-...) |
343
+ | `slack.appToken` | string | Yes | App-Level Token for Socket Mode (xapp-...) |
344
+ | `slack.signingSecret` | string | Yes | Signing Secret for request verification |
345
+ | `slack.allowedChannelIds` | string[] | No | Restrict to specific channel IDs |
346
+
347
+ #### Discord Settings
348
+
349
+ | Field | Type | Required | Description |
350
+ |-------|------|----------|-------------|
351
+ | `discord.enabled` | boolean | No | Enable/disable (default: true if botToken set) |
352
+ | `discord.botToken` | string | Yes | Bot token from Developer Portal |
353
+ | `discord.allowedGuildIds` | string[] | No | Restrict to specific server IDs |
354
+ | `discord.allowedChannelIds` | string[] | No | Restrict to specific channel IDs |
355
+
356
+ ---
357
+
358
+ ## Using the TUI Config Editor
359
+
360
+ Ralph includes a terminal UI config editor that makes setup easier:
361
+
362
+ ```bash
363
+ ralph config
364
+ ```
365
+
366
+ 1. Navigate to the **Chat** section
367
+ 2. Press `p` to select a preset (Telegram, Slack, or Discord)
368
+ 3. Fill in your credentials
369
+ 4. Press `S` to save
370
+
371
+ ---
372
+
373
+ ## Daemon Notifications
374
+
375
+ You can also configure the daemon to send notifications to chat when events occur:
376
+
377
+ ```json
378
+ {
379
+ "daemon": {
380
+ "actions": {
381
+ "notify": {
382
+ "command": "ralph notify"
383
+ }
384
+ },
385
+ "events": {
386
+ "task_complete": [
387
+ { "action": "telegram_notify", "message": "✅ Task complete: {{task}}" }
388
+ ],
389
+ "ralph_complete": [
390
+ { "action": "telegram_notify", "message": "🎉 All tasks complete!" }
391
+ ],
392
+ "error": [
393
+ { "action": "telegram_notify", "message": "❌ Error: {{error}}" }
394
+ ]
395
+ }
396
+ }
397
+ }
398
+ ```
399
+
400
+ Built-in notification actions (available when daemon is running):
401
+ - `telegram_notify` - Send via Telegram
402
+ - `slack_notify` - Send via Slack
403
+ - `discord_notify` - Send via Discord
404
+
405
+ ---
406
+
407
+ ## Troubleshooting
408
+
409
+ ### General Issues
410
+
411
+ #### "Chat daemon not responding"
412
+
413
+ 1. Check that the daemon is running:
414
+ ```bash
415
+ ralph chat status
416
+ ```
417
+
418
+ 2. Start the daemon if it's not running:
419
+ ```bash
420
+ ralph chat start
421
+ ```
422
+
423
+ 3. Check your credentials are correct in config.json
424
+
425
+ #### "Command not recognized"
426
+
427
+ Make sure you're using the correct command format:
428
+ - Telegram: `/run`, `/status`, etc.
429
+ - Slack: `/run` or message the bot
430
+ - Discord: `/run` (slash commands)
431
+
432
+ ### Telegram Issues
433
+
434
+ #### "Unauthorized chat" messages not appearing
435
+
436
+ Your chat ID may not be in `allowedChatIds`. Get your chat ID:
437
+
438
+ ```bash
439
+ curl "https://api.telegram.org/botYOUR_TOKEN/getUpdates"
440
+ ```
441
+
442
+ Look for `"chat":{"id":...}` in the response.
443
+
444
+ #### Bot not responding in groups
445
+
446
+ 1. Make sure the bot is added to the group
447
+ 2. In BotFather, use `/setprivacy` and set to DISABLED to receive all messages
448
+ 3. Or mention the bot directly with commands
449
+
450
+ ### Slack Issues
451
+
452
+ #### "Failed to load Slack modules"
453
+
454
+ Install the required packages:
455
+
456
+ ```bash
457
+ npm install @slack/bolt @slack/web-api
458
+ ```
459
+
460
+ #### "Socket Mode connection failed"
461
+
462
+ 1. Verify Socket Mode is enabled in your Slack app settings
463
+ 2. Check that your App Token (xapp-...) is correct
464
+ 3. Make sure the App Token has the `connections:write` scope
465
+
466
+ #### Slash commands not appearing
467
+
468
+ 1. Reinstall the app to your workspace from the OAuth & Permissions page
469
+ 2. Wait a few minutes for changes to propagate
470
+ 3. Try refreshing Slack (Cmd+R / Ctrl+R)
471
+
472
+ ### Discord Issues
473
+
474
+ #### "Failed to load Discord modules"
475
+
476
+ Install the required package:
477
+
478
+ ```bash
479
+ npm install discord.js
480
+ ```
481
+
482
+ #### "Missing Intents"
483
+
484
+ Make sure **Message Content Intent** is enabled in the Discord Developer Portal under Bot settings.
485
+
486
+ #### Slash commands not appearing
487
+
488
+ 1. Discord can take up to an hour to register global commands
489
+ 2. Try kicking and re-inviting the bot
490
+ 3. Check the bot has `applications.commands` scope
491
+
492
+ #### "Missing Access" errors
493
+
494
+ Ensure the bot has permissions in the channel:
495
+ 1. Right-click the channel → Edit Channel
496
+ 2. Go to Permissions
497
+ 3. Add the bot role with Send Messages and Read Message History
498
+
499
+ ### Connection Timeouts
500
+
501
+ If the chat daemon keeps disconnecting:
502
+
503
+ 1. Check your internet connection
504
+ 2. Verify your tokens haven't expired or been revoked
505
+ 3. Check rate limits (don't send too many messages)
506
+
507
+ ### Security Best Practices
508
+
509
+ 1. **Always use `allowedChatIds`/`allowedChannelIds`** to restrict which chats can control Ralph
510
+ 2. **Never commit tokens** to version control - use environment variables or `.gitignore` your config
511
+ 3. **Rotate tokens** periodically and if you suspect they've been compromised
512
+ 4. **Limit permissions** - only grant the minimum required scopes
513
+
514
+ ---
515
+
516
+ ## Related Documentation
517
+
518
+ - [Daemon Configuration](../README.md#daemon-configuration) - Host daemon setup
519
+ - [Notifications](../README.md#notifications) - Notification system setup
520
+ - [Docker Sandbox](./DOCKER.md) - Running Ralph in containers