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

@aicaigou/cli

v0.3.4

Published

CLI tool for CAI B2B platform (cai-cli)

Readme

cai-cli

B2B CAI 平台命令行工具,提供店铺管理、商品、广告等能力,支持在终端和 AI Agent(Ducc/Claude Code)中使用。


安装

npm(推荐)

npm install -g @aicaigou/cli

安装完成后:

  • CLI 二进制自动下载到 node_modules/@aicaigou/cli/bin/
  • AI Agent Skills 自动安装到 ~/.agents/skills/(Ducc / Claude Code 自动加载)

无需额外步骤,一步完成。

从源码构建

# 克隆仓库
git clone icode.baidu.com/baidu/b2b/cai-cli
cd cai-cli

# 构建(当前平台)
make build

# 或直接安装到 $GOPATH/bin
make install

要求

  • Go 1.23+
  • GOPROXY=http://goproxy.baidu-int.com

快速开始

1. 配置 Token

登录 CAI 平台获取 API Token,然后:

cai-cli auth login
# 提示:请输入 API Token: xxxxxxxx
# ✓ Token 已保存。

或通过环境变量传入(临时使用):

export CAI_CLI_TOKEN=your_token_here

2. 验证配置

# 本地检测 Token 格式与过期时间
cai-cli auth status

# 调用服务端验证(需要网络)
cai-cli auth status --verify

3. 环境诊断

cai-cli doctor

输出示例:

cai-cli 环境诊断
  版本: 0.1.0 (构建于 2026-04-24T12:00:00Z)

  ✓ 配置文件: /root/.cai-cli
  ✓ Token: 已配置(本地有效)
  ✓ 网络连通(http://b2bwork.baidu.com): HTTP 200

所有检查通过。

命令参考

认证管理

cai-cli auth login           # 交互式配置 Token
cai-cli auth logout          # 删除本地 Token
cai-cli auth status          # 查看 Token 状态(本地)
cai-cli auth status --verify # 查看 Token 状态(服务端验证)

配置管理

cai-cli config init              # 首次引导配置
cai-cli config show              # 查看当前配置(Token 脱敏)
cai-cli config set token <value> # 直接设置 Token

店铺管理

cai-cli shop +info               # 查询店铺基本信息
cai-cli shop +info --format table # 表格格式输出
cai-cli shop +info --jq '.shopName'  # 只输出店铺名称

原始 API 调用

# GET 请求
cai-cli api GET /gcli/cliapi/shop/info

# POST 请求(带请求体)
cai-cli api POST /gcli/cliapi/product/list --data '{"page":1,"page_size":20}'

# 带 Query 参数
cai-cli api GET /gcli/cliapi/product/detail --params '{"product_id":"123"}'

# 预览请求(不发送)
cai-cli api GET /gcli/cliapi/shop/info --dry-run

Shell 自动补全

# Bash
cai-cli completion bash > /etc/bash_completion.d/cai-cli

# Zsh
cai-cli completion zsh > "${fpath[1]}/_cai-cli"

# Fish
cai-cli completion fish | source

全局参数

所有命令均支持以下参数:

| 参数 | 说明 | 示例 | |------|------|------| | --format | 输出格式:json(默认)|table|csv|ndjson | --format table | | --jq <expr> | jq 过滤表达式 | --jq '.shopName' | | --output <file> | 输出写入文件 | --output result.json | | --dry-run | 打印请求信息,不实际发送 | --dry-run | | --page-all | 自动翻页获取全部数据 | --page-all |


输出格式

所有命令的 stdout 为标准 JSON Envelope:

{
  "ok": true,
  "data": {
    "shop_id": "123456",
    "shopName": "示例旗舰店"
  }
}

错误时输出到 stderr

{
  "ok": false,
  "error": {
    "type": "auth_error",
    "code": 212011,
    "message": "Token 无效",
    "hint": "logId: abc123"
  }
}

退出码

| 代码 | 含义 | |------|------| | 0 | 成功 | | 1 | 通用错误 | | 2 | 参数错误 | | 3 | 认证错误(Token 未配置/无效/过期)| | 4 | 网络错误 |


环境变量

| 变量 | 说明 | 优先级 | |------|------|--------| | CAI_CLI_TOKEN | API Token | 最高(覆盖 keychain)| | CAI_CLI_CONFIG_DIR | 配置目录(默认 ~/.cai-cli)| — |


在 AI Agent 中使用(Skills)

cai-cli 内置 Skills 文档,可被 Ducc / Claude Code 读取:

skills/cai-shared/SKILL.md   # 通用规范:认证、全局参数、错误处理
skills/cai-shop/SKILL.md     # 店铺管理命令详细说明

在 Agent 对话中,直接描述需求即可:

"帮我查一下当前店铺的基本信息" "把店铺名称提取出来存到文件里"


开发

# 运行测试
make test

# 代码检查
make lint

# 交叉编译(所有平台)
make dist

# 整理依赖
make tidy

添加新业务命令

  1. shortcuts/<domain>/shortcuts.go 中添加 Shortcut 定义
  2. 实现 Execute 函数,通过 rt.Factory.APIClient() 调用接口
  3. 在该文件的 Shortcuts() 函数中注册
  4. 完成后即可通过 cai-cli <domain> +<command> 调用

示例:

var ProductGet = shortcut.Shortcut{
    Service:     "product",
    Command:     "+get",
    Description: "查询商品详情",
    Flags: []shortcut.Flag{
        {Name: "product-id", Required: true, Desc: "商品 ID"},
    },
    Execute: func(ctx context.Context, rt *shortcut.RuntimeContext) error {
        apiClient, _ := rt.Factory.APIClient()
        data, err := apiClient.CallAPI(ctx, client.RawApiRequest{
            Method: "GET",
            URL:    "/gcli/cliapi/product/detail",
            Params: map[string]interface{}{"product_id": rt.Str("product-id")},
        })
        if err != nil {
            return err
        }
        return rt.Out(data)
    },
}

前端: https://b2b-material.bj.bcebos.com/cai-cli/web/latest/install-guide.html