Skip to content

Commit bea7c08

Browse files
Stewart86opencode
andcommitted
enhance: improve Bobby's GitHub issue creation with comprehensive clarification workflow
- Add mandatory 5-step process for GitHub issue creation - Require code examination and iterative clarification before creating issues - Include detailed examples for clarification and creation phases - Ensure Bobby creates well-researched, comprehensive GitHub issues - Add node_modules/ to .gitignore for cleaner repository 🤖 Generated with [opencode](https://opencode.ai) Co-Authored-By: opencode <[email protected]>
1 parent 8fed246 commit bea7c08

File tree

3 files changed

+295
-19
lines changed

3 files changed

+295
-19
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
secret.md
22
.claude.json
3+
4+
node_modules/

AGENT.md

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# Bobby - Discord AI Assistant Bot
2+
3+
## Overview
4+
5+
Bobby is a Discord chatbot that helps answer questions about your codebase, file bugs, and translate business requirements into technical requirements. Bobby leverages Claude Code to understand your codebase and provide intelligent responses in a self-hosted, privacy-first environment.
6+
7+
## Core Architecture
8+
9+
### Main Components
10+
11+
- **index.js** - Main Node.js application using Bun runtime
12+
- **Discord.js** - Handles Discord bot interactions and thread management
13+
- **Claude Code CLI** - Powers AI analysis of codebases with streaming responses
14+
- **GitHub CLI** - Creates issues automatically when bugs are detected
15+
- **Docker Container** - Self-contained environment with all dependencies
16+
17+
### Environment Variables Required
18+
19+
```
20+
DISCORD_TOKEN=your_discord_bot_token
21+
ANTHROPIC_API_KEY=your_anthropic_api_key
22+
GH_TOKEN=your_github_personal_access_token
23+
GITHUB_REPO=owner/repo-name
24+
ALLOWED_DISCORD_SERVERS=server_id1,server_id2 (optional)
25+
```
26+
27+
### Docker Architecture
28+
29+
- **Base Image**: `oven/bun:latest`
30+
- **Dependencies**: Git, GitHub CLI v2.61.0, Claude Code CLI
31+
- **Working Directory**: `/app`
32+
- **Repository Clone**: `/app/repo` (target repository)
33+
- **Data Storage**: `/app/data` (Claude Code sessions and configs)
34+
- **Entrypoint**: `entrypoint.sh` (handles authentication and setup)
35+
36+
## Thread-Based Session Management
37+
38+
Bobby uses Discord threads for session management with streaming responses:
39+
40+
1. **New Conversations**: Mention Bobby in any channel to create a new thread with a new Claude Code session
41+
2. **Follow-ups**: Simply type in the thread (no need to mention Bobby) to continue the same Claude Code session
42+
3. **Thread Naming**: Threads are automatically named as `Bobby - Title - session-id` where:
43+
- `Title` is a 3-5 word summary generated by Claude (hidden from user via regex)
44+
- `session-id` is the Claude Code session identifier
45+
4. **Streaming Responses**: Real-time message streaming with JSON parsing
46+
5. **Auto-Archive**: Threads automatically archive after 24 hours of inactivity
47+
48+
### Session Flow
49+
50+
```
51+
User mentions Bobby → Create thread → Spawn Claude process → Stream JSON responses → Extract session ID → Update thread name
52+
```
53+
54+
## Available Tools & Capabilities
55+
56+
Bobby has access to the following tools through Claude Code:
57+
58+
- **Read, Grep, Glob, LS** - File operations for codebase analysis
59+
- **Bash(gh:*)** - GitHub CLI for issue creation and repository access
60+
- **Bash(git:*)** - Git commands for repository operations
61+
- **WebFetch, WebSearch** - Web access for additional information
62+
63+
## Important Limitations
64+
65+
Bobby is designed as a **READ-ONLY** assistant:
66+
67+
- ✅ Can analyze, explore, and read your codebase
68+
- ✅ Can create GitHub issues for bugs and improvements
69+
- ✅ Can provide code recommendations and suggestions
70+
- ✅ Can fetch latest git changes and analyze repository state
71+
- ❌ Cannot modify, edit, or write code files
72+
- ❌ Cannot make commits or push changes
73+
74+
**Enforcement**: The system prompt explicitly instructs Claude to immediately decline any modification requests and offer to create GitHub issues instead.
75+
76+
## System Prompt Configuration
77+
78+
Bobby uses an optimized system prompt with:
79+
80+
- **Role Definition**: Expert code analysis assistant
81+
- **Context Awareness**: Discord environment constraints
82+
- **Session Management**: Thread-based conversation handling
83+
- **Response Format**: Concise, actionable responses with bullet points
84+
- **Thread Title Generation**: `[THREAD_TITLE: <title>]` pattern (filtered from user view)
85+
- **GitHub Integration**: Automatic issue creation for bugs and feature requests
86+
87+
## Streaming Response Processing
88+
89+
Bobby implements real-time response streaming:
90+
91+
1. **Process Spawning**: `claude` CLI with `--output-format stream-json`
92+
2. **JSON Parsing**: Line-by-line JSON object parsing from stdout
93+
3. **Content Filtering**: Removes `[THREAD_TITLE: <title>]` patterns before sending to user
94+
4. **Session Tracking**: Extracts session IDs and thread titles from metadata
95+
5. **Error Handling**: Captures stderr and provides fallback responses
96+
97+
## Security Features
98+
99+
- **Server Whitelist**: `ALLOWED_DISCORD_SERVERS` environment variable controls access
100+
- **Private Bot**: Designed to be run as private Discord application
101+
- **Token Validation**: Validates all required environment variables on startup
102+
- **Container Isolation**: Runs in isolated Docker environment
103+
- **Data Persistence**: Claude Code sessions persist in `/app/data` volume
104+
105+
## Deployment Options
106+
107+
### Docker Hub (Recommended)
108+
```bash
109+
docker run -d --name bobby \
110+
-e DISCORD_TOKEN=your_token \
111+
-e ANTHROPIC_API_KEY=your_key \
112+
-e GH_TOKEN=your_gh_token \
113+
-e GITHUB_REPO=owner/repo \
114+
-v bobby-data:/app/data \
115+
stewart86/bobby:latest
116+
```
117+
118+
### Build from Source
119+
```bash
120+
git clone https://github.com/Stewart86/bobby.git
121+
docker build -t bobby-bot .
122+
docker run -d --name bobby [env vars] bobby-bot
123+
```
124+
125+
## Automated Publishing
126+
127+
GitHub Actions workflow (`docker-publish.yml`) automatically:
128+
- Builds Docker images on commits to main
129+
- Creates versioned releases on git tags
130+
- Publishes to Docker Hub as `stewart86/bobby`
131+
- Syncs README to Docker Hub (with error tolerance)
132+
133+
## Issue Filing Guidelines
134+
135+
When Bobby detects bugs, it follows these guidelines:
136+
137+
1. **Clear title** describing the bug
138+
2. **Detailed description** with technical details
139+
3. **Reproduction steps** when available
140+
4. **Labels**: "bug,bobby-detected" or "enhancement,bobby-detected"
141+
5. **Attribution**: "Detected by Bobby (Claude Code assistant)"
142+
6. **Response Format**: Always includes issue link and number
143+
144+
## Memory Management
145+
146+
Bobby stores information in Markdown files in the `docs/` directory, organized by topic. The `CLAUDE.md` file serves as an index to these memory files, helping Claude find relevant information during conversations.
147+
148+
## Troubleshooting
149+
150+
### Claude API Authentication Issues
151+
152+
If authentication errors occur (known issue):
153+
154+
1. Access running container: `docker exec -it bobby /bin/sh`
155+
2. Manually authenticate: `claude` (follow prompts)
156+
3. Exit container: `exit`
157+
158+
This typically resolves authentication problems in the Docker environment.
159+
160+
## Performance Characteristics
161+
162+
- **Startup Time**: ~30 seconds (includes repository cloning)
163+
- **Response Time**: Real-time streaming (starts within 2-3 seconds)
164+
- **Memory Usage**: ~100-200MB base + Claude Code processes
165+
- **Storage**: Minimal (repository clone + session data)
166+
- **Network**: Outbound only (Discord, GitHub, Anthropic APIs)

index.js

Lines changed: 127 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ When users ask about your capabilities or session management, explain this syste
134134
<instructions>
135135
1. **FIRST: Check if the request involves code modification** - if yes, immediately decline and offer to create a GitHub issue
136136
2. **Always start by fetching latest git changes** using available tools (only for analysis requests)
137-
3. **Analyze the relevant code sections** thoroughly but efficiently
137+
3. **Analyze the relevant code sections** thoroughly but efficiently
138138
4. **Provide direct, actionable answers** - users need solutions, not explanations of problems
139139
5. **If you discover genuine bugs:** Check for existing GitHub issues first, then create a detailed issue if none exists
140140
6. **When declining code modifications:** IMMEDIATELY create a GitHub issue using the Bash tool with gh CLI
141-
7. **You HAVE Bash tool access** - use it confidently to run gh commands for issue creation
141+
7. **When users ask to create GitHub issues:** Follow the mandatory clarification process - examine code, ask questions, iterate until complete understanding, then create
142+
8. **You HAVE Bash tool access** - use it confidently to run gh commands for issue creation
142143
143144
<response_format>
144145
- Lead with the **direct answer** (1-2 sentences max)
@@ -153,26 +154,88 @@ You HAVE the Bash tool with gh CLI access and MUST create GitHub issues for:
153154
- Bugs you discover in the code
154155
- Feature requests when users ask for code modifications
155156
- Improvements you identify
157+
- **When users explicitly ask you to create a GitHub issue**
156158
157159
IMPORTANT: You have these tools available - use them confidently:
158160
- Bash tool (for gh and git commands)
159161
- Read, Grep, Glob, List tools (for file operations)
160162
161-
To create GitHub issues, use the Bash tool with:
162-
- Command: \`gh issue create --title "Title" --body "Description" --label bug,bobby-detected\`
163-
- Title: Clear, specific problem statement
164-
- Body: Problem summary + technical details + reproduction steps
165-
- Labels: "bug" and "bobby-detected" (or "enhancement,bobby-detected" for features)
166-
- Mention: "Detected by Bobby (Claude Code assistant)"
167-
- ALWAYS provide the issue link and number in your response
168-
- Format: "Created GitHub issue #123: https://github.com/owner/repo/issues/123"
163+
**GitHub Issue Creation Protocol:**
164+
When users ask you to create a GitHub issue, follow this MANDATORY process:
165+
166+
**STEP 1: CLARIFICATION & CODE EXAMINATION**
167+
- **NEVER create an issue immediately** - always gather complete information first
168+
- Ask clarifying questions about:
169+
- Specific problem or feature details
170+
- Expected behavior vs actual behavior (for bugs)
171+
- Use cases and requirements (for features)
172+
- Priority and scope
173+
- Any relevant file paths or components
174+
175+
**STEP 2: CODE INVESTIGATION**
176+
- Use Read, Grep, Glob tools to examine relevant code sections
177+
- Understand the current implementation
178+
- Identify related files, functions, or components
179+
- Look for existing similar features or bug patterns
180+
- Check for any existing issues that might be related
181+
182+
**STEP 3: ITERATIVE CLARIFICATION**
183+
- If code examination reveals gaps in understanding, ask MORE specific questions
184+
- Continue this process until you have a complete picture OR user says "create the issue anyway"
185+
- Ask technical questions based on your code analysis
186+
- Suggest specific implementation approaches for features
187+
- Identify potential edge cases or considerations
188+
189+
**STEP 4: FINAL CONFIRMATION**
190+
- Summarize your understanding of the issue/feature
191+
- Present the proposed issue title and description outline
192+
- Ask: "Does this capture everything correctly? Should I create the GitHub issue now?"
193+
- Only proceed when user confirms OR explicitly says it's good enough
194+
195+
**STEP 5: ISSUE CREATION**
196+
Use the gh CLI via Bash tool with this format:
197+
```
198+
gh issue create --title "Issue Title" --body "Detailed Description" --label appropriate-labels
199+
```
200+
201+
**Required components:**
202+
- Title: Clear, specific problem statement or feature request
203+
- Body: Comprehensive description including:
204+
- Problem/feature description
205+
- Current behavior (for bugs) or current state (for features)
206+
- Expected behavior or desired outcome
207+
- Technical context from code examination
208+
- Relevant file paths and code references
209+
- Implementation suggestions (if applicable)
210+
- Edge cases or considerations identified
211+
- Labels: "bug,bobby-detected", "enhancement,bobby-detected", or "question,bobby-detected"
212+
- Attribution: "Created by Bobby (Claude Code assistant) after thorough analysis"
213+
214+
**Response format after creation:**
215+
- Provide issue link and number: "Created GitHub issue #123: https://github.com/owner/repo/issues/123"
216+
- Brief summary of what was created
217+
218+
**Example Clarification Flow:**
219+
User: "Create an issue for the login problem"
220+
Bobby: "I need more details about the login problem. Let me examine the authentication code first..."
221+
[Examines auth-related files]
222+
Bobby: "I found the login components in src/auth/. Can you clarify:
223+
• What specific error occurs during login?
224+
• Does it happen with all users or specific accounts?
225+
• Is this on the web interface, mobile app, or API?
226+
• When did this issue start occurring?"
227+
228+
[User provides details]
229+
Bobby: "Based on the code and your description, I see the issue is in the JWT validation. Should I create an issue titled 'JWT token validation fails for expired sessions' with the technical details I found?"
230+
231+
[Only creates issue after user confirmation]
169232
</github_issues>
170233
171234
<examples>
172235
Good analysis response:
173236
"The function is missing null checks on line 42. This will cause crashes when users pass undefined values.
174237
175-
• Problem: No validation for \`user.email\` parameter
238+
• Problem: No validation for \`user.email\` parameter
176239
• Impact: Runtime errors in production
177240
• Fix: Add \`if (!user?.email) return null;\`"
178241
@@ -188,9 +251,54 @@ Created GitHub issue #156: https://github.com/owner/repo/issues/156"
188251
Good modification decline with issue creation:
189252
"I can't create or modify code, but I'll create a GitHub issue for this listOrders feature request.
190253
191-
[Uses Bash tool to run: gh issue create --title "Add listOrders method to KosmoService" --body "Feature request for retrieving multiple delivery orders with filtering capabilities. Detected by Bobby (Claude Code assistant)" --label enhancement,bobby-detected]
254+
[Uses Bash tool to run: gh issue create --title "Add listOrders method to KosmoService" --body "Feature request for retrieving multiple delivery orders with filtering capabilities. Created by Bobby (Claude Code assistant)" --label enhancement,bobby-detected]
192255
193256
Created GitHub issue #157: https://github.com/owner/repo/issues/157"
257+
258+
Good response when user asks to create an issue (CLARIFICATION PHASE):
259+
User: "Create an issue for the dashboard being slow"
260+
Bobby: "I need to understand the dashboard performance issue better. Let me examine the dashboard code first..."
261+
262+
[Uses Read/Grep tools to examine dashboard components]
263+
264+
Bobby: "I found the dashboard components in src/components/Dashboard.tsx. To create a comprehensive issue, I need clarification:
265+
266+
• Which specific dashboard sections are slow?
267+
• How many records typically load when it's slow?
268+
• Is the slowness during initial load or when filtering/sorting?
269+
• What's the acceptable vs current load time?
270+
• Does this affect all users or specific user roles?"
271+
272+
[After user provides details and Bobby confirms understanding]
273+
274+
Good response when creating the issue (CREATION PHASE):
275+
"Perfect! Based on our discussion and code analysis, I'll create the issue now.
276+
277+
[Uses Bash tool to run: gh issue create --title "Dashboard performance degradation with large datasets (>1000 records)" --body "## Problem
278+
Users experience 8-10 second load times on the main dashboard when viewing datasets over 1000 records, compared to expected 2-3 seconds.
279+
280+
## Current Behavior
281+
- Initial dashboard load takes 8-10 seconds with large datasets
282+
- Affects the data table component in src/components/Dashboard.tsx:45
283+
- Issue occurs during data fetching and rendering phases
284+
285+
## Expected Behavior
286+
- Dashboard should load within 2-3 seconds regardless of dataset size
287+
- Smooth user experience for all data volumes
288+
289+
## Technical Context
290+
- Dashboard component uses inefficient data fetching in useEffect
291+
- No pagination or virtualization implemented
292+
- Large DOM rendering without optimization
293+
294+
## Suggested Implementation
295+
- Implement server-side pagination
296+
- Add virtual scrolling for large tables
297+
- Optimize data fetching with proper caching
298+
299+
Created by Bobby (Claude Code assistant) after thorough analysis" --label bug,bobby-detected]
300+
301+
Created GitHub issue #158: https://github.com/owner/repo/issues/158"
194302
</examples>
195303
</instructions>
196304
@@ -250,28 +358,28 @@ Be precise, actionable, and concise. Users value speed and accuracy over verbose
250358

251359
for (let i = 0; i < jsonBuffer.length; i++) {
252360
const char = jsonBuffer[i];
253-
361+
254362
if (escapeNext) {
255363
escapeNext = false;
256364
continue;
257365
}
258-
366+
259367
if (char === '\\' && inString) {
260368
escapeNext = true;
261369
continue;
262370
}
263-
371+
264372
if (char === '"') {
265373
inString = !inString;
266374
continue;
267375
}
268-
376+
269377
if (!inString) {
270378
if (char === '{') {
271379
braceCount++;
272380
} else if (char === '}') {
273381
braceCount--;
274-
382+
275383
// Complete JSON object found
276384
if (braceCount === 0) {
277385
const jsonStr = jsonBuffer.substring(startIndex, i + 1);
@@ -358,15 +466,15 @@ Be precise, actionable, and concise. Users value speed and accuracy over verbose
358466
} catch (parseError) {
359467
console.log("Failed to parse JSON object:", parseError.message);
360468
}
361-
469+
362470
// Move to next potential JSON object
363471
startIndex = i + 1;
364472
braceCount = 0;
365473
}
366474
}
367475
}
368476
}
369-
477+
370478
// Remove processed JSON objects from buffer
371479
jsonBuffer = jsonBuffer.substring(startIndex);
372480
}

0 commit comments

Comments
 (0)