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

xx-ai-cli

v0.1.58

Published

🤖 支持国内主流大模型的 AI 命令行工具,内置 Agent 模式、历史会话、管道输入

Readme

🤖 XX-AI-CLI

国内主流大模型命令行工具,支持 DeepSeek、通义千问、智谱GLM、豆包、Kimi、MiniMax、腾讯混元、百度文心等 8 大平台。

npm Node.js TypeScript


✨ 功能特性

  • 🗨️ 交互式对话 - 多轮对话,支持历史上下文,自动持久化
  • 🤖 Agent 模式 - 自主执行任务,调用工具(文件读写、命令执行、联网搜索)
  • 单次提问 - 快速问答,流式输出
  • 💻 代码助手 - 生成、解释、优化、Review 代码
  • 📄 文件分析 - 读取本地文件让 AI 分析
  • 🔧 命令建议 - 自然语言转 Shell 命令
  • 🔄 多模型切换 - 对话中随时切换,无需重启
  • 🎯 一键初始化 - xx init 交互式向导,新用户 1 分钟完成配置
  • 📚 历史会话 - 查看、恢复任意历史对话
  • 🔗 管道输入 - cat file | xx "问题" 无缝联动其他工具

📦 支持的模型

| 模型 | Provider | 默认模型 | 获取 API Key | | ------------- | ---------- | -------------- | -------------------------------------------------------------------- | | DeepSeek | deepseek | deepseek-chat | platform.deepseek.com | | 通义千问 | qwen | qwen-turbo | dashscope.console.aliyun.com | | 智谱 GLM | glm | glm-4-flash | open.bigmodel.cn | | 豆包 | doubao | doubao-pro-4k | console.volcengine.com | | 月之暗面 Kimi | moonshot | moonshot-v1-8k | platform.moonshot.cn | | MiniMax 海螺 | minimax | abab6.5s-chat | api.minimax.chat | | 腾讯混元 | hunyuan | hunyuan-pro | cloud.tencent.com | | 百度文心一言 | ernie | ernie-4.0-8k | qianfan.baidu.com |


🚀 快速开始

安装

npm install -g xx-ai-cli

安装后提供两个命令:xx(短别名,推荐)和 xxcli(完整名)。

初始化

xx init

向导会引导你:选择模型 → 输入 API Key → 设置默认模型 → 开启流式输出,1 分钟完成配置。


📖 使用示例

💬 交互式对话

xx chat
xx chat --model qwen
xx chat --system "你是一个 Python 专家"

对话内置命令(输入 / 可查看全部):

| 命令 | 说明 | | ---------- | ---------------------- | | /clear | 清空当前对话 | | /model | 切换模型(无需退出) | | /history | 查看最近 10 条历史会话 | | /exit | 退出(会话自动保存) |

🤖 Agent 模式(自主执行任务)

xx agent "帮我查一下杭州今天的天气"
xx agent "读取 src/index.ts,找出潜在 Bug"
xx agent "帮我改一下 deepseek 的 API Key"
xx agent --model deepseek "分析当前项目结构"

Agent 对话内置命令(输入 / 可查看全部):

| 命令 | 说明 | | -------------- | ------------------ | | /clear | 清空当前对话 | | /tools | 查看可用工具列表 | | /context | 查看当前上下文内容 | | /tokens | Token 消耗统计 | | /model | 切换模型 | | /cache clear | 清空工具缓存 | | /exit | 退出 |

⚡ 单次提问

xx ask "什么是 CAP 定理"
xx ask "解释 React Hooks" --model glm
xx ask "写个斐波那契数列" --no-stream

💻 代码助手

# 生成代码
xx code gen "用 TypeScript 写一个单例模式"

# 解释代码
xx code explain ./src/index.ts

# 优化代码
xx code optimize ./src/utils.ts

# Code Review
xx code review ./src/api.ts

📄 文件分析

xx file ./package.json "这个项目依赖了哪些主要库?"
xx file ./src/index.ts "帮我找出潜在的 Bug"

🔧 Shell 命令建议

