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,251 @@
1
+ # Ralph Chat Architecture
2
+
3
+ ## Overview
4
+
5
+ The Ralph CLI chat system enables external control of Ralph projects via chat platforms (Slack, Discord, Telegram). It consists of two main components that communicate via a file-based message queue.
6
+
7
+ ## High-Level Architecture
8
+
9
+ ```
10
+ ┌─────────────────────────────────────────────────────────────────────────────┐
11
+ │ SLACK / DISCORD │
12
+ │ │
13
+ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌──────────────────┐ │
14
+ │ │ /ralph cmd │ │ @bot mention │ │ @qa @review │ │ Thread replies │ │
15
+ │ │ (slash cmd) │ │ (app_mention)│ │ (responders) │ │ (continuation) │ │
16
+ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ └────────┬─────────┘ │
17
+ └─────────┼─────────────────┼─────────────────┼───────────────────┼───────────┘
18
+ │ │ │ │
19
+ ▼ ▼ ▼ ▼
20
+ ┌─────────────────────────────────────────────────────────────────────────────┐
21
+ │ HOST: ralph chat start │
22
+ │ │
23
+ │ ┌───────────────────────────────────────────────────────────────────────┐ │
24
+ │ │ CHAT PROVIDER (Slack/Discord) │ │
25
+ │ │ │ │
26
+ │ │ ┌─────────────┐ ┌─────────────────┐ ┌──────────────────────┐ │ │
27
+ │ │ │ Event │───▶│ ResponderMatcher │───▶│ Thread Conversations │ │ │
28
+ │ │ │ Handlers │ │ (@qa, @review) │ │ (multi-turn memory) │ │ │
29
+ │ │ └─────────────┘ └────────┬────────┘ └──────────────────────┘ │ │
30
+ │ │ │ │ │
31
+ │ └──────────────────────────────┼─────────────────────────────────────────┘ │
32
+ │ │ │
33
+ │ ┌───────────────────────┼───────────────────────┐ │
34
+ │ ▼ ▼ ▼ │
35
+ │ ┌─────────────┐ ┌───────────────────┐ ┌───────────────────┐ │
36
+ │ │ LLM │ │ Claude Code │ │ CLI Responder │ │
37
+ │ │ Responder │ │ Responder │ │ (shell commands) │ │
38
+ │ │ │ │ │ │ │ │
39
+ │ │ ┌─────────┐ │ │ claude -p "..." │ │ eslint, etc. │ │
40
+ │ │ │Anthropic│ │ │ --print │ │ │ │
41
+ │ │ │ OpenAI │ │ │ │ │ │ │
42
+ │ │ └─────────┘ │ └───────────────────┘ └───────────────────┘ │
43
+ │ │ │ │
44
+ │ │ ┌─────────┐ │ │
45
+ │ │ │Git Diff │ │ /ralph commands (run, status, exec, etc.) │
46
+ │ │ │Keywords │ │ │ │
47
+ │ │ └─────────┘ │ ▼ │
48
+ │ └─────────────┘ ┌───────────────────────────────────────┐ │
49
+ │ │ Command Handler │ │
50
+ │ │ run, stop, status, exec, add, claude │ │
51
+ │ └───────────────────┬───────────────────┘ │
52
+ │ │ │
53
+ │ ▼ │
54
+ │ ┌───────────────────────────────────────┐ │
55
+ │ │ .ralph/messages.json │ │
56
+ │ │ (Message Queue) │ │
57
+ │ └───────────────────┬───────────────────┘ │
58
+ └─────────────────────────────────────────┼────────────────────────────────────┘
59
+
60
+ ══════════════════════╪══════════════════════
61
+ DOCKER BOUNDARY │ (volume mount)
62
+ ══════════════════════╪══════════════════════
63
+
64
+ ┌─────────────────────────────────────────┼────────────────────────────────────┐
65
+ │ ▼ │
66
+ │ ┌───────────────────────────────────────┐ │
67
+ │ │ /workspace/.ralph/messages.json │ │
68
+ │ │ (same file via mount) │ │
69
+ │ └───────────────────┬───────────────────┘ │
70
+ │ │ │
71
+ │ ▼ │
72
+ │ ┌───────────────────────────────────────┐ │
73
+ │ │ ralph listen │ │
74
+ │ │ (polls for pending messages) │ │
75
+ │ └───────────────────┬───────────────────┘ │
76
+ │ │ │
77
+ │ ┌───────────────────────────────┼───────────────────┐ │
78
+ │ ▼ ▼ ▼ │
79
+ │ ┌─────────────┐ ┌───────────────┐ ┌─────────────┐ │
80
+ │ │ ralph run │ │ exec command │ │ ralph │ │
81
+ │ │ --category │ │ (shell) │ │ status │ │
82
+ │ └─────────────┘ └───────────────┘ └─────────────┘ │
83
+ │ │
84
+ │ CONTAINER: ralph listen │
85
+ └──────────────────────────────────────────────────────────────────────────────┘
86
+ ```
87
+
88
+ ## Responder Flow
89
+
90
+ ```
91
+ ┌─────────────────────────────────────────────────────────────────┐
92
+ │ Message: "@review last" │
93
+ └─────────────────────────────┬───────────────────────────────────┘
94
+
95
+
96
+ ┌─────────────────────────────────────────────────────────────────┐
97
+ │ ResponderMatcher │
98
+ │ │
99
+ │ 1. Check @mention triggers: @qa, @review, @explain, @code │
100
+ │ 2. Check keyword triggers: !lint, help │
101
+ │ 3. Fall back to default responder │
102
+ └─────────────────────────────┬───────────────────────────────────┘
103
+
104
+
105
+ ┌─────────────────────────────────────────────────────────────────┐
106
+ │ Match: @review → "reviewer" │
107
+ │ Args: "last" │
108
+ └─────────────────────────────┬───────────────────────────────────┘
109
+
110
+
111
+ ┌─────────────────────────────────────────────────────────────────┐
112
+ │ LLM Responder │
113
+ │ │
114
+ │ 1. Detect git keyword: "last" → git show HEAD │
115
+ │ 2. Fetch git diff content │
116
+ │ 3. Build message with diff │
117
+ │ 4. Load conversation history (if thread) │
118
+ │ 5. Send to LLM (Anthropic/OpenAI) │
119
+ │ 6. Log to .ralph/logs/responder-YYYY-MM-DD.log │
120
+ │ 7. Return response │
121
+ └─────────────────────────────┬───────────────────────────────────┘
122
+
123
+
124
+ ┌─────────────────────────────────────────────────────────────────┐
125
+ │ Store in Thread Conversation │
126
+ │ │
127
+ │ threadConversations.set(threadTs, { │
128
+ │ responderName: "reviewer", │
129
+ │ messages: [ │
130
+ │ { role: "user", content: "..." }, │
131
+ │ { role: "assistant", content: "..." } │
132
+ │ ] │
133
+ │ }) │
134
+ └─────────────────────────────┬───────────────────────────────────┘
135
+
136
+
137
+ ┌─────────────────────────────────────────────────────────────────┐
138
+ │ Reply in Slack Thread │
139
+ └─────────────────────────────────────────────────────────────────┘
140
+ ```
141
+
142
+ ## Thread Conversation Flow
143
+
144
+ ```
145
+ Thread Start Thread Continuation
146
+ ───────────── ───────────────────
147
+
148
+ User: @review diff User: What about security?
149
+ │ │
150
+ ▼ ▼
151
+ ResponderMatcher Check threadConversations
152
+ matches "@review" ─────────────────────────
153
+ │ Found existing conversation
154
+ ▼ for this thread_ts
155
+ Execute LLM with │
156
+ git diff content ▼
157
+ │ Execute LLM with:
158
+ ▼ - Previous messages (history)
159
+ Store conversation - New user message
160
+ in threadConversations │
161
+ │ ▼
162
+ ▼ Append to conversation
163
+ Reply in thread history (max 20 messages)
164
+
165
+
166
+ Reply in thread
167
+ ```
168
+
169
+ ## Message Queue Format
170
+
171
+ ```json
172
+ {
173
+ "messages": [
174
+ {
175
+ "id": "uuid-1234",
176
+ "from": "host",
177
+ "action": "run",
178
+ "args": ["feature"],
179
+ "timestamp": 1706789012345,
180
+ "status": "pending"
181
+ },
182
+ {
183
+ "id": "uuid-1234",
184
+ "from": "host",
185
+ "action": "run",
186
+ "args": ["feature"],
187
+ "timestamp": 1706789012345,
188
+ "status": "done",
189
+ "response": {
190
+ "success": true,
191
+ "output": "Ralph run started (category: feature)"
192
+ }
193
+ }
194
+ ]
195
+ }
196
+ ```
197
+
198
+ ## Git Diff Keywords
199
+
200
+ | Keyword | Git Command | Description |
201
+ |---------|-------------|-------------|
202
+ | `diff` / `changes` | `git diff` | Unstaged changes |
203
+ | `staged` | `git diff --cached` | Staged changes |
204
+ | `last` / `last commit` | `git show HEAD` | Last commit |
205
+ | `all` | `git diff HEAD` | All uncommitted |
206
+ | `HEAD~N` | `git show HEAD~N` | N commits ago |
207
+
208
+ ## Responder Types
209
+
210
+ | Type | Description | Example Trigger |
211
+ |------|-------------|-----------------|
212
+ | `llm` | Send to LLM (Anthropic/OpenAI) | `@qa`, `@review` |
213
+ | `claude-code` | Spawn Claude Code CLI | `@code` |
214
+ | `cli` | Run shell command | `!lint` |
215
+
216
+ ## Configuration
217
+
218
+ ```json
219
+ {
220
+ "chat": {
221
+ "provider": "slack",
222
+ "slack": {
223
+ "botToken": "xoxb-...",
224
+ "appToken": "xapp-...",
225
+ "signingSecret": "...",
226
+ "allowedChannelIds": ["C1234567890"]
227
+ },
228
+ "responders": {
229
+ "qa": {
230
+ "type": "llm",
231
+ "trigger": "@qa",
232
+ "provider": "anthropic",
233
+ "systemPrompt": "You are a QA assistant for {{project}}..."
234
+ }
235
+ }
236
+ }
237
+ }
238
+ ```
239
+
240
+ ## File Locations
241
+
242
+ ```
243
+ Host Machine Container
244
+ ──────────── ─────────
245
+ .ralph/
246
+ ├── config.json /workspace/.ralph/
247
+ ├── chat-state.json ├── messages.json (shared)
248
+ ├── messages.json ◄──── mount ────► ├── run.pid
249
+ └── logs/ └── ...
250
+ └── responder-YYYY-MM-DD.log
251
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ralph-cli-sandboxed",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "AI-driven development automation CLI for Claude Code",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,19 +17,29 @@
17
17
  "copy-config": "mkdir -p dist/config && cp src/config/*.json dist/config/",
18
18
  "dev": "npx tsx src/index.ts",
19
19
  "typecheck": "tsc --noEmit",
20
+ "lint": "oxlint src/",
21
+ "format": "oxfmt src/",
22
+ "format:check": "oxfmt --check src/",
20
23
  "prepublishOnly": "npm run build",
21
24
  "prepare": "npm run build"
22
25
  },
23
26
  "dependencies": {
27
+ "@anthropic-ai/sdk": "^0.39.0",
24
28
  "@inkjs/ui": "^2.0.0",
29
+ "@slack/bolt": "^4.6.0",
30
+ "@slack/web-api": "^7.13.0",
31
+ "discord.js": "^14.16.0",
25
32
  "ink": "^5.0.1",
26
33
  "ink-text-input": "^6.0.0",
34
+ "openai": "^4.77.0",
27
35
  "react": "^18.3.1",
28
36
  "readline": "^1.3.0"
29
37
  },
30
38
  "devDependencies": {
31
39
  "@types/node": "^20.0.0",
32
40
  "@types/react": "^18.3.12",
41
+ "oxfmt": "^0.27.0",
42
+ "oxlint": "^1.42.0",
33
43
  "tsx": "^4.0.0",
34
44
  "typescript": "^5.0.0"
35
45
  },
@@ -57,5 +67,8 @@
57
67
  },
58
68
  "engines": {
59
69
  "node": ">=18.0.0"
70
+ },
71
+ "overrides": {
72
+ "undici": "^6.23.0"
60
73
  }
61
74
  }