|
1 | | -# Bobby Memory Index |
| 1 | +# Bobby - Discord AI Assistant Bot |
2 | 2 |
|
3 | | -This file maintains references to Bobby's memory documents stored in the docs/ directory. |
| 3 | +## Overview |
4 | 4 |
|
5 | | -## Memory Access Instructions |
| 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 | 6 |
|
7 | | -- Read documents from the docs/ directory to retrieve stored information |
8 | | -- Store new information in topic-specific markdown files in the docs/ directory |
9 | | -- Update this index when creating new documents |
| 7 | +## Core Architecture |
10 | 8 |
|
11 | | -## Memory Index |
| 9 | +### Main Components |
12 | 10 |
|
13 | | -- No memories stored yet |
| 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 |
14 | 16 |
|
15 | | -## Bobby Commands |
| 17 | +### Environment Variables Required |
16 | 18 |
|
17 | | -The following commands can be used to interact with Bobby: |
| 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 | +``` |
18 | 26 |
|
19 | | -- `Hey Bobby, [your question]` - Ask Bobby a question about the codebase (creates a new thread) |
20 | | -- `Bobby, what does [code or function] do?` - Ask Bobby to explain specific code (creates a new thread) |
21 | | -- `Bobby, is there a bug in [feature or component]?` - Ask Bobby to check for bugs (creates a new thread) |
| 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) |
22 | 35 |
|
23 | 36 | ## Thread-Based Session Management |
24 | 37 |
|
25 | | -Bobby now uses Discord threads for session management: |
| 38 | +Bobby uses Discord threads for session management with streaming responses: |
26 | 39 |
|
27 | 40 | 1. **New Conversations**: Mention Bobby in any channel to create a new thread with a new Claude Code session |
28 | 41 | 2. **Follow-ups**: Simply type in the thread (no need to mention Bobby) to continue the same Claude Code session |
29 | 42 | 3. **Thread Naming**: Threads are automatically named as `Bobby - Title - session-id` where: |
30 | | - - `Title` is a 3-5 word summary generated by Claude |
| 43 | + - `Title` is a 3-5 word summary generated by Claude (hidden from user via regex) |
31 | 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 |
32 | 47 |
|
33 | | -### How It Works |
| 48 | +### Session Flow |
34 | 49 |
|
35 | | -- Each thread maintains its own Claude Code session context |
36 | | -- All messages in a thread share the same session (memory retained) |
37 | | -- Starting a new conversation creates a new thread and new session |
38 | | -- No cleanup needed - threads auto-archive after 24 hours of inactivity |
| 50 | +``` |
| 51 | +User mentions Bobby → Create thread → Spawn Claude process → Stream JSON responses → Extract session ID → Update thread name |
| 52 | +``` |
39 | 53 |
|
40 | | -## Available Tools |
| 54 | +## Available Tools & Capabilities |
41 | 55 |
|
42 | | -Bobby has access to the following tools: |
| 56 | +Bobby has access to the following tools through Claude Code: |
43 | 57 |
|
44 | | -- Claude Code - For codebase analysis and question answering (READ-ONLY) |
45 | | -- GitHub CLI - For issue creation and repository access |
46 | | -- Discord.js - For interaction with Discord |
| 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 |
47 | 62 |
|
48 | 63 | ## Important Limitations |
49 | 64 |
|
50 | 65 | Bobby is designed as a **READ-ONLY** assistant: |
51 | 66 |
|
52 | 67 | - ✅ Can analyze, explore, and read your codebase |
53 | | -- ✅ Can create GitHub issues for bugs and improvements |
| 68 | +- ✅ Can create GitHub issues for bugs and improvements |
54 | 69 | - ✅ Can provide code recommendations and suggestions |
| 70 | +- ✅ Can fetch latest git changes and analyze repository state |
55 | 71 | - ❌ Cannot modify, edit, or write code files |
56 | 72 | - ❌ Cannot make commits or push changes |
57 | 73 |
|
58 | | -If you ask Bobby to modify code, he will politely decline and offer to create a GitHub issue instead. |
| 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 |
59 | 151 |
|
60 | | -## Guidelines for Issue Filing |
| 152 | +If authentication errors occur (known issue): |
61 | 153 |
|
62 | | -When Bobby detects a bug, it follows these guidelines for filing issues: |
| 154 | +1. Access running container: `docker exec -it bobby /bin/sh` |
| 155 | +2. Manually authenticate: `claude` (follow prompts) |
| 156 | +3. Exit container: `exit` |
63 | 157 |
|
64 | | -1. Clear title describing the bug |
65 | | -2. Detailed description of the issue |
66 | | -3. Steps to reproduce (when available) |
67 | | -4. Tagged with "bobby-detected" label |
| 158 | +This typically resolves authentication problems in the Docker environment. |
68 | 159 |
|
69 | | -## Memory Locations |
| 160 | +## Performance Characteristics |
70 | 161 |
|
71 | | -- General queries: docs/general-queries.md |
72 | | -- Bugs: docs/bugs.md |
73 | | -- Technical requirements: docs/technical-requirements.md |
74 | | -- Feature requests: docs/feature-requests.md |
| 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) |
0 commit comments