mcpField
M
moai-domain-adb

moai-domain-adb

github.com/rdmptv开发144 次安装47 周前更新
代码仓库

关于 moai-domain-adb

moai-domain-adb 是使用 ADB 进行 Android 自动化的模块化技能,面向设备编排和游戏 Bot 开发。其模块涵盖设备操作、视觉检测和 Tauri 集成。

主要功能

  1. 01ADB 连接与 Shell 操作
  2. 02多设备状态及生命周期管理
  3. 03游戏 Bot 脚本与动作计时
  4. 04模板匹配与 OCR 检测
  5. 05Tauri-Python 通信模式
  6. 06设备及 Bot 任务脚本

适用场景

  1. 01检查和控制 Android 设备
  2. 02协调多个设备的操作
  3. 03使用 OCR 或图像匹配构建游戏 Bot
  4. 04将 Bot 状态与命令接入 Tauri UI

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/rdmptv/adbautoplayer --skill moai-domain-adb

安装后在 Claude Code 中输入/moai-domain-adb确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

COMMON-UTILS-QUICKREF.md
DELIVERABLES-INDEX.md
DELIVERABLES.md
FILE-LOCATIONS.txt
FILES-REFERENCE.md
MULTIRESOLUTION-FILE-INDEX.md
MULTIRESOLUTION-MATCHING-SUMMARY.md
MULTIRESOLUTION-QUICKREF.md
PHASE_9B_WORKSTREAM_C_COMPLETION.md
PHASE-11-RESILIENCE-SUMMARY.md
PHASE-5-FOUNDATION-REPORT.md
PHASE-5-INDEX.md
PHASE-5-SUMMARY.txt
PHASE-9B-COMPLETION-REPORT.md
PHASE-9B-WORKSTREAM-B-SUMMARY.md
RESILIENCE-QUICKREF.md
examples/
afk-journey-fsm.py
modules/
adb-fundamentals.md
computer-vision.md
device-management.md
game-automation.md
resilience-patterns.md
tauri-integration.md
scripts/
adb_action_recorder.py
adb_bot_generator.py
adb_checkpoint_manager.py
adb_config_validator.py
adb_cv_preprocess.py
adb_deployment_helper.py
adb_device_analyzer.py

详细介绍

moai-domain-adb:ADB 自动化领域专家

用于智能 Android 自动化、游戏机器人开发和实时设备编排的第 3 级模块化技能。


🎯 快速参考

核心能力
领域能力模块
设备控制ADB 连接、shell 执行、属性检查adb-fundamentals
设备管理多设备编排、状态跟踪、生命周期管理device-management
游戏自动化机器人脚本、动作序列、时序控制game-automation
视觉与检测模板匹配、OCR、基于区域的检测computer-vision
Tauri 集成UI-Python 桥接、实时通信、部署tauri-integration
关键功能(快速访问)

设备操作

# 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

机器人控制

# 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

模块选择指南

在以下情况下使用:

  • 了解 ADB 基础知识:加载 adb-fundamentals 模块

    • 连接协议、身份验证、基本 shell 操作
    • 设备发现、属性读取、系统交互
  • 管理多台设备:加载 device-management 模块

    • 设备状态跟踪、连接池、故障转移策略
    • 批量操作、监控、生命周期管理
  • 开发游戏机器人:加载 game-automation 模块

    • 点击序列、时序、OCR 解析、状态检测
    • 自定义例程、动作模板、机器人模式
  • 使用视觉进行检测:加载 computer-vision 模块

    • 模板匹配(OpenCV)、OCR(Tesseract)
    • 基于区域的检测、图像分析、模式识别
  • 与 Tauri UI 集成:加载 tauri-integration 模块

    • 实时机器人状态更新、命令排队
    • UI ↔ Python 通信、资源管理

📚 实现指南

架构概览

moai-domain-adb 采用 5 模块渐进式披露模式:

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
第 3 级特性

✅ 模块化:5 个独立模块(无跨模块导入) ✅ 可用于生产:500 多行的 SKILL.md,包含全面的文档 ✅ 脚本化:7 个 UV 脚本,遵循 IndieDevDan 13 条规则 ✅ 可委派:可与 expert-* 和 manager-* Agent 配合使用 ✅ 可复用:适用于任何 Android 自动化项目

