claude-unity-bridge 0.1.2__tar.gz
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.
- claude_unity_bridge-0.1.2/PKG-INFO +441 -0
- claude_unity_bridge-0.1.2/SKILL.md +428 -0
- claude_unity_bridge-0.1.2/pyproject.toml +20 -0
- claude_unity_bridge-0.1.2/setup.cfg +4 -0
- claude_unity_bridge-0.1.2/src/claude_unity_bridge/__init__.py +3 -0
- claude_unity_bridge-0.1.2/src/claude_unity_bridge/cli.py +628 -0
- claude_unity_bridge-0.1.2/src/claude_unity_bridge.egg-info/PKG-INFO +441 -0
- claude_unity_bridge-0.1.2/src/claude_unity_bridge.egg-info/SOURCES.txt +11 -0
- claude_unity_bridge-0.1.2/src/claude_unity_bridge.egg-info/dependency_links.txt +1 -0
- claude_unity_bridge-0.1.2/src/claude_unity_bridge.egg-info/entry_points.txt +2 -0
- claude_unity_bridge-0.1.2/src/claude_unity_bridge.egg-info/requires.txt +6 -0
- claude_unity_bridge-0.1.2/src/claude_unity_bridge.egg-info/top_level.txt +1 -0
- claude_unity_bridge-0.1.2/tests/test_cli.py +1179 -0
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: claude-unity-bridge
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: Control Unity Editor from Claude Code
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Provides-Extra: dev
|
|
9
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
10
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
11
|
+
Requires-Dist: black>=23.0; extra == "dev"
|
|
12
|
+
Requires-Dist: flake8>=6.0; extra == "dev"
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
name: unity
|
|
16
|
+
description: Execute Unity Editor commands (run tests, compile, get logs, refresh assets) via file-based bridge. Auto-activates for Unity-related tasks. Requires com.managexr.claude-bridge package installed in Unity project.
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
# Unity Bridge Skill
|
|
20
|
+
|
|
21
|
+
Control Unity Editor operations from Claude Code using a reliable file-based communication protocol.
|
|
22
|
+
|
|
23
|
+
## Overview
|
|
24
|
+
|
|
25
|
+
The Unity Bridge enables Claude Code to trigger operations in a running Unity Editor instance without network configuration or port conflicts. It uses a simple file-based protocol where commands are written to `.unity-bridge/command.json` and responses are read from `.unity-bridge/response-{id}.json`.
|
|
26
|
+
|
|
27
|
+
**Key Features:**
|
|
28
|
+
- Execute EditMode and PlayMode tests
|
|
29
|
+
- Trigger script compilation
|
|
30
|
+
- Refresh asset database
|
|
31
|
+
- Check editor status (compilation, play mode, etc.)
|
|
32
|
+
- Retrieve Unity console logs
|
|
33
|
+
|
|
34
|
+
**Multi-Project Support:** Each Unity project has its own `.unity-bridge/` directory, allowing multiple projects to be worked on simultaneously.
|
|
35
|
+
|
|
36
|
+
## Requirements
|
|
37
|
+
|
|
38
|
+
1. **Unity Package:** Install `com.managexr.claude-bridge` in your Unity project
|
|
39
|
+
- Via Package Manager: `https://github.com/ManageXR/claude-unity-bridge.git`
|
|
40
|
+
- See main package README for installation instructions
|
|
41
|
+
|
|
42
|
+
2. **Unity Editor:** Must be open with your project loaded
|
|
43
|
+
|
|
44
|
+
3. **Python 3:** The skill uses a Python script for reliable command execution
|
|
45
|
+
|
|
46
|
+
## How It Works
|
|
47
|
+
|
|
48
|
+
The skill uses a CLI tool (`unity-bridge`) that handles:
|
|
49
|
+
- UUID generation for command tracking
|
|
50
|
+
- Atomic file writes to prevent corruption
|
|
51
|
+
- Exponential backoff polling for responses
|
|
52
|
+
- File locking handling
|
|
53
|
+
- Automatic cleanup of old response files
|
|
54
|
+
- Formatted, human-readable output
|
|
55
|
+
|
|
56
|
+
This approach ensures **deterministic, rock-solid execution** - the script is tested once and behaves identically every time, handling all edge cases (timeouts, file locking, malformed responses, etc.) without requiring Claude to manage these details in-context.
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
### Basic Pattern
|
|
61
|
+
|
|
62
|
+
When you need to interact with Unity, use the CLI directly:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
unity-bridge [command] [options]
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
All commands automatically:
|
|
69
|
+
- Generate a unique UUID for tracking
|
|
70
|
+
- Write the command atomically
|
|
71
|
+
- Poll for response with timeout
|
|
72
|
+
- Format output for readability
|
|
73
|
+
- Cleanup response files
|
|
74
|
+
|
|
75
|
+
### Command Examples
|
|
76
|
+
|
|
77
|
+
#### Run Tests
|
|
78
|
+
|
|
79
|
+
Execute Unity tests in EditMode or PlayMode:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
# Run all EditMode tests
|
|
83
|
+
unity-bridge run-tests --mode EditMode
|
|
84
|
+
|
|
85
|
+
# Run tests with filter
|
|
86
|
+
unity-bridge run-tests --mode EditMode --filter "MXR.Tests"
|
|
87
|
+
|
|
88
|
+
# Run all tests (both modes)
|
|
89
|
+
unity-bridge run-tests
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Output:**
|
|
93
|
+
```
|
|
94
|
+
✓ Tests Passed: 410
|
|
95
|
+
✗ Tests Failed: 2
|
|
96
|
+
○ Tests Skipped: 0
|
|
97
|
+
Duration: 1.25s
|
|
98
|
+
|
|
99
|
+
Failed Tests:
|
|
100
|
+
- MXR.Tests.AuthTests.LoginWithInvalidCredentials
|
|
101
|
+
Expected: success, Actual: failure
|
|
102
|
+
- MXR.Tests.NetworkTests.TimeoutHandling
|
|
103
|
+
NullReferenceException: Object reference not set
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
**Parameters:**
|
|
107
|
+
- `--mode` - `EditMode` or `PlayMode` (optional, defaults to both)
|
|
108
|
+
- `--filter` - Test name filter pattern (optional)
|
|
109
|
+
- `--timeout` - Override default 30s timeout
|
|
110
|
+
|
|
111
|
+
#### Compile Scripts
|
|
112
|
+
|
|
113
|
+
Trigger Unity script compilation:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
unity-bridge compile
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**Output (Success):**
|
|
120
|
+
```
|
|
121
|
+
✓ Compilation Successful
|
|
122
|
+
Duration: 2.3s
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Output (Failure):**
|
|
126
|
+
```
|
|
127
|
+
✗ Compilation Failed
|
|
128
|
+
|
|
129
|
+
Assets/Scripts/Player.cs:25: error CS0103: The name 'invalidVar' does not exist
|
|
130
|
+
Assets/Scripts/Enemy.cs:67: error CS0246: Type 'MissingClass' could not be found
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### Get Console Logs
|
|
134
|
+
|
|
135
|
+
Retrieve Unity console output:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Get last 20 logs
|
|
139
|
+
unity-bridge get-console-logs --limit 20
|
|
140
|
+
|
|
141
|
+
# Get only errors
|
|
142
|
+
unity-bridge get-console-logs --limit 10 --filter Error
|
|
143
|
+
|
|
144
|
+
# Get warnings
|
|
145
|
+
unity-bridge get-console-logs --filter Warning
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**Output:**
|
|
149
|
+
```
|
|
150
|
+
Console Logs (last 10, filtered by Error):
|
|
151
|
+
|
|
152
|
+
[Error] NullReferenceException: Object reference not set
|
|
153
|
+
at Player.Update() in Assets/Scripts/Player.cs:34
|
|
154
|
+
|
|
155
|
+
[Error] Failed to load asset: missing_texture.png
|
|
156
|
+
|
|
157
|
+
[Error] (x3) Shader compilation failed
|
|
158
|
+
See Console for details
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**Parameters:**
|
|
162
|
+
- `--limit` - Maximum number of logs (default: 50)
|
|
163
|
+
- `--filter` - Filter by type: `Log`, `Warning`, or `Error`
|
|
164
|
+
|
|
165
|
+
#### Get Editor Status
|
|
166
|
+
|
|
167
|
+
Check Unity Editor state:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
unity-bridge get-status
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
**Output:**
|
|
174
|
+
```
|
|
175
|
+
Unity Editor Status:
|
|
176
|
+
- Compilation: ✓ Ready
|
|
177
|
+
- Play Mode: ✏ Editing
|
|
178
|
+
- Updating: No
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
**Possible States:**
|
|
182
|
+
- Compilation: `✓ Ready` or `⏳ Compiling...`
|
|
183
|
+
- Play Mode: `✏ Editing`, `▶ Playing`, or `⏸ Paused`
|
|
184
|
+
- Updating: `Yes` or `No`
|
|
185
|
+
|
|
186
|
+
#### Refresh Asset Database
|
|
187
|
+
|
|
188
|
+
Force Unity to refresh assets:
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
unity-bridge refresh
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Output:**
|
|
195
|
+
```
|
|
196
|
+
✓ Asset Database Refreshed
|
|
197
|
+
Duration: 0.5s
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Advanced Options
|
|
201
|
+
|
|
202
|
+
#### Timeout Configuration
|
|
203
|
+
|
|
204
|
+
Override the default 30-second timeout:
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
unity-bridge run-tests --timeout 60
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Use longer timeouts for:
|
|
211
|
+
- Large test suites
|
|
212
|
+
- PlayMode tests (which start/stop Play Mode)
|
|
213
|
+
- Full project compilation
|
|
214
|
+
|
|
215
|
+
#### Cleanup Old Responses
|
|
216
|
+
|
|
217
|
+
Automatically remove old response files before executing:
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
unity-bridge compile --cleanup
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
This removes response files older than 1 hour. Useful for maintaining a clean workspace.
|
|
224
|
+
|
|
225
|
+
#### Verbose Output
|
|
226
|
+
|
|
227
|
+
See detailed execution progress:
|
|
228
|
+
|
|
229
|
+
```bash
|
|
230
|
+
unity-bridge run-tests --verbose
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Prints:
|
|
234
|
+
- Command ID
|
|
235
|
+
- Polling attempts
|
|
236
|
+
- Response file detection
|
|
237
|
+
- Cleanup operations
|
|
238
|
+
|
|
239
|
+
### Error Handling
|
|
240
|
+
|
|
241
|
+
The script provides clear error messages for common issues:
|
|
242
|
+
|
|
243
|
+
**Unity Not Running:**
|
|
244
|
+
```
|
|
245
|
+
Error: Unity Editor not detected. Ensure Unity is open with the project loaded.
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
**Command Timeout:**
|
|
249
|
+
```
|
|
250
|
+
Error: Command timed out after 30s. Check Unity Console for errors.
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
**Invalid Parameters:**
|
|
254
|
+
```
|
|
255
|
+
Error: Failed to write command file: Invalid mode 'InvalidMode'
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
**Exit Codes:**
|
|
259
|
+
- `0` - Success
|
|
260
|
+
- `1` - Error (Unity not running, invalid params, etc.)
|
|
261
|
+
- `2` - Timeout
|
|
262
|
+
|
|
263
|
+
## Integration with Claude Code
|
|
264
|
+
|
|
265
|
+
When you're working in a Unity project directory, you can ask Claude Code to perform Unity operations naturally:
|
|
266
|
+
|
|
267
|
+
- "Run the Unity tests in EditMode"
|
|
268
|
+
- "Check if there are any compilation errors"
|
|
269
|
+
- "Show me the last 10 error logs from Unity"
|
|
270
|
+
- "Refresh the Unity asset database"
|
|
271
|
+
|
|
272
|
+
Claude Code will automatically use this skill to execute the commands via the Python script.
|
|
273
|
+
|
|
274
|
+
## File Protocol Details
|
|
275
|
+
|
|
276
|
+
### Command Format
|
|
277
|
+
|
|
278
|
+
Written to `.unity-bridge/command.json`:
|
|
279
|
+
|
|
280
|
+
```json
|
|
281
|
+
{
|
|
282
|
+
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
283
|
+
"action": "run-tests",
|
|
284
|
+
"params": {
|
|
285
|
+
"testMode": "EditMode",
|
|
286
|
+
"filter": "MyTests"
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
### Response Format
|
|
292
|
+
|
|
293
|
+
Read from `.unity-bridge/response-{id}.json`:
|
|
294
|
+
|
|
295
|
+
```json
|
|
296
|
+
{
|
|
297
|
+
"id": "550e8400-e29b-41d4-a716-446655440000",
|
|
298
|
+
"status": "success",
|
|
299
|
+
"action": "run-tests",
|
|
300
|
+
"duration_ms": 1250,
|
|
301
|
+
"result": {
|
|
302
|
+
"passed": 410,
|
|
303
|
+
"failed": 0,
|
|
304
|
+
"skipped": 0,
|
|
305
|
+
"failures": []
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
**Status Values:**
|
|
311
|
+
- `running` - Command in progress (may see intermediate responses)
|
|
312
|
+
- `success` - Command completed successfully
|
|
313
|
+
- `failure` - Command completed with failures (e.g., failed tests)
|
|
314
|
+
- `error` - Command execution error
|
|
315
|
+
|
|
316
|
+
## Project Structure
|
|
317
|
+
|
|
318
|
+
```
|
|
319
|
+
skill/
|
|
320
|
+
├── SKILL.md # This file
|
|
321
|
+
├── pyproject.toml # Package configuration
|
|
322
|
+
├── src/
|
|
323
|
+
│ └── claude_unity_bridge/
|
|
324
|
+
│ ├── __init__.py # Package version
|
|
325
|
+
│ └── cli.py # CLI implementation
|
|
326
|
+
├── tests/
|
|
327
|
+
│ └── test_cli.py # Unit tests
|
|
328
|
+
└── references/
|
|
329
|
+
├── COMMANDS.md # Detailed command specifications
|
|
330
|
+
└── EXTENDING.md # Guide for adding custom commands
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## Detailed Documentation
|
|
334
|
+
|
|
335
|
+
For more information, see:
|
|
336
|
+
|
|
337
|
+
- **[COMMANDS.md](references/COMMANDS.md)** - Complete command reference with all parameters, response formats, and edge cases
|
|
338
|
+
- **[EXTENDING.md](references/EXTENDING.md)** - Tutorial for adding custom commands to the Unity Bridge for project-specific workflows
|
|
339
|
+
|
|
340
|
+
## Troubleshooting
|
|
341
|
+
|
|
342
|
+
### Unity Not Responding
|
|
343
|
+
|
|
344
|
+
**Symptoms:** Commands timeout or "Unity not detected" error
|
|
345
|
+
|
|
346
|
+
**Solutions:**
|
|
347
|
+
1. Ensure Unity Editor is open with the project loaded
|
|
348
|
+
2. Check that the package is installed (`Window > Package Manager`)
|
|
349
|
+
3. Verify `.unity-bridge/` directory exists in project root
|
|
350
|
+
4. Check Unity Console for errors from ClaudeBridge package
|
|
351
|
+
|
|
352
|
+
### Response File Issues
|
|
353
|
+
|
|
354
|
+
**Symptoms:** "Failed to parse response JSON" error
|
|
355
|
+
|
|
356
|
+
**Solutions:**
|
|
357
|
+
1. Check Unity Console for ClaudeBridge errors
|
|
358
|
+
2. Manually inspect `.unity-bridge/response-*.json` files
|
|
359
|
+
3. Try cleaning up old responses with `--cleanup` flag
|
|
360
|
+
4. Restart Unity Editor if file system is in bad state
|
|
361
|
+
|
|
362
|
+
### Performance Issues
|
|
363
|
+
|
|
364
|
+
**Symptoms:** Slow response times, frequent timeouts
|
|
365
|
+
|
|
366
|
+
**Solutions:**
|
|
367
|
+
1. Increase timeout with `--timeout 60` or higher
|
|
368
|
+
2. Close unnecessary Unity Editor windows
|
|
369
|
+
3. Reduce test scope with `--filter` parameter
|
|
370
|
+
4. Check system resources (CPU, memory)
|
|
371
|
+
|
|
372
|
+
### File Locking Errors
|
|
373
|
+
|
|
374
|
+
**Symptoms:** Intermittent errors reading/writing files
|
|
375
|
+
|
|
376
|
+
**Solutions:**
|
|
377
|
+
1. The CLI handles file locking automatically with retries
|
|
378
|
+
2. If persistent, check for antivirus interference
|
|
379
|
+
3. Verify file permissions on `.unity-bridge/` directory
|
|
380
|
+
|
|
381
|
+
## Installation
|
|
382
|
+
|
|
383
|
+
### Install the CLI
|
|
384
|
+
|
|
385
|
+
```bash
|
|
386
|
+
pip install claude-unity-bridge
|
|
387
|
+
```
|
|
388
|
+
|
|
389
|
+
Or for development:
|
|
390
|
+
```bash
|
|
391
|
+
cd claude-unity-bridge/skill
|
|
392
|
+
pip install -e ".[dev]"
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### Verify Setup
|
|
396
|
+
|
|
397
|
+
```bash
|
|
398
|
+
unity-bridge health-check
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
### Install the Skill (Optional)
|
|
402
|
+
|
|
403
|
+
To use this skill in Claude Code:
|
|
404
|
+
|
|
405
|
+
1. Symlink the skill directory:
|
|
406
|
+
```bash
|
|
407
|
+
ln -s "$(pwd)/skill" ~/.claude/skills/unity
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
2. Restart Claude Code to load the skill
|
|
411
|
+
|
|
412
|
+
3. Navigate to your Unity project directory in Claude Code
|
|
413
|
+
|
|
414
|
+
4. Ask Claude to perform Unity operations naturally
|
|
415
|
+
|
|
416
|
+
## Why a CLI Tool?
|
|
417
|
+
|
|
418
|
+
The skill uses a CLI tool instead of implementing the protocol directly in Claude Code prompts for several critical reasons:
|
|
419
|
+
|
|
420
|
+
**Consistency:** UUID generation, polling logic, and error handling work identically every time. Without the CLI, Claude might implement these differently across sessions, leading to subtle bugs.
|
|
421
|
+
|
|
422
|
+
**Reliability:** All edge cases are handled once in tested code:
|
|
423
|
+
- File locking when Unity writes responses
|
|
424
|
+
- Exponential backoff for polling
|
|
425
|
+
- Atomic command writes to prevent corruption
|
|
426
|
+
- Graceful handling of malformed JSON
|
|
427
|
+
- Proper cleanup of stale files
|
|
428
|
+
|
|
429
|
+
**Error Messages:** Clear, actionable error messages for all failure modes. Claude doesn't have to figure out what went wrong each time.
|
|
430
|
+
|
|
431
|
+
**Token Efficiency:** The CLI handles complexity, so Claude doesn't need to manage low-level details in-context. The SKILL.md stays concise while providing full functionality.
|
|
432
|
+
|
|
433
|
+
**Deterministic Exit Codes:** Shell integration works reliably with standard exit codes (0=success, 1=error, 2=timeout).
|
|
434
|
+
|
|
435
|
+
**Rock Solid:** Test the CLI once, it works forever. No variability between Claude sessions.
|
|
436
|
+
|
|
437
|
+
## Support
|
|
438
|
+
|
|
439
|
+
For issues or questions:
|
|
440
|
+
- Package Issues: https://github.com/ManageXR/claude-unity-bridge/issues
|
|
441
|
+
- Skill Issues: Report in the same repository with `[Skill]` prefix
|