npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

autojs-skill

v1.0.0

Published

CLI tool for AutojsRun broadcast

Readme

robot-cli

用CLI执行autojs代码

CLI tool for Autojs broadcast and device interaction via ADB.

前置要求

一般不用检查,默认已经安装了以下内容

  • Node.js 18+
  • 已安装 adb 并加入 PATH
  • 通过 USB 或网络连接 Android 设备(adb devices 能看到设备)
  • 目标应用 com.hammer.auto_debug 已安装在设备上

安装

cd robot-cli
npm install
# 可选:全局链接
npm link

链接后即可在任意目录直接使用 robot-cli 命令;否则用 node ./index.js <command>

命令一览

| 命令 | 说明 | | ------------ | --------------------------------------------- | | init | 初始化 License | | exec | 在新上下文中执行 JS 代码 | | eval | 在当前上下文中执行 JS 代码 | | run-file | 运行设备上的脚本文件 | | stop | 停止正在运行的脚本 | | start-app | 启动目标应用 | | stop-app | 强制停止目标应用 | | layout | 获取当前手机 UI 布局(XML) | | screenshot | 截取当前手机屏幕 | | version | 查看目标应用在设备上的版本号 | | logs | 查看 logcat 中包含关键字的最近日志 |


init — 初始化 License

License 在每个 app 进程生命周期内只需初始化一次。

robot-cli init [options]

选项:

  • -l, --license <license>:License key,默认 __UNI__9D97713
  • -r, --requestId <id>:可选请求 ID

示例:

robot-cli init
robot-cli init -l __UNI__9D97713 -r req-001

注意:init 需要联网进行 License 校验,无网络会返回 network_fail

exec — 在新上下文执行代码

robot-cli exec <code> [options]

参数:

  • <code>:要执行的 JavaScript 代码

选项:

  • -r, --requestId <id>:请求 ID
  • -a, --args <args>:JSON 字符串形式的参数

示例:

robot-cli exec "log(123);"
robot-cli exec "click(500, 500);" -a '{"x":500,"y":500}'

eval — 在当前上下文执行代码

robot-cli eval <code> [options]

参数:

  • <code>:要执行的 JavaScript 代码

选项:

  • -r, --requestId <id>:请求 ID

示例:

robot-cli eval "currentPackage();"

run-file — 运行脚本文件

robot-cli run-file <path> [options]

参数:

  • <path>:设备上的脚本文件路径

选项:

  • -r, --requestId <id>:请求 ID
  • -a, --args <args>:JSON 字符串形式的参数

示例:

robot-cli run-file /sdcard/scripts/main.js

stop — 停止脚本

robot-cli stop [options]

选项:

  • -r, --requestId <id>:请求 ID

示例:

robot-cli stop

start-app — 启动应用

robot-cli start-app

stop-app — 强制停止应用

robot-cli stop-app

layout — 获取当前 UI 布局

通过 adb shell uiautomator dump 获取当前界面布局 XML,默认输出到 stdout,也可保存到文件。

robot-cli layout [options]

选项:

  • -o, --output <file>:保存到指定文件
  • -c, --compressed:使用压缩格式(部分 Android 版本支持,输出更小)

示例:

# 打印到终端
robot-cli layout

# 保存到文件
robot-cli layout -o layout.xml

# 压缩格式
robot-cli layout -c -o layout.xml

注意:执行前设备需亮屏解锁,否则可能拿到空布局。

screenshot — 截图

通过 adb exec-out screencap -p 捕获屏幕 PNG。截图为二进制数据,默认保存到当前目录,文件名带时间戳。

robot-cli screenshot [options]

选项:

  • -o, --output <file>:保存到指定文件,默认 screenshot-<timestamp>.png

示例:

# 默认文件名
robot-cli screenshot

# 指定文件名
robot-cli screenshot -o cap.png

version — 查看应用版本号

通过 adb shell dumpsys package 查看目标应用在设备上的 versionNameversionCode

robot-cli version

示例输出:

Package: com.hammer.auto_debug
Version: 1.0.0
Version Code: 1

提示:CLI 自身版本可用 robot-cli --versionrobot-cli -V 查看。

logs — 查看日志

adb logcat -d 中过滤包含关键字的最近 N 条日志。

robot-cli logs [options]

选项:

  • -n, --lines <number>:显示条数,默认 20
  • -f, --filter <filter>:过滤关键字,默认 AutojsRun

示例:

robot-cli logs
robot-cli logs -n 50 -f AutojsRun

典型工作流

# 1. 启动应用并保持进程存活
robot-cli start-app

# 2. 初始化 License(每个进程生命周期一次)
robot-cli init

# 3. 执行脚本 / 代码
robot-cli exec "log('hello');"

# 4. 调试时获取布局和截图
robot-cli layout -o layout.xml
robot-cli screenshot -o debug.png

# 5. 查看日志
robot-cli logs -n 50

# 6. 完成后停止脚本和应用
robot-cli stop
robot-cli stop-app

常见问题

ADB 广播命令包含括号报语法错误

包含 ( ) 等特殊字符的代码(如 log(123);)在设备 shell 中会被错误解析。解决方法是把整个 am broadcast 命令用双引号包裹:

adb shell "am broadcast -a com.hammer.controller.userobot.RUN -n com.hammer.auto_debug/com.hammer.controller.userobot.AutojsRun --es action 'exec' --es code 'log(123);'"

本 CLI 已在内部正确处理参数转义。

Android 12+ 无法从后台启动前台服务

请先手动打开应用让进程存活,再发送广播命令。

init 报 network_fail

License 校验需要联网,请确认设备和开发机网络正常。

项目结构

robot-cli/
├── index.js        # CLI 入口与所有命令实现
├── package.json
└── README.md

相关广播 Action

  • com.hammer.controller.userobot.RUN:执行脚本/代码的广播
  • com.hammer.controller.userobot.RUN_RESULT:执行结果回传广播
  • 接收器组件:com.hammer.auto_debug/com.hammer.controller.userobot.AutojsRun