使用模式
# 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
集成点

与 Agent 集成:

  • adb-bot-runner:使用 game-automation 模式执行机器人
  • adb-device-manager:运用 device-management 专业知识管理设备
  • adb-game-tester:使用 computer-vision 和 game-automation 测试机器人
  • adb-config-manager:使用 config-validator 脚本验证配置
  • adb-workflow-orchestrator:使用 tauri-integration 模式协调所有 Agent

与命令集成:

  • /adb:init → 使用 adb-fundamentals + adb_device_analyzer
  • /adb:bot → 使用 game-automation + adb_bot_generator
  • /adb:test → 使用 computer-vision + adb_game_tester
  • /adb:deploy → 使用 tauri-integration + adb_deployment_helper

与 UV 脚本集成: 所有 7 个脚本均可独立运行(彼此之间零依赖),遵循 PEP 723,并实现双输出(人类可读内容 + JSON)。

渐进式信息披露策略

第 1 级:入门

  • 阅读:adb-fundamentals 模块
  • 运行:adb_device_analyzer.py,列出设备
  • 了解:设备连接和属性读取基础

第 2 级:多设备工作流

  • 阅读:device-management 模块
  • 了解:连接池、状态跟踪、故障转移
  • 构建:可同时管理 5 台以上设备的脚本

第 3 级:游戏机器人开发

  • 阅读:game-automation 模块
  • 了解:点击序列、时间控制、OCR 集成
  • 构建:用于游戏专属任务的自定义例程

第 4 级:基于视觉的自动化

  • 阅读:computer-vision 模块
  • 了解:模板匹配、OCR 解析、区域检测
  • 构建:能够动态适应 UI 变化的机器人

第 5 级:生产环境编排

  • 阅读:tauri-integration 模块
  • 了解:实时 UI 更新、命令排队、资源管理
  • 构建:使用 Tauri UI 控制的企业级工作流

🚀 高级主题

技能组合策略

moai-domain-adb 专为模块化组合而设计:

# 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"
)
性能优化

设备批处理:

  • 按设备分组命令,以减少往返延迟
  • 使用 adb_performance_profiler.py 识别瓶颈
  • 目标:在 <5 秒内执行 100 个操作

缓存策略:

  • 缓存设备属性(每 60s 刷新)
  • 缓存模板图像(检测失败时刷新)
  • 缓存机器人配置(用户编辑后失效)

并发:

  • 使用 ThreadPoolExecutor 运行多设备操作
  • 每台主机最多限制 5 个并发 ADB 操作
  • 设备超过 5 台时使用队列
安全注意事项

身份验证:

  • ADB 使用 RSA 密钥交换;验证设备证书
  • 切勿存储未加密的设备配对密钥
  • 对生产设备每季度轮换一次配对密钥

权限:

  • 仅请求必要的 shell 命令(除非必要,否则避免使用 su)
  • 使用应用专属命令,而非 root 访问权限
  • 审查机器人操作,避免意外副作用

数据保护:

  • 切勿在屏幕截图中捕获敏感数据
  • 加密存储包含 API 密钥的配置
  • 使用安全存储保存游戏凭据
调试与故障排除

常见问题:

问题诊断解决方案
未找到设备adb_device_analyzer.py --check-connection检查 USB 连接,检查 ADB 守护进程
机器人执行缓慢adb_performance_profiler.py --device <id>缩短点击延迟,批处理操作
模板匹配失败检查图像 DPI/分辨率运行 adb_template_creator.py --device <id>
OCR 准确率低预处理图像(对比度、阈值)查看 computer-vision 模块获取建议
Tauri 通信延迟检查 Python 进程 CPU 占用降低日志详细程度,优化渲染循环

调试模式:

# 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"
测试策略(TRUST 5 框架)

测试覆盖率目标:≥85%

  • 单元测试:各模块函数(py.test)
  • 集成测试:模块交互(设备模拟)
  • 端到端测试:使用真实设备执行完整工作流(可选)
  • 性能测试:执行时间基准测试
  • 安全测试:输入验证、权限检查

测试执行:

# 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

📖 模块导航