xx cmd "找出所有大于 1MB 的文件"
xx cmd "查看端口 8080 被哪个进程占用"
xx cmd "统计当前目录下 ts 文件数量"

🔗 管道输入

cat error.log | xx "帮我分析这个错误"
git diff | xx "帮我写 commit message"
cat src/utils.ts | xx "帮我 code review"

📚 历史会话管理

xx history list          # 列出最近 20 条历史会话
xx history show <ID>     # 查看某条历史详情
xx history resume <ID>   # 从历史会话继续对话
xx history clear         # 清空所有历史

🔧 模型管理

# 查看所有模型状态
xx model list

# 设置 API Key
xx model set-key deepseek sk-xxxxxxxxxxxxxxxx
xx model set-key qwen sk-xxxxxxxxxxxxxxxx
xx model set-key glm xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxx
xx model set-key doubao xxxxxxxxxxxxxxxx
xx model set-key moonshot sk-xxxxxxxxxxxxxxxx
xx model set-key minimax xxxxxxxxxxxxxxxx
xx model set-key hunyuan xxxxxxxxxxxxxxxx
xx model set-key ernie xxxxxxxxxxxxxxxx

# 切换默认模型
xx model use deepseek
xx model use qwen

# 检测连通性
xx model check deepseek

⚙️ 高级配置

# 查看当前配置
xx config show

# 关闭流式输出
xx config set stream false

# 设置历史长度
xx config set historySize 30

# 显示 AI 思考过程(DeepSeek R1 / Qwen3 等推理模型)
xx agent --thinking "你的问题"

� API Key 安全性说明

Key 绝不离开你的设备

  • 本工具不设任何服务端,所有 AI 请求均由你的设备直连各模型官方 API
  • Key 仅用于构造请求头 Authorization: Bearer <key>,全程不经过任何第三方
  • 代码完全开源,可自行审查 src/core/stream.ts

Key 的存储位置

| 系统 | 配置文件路径 | | ------------- | ------------------------------ | | macOS / Linux | ~/.config/ai-cli/config.json | | Windows | %APPDATA%\ai-cli\config.json |

三种方式存储 Key(安全性递增)

# 方式一:命令行直接传入(会留在 shell history)
xx model set-key deepseek sk-xxxxxxxxxxxxxxxx

# 方式二:隐藏输入模式(推荐)
xx model set-key deepseek
# 在提示符下输入 Key,输入内容不会回显

# 方式三:环境变量(最安全,Key 永不写入磁盘)
export DEEPSEEK_API_KEY=sk-xxxxxxxxxxxxxxxx
xx chat

环境变量一览:

| 模型 | 环境变量名 | | ------------- | ------------------ | | DeepSeek | DEEPSEEK_API_KEY | | 通义千问 | QWEN_API_KEY | | 智谱 GLM | GLM_API_KEY | | 豆包 | DOUBAO_API_KEY | | 月之暗面 Kimi | MOONSHOT_API_KEY | | MiniMax 海螺 | MINIMAX_API_KEY | | 腾讯混元 | HUNYUAN_API_KEY | | 百度文心一言 | ERNIE_API_KEY |


🗂️ 项目结构

src/
├── commands/       # CLI 命令实现
│   ├── agent.ts    # Agent 自主任务模式
│   ├── chat.ts     # 交互式对话
│   ├── ask.ts      # 单次提问
│   ├── code.ts     # 代码助手
│   ├── file.ts     # 文件分析
│   ├── cmd.ts      # 命令建议
│   ├── model.ts    # 模型/配置管理
│   └── history.ts  # 历史会话管理
├── core/
│   ├── config.ts   # 配置 & 模型定义
│   ├── tools.ts    # Agent 工具集(文件/命令/搜索)
│   ├── search.ts   # 联网搜索(必应 + wttr.in)
│   ├── session.ts  # 会话/历史持久化
│   ├── stream.ts   # 流式 API 调用
│   └── prompt.ts   # Prompt 模板
├── ui/
│   └── renderer.ts # 终端 UI 渲染
└── index.ts        # 主入口

📝 License

MIT