← 返回集成

集成指南

已支持

CLI 与 shell 脚本 + OpenPets

使用已发布的 OpenPets npm CLI 检查桌面状态、列出宠物、发送反应、显示简短消息,并将 OpenPets 接入本地 shell 自动化流程。

此集成的功能

OpenPets CLI 允许终端命令与正在运行的 OpenPets 桌面应用通信。当你希望通过 shell 脚本、npm 脚本、本地构建命令、git hook 或自定义自动化工具触发宠物反应时,可以使用它。

命令功能说明适用场景
npx -y @open-pets/cli@latest status检查桌面应用是否可达。设置检查和故障排查。
npx -y @open-pets/cli@latest pets列出已安装的宠物并标记默认宠物。在路由设置前查找宠物 ID。
npx -y @open-pets/cli@latest react <reaction>在不显示文本的情况下更改宠物反应。静默成功、错误、测试、等待或工作状态。
npx -y @open-pets/cli@latest say <message>显示一条简短的可见对话气泡。有意义的本地自动化状态更新。

CLI 以 npm 包 @open-pets/cli 的形式分发。桌面应用不会安装 shell 命令;一次性命令可用 npx,显式包执行可用 npm exec,如果想要永久的 openpets 命令,也可以选择全局 npm 安装。

使用要求

  • OpenPets 桌面应用必须正在运行。
  • 使用 npxnpm exec 或可选全局 npm 安装时,必须有可用的 Node.js 和 npm。
  • CLI 通过 OpenPets 本地 IPC 与桌面应用通信,不通过云服务发送命令。

使用 npx 快速开始

当你不想全局安装时,使用 npx。以下示例始终获取最新发布的 OpenPets CLI。

检查桌面状态bash
npx -y @open-pets/cli@latest status
列出已安装的宠物bash
npx -y @open-pets/cli@latest pets
发送反应bash
npx -y @open-pets/cli@latest react success
显示简短消息bash
npx -y @open-pets/cli@latest say "Build finished" --reaction celebrating

如果你的 npm 环境有过期的 npx 缓存元数据,等效的 npm exec 形式为:

npm exec 形式bash
npm exec --yes --package=@open-pets/cli@latest -- openpets --help

可选的全局安装

如果你希望在终端直接输入 openpets,可以全局安装 CLI。这与下载桌面应用是分开的操作。

一次性安装bash
npm install -g @open-pets/cli
直接使用bash
openpets status
openpets react testing
openpets say "Tests are running" --reaction testing

Shell 脚本示例

保持消息简短且面向用户。对于嘈杂的步骤使用反应,仅在有意义的时刻使用语音。

npm test 通知bash
npm test \
  && npx -y @open-pets/cli@latest say "Tests passed" --reaction success \
  || npx -y @open-pets/cli@latest say "Tests failed" --reaction error
构建脚本bash
npx -y @open-pets/cli@latest react running
pnpm build
npx -y @open-pets/cli@latest react success
package.json 脚本json
{
  "scripts": {
    "test:pet": "npm test && npx -y @open-pets/cli@latest say 'Tests passed' --reaction success"
  }
}

可用反应

CLI 接受与 OpenPets 本地客户端和 MCP 工具相同的反应名称:

反应名称text
idle
thinking
working
editing
running
testing
waiting
waving
success
error
celebrating

消息安全

宠物语音在你的桌面上可见。将其视为一个微型公开状态频道,而非日志输出。

良好示例应避免的内容
Build finished.完整命令输出或错误堆栈。
Tests are running.文件路径、URL 或私有仓库详情。
Waiting for review.密钥、令牌、提示词或用户消息。

故障排查

npx -y @open-pets/cli@latest status 提示应用不可用

  • 先打开 OpenPets 桌面应用。
  • 如果桌面应用在运行时被更新,请重启它。
  • 再次运行 npx -y @open-pets/cli@latest status

桌面应用没有安装 shell 命令

下载桌面应用不会安装 shell 命令。请使用 npx -y @open-pets/cli@latest ...npm exec,或在需要永久命令时通过 npm 全局安装 @open-pets/cli

反应名称被拒绝

请使用上面列出的反应名称之一。CLI 在将反应名称发送到桌面应用之前会进行验证。

Alvin 制作