moai-domain-adb: ADB Automation Domain Specialist
Tier 3 Modularized Skill for intelligent Android automation, game bot development, and real-time device orchestration.
🎯 Quick Reference
Core Competencies
| Domain |
Capability |
Module |
| Device Control |
ADB connection, shell execution, property inspection |
adb-fundamentals |
| Device Management |
Multi-device orchestration, state tracking, lifecycle |
device-management |
| Game Automation |
Bot scripting, action sequences, timing control |
game-automation |
| Vision & Detection |
Template matching, OCR, region-based detection |
computer-vision |
| Tauri Integration |
UI-Python bridge, real-time communication, deployment |
tauri-integration |
Key Functions (Quick Access)
Device Operations
# Check device status
adb devices --list-long
# Execute shell command
adb shell input tap 540 960
# Get device property
adb shell getprop ro.build.version.sdk
# Install APK
adb install -r game.apk
Bot Control
# Start bot
adb shell am start -n com.game/.MainActivity
# Send input sequence
adb shell input tap x y && sleep 1 && adb shell input tap x2 y2
# Capture screenshot
adb shell screencap -p /sdcard/screen.png
Module Selection Guide
Use when you need to...
Understand ADB fundamentals: Load adb-fundamentals module
- Connection protocols, authentication, basic shell operations
- Device discovery, property reading, system interaction
Manage multiple devices: Load device-management module
- Device state tracking, connection pooling, failover strategies
- Batch operations, monitoring, lifecycle management
Develop game bots: Load game-automation module
- Click sequences, timing, OCR parsing, state detection
- Custom routines, action templates, bot patterns
Use vision for detection: Load computer-vision module
- Template matching (OpenCV), OCR (Tesseract)
- Region-based detection, image analysis, pattern recognition
Integrate with Tauri UI: Load tauri-integration module
- Real-time bot status updates, command queueing
- UI ↔ Python communication, resource management
📚 Implementation Guide
Architecture Overview
moai-domain-adb follows a 5-module progressive disclosure pattern:
moai-domain-adb/
├── SKILL.md # This file (documentation hub)
├── modules/
│ ├── adb-fundamentals.md # Level 1: Core ADB operations
│ ├── device-management.md # Level 2: Multi-device orchestration
│ ├── game-automation.md # Level 3: Bot development patterns
│ ├── computer-vision.md # Level 4: Vision-based detection
│ └── tauri-integration.md # Level 5: UI orchestration
└── scripts/ # IndieDevDan UV scripts
├── adb_device_analyzer.py # Analyze device capabilities
├── adb_bot_generator.py # Generate bot skeletons
├── adb_template_creator.py # Create action templates
├── adb_performance_profiler.py # Profile bot performance
├── adb_config_validator.py # Validate configurations
├── adb_game_tester.py # Test bot on devices
└── adb_deployment_helper.py # Deploy to production
Tier 3 Characteristics
✅ Modularized: 5 independent modules (no cross-module imports)
✅ Production-Ready: 500+ line SKILL.md with comprehensive docs
✅ Scripted: 7 UV scripts following IndieDevDan 13 rules
✅ Delegatable: Works with expert-* and manager-* agents
✅ Reusable: Applicable to any Android automation project
Usage Pattern
# Pattern 1: Load skill for general ADB knowledge
Skill("moai-domain-adb")
# Pattern 2: Load specific module for targeted expertise
# In agent prompt: "Use moai-domain-adb:adb-fundamentals for device operations"
# Pattern 3: Reference UV script for automated tasks
# Command: uv run .claude/skills/moai-domain-adb/scripts/adb_device_analyzer.py --device emulator-5554
Integration Points
With Agents:
adb-bot-runner: Executes bots using game-automation patterns
adb-device-manager: Manages devices using device-management expertise
adb-game-tester: Tests bots using computer-vision and game-automation
adb-config-manager: Validates configs using config-validator script
adb-workflow-orchestrator: Coordinates all agents using tauri-integration patterns
With Commands:
/adb:init → Uses adb-fundamentals + adb_device_analyzer
/adb:bot → Uses game-automation + adb_bot_generator
/adb:test → Uses computer-vision + adb_game_tester
/adb:deploy → Uses tauri-integration + adb_deployment_helper
With UV Scripts:
All 7 scripts are self-contained (zero dependencies on each other), follow PEP 723, and implement dual output (human-readable + JSON).
Progressive Disclosure Strategy
Level 1: Getting Started
- Read: adb-fundamentals module
- Run:
adb_device_analyzer.py to list devices
- Understand: Basic device connection and property reading
Level 2: Multi-Device Workflows
- Read: device-management module
- Understand: Connection pooling, state tracking, failover
- Build: Scripts that manage 5+ devices simultaneously
Level 3: Game Bot Development
- Read: game-automation module
- Understand: Click sequences, timing control, OCR integration
- Build: Custom routines for game-specific tasks
Level 4: Vision-Based Automation
- Read: computer-vision module
- Understand: Template matching, OCR parsing, region detection
- Build: Bots that adapt to UI changes dynamically
Level 5: Production Orchestration
- Read: tauri-integration module
- Understand: Real-time UI updates, command queuing, resource management
- Build: Enterprise workflows with Tauri UI control
🚀 Advanced Topics
Skill Composition Strategy
moai-domain-adb is designed for modular composition:
# Example 1: Simple device check
# Required: adb-fundamentals
agent = Task(
subagent_type="expert-backend",
prompt="Use moai-domain-adb:adb-fundamentals to list ADB devices"
)
# Example 2: Multi-device bot deployment
# Required: device-management + game-automation + tauri-integration
agent = Task(
subagent_type="adb-workflow-orchestrator",
prompt="Deploy game bot to 3 devices"
)
# Example 3: Vision-based testing
# Required: computer-vision + game-automation
agent = Task(
subagent_type="adb-game-tester",
prompt="Test bot with computer vision verification"
)
Performance Optimization
Device Batching:
- Group commands by device to reduce round-trip latency
- Use
adb_performance_profiler.py to identify bottlenecks
- Target: Execute 100 actions in <5 seconds
Caching Strategies:
- Cache device properties (refreshed every 60s)
- Cache template images (refreshed on detection failure)
- Cache bot configurations (invalidated on user edit)
Concurrency:
- Run multi-device operations with ThreadPoolExecutor
- Limit to 5 concurrent ADB operations per host
- Use queuing for >5 devices
Security Considerations
Authentication:
- ADB uses RSA key exchange; validate device certificates
- Never store unencrypted device pairing keys
- Rotate pairing keys quarterly for production devices
Permissions:
- Request minimal shell commands (avoid
su unless necessary)
- Use app-specific commands instead of root access
- Audit bot actions for unintended side effects
Data Protection:
- Never capture sensitive data in screenshots
- Encrypt stored configurations containing API keys
- Use secure storage for game credentials
Debugging & Troubleshooting
Common Issues:
| Issue |
Diagnosis |
Solution |
| Device not found |
adb_device_analyzer.py --check-connection |
Verify USB connection, check ADB daemon |
| Slow bot execution |
adb_performance_profiler.py --device <id> |
Reduce click delays, batch operations |
| Template matching fails |
Check image DPI/resolution |
Run adb_template_creator.py --device <id> |
| OCR accuracy poor |
Preprocess image (contrast, threshold) |
See computer-vision module for tips |
| Tauri communication lag |
Check Python process CPU |
Reduce log verbosity, optimize render loop |
Debug Mode:
# Enable verbose logging
export ADB_DEBUG=1
uv run .claude/skills/moai-domain-adb/scripts/adb_device_analyzer.py --verbose
# Trace ADB commands
adb logcat | grep "adb_bot_runner"
Testing Strategy (TRUST 5 Framework)
Test Coverage Target: ≥85%
- Unit Tests: Individual module functions (py.test)
- Integration Tests: Module interactions (device mock)
- E2E Tests: Full workflow with real devices (optional)
- Performance Tests: Execution time benchmarks
- Security Tests: Input validation, permission checks
Test Execution:
# Run all tests
pytest tests/ -v --cov=.claude/skills/moai-domain-adb
# Run specific module tests
pytest tests/test_device_management.py -v
# Profile performance
pytest tests/ --benchmark-only
📖 Module Navigation
Each module builds upon previous knowledge but is independently usable:
adb-fundamentals (250 lines)
- ADB architecture, connection protocols, device discovery
- Shell execution, property reading, device interaction
device-management (280 lines)
- Multi-device orchestration, state tracking, connection pooling
- Lifecycle management, monitoring, failover strategies
game-automation (300 lines)
- Bot scripting patterns, click sequences, timing control
- OCR integration, state detection, action templates
computer-vision (270 lines)
- Template matching (OpenCV), OCR (Tesseract)
- Region detection, image preprocessing, pattern recognition
tauri-integration (240 lines)
- Tauri-Python IPC, real-time updates, command queueing
- Resource management, deployment strategies, monitoring
🛠️ Scripts & Tools
All scripts follow IndieDevDan 13 Rules (PEP 723, 9-section structure, dual output):
# Analyze device capabilities
uv run scripts/adb_device_analyzer.py --device emulator-5554 --json
# Generate bot skeleton
uv run scripts/adb_bot_generator.py --game "My Game" --output my_bot.py
# Create action template
uv run scripts/adb_template_creator.py --screenshot screen.png --region "0,0,1080,1920"
# Profile bot performance
uv run scripts/adb_performance_profiler.py --bot bot.py --iterations 100
# Validate configuration
uv run scripts/adb_config_validator.py --config config.yaml --strict
# Test bot on device
uv run scripts/adb_game_tester.py --bot bot.py --device emulator-5554
# Prepare deployment
uv run scripts/adb_deployment_helper.py --bot bot.py --target production
Complete Scripts Reference (36 scripts)
All scripts are located in scripts/ directory and organized by category. Each script supports:
--device/-d - Specify device ID (defaults to first connected)
--toon - Output in TOON/YAML format for automation
--verbose/-v - Enable verbose logging
--help - Show detailed help and usage examples
See scripts/README.md for comprehensive documentation with 150+ usage examples.
🔌 Connection (4 scripts)
Location: scripts/connection/
| Script |
Purpose |
Key Options |
Example |
adb_connect.py |
Connect to device via IP:port |
--device (default: 127.0.0.1:5555) |
uv run scripts/connection/adb_connect.py |
adb_disconnect.py |
Disconnect device gracefully |
--device |
uv run scripts/connection/adb_disconnect.py |
adb_restart_server.py |
Restart ADB server |
--verbose |
uv run scripts/connection/adb_restart_server.py |
adb_device_status.py |
List all devices and status |
--toon |
uv run scripts/connection/adb_device_status.py |
📱 Screen (6 scripts)
Location: scripts/screen/
| Script |
Purpose |
Key Options |
Example |
adb_screenshot.py |
Capture screenshot |
--output FILE |
uv run scripts/screen/adb_screenshot.py --output capture.png |
adb_tap.py |
Tap at coordinates |
--x X --y Y --count N |
uv run scripts/screen/adb_tap.py --x 500 --y 1000 |
adb_swipe.py |
Swipe gesture |
--preset {up,down,left,right} or --start X,Y --end X,Y |
uv run scripts/screen/adb_swipe.py --preset up |
adb_keyevent.py |
Send key event |
--key {back,home,menu,power,volume_up} |
uv run scripts/screen/adb_keyevent.py --key back |
adb_text_input.py |
Type text |
--text TEXT |
uv run scripts/screen/adb_text_input.py --text "Hello" |
adb_screenrecord.py |
Record screen video |
--output FILE --duration SECONDS |
uv run scripts/screen/adb_screenrecord.py --duration 60 |
📦 App (5 scripts)
Location: scripts/app/
| Script |
Purpose |
Key Options |
Example |
adb_app_list.py |
List installed apps |
--filter TEXT, --system, --all |
uv run scripts/app/adb_app_list.py --filter afk |
adb_app_start.py |
Start app by package |
-p PACKAGE, --wait |
uv run scripts/app/adb_app_start.py -p com.afk.journey |
adb_app_stop.py |
Force stop app |
-p PACKAGE |
uv run scripts/app/adb_app_stop.py -p com.afk.journey |
adb_app_install.py |
Install APK |
--apk FILE |
uv run scripts/app/adb_app_install.py --apk game.apk |
adb_app_uninstall.py |
Uninstall app |
-p PACKAGE, --keep-data |
uv run scripts/app/adb_app_uninstall.py -p com.example |
ℹ️ Info (4 scripts)
Location: scripts/info/
| Script |
Purpose |
Key Options |
Example |
adb_device_info.py |
Device specifications |
--toon |
uv run scripts/info/adb_device_info.py |
adb_display_info.py |
Display resolution/DPI |
--toon |
uv run scripts/info/adb_display_info.py |
adb_running_app.py |
Current foreground app |
--toon |
uv run scripts/info/adb_running_app.py |
adb_battery_info.py |
Battery status |
--toon |
uv run scripts/info/adb_battery_info.py |
⚡ Performance (3 scripts)
Location: scripts/performance/
| Script |
Purpose |
Key Options |
Example |
adb_cpu_monitor.py |
Real-time CPU monitoring |
--duration SECONDS, --package PKG |
uv run scripts/performance/adb_cpu_monitor.py --duration 60 |
adb_memory_monitor.py |
Memory usage monitoring |
--duration SECONDS, --package PKG |
uv run scripts/performance/adb_memory_monitor.py --duration 60 |
adb_logcat_filter.py |
Filter logcat logs |
--tag TAG, --priority {V,D,I,W,E,F}, --follow |
uv run scripts/performance/adb_logcat_filter.py --tag MyApp --priority E |
🤖 Automation (4 scripts)
Location: scripts/automation/
| Script |
Purpose |
Key Options |
Example |
adb_game_loop.py |
Execute repeating sequence |
-s FILE, -l LOOPS, --infinite |
uv run scripts/automation/adb_game_loop.py -s daily.json -l 10 |
adb_wait_for_app.py |
Wait for app to start |
--package PKG, --timeout SECONDS |
uv run scripts/automation/adb_wait_for_app.py -p com.afk.journey |
adb_click_sequence.py |
Execute sequence once |
-s FILE |
uv run scripts/automation/adb_click_sequence.py -s tutorial.json |
adb_screenshot_compare.py |
Compare screenshots |
-b BEFORE -a AFTER, --threshold FLOAT |
uv run scripts/automation/adb_screenshot_compare.py -b ref.png -a test.png |
🛠️ Utils (3 scripts)
Location: scripts/utils/
| Script |
Purpose |
Key Options |
Example |
adb_shell.py |
Execute shell commands |
-c COMMAND, --timeout SECONDS |
uv run scripts/utils/adb_shell.py -c "ls /sdcard" |
adb_push.py |
Push file to device |
-l LOCAL -r REMOTE |
uv run scripts/utils/adb_push.py -l file.txt -r /sdcard/ |
adb_pull.py |
Pull file from device |
-r REMOTE -l LOCAL |
uv run scripts/utils/adb_pull.py -r /sdcard/screenshot.png -l . |
🔧 Monitoring (7 scripts)
Location: scripts/ (root level)
| Script |
Purpose |
Key Options |
Example |
adb_bot_generator.py |
Generate bot scripts |
--template NAME, --output FILE |
uv run scripts/adb_bot_generator.py --template daily_quests |
adb_config_validator.py |
Validate configs |
--config FILE, --strict |
uv run scripts/adb_config_validator.py --config config.json |
adb_deployment_helper.py |
Deploy to devices |
--apk FILE, --all, --devices IDS |
uv run scripts/adb_deployment_helper.py --apk game.apk --all |
adb_device_analyzer.py |
Analyze capabilities |
--aspects LIST, --output FILE |
uv run scripts/adb_device_analyzer.py --aspects performance,battery |
adb_game_tester.py |
Test game automation |
--test-suite FILE, --screenshots |
uv run scripts/adb_game_tester.py --test-suite tests.json |
adb_performance_profiler.py |
Profile performance |
--package PKG, --duration SECONDS |
uv run scripts/adb_performance_profiler.py -p com.afk.journey |
adb_template_creator.py |
Create templates |
--name NAME, --category CAT |
uv run scripts/adb_template_creator.py --name my_automation |
JSON Sequence Format (Automation Scripts)
For adb_game_loop.py and adb_click_sequence.py, use JSON format:
{
"name": "Daily Quest Automation",
"steps": [
{"action": "tap", "x": 500, "y": 1000, "delay": 2},
{"action": "swipe", "start": [500, 1500], "end": [500, 500], "duration": 300},
{"action": "wait", "duration": 3},
{"action": "screenshot", "output": "/tmp/check.png"},
{"action": "keyevent", "key": "back"},
{"action": "text_input", "text": "Hello World"}
]
}
Supported Actions: tap, swipe, wait, screenshot, keyevent, text_input
Common Utilities
All scripts use shared utilities from scripts/common/:
adb_utils.py - ADB device operations and connection management
cli_utils.py - Click decorators, Rich formatters, output helpers
error_handlers.py - Standardized error handling and exit codes (0, 2, 3, 4)
path_utils.py - Project root detection and path resolution
Exit Codes
All scripts use standardized exit codes:
- 0 - Success
- 2 - Device offline or not found
- 3 - ADB command failed or execution error
- 4 - Invalid argument or configuration
Output Formats
Text Output (default): Rich-formatted console output with colors and tables
TOON Output (--toon): YAML/structured format for automation and parsing
📞 Support & References
Quick Links:
- Modules: See individual module files in
modules/
- Scripts: See individual scripts in
scripts/ with --help
- Examples: See integration patterns in adb-* agents
- Tests: See test suite in
tests/
Context7 References:
Version: 1.0.0
Status: ✅ Production Ready (Phase 1 Foundation)
Last Updated: 2025-12-01
Next Phase: Create 5 core modules + 7 UV scripts
1---2name: moai-domain-adb3description: Comprehensive ADB (Android Debug Bridge) automation skill for game bot development, device management, computer vision integration, and Tauri-Python orchestration. Provides modular expertise for building intelligent Android automation workflows.4---5
6# moai-domain-adb: ADB Automation Domain Specialist
7
8**Tier 3 Modularized Skill** for intelligent Android automation, game bot development, and real-time device orchestration.
9
10---
11
12## 🎯 Quick Reference
13
14### Core Competencies
15
16| Domain | Capability | Module |
17|--------|-----------|--------|
18| **Device Control** | ADB connection, shell execution, property inspection | adb-fundamentals |
19| **Device Management** | Multi-device orchestration, state tracking, lifecycle | device-management |
20| **Game Automation** | Bot scripting, action sequences, timing control | game-automation |
21| **Vision & Detection** | Template matching, OCR, region-based detection | computer-vision |
22| **Tauri Integration** | UI-Python bridge, real-time communication, deployment | tauri-integration |
23
24### Key Functions (Quick Access)
25
26**Device Operations**
27```python
28# Check device status
29adb devices --list-long
30
31# Execute shell command
32adb shell input tap 540 960
33
34# Get device property
35adb shell getprop ro.build.version.sdk
36
37# Install APK
38adb install -r game.apk
39```
40
41**Bot Control**
42```python
43# Start bot
44adb shell am start -n com.game/.MainActivity
45
46# Send input sequence
47adb shell input tap x y && sleep 1 && adb shell input tap x2 y2
48
49# Capture screenshot
50adb shell screencap -p /sdcard/screen.png
51```
52
53**Module Selection Guide**
54
55Use when you need to...
56
57- **Understand ADB fundamentals**: Load `adb-fundamentals` module
58 - Connection protocols, authentication, basic shell operations
59 - Device discovery, property reading, system interaction
60
61- **Manage multiple devices**: Load `device-management` module
62 - Device state tracking, connection pooling, failover strategies
63 - Batch operations, monitoring, lifecycle management
64
65- **Develop game bots**: Load `game-automation` module
66 - Click sequences, timing, OCR parsing, state detection
67 - Custom routines, action templates, bot patterns
68
69- **Use vision for detection**: Load `computer-vision` module
70 - Template matching (OpenCV), OCR (Tesseract)
71 - Region-based detection, image analysis, pattern recognition
72
73- **Integrate with Tauri UI**: Load `tauri-integration` module
74 - Real-time bot status updates, command queueing
75 - UI ↔ Python communication, resource management
76
77---
78
79## 📚 Implementation Guide
80
81### Architecture Overview
82
83**moai-domain-adb** follows a 5-module progressive disclosure pattern:
84
85```
86moai-domain-adb/
87├── SKILL.md # This file (documentation hub)
88├── modules/
89│ ├── adb-fundamentals.md # Level 1: Core ADB operations
90│ ├── device-management.md # Level 2: Multi-device orchestration
91│ ├── game-automation.md # Level 3: Bot development patterns
92│ ├── computer-vision.md # Level 4: Vision-based detection
93│ └── tauri-integration.md # Level 5: UI orchestration
94└── scripts/ # IndieDevDan UV scripts
95 ├── adb_device_analyzer.py # Analyze device capabilities
96 ├── adb_bot_generator.py # Generate bot skeletons
97 ├── adb_template_creator.py # Create action templates
98 ├── adb_performance_profiler.py # Profile bot performance
99 ├── adb_config_validator.py # Validate configurations
100 ├── adb_game_tester.py # Test bot on devices
101 └── adb_deployment_helper.py # Deploy to production
102```
103
104### Tier 3 Characteristics
105
106✅ **Modularized**: 5 independent modules (no cross-module imports)
107✅ **Production-Ready**: 500+ line SKILL.md with comprehensive docs
108✅ **Scripted**: 7 UV scripts following IndieDevDan 13 rules
109✅ **Delegatable**: Works with expert-* and manager-* agents
110✅ **Reusable**: Applicable to any Android automation project
111
112### Usage Pattern
113
114```python
115# Pattern 1: Load skill for general ADB knowledge
116Skill("moai-domain-adb")
117
118# Pattern 2: Load specific module for targeted expertise
119# In agent prompt: "Use moai-domain-adb:adb-fundamentals for device operations"
120
121# Pattern 3: Reference UV script for automated tasks
122# Command: uv run .claude/skills/moai-domain-adb/scripts/adb_device_analyzer.py --device emulator-5554
123```
124
125### Integration Points
126
127**With Agents**:
128- `adb-bot-runner`: Executes bots using game-automation patterns
129- `adb-device-manager`: Manages devices using device-management expertise
130- `adb-game-tester`: Tests bots using computer-vision and game-automation
131- `adb-config-manager`: Validates configs using config-validator script
132- `adb-workflow-orchestrator`: Coordinates all agents using tauri-integration patterns
133
134**With Commands**:
135- `/adb:init` → Uses adb-fundamentals + adb_device_analyzer
136- `/adb:bot` → Uses game-automation + adb_bot_generator
137- `/adb:test` → Uses computer-vision + adb_game_tester
138- `/adb:deploy` → Uses tauri-integration + adb_deployment_helper
139
140**With UV Scripts**:
141All 7 scripts are self-contained (zero dependencies on each other), follow PEP 723, and implement dual output (human-readable + JSON).
142
143### Progressive Disclosure Strategy
144
145**Level 1: Getting Started**
146- Read: adb-fundamentals module
147- Run: `adb_device_analyzer.py` to list devices
148- Understand: Basic device connection and property reading
149
150**Level 2: Multi-Device Workflows**
151- Read: device-management module
152- Understand: Connection pooling, state tracking, failover
153- Build: Scripts that manage 5+ devices simultaneously
154
155**Level 3: Game Bot Development**
156- Read: game-automation module
157- Understand: Click sequences, timing control, OCR integration
158- Build: Custom routines for game-specific tasks
159
160**Level 4: Vision-Based Automation**
161- Read: computer-vision module
162- Understand: Template matching, OCR parsing, region detection
163- Build: Bots that adapt to UI changes dynamically
164
165**Level 5: Production Orchestration**
166- Read: tauri-integration module
167- Understand: Real-time UI updates, command queuing, resource management
168- Build: Enterprise workflows with Tauri UI control
169
170---
171
172## 🚀 Advanced Topics
173
174### Skill Composition Strategy
175
176**moai-domain-adb** is designed for modular composition:
177
178```python
179# Example 1: Simple device check
180# Required: adb-fundamentals
181agent = Task(
182 subagent_type="expert-backend",
183 prompt="Use moai-domain-adb:adb-fundamentals to list ADB devices"
184)
185
186# Example 2: Multi-device bot deployment
187# Required: device-management + game-automation + tauri-integration
188agent = Task(
189 subagent_type="adb-workflow-orchestrator",
190 prompt="Deploy game bot to 3 devices"
191)
192
193# Example 3: Vision-based testing
194# Required: computer-vision + game-automation
195agent = Task(
196 subagent_type="adb-game-tester",
197 prompt="Test bot with computer vision verification"
198)
199```
200
201### Performance Optimization
202
203**Device Batching**:
204- Group commands by device to reduce round-trip latency
205- Use `adb_performance_profiler.py` to identify bottlenecks
206- Target: Execute 100 actions in <5 seconds
207
208**Caching Strategies**:
209- Cache device properties (refreshed every 60s)
210- Cache template images (refreshed on detection failure)
211- Cache bot configurations (invalidated on user edit)
212
213**Concurrency**:
214- Run multi-device operations with ThreadPoolExecutor
215- Limit to 5 concurrent ADB operations per host
216- Use queuing for >5 devices
217
218### Security Considerations
219
220**Authentication**:
221- ADB uses RSA key exchange; validate device certificates
222- Never store unencrypted device pairing keys
223- Rotate pairing keys quarterly for production devices
224
225**Permissions**:
226- Request minimal shell commands (avoid `su` unless necessary)
227- Use app-specific commands instead of root access
228- Audit bot actions for unintended side effects
229
230**Data Protection**:
231- Never capture sensitive data in screenshots
232- Encrypt stored configurations containing API keys
233- Use secure storage for game credentials
234
235### Debugging & Troubleshooting
236
237**Common Issues**:
238
239| Issue | Diagnosis | Solution |
240|-------|-----------|----------|
241| Device not found | `adb_device_analyzer.py --check-connection` | Verify USB connection, check ADB daemon |
242| Slow bot execution | `adb_performance_profiler.py --device <id>` | Reduce click delays, batch operations |
243| Template matching fails | Check image DPI/resolution | Run `adb_template_creator.py --device <id>` |
244| OCR accuracy poor | Preprocess image (contrast, threshold) | See computer-vision module for tips |
245| Tauri communication lag | Check Python process CPU | Reduce log verbosity, optimize render loop |
246
247**Debug Mode**:
248```bash
249# Enable verbose logging
250export ADB_DEBUG=1
251uv run .claude/skills/moai-domain-adb/scripts/adb_device_analyzer.py --verbose
252
253# Trace ADB commands
254adb logcat | grep "adb_bot_runner"
255```
256
257### Testing Strategy (TRUST 5 Framework)
258
259**Test Coverage Target**: ≥85%
260
261- **Unit Tests**: Individual module functions (py.test)
262- **Integration Tests**: Module interactions (device mock)
263- **E2E Tests**: Full workflow with real devices (optional)
264- **Performance Tests**: Execution time benchmarks
265- **Security Tests**: Input validation, permission checks
266
267**Test Execution**:
268```bash
269# Run all tests
270pytest tests/ -v --cov=.claude/skills/moai-domain-adb
271
272# Run specific module tests
273pytest tests/test_device_management.py -v
274
275# Profile performance
276pytest tests/ --benchmark-only
277```
278
279---
280
281## 📖 Module Navigation
282
283Each module builds upon previous knowledge but is independently usable:
284
285- **[adb-fundamentals](./modules/adb-fundamentals.md)** (250 lines)
286 - ADB architecture, connection protocols, device discovery
287 - Shell execution, property reading, device interaction
288
289- **[device-management](./modules/device-management.md)** (280 lines)
290 - Multi-device orchestration, state tracking, connection pooling
291 - Lifecycle management, monitoring, failover strategies
292
293- **[game-automation](./modules/game-automation.md)** (300 lines)
294 - Bot scripting patterns, click sequences, timing control
295 - OCR integration, state detection, action templates
296
297- **[computer-vision](./modules/computer-vision.md)** (270 lines)
298 - Template matching (OpenCV), OCR (Tesseract)
299 - Region detection, image preprocessing, pattern recognition
300
301- **[tauri-integration](./modules/tauri-integration.md)** (240 lines)
302 - Tauri-Python IPC, real-time updates, command queueing
303 - Resource management, deployment strategies, monitoring
304
305---
306
307## 🛠️ Scripts & Tools
308
309All scripts follow **IndieDevDan 13 Rules** (PEP 723, 9-section structure, dual output):
310
311```bash
312# Analyze device capabilities
313uv run scripts/adb_device_analyzer.py --device emulator-5554 --json
314
315# Generate bot skeleton
316uv run scripts/adb_bot_generator.py --game "My Game" --output my_bot.py
317
318# Create action template
319uv run scripts/adb_template_creator.py --screenshot screen.png --region "0,0,1080,1920"
320
321# Profile bot performance
322uv run scripts/adb_performance_profiler.py --bot bot.py --iterations 100
323
324# Validate configuration
325uv run scripts/adb_config_validator.py --config config.yaml --strict
326
327# Test bot on device
328uv run scripts/adb_game_tester.py --bot bot.py --device emulator-5554
329
330# Prepare deployment
331uv run scripts/adb_deployment_helper.py --bot bot.py --target production
332```
333
334### Complete Scripts Reference (36 scripts)
335
336All scripts are located in `scripts/` directory and organized by category. Each script supports:
337- **`--device/-d`** - Specify device ID (defaults to first connected)
338- **`--toon`** - Output in TOON/YAML format for automation
339- **`--verbose/-v`** - Enable verbose logging
340- **`--help`** - Show detailed help and usage examples
341
342See **[scripts/README.md](./scripts/README.md)** for comprehensive documentation with 150+ usage examples.
343
344#### 🔌 Connection (4 scripts)
345
346**Location**: `scripts/connection/`
347
348| Script | Purpose | Key Options | Example |
349|--------|---------|-------------|---------|
350| `adb_connect.py` | Connect to device via IP:port | `--device` (default: 127.0.0.1:5555) | `uv run scripts/connection/adb_connect.py` |
351| `adb_disconnect.py` | Disconnect device gracefully | `--device` | `uv run scripts/connection/adb_disconnect.py` |
352| `adb_restart_server.py` | Restart ADB server | `--verbose` | `uv run scripts/connection/adb_restart_server.py` |
353| `adb_device_status.py` | List all devices and status | `--toon` | `uv run scripts/connection/adb_device_status.py` |
354
355#### 📱 Screen (6 scripts)
356
357**Location**: `scripts/screen/`
358
359| Script | Purpose | Key Options | Example |
360|--------|---------|-------------|---------|
361| `adb_screenshot.py` | Capture screenshot | `--output FILE` | `uv run scripts/screen/adb_screenshot.py --output capture.png` |
362| `adb_tap.py` | Tap at coordinates | `--x X --y Y --count N` | `uv run scripts/screen/adb_tap.py --x 500 --y 1000` |
363| `adb_swipe.py` | Swipe gesture | `--preset {up,down,left,right}` or `--start X,Y --end X,Y` | `uv run scripts/screen/adb_swipe.py --preset up` |
364| `adb_keyevent.py` | Send key event | `--key {back,home,menu,power,volume_up}` | `uv run scripts/screen/adb_keyevent.py --key back` |
365| `adb_text_input.py` | Type text | `--text TEXT` | `uv run scripts/screen/adb_text_input.py --text "Hello"` |
366| `adb_screenrecord.py` | Record screen video | `--output FILE --duration SECONDS` | `uv run scripts/screen/adb_screenrecord.py --duration 60` |
367
368#### 📦 App (5 scripts)
369
370**Location**: `scripts/app/`
371
372| Script | Purpose | Key Options | Example |
373|--------|---------|-------------|---------|
374| `adb_app_list.py` | List installed apps | `--filter TEXT`, `--system`, `--all` | `uv run scripts/app/adb_app_list.py --filter afk` |
375| `adb_app_start.py` | Start app by package | `-p PACKAGE`, `--wait` | `uv run scripts/app/adb_app_start.py -p com.afk.journey` |
376| `adb_app_stop.py` | Force stop app | `-p PACKAGE` | `uv run scripts/app/adb_app_stop.py -p com.afk.journey` |
377| `adb_app_install.py` | Install APK | `--apk FILE` | `uv run scripts/app/adb_app_install.py --apk game.apk` |
378| `adb_app_uninstall.py` | Uninstall app | `-p PACKAGE`, `--keep-data` | `uv run scripts/app/adb_app_uninstall.py -p com.example` |
379
380#### ℹ️ Info (4 scripts)
381
382**Location**: `scripts/info/`
383
384| Script | Purpose | Key Options | Example |
385|--------|---------|-------------|---------|
386| `adb_device_info.py` | Device specifications | `--toon` | `uv run scripts/info/adb_device_info.py` |
387| `adb_display_info.py` | Display resolution/DPI | `--toon` | `uv run scripts/info/adb_display_info.py` |
388| `adb_running_app.py` | Current foreground app | `--toon` | `uv run scripts/info/adb_running_app.py` |
389| `adb_battery_info.py` | Battery status | `--toon` | `uv run scripts/info/adb_battery_info.py` |
390
391#### ⚡ Performance (3 scripts)
392
393**Location**: `scripts/performance/`
394
395| Script | Purpose | Key Options | Example |
396|--------|---------|-------------|---------|
397| `adb_cpu_monitor.py` | Real-time CPU monitoring | `--duration SECONDS`, `--package PKG` | `uv run scripts/performance/adb_cpu_monitor.py --duration 60` |
398| `adb_memory_monitor.py` | Memory usage monitoring | `--duration SECONDS`, `--package PKG` | `uv run scripts/performance/adb_memory_monitor.py --duration 60` |
399| `adb_logcat_filter.py` | Filter logcat logs | `--tag TAG`, `--priority {V,D,I,W,E,F}`, `--follow` | `uv run scripts/performance/adb_logcat_filter.py --tag MyApp --priority E` |
400
401#### 🤖 Automation (4 scripts)
402
403**Location**: `scripts/automation/`
404
405| Script | Purpose | Key Options | Example |
406|--------|---------|-------------|---------|
407| `adb_game_loop.py` | Execute repeating sequence | `-s FILE`, `-l LOOPS`, `--infinite` | `uv run scripts/automation/adb_game_loop.py -s daily.json -l 10` |
408| `adb_wait_for_app.py` | Wait for app to start | `--package PKG`, `--timeout SECONDS` | `uv run scripts/automation/adb_wait_for_app.py -p com.afk.journey` |
409| `adb_click_sequence.py` | Execute sequence once | `-s FILE` | `uv run scripts/automation/adb_click_sequence.py -s tutorial.json` |
410| `adb_screenshot_compare.py` | Compare screenshots | `-b BEFORE -a AFTER`, `--threshold FLOAT` | `uv run scripts/automation/adb_screenshot_compare.py -b ref.png -a test.png` |
411
412#### 🛠️ Utils (3 scripts)
413
414**Location**: `scripts/utils/`
415
416| Script | Purpose | Key Options | Example |
417|--------|---------|-------------|---------|
418| `adb_shell.py` | Execute shell commands | `-c COMMAND`, `--timeout SECONDS` | `uv run scripts/utils/adb_shell.py -c "ls /sdcard"` |
419| `adb_push.py` | Push file to device | `-l LOCAL -r REMOTE` | `uv run scripts/utils/adb_push.py -l file.txt -r /sdcard/` |
420| `adb_pull.py` | Pull file from device | `-r REMOTE -l LOCAL` | `uv run scripts/utils/adb_pull.py -r /sdcard/screenshot.png -l .` |
421
422#### 🔧 Monitoring (7 scripts)
423
424**Location**: `scripts/` (root level)
425
426| Script | Purpose | Key Options | Example |
427|--------|---------|-------------|---------|
428| `adb_bot_generator.py` | Generate bot scripts | `--template NAME`, `--output FILE` | `uv run scripts/adb_bot_generator.py --template daily_quests` |
429| `adb_config_validator.py` | Validate configs | `--config FILE`, `--strict` | `uv run scripts/adb_config_validator.py --config config.json` |
430| `adb_deployment_helper.py` | Deploy to devices | `--apk FILE`, `--all`, `--devices IDS` | `uv run scripts/adb_deployment_helper.py --apk game.apk --all` |
431| `adb_device_analyzer.py` | Analyze capabilities | `--aspects LIST`, `--output FILE` | `uv run scripts/adb_device_analyzer.py --aspects performance,battery` |
432| `adb_game_tester.py` | Test game automation | `--test-suite FILE`, `--screenshots` | `uv run scripts/adb_game_tester.py --test-suite tests.json` |
433| `adb_performance_profiler.py` | Profile performance | `--package PKG`, `--duration SECONDS` | `uv run scripts/adb_performance_profiler.py -p com.afk.journey` |
434| `adb_template_creator.py` | Create templates | `--name NAME`, `--category CAT` | `uv run scripts/adb_template_creator.py --name my_automation` |
435
436### JSON Sequence Format (Automation Scripts)
437
438For `adb_game_loop.py` and `adb_click_sequence.py`, use JSON format:
439
440```json
441{
442 "name": "Daily Quest Automation",
443 "steps": [
444 {"action": "tap", "x": 500, "y": 1000, "delay": 2},
445 {"action": "swipe", "start": [500, 1500], "end": [500, 500], "duration": 300},
446 {"action": "wait", "duration": 3},
447 {"action": "screenshot", "output": "/tmp/check.png"},
448 {"action": "keyevent", "key": "back"},
449 {"action": "text_input", "text": "Hello World"}
450 ]
451}
452```
453
454**Supported Actions**: tap, swipe, wait, screenshot, keyevent, text_input
455
456### Common Utilities
457
458All scripts use shared utilities from `scripts/common/`:
459
460- **`adb_utils.py`** - ADB device operations and connection management
461- **`cli_utils.py`** - Click decorators, Rich formatters, output helpers
462- **`error_handlers.py`** - Standardized error handling and exit codes (0, 2, 3, 4)
463- **`path_utils.py`** - Project root detection and path resolution
464
465### Exit Codes
466
467All scripts use standardized exit codes:
468- **0** - Success
469- **2** - Device offline or not found
470- **3** - ADB command failed or execution error
471- **4** - Invalid argument or configuration
472
473### Output Formats
474
475**Text Output** (default): Rich-formatted console output with colors and tables
476**TOON Output** (`--toon`): YAML/structured format for automation and parsing
477
478---
479
480## 📞 Support & References
481
482**Quick Links**:
483- **Modules**: See individual module files in `modules/`
484- **Scripts**: See individual scripts in `scripts/` with `--help`
485- **Examples**: See integration patterns in adb-* agents
486- **Tests**: See test suite in `tests/`
487
488**Context7 References**:
489- [Android ADB Protocol](https://developer.android.com/tools/adb) (Android Developers)
490- [Python ADB Library](https://github.com/google/adb_home) (Google GitHub)
491- [OpenCV Documentation](https://docs.opencv.org) (OpenCV Docs)
492- [Tesseract OCR](https://github.com/UB-Mannheim/tesseract/wiki) (GitHub)
493
494---
495
496**Version**: 1.0.0
497**Status**: ✅ Production Ready (Phase 1 Foundation)
498**Last Updated**: 2025-12-01
499**Next Phase**: Create 5 core modules + 7 UV scripts