opencode-avatar 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 OpenCode Community
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,239 @@
1
+ # OpenCode Avatar Plugin
2
+
3
+ A dynamic desktop avatar plugin for OpenCode that displays animated character reactions based on your coding activities.
4
+
5
+ <div align="center"><img src="avatar.png" alt="Avatar" width="200" /></div>
6
+
7
+ ## Features
8
+
9
+ - **Dynamic Avatar Display**: Desktop character that reacts to your OpenCode usage
10
+ - **Thinking Animation**: Shows "thinking hard" when you send messages
11
+ - **Tool-Based Reactions**: Avatar changes pose based on which tools are being used
12
+ - **Smart Caching**: Generated avatars are cached for instant loading
13
+ - **Non-Intrusive**: Appears without stealing focus, stays on top
14
+ - **Auto-Shutdown**: Automatically closes when OpenCode exits
15
+ - **Toast Notifications**: Shows progress for avatar generation
16
+
17
+ ## Installation
18
+
19
+ ### Option 1: From NPM (Recommended)
20
+
21
+ ```bash
22
+ npm install -g opencode-avatar
23
+ ```
24
+
25
+ Then add to your OpenCode config:
26
+
27
+ ```json
28
+ {
29
+ "$schema": "https://opencode.ai/config.json",
30
+ "plugin": ["opencode-avatar"]
31
+ }
32
+ ```
33
+
34
+ ### Option 2: Local Development
35
+
36
+ 1. Clone this repository
37
+ 2. Run `npm install`
38
+ 3. Run `npm run build`
39
+ 4. Copy to your OpenCode plugins directory:
40
+ - Project: `.opencode/plugins/`
41
+ - Global: `~/.config/opencode/plugins/`
42
+
43
+ ## Configuration
44
+
45
+ ### Environment Variables
46
+
47
+ Create a `.env` file in the plugin directory:
48
+
49
+ ```env
50
+ FAL_KEY=your_fal_ai_api_key_here
51
+ ```
52
+
53
+ Get your FAL.ai API key from [fal.ai](https://fal.ai).
54
+
55
+ ### Avatar Images
56
+
57
+ The plugin comes with a default avatar (`avatar.png`). Place custom avatars in the plugin directory:
58
+
59
+ - `avatar.png` - Default avatar (required)
60
+ - `avatar.svg` - Fallback avatar (optional)
61
+
62
+ ## How It Works
63
+
64
+ ### Avatar States
65
+
66
+ | State | Trigger | Description |
67
+ |-------|---------|-------------|
68
+ | **Default** | Session idle | Neutral pose, waiting for input |
69
+ | **Thinking** | User message | "Thinking hard" animation while processing |
70
+ | **Tool Active** | Tool execution | Pose based on current tool (write, read, etc.) |
71
+
72
+ ### Tool Mappings
73
+
74
+ The avatar automatically detects which tools you're using and shows appropriate reactions:
75
+
76
+ | Tool | Avatar Pose |
77
+ |------|-------------|
78
+ | `write` | Writing with pencil |
79
+ | `read` | Reading a book |
80
+ | `edit` | Editing with scissors |
81
+ | `glob` | Searching with magnifying glass |
82
+ | `grep` | Detective searching |
83
+ | `bash` | Hacker typing |
84
+ | `webfetch` | Surfing the web |
85
+
86
+ ### File Naming
87
+
88
+ Avatar images are cached with predictable filenames:
89
+ - `avatar_write.png` - Writing tool
90
+ - `avatar_read.png` - Reading tool
91
+ - `avatar_thinking_hard.png` - Thinking state
92
+
93
+ ## Usage
94
+
95
+ ### Basic Usage
96
+
97
+ 1. Install the plugin
98
+ 2. Configure your FAL.ai API key
99
+ 3. Start OpenCode - avatar appears automatically
100
+ 4. Send messages - avatar shows thinking animation
101
+ 5. Use tools - avatar reacts to each tool
102
+
103
+ ### Manual Control
104
+
105
+ The avatar responds automatically, but you can also:
106
+
107
+ - **Show/Hide**: Click the system tray icon
108
+ - **Quit**: Right-click tray icon → Quit
109
+ - **Move**: Drag the avatar window to reposition
110
+
111
+ ### Logs and Debugging
112
+
113
+ Check the console output for detailed information.
114
+
115
+ The output shows:
116
+ - Plugin initialization
117
+ - Avatar generation requests
118
+ - Tool execution detection
119
+ - Electron process lifecycle
120
+
121
+ ## Architecture
122
+
123
+ ### Components
124
+
125
+ ```
126
+ ├── index.ts # Main plugin logic
127
+ ├── electron.ts # Desktop window management
128
+ ├── avatar.png # Default avatar image
129
+ └── dist/ # Compiled output
130
+ ```
131
+
132
+ ### Communication Flow
133
+
134
+ 1. **Plugin** detects OpenCode events (messages, tool usage)
135
+ 2. **HTTP** requests sent to Electron process
136
+ 3. **Electron** generates/updates avatar via FAL.ai API
137
+ 4. **Window** displays new avatar image
138
+ 5. **Heartbeat** ensures Electron stays alive
139
+
140
+ ### Safety Features
141
+
142
+ - **Duplicate Prevention**: Only one avatar instance runs
143
+ - **Multi-Instance Support**: Multiple OpenCode instances share the same avatar window
144
+ - **Auto-Shutdown**: Closes when OpenCode exits
145
+ - **Focus Protection**: Never steals keyboard focus
146
+ - **Error Handling**: Graceful fallbacks on failures
147
+
148
+ ## API Reference
149
+
150
+ ### Plugin Hooks
151
+
152
+ - `chat.message` - Detects user input
153
+ - `tool.execute.before` - Detects tool usage
154
+ - `event` - Handles session state changes
155
+
156
+ ### HTTP Endpoints
157
+
158
+ | Endpoint | Method | Description |
159
+ |----------|--------|-------------|
160
+ | `/health` | GET | Health check |
161
+ | `/heartbeat` | POST | Keep-alive signal |
162
+ | `/set-avatar` | POST | Change displayed avatar |
163
+ | `/generate-avatar` | POST | Generate new avatar |
164
+ | `/shutdown` | POST | Graceful shutdown |
165
+
166
+ ## Troubleshooting
167
+
168
+ ### Avatar Not Showing
169
+
170
+ 1. Check console output for errors
171
+ 2. Verify FAL.ai API key in `.env`
172
+ 3. Ensure port 47291 is available
173
+ 4. Try restarting OpenCode
174
+
175
+ ### Avatar Generation Failing
176
+
177
+ 1. Check FAL.ai API key validity
178
+ 2. Verify internet connection
179
+ 3. Check available disk space for cache
180
+ 4. Look for API rate limits
181
+
182
+ ### Focus Issues
183
+
184
+ - Avatar should never steal focus
185
+ - If it does, check Electron window settings
186
+ - Try `focusable: false` in window config
187
+
188
+ ### Performance Issues
189
+
190
+ - First avatar generation takes ~10-30 seconds
191
+ - Subsequent loads are instant (cached)
192
+ - Reduce avatar size for faster generation
193
+
194
+ ## Development
195
+
196
+ ### Building
197
+
198
+ ```bash
199
+ npm run build
200
+ ```
201
+
202
+ ### Testing
203
+
204
+ ```bash
205
+ # Test Electron window
206
+ npm run start
207
+
208
+ # Test with thinking avatar
209
+ npm run start:thinking
210
+ ```
211
+
212
+ ### Contributing
213
+
214
+ 1. Fork the repository
215
+ 2. Create a feature branch
216
+ 3. Make your changes
217
+ 4. Add tests if applicable
218
+ 5. Submit a pull request
219
+
220
+ ## License
221
+
222
+ MIT License - see LICENSE file for details.
223
+
224
+ ## Credits
225
+
226
+ - **FAL.ai** - AI image generation
227
+ - **Electron** - Desktop application framework
228
+ - **OpenCode** - Plugin ecosystem
229
+
230
+ ## Changelog
231
+
232
+ ### v0.1.0
233
+ - Initial release
234
+ - Basic avatar display
235
+ - Thinking animation
236
+ - Tool-based reactions
237
+ - Caching system
238
+ - Auto-shutdown
239
+ - Focus protection
package/avatar.png ADDED
Binary file