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

ask2-ai-cli

v1.1.6

Published

Convert natural language to executable commands

Readme

Ask CLI

基于AI的强大命令行助手,将自然语言转换为可执行命令。支持多模型管理、智能切换和全面的安全检查。

Demo GIF

🔗 仓库地址

GitHub: https://github.com/zhump/ask2-ai-cli

✨ 核心特性

🎯 Shell集成功能

  • askx辅助函数,无缝集成shell历史记录
  • 一键安装,自动检测shell类型
  • 回车确认执行,简化的确认流程
  • 彩色命令显示,更好的可读性
  • 自动清理和便捷卸载

🎯 多AI模型支持

  • 配置多个AI模型,支持不同设置(温度参数、API端点)
  • 简单切换模型,使用简单命令即可
  • 智能模型管理,带有可视化状态指示器

🛡️ 高级安全保护

  • 危险命令检测,双重确认机制
  • 权限提升警告和建议
  • 交互式确认,执行前人工审核
  • 命令解释,教育性功能

🔧 开发者友好

  • 调试模式,详细时间统计和提示词可见性
  • 命令历史记录,执行跟踪
  • 跨平台支持(macOS、Linux、Windows、WSL)
  • 智能环境检测(Shell、包管理器、项目类型)

🚀 安装

npm install ask2-ai-cli -g

⚙️ 配置

初始设置

ask config

显示配置文件路径,编辑文件添加API配置:

配置格式

{
  "models": [
    {
      "name": "moonshotai/kimi-k2:free",
      "apiKey": "your-api-key-here",
      "apiUrl": "https://openrouter.ai/api/v1/chat/completions",
      "model": "moonshotai/kimi-k2:free",
      "temperature": 0.3,
      "enabled": true
    },
    {
      "name": "Creative Mode",
      "apiKey": "your-api-key-here",
      "apiUrl": "https://open.bigmodel.cn/api/paas/v4/chat/completions",
      "model": "glm-4.5",
      "temperature": 0.3,
      "enabled": false
    }
  ]
}

推荐使用openrouter免费的模型API和您内网的模型API,避免信息泄漏,增强安全性。

测试配置

ask test

📖 使用方法

Shell集成(推荐)

为了获得最佳的shell历史记录支持体验,请安装 askx 辅助函数:

# 安装askx函数到你的shell
ask install

# 重新加载shell配置
source ~/.zshrc    # zsh用户,bash用户使用 ~/.bashrc

# 使用askx执行命令,支持历史记录
askx "列出所有文件"
askx "杀死3000端口的进程"
askx "查找大于100MB的大文件"

askx的优势:

  • ✅ 命令会添加到shell历史记录中
  • ✅ 可以使用上下箭头键查找之前执行的命令
  • ✅ 简化的确认流程:直接按回车执行
  • ✅ 彩色命令显示,更好的可读性

askx使用示例:

$ askx "删除30天前的文件"

Execute this command? (Enter/n): find . -type f -mtime +30 -delete 
[按回车]
✅ Command executed successfully and added to history

卸载askx:

ask uninstall      # 移除askx函数
source ~/.zshrc    # 重新加载shell

基本命令

# 传统交互模式
ask 列出所有文件
ask 查找大于100MB的大文件
ask 杀死3000端口的进程

# 模型管理
ask ls                     # 列出所有模型
ask use xxx                # 切换模型
ask config                 # 查看配置

# 高级选项
ask --debug "复杂查询"      # 调试模式
ask --explain "rm -rf 文件夹" # 获取解释
ask --print "你的查询"       # 仅打印命令(askx内部使用)

模型管理工作流

1. 列出可用模型

ask ls
📋 Available Models
──────────────────────────────────────────────────
✅ GLM-4.5 主要
   Model: glm-4.5 | Temperature: 0.3 | API: open.bigmodel.cn
⚪ 创意模式  
   Model: glm-4.5 | Temperature: 0.8 | API: open.bigmodel.cn
──────────────────────────────────────────────────
🎯 Current: GLM-4.5 主要

2. 切换模型

ask use qwen3
✅ Successfully switched to model qwen3

📋 Active model details:
──────────────────────────────
  Name: qwen3
  Model: qwen3
  Temperature: 0.8

交互式命令流程

Ask生成命令后,你可以选择:

  • 回车 → 立即执行
  • N → 取消并退出
  • C → 生成不同解决方案
  • E → 获取详细解释
$ ask 检查磁盘空间

建议的命令:
df -h

⚠️  请仔细检查命令后再执行!

选择操作:
  回车 - 执行命令
  N - 退出
  C - 换个答案
  E - 解释命令

请选择 (回车/N/C/E): [E]

📚 命令解释
──────────────────────────────────────────────────
命令: df -h

解释:
• df: 显示文件系统磁盘空间使用情况
• -h: 人类可读格式(KB、MB、GB而不是字节)
• 显示可用空间、已用空间和挂载点
• 安全的只读操作,不会改变系统

🔧 命令参考

| 命令 | 描述 | 示例 | |------|------|------| | ask [查询] | 将自然语言转换为命令 | ask 安装docker | | askx [查询] | 执行命令并支持shell历史记录 | askx "列出所有文件" | | ask install | 安装askx辅助函数 | ask install | | ask uninstall | 移除askx辅助函数 | ask uninstall | | ask ls | 列出所有模型配置 | ask ls | | ask use <名称> | 切换到指定模型 | ask use "创意模式" | | ask config | 显示配置文件路径和内容 | ask config | | ask test | 测试AI连接 | ask test --debug | | ask log | 查看命令历史 | ask log --limit 10 |

命令选项

全局选项:

  • --debug, -d → 启用带时间信息的调试模式
  • --explain, -e → 获取命令解释
  • --print, -p → 仅打印命令(askx内部使用)

日志选项:

  • --clear → 清除命令历史
  • --limit <n> → 显示最近N条记录

🛡️ 安全特性

危险命令保护

$ ask 删除当前目录下的所有文件

⚠️  检测到危险操作!
此命令可能对您的系统造成不可逆的损害:
rm -rf *

您确定要执行此命令吗?

按回车键明确确认(其他任何输入将取消): [取消]

✅ 为安全起见,操作已取消。

权限提升检测

$ ask 安装nginx

建议的命令:
apt install nginx

⚠️  此命令可能需要提升权限。
建议使用: sudo apt install nginx

🌍 系统支持

操作系统: macOS、Linux、Windows、WSL
包管理器: brew、apt、yum、dnf、pacman、winget、choco
项目类型: Node.js、Python、Java、Go、Rust、Git仓库
Shell: bash、zsh、fish、PowerShell、cmd

📝 许可证

MIT