每个模块都基于之前的知识构建,但也可独立使用:

  • adb-fundamentals(250 行)

    • ADB 架构、连接协议、设备发现
    • Shell 执行、属性读取、设备交互
  • device-management(280 行)

    • 多设备编排、状态跟踪、连接池
    • 生命周期管理、监控、故障转移策略
  • game-automation(300 行)

    • Bot 脚本编写模式、点击序列、时间控制
    • OCR 集成、状态检测、操作模板
  • computer-vision(270 行)

    • 模板匹配(OpenCV)、OCR(Tesseract)
    • 区域检测、图像预处理、模式识别
  • tauri-integration(240 行)

    • Tauri-Python IPC、实时更新、命令排队
    • 资源管理、部署策略、监控

🛠️ 脚本与工具

所有脚本均遵循 IndieDevDan 13 Rules(PEP 723、9 部分结构、双重输出):

# 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
完整脚本参考(36 个脚本)

所有脚本均位于 scripts/ 目录中,并按类别整理。每个脚本都支持:

  • --device/-d - 指定设备 ID(默认为第一个已连接的设备)
  • --toon - 以 TOON/YAML 格式输出,便于自动化
  • --verbose/-v - 启用详细日志
  • --help - 显示详细的帮助信息和使用示例

请参阅 scripts/README.md,其中包含 150 多个用法示例和完整文档。

🔌 连接(4 个脚本)

位置:scripts/connection/

脚本用途主要选项示例
adb_connect.py通过 IP:端口连接设备--device(默认:127.0.0.1:5555)uv run scripts/connection/adb_connect.py
adb_disconnect.py安全断开设备连接--deviceuv run scripts/connection/adb_disconnect.py
adb_restart_server.py重启 ADB 服务--verboseuv run scripts/connection/adb_restart_server.py
adb_device_status.py列出所有设备及其状态--toonuv run scripts/connection/adb_device_status.py
📱 屏幕(6 个脚本)

位置:scripts/screen/

脚本用途主要选项示例
adb_screenshot.py截取屏幕截图--output FILEuv run scripts/screen/adb_screenshot.py --output capture.png
adb_tap.py点击指定坐标--x X --y Y --count Nuv run scripts/screen/adb_tap.py --x 500 --y 1000
adb_swipe.py执行滑动手势--preset {up,down,left,right} 或 --start X,Y --end X,Yuv run scripts/screen/adb_swipe.py --preset up
adb_keyevent.py发送按键事件--key {back,home,menu,power,volume_up}uv run scripts/screen/adb_keyevent.py --key back
adb_text_input.py输入文本--text TEXTuv run scripts/screen/adb_text_input.py --text "Hello"
adb_screenrecord.py录制屏幕视频--output FILE --duration SECONDSuv run scripts/screen/adb_screenrecord.py --duration 60
📦 应用(5 个脚本)

位置:scripts/app/

脚本用途主要选项示例
adb_app_list.py列出已安装的应用--filter TEXT、--system、--alluv run scripts/app/adb_app_list.py --filter afk
adb_app_start.py按包名启动应用-p PACKAGE、--waituv run scripts/app/adb_app_start.py -p com.afk.journey
adb_app_stop.py强制停止应用-p PACKAGEuv run scripts/app/adb_app_stop.py -p com.afk.journey
adb_app_install.py安装 APK--apk FILEuv run scripts/app/adb_app_install.py --apk game.apk
adb_app_uninstall.py卸载应用-p PACKAGE、--keep-datauv run scripts/app/adb_app_uninstall.py -p com.example
ℹ️ 信息(4 个脚本)

位置:scripts/info/

脚本用途主要选项示例
adb_device_info.py设备规格--toonuv run scripts/info/adb_device_info.py
adb_display_info.py显示分辨率/DPI--toonuv run scripts/info/adb_display_info.py
adb_running_app.py当前前台应用--toonuv run scripts/info/adb_running_app.py
adb_battery_info.py电池状态--toonuv run scripts/info/adb_battery_info.py
⚡ 性能(3 个脚本)

位置:scripts/performance/

脚本用途主要选项示例
adb_cpu_monitor.py实时 CPU 监控--duration SECONDS、--package PKGuv run scripts/performance/adb_cpu_monitor.py --duration 60
adb_memory_monitor.py内存使用监控--duration SECONDS、--package PKGuv run scripts/performance/adb_memory_monitor.py --duration 60
adb_logcat_filter.py过滤 logcat 日志--tag TAG、--priority {V,D,I,W,E,F}、--followuv run scripts/performance/adb_logcat_filter.py --tag MyApp --priority E
🤖 自动化(4 个脚本)

位置:scripts/automation/

脚本用途主要选项示例
adb_game_loop.py执行重复序列-s FILE、-l LOOPS、--infiniteuv run scripts/automation/adb_game_loop.py -s daily.json -l 10
adb_wait_for_app.py等待应用启动--package PKG、--timeout SECONDSuv run scripts/automation/adb_wait_for_app.py -p com.afk.journey
adb_click_sequence.py执行一次序列-s FILEuv run scripts/automation/adb_click_sequence.py -s tutorial.json
adb_screenshot_compare.py比较截图-b BEFORE -a AFTER、--threshold FLOATuv run scripts/automation/adb_screenshot_compare.py -b ref.png -a test.png
🛠️ 工具(3 个脚本)

位置:scripts/utils/

脚本用途主要选项示例
adb_shell.py执行 shell 命令-c COMMAND、--timeout SECONDSuv run scripts/utils/adb_shell.py -c "ls /sdcard"
adb_push.py将文件推送到设备-l LOCAL -r REMOTEuv run scripts/utils/adb_push.py -l file.txt -r /sdcard/
adb_pull.py从设备拉取文件-r REMOTE -l LOCALuv run scripts/utils/adb_pull.py -r /sdcard/screenshot.png -l .
🔧 监控(7 个脚本)

位置:scripts/(根目录)

脚本用途主要选项示例
adb_bot_generator.py生成 bot 脚本--template NAME、--output FILEuv run scripts/adb_bot_generator.py --template daily_quests
adb_config_validator.py验证配置--config FILE、--strictuv run scripts/adb_config_validator.py --config config.json
adb_deployment_helper.py部署到设备--apk FILE、--all、--devices IDSuv run scripts/adb_deployment_helper.py --apk game.apk --all
adb_device_analyzer.py分析设备能力--aspects LIST、--output FILEuv run scripts/adb_device_analyzer.py --aspects performance,battery
adb_game_tester.py测试游戏自动化--test-suite FILE、--screenshotsuv run scripts/adb_game_tester.py --test-suite tests.json
adb_performance_profiler.py分析性能--package PKG、--duration SECONDSuv run scripts/adb_performance_profiler.py -p com.afk.journey
adb_template_creator.py创建模板--name NAME、--category CATuv run scripts/adb_template_creator.py --name my_automation
JSON 序列格式(自动化脚本)

对于 adb_game_loop.py 和 adb_click_sequence.py,请使用 JSON 格式:

{
  "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"}
  ]
}

支持的操作:tap、swipe、wait、screenshot、keyevent、text_input

通用实用工具

所有脚本都使用 scripts/common/ 中的共享实用工具:

  • adb_utils.py - ADB 设备操作和连接管理
  • cli_utils.py - Click 装饰器、Rich 格式化器和输出辅助工具
  • error_handlers.py - 标准化错误处理和退出码(0、2、3、4)
  • path_utils.py - 项目根目录检测和路径解析
退出码

所有脚本都使用标准化退出码:

  • 0 - 成功
  • 2 - 设备离线或未找到
  • 3 - ADB 命令失败或执行错误
  • 4 - 参数或配置无效
输出格式

文本输出(默认):带颜色和表格的 Rich 格式化控制台输出
TOON 输出(--toon):用于自动化和解析的 YAML/结构化格式


📞 支持与参考资料

快速链接:

  • 模块:参阅 modules/ 中的各个模块文件
  • 脚本:参阅 scripts/ 中的各个脚本,并使用 --help
  • 示例:参阅 adb-* Agent 中的集成模式
  • 测试:参阅 tests/ 中的测试套件

Context7 参考资料:


版本:1.0.0 状态:✅ 已可用于生产环境(第一阶段基础) 最后更新:2025-12-01 下一阶段:创建 5 个核心模块和 7 个 UV 脚本

评论

支持 Markdown