@huyooo/ai-chat-cli
v0.3.29
Published
AI Chat 命令行工具 - 终端中与 AI 对话
Maintainers
Readme
@huyooo/ai-chat-cli
终端 AI 对话工具,与业界 CLI(Claude Code、Aider、Gemini CLI、OpenCode)使用方式一致。
特性
- TUI 界面 - 现代化终端界面,支持快捷键和命令菜单
- 多行输入 -
\+ Enter 换行 - 文件管理 -
@引用文件,/add/drop管理上下文 - 命令执行 -
!执行 Shell 命令 - 网页抓取 -
/web URL抓取网页内容 - Git 集成 -
/git快速查看状态、diff、log - Token 统计 - 实时显示 token 消耗
- 上下文压缩 -
/compress压缩长对话 - 自定义命令 - 定义可复用提示模板
- 会话管理 - 保存、恢复对话
安装
# npm 全局安装
npm install -g @huyooo/ai-chat-cli
# 或从源码安装
cd ai-chat/packages/ai-chat-cli
npm link配置
# 设置 API Key(至少配置一个)
ai-chat config --set arkApiKey=YOUR_ARK_API_KEY
ai-chat config --set geminiApiKey=YOUR_GEMINI_KEY
ai-chat config --set qwenApiKey=YOUR_QWEN_KEY
# Web 搜索(可选)
ai-chat config --set tavilyApiKey=YOUR_TAVILY_KEY
# 查看配置
ai-chat config --list配置文件:~/.ai-chat/config.json
使用
启动 TUI
ai-chat界面:
◆ AI Chat • ask • doubao-seed-1-6 1.2k↑ 0.8k↓
你: 你好
AI: 你好!有什么我可以帮助你的吗?
❯ _
@ 文件 • / 命令 • ! Shell • \↵ 换行 • ^L 清屏快捷键
| 按键 | 功能 |
|------|------|
| @ | 打开文件选择器 |
| / | 打开命令菜单 |
| !cmd | 执行 Shell 命令 |
| \ + Enter | 多行输入 |
| ↑↓ | 历史记录 |
| Ctrl+L | 清屏 |
| Ctrl+C | 取消生成/退出 |
| Ctrl+D | 退出 |
| t | 切换思考显示 |
命令
输入 / 打开命令菜单,或直接输入:
| 命令 | 说明 |
|------|------|
| /help | 显示帮助 |
| /model | 选择模型 |
| /mode ask\|agent | 切换模式 |
| /add <file> | 添加文件到上下文 |
| /drop [file] | 移除文件(不带参数移除全部)|
| /files | 列出上下文文件 |
| /web <URL> | 抓取网页内容 |
| /git [cmd] | Git 命令(status/diff/log/branch)|
| /compress | 压缩对话上下文 |
| /tokens | 显示 Token 统计 |
| /clear | 清空对话 |
| /exit | 退出 |
非交互模式
# 单次查询
ai-chat -p "解释这段代码"
# 管道输入
cat error.log | ai-chat -p "分析这个错误"
# JSON 输出
ai-chat -p "1+1" --json
# 继续上次对话
ai-chat -c -p "继续"经典模式
# 使用 readline 风格的经典界面
ai-chat --classic自定义命令
在 .ai-chat/commands/ 创建 .md 文件定义自定义命令:
---
name: review
description: 代码审查
---
请审查以下代码,关注:
1. 代码质量
2. 潜在 bug
3. 性能问题
$ARGS支持位置:
~/.ai-chat/commands/- 全局命令.ai-chat/commands/- 项目命令(优先)
命令菜单中自定义命令显示 ✦ 标记。
文件排除规则
创建 .aiignore 文件定义文件选择器排除规则:
# .aiignore
*.log
tmp/
secret/支持位置:
.aiignore- 项目根目录.ai-chat/ignore- 项目配置目录~/.ai-chat/ignore- 全局配置
项目指令
类似 Claude Code 的 CLAUDE.md,支持项目级指令:
项目/
├── AI-CHAT.md # 项目指令(优先)
├── .ai-chat/
│ └── instructions.md # 备选位置全局指令:~/.ai-chat/instructions.md
会话管理
ai-chat chat list # 列出会话
ai-chat chat save <tag> # 保存会话
ai-chat chat resume <tag> # 恢复会话
ai-chat chat show <id> # 显示详情
ai-chat chat delete <id> # 删除会话TUI 中使用 -c 继续上次对话:
ai-chat -c与业界对比
| 特性 | Claude Code | Aider | Gemini CLI | ai-chat | |------|:-----------:|:-----:|:----------:|:-----------:| | TUI 界面 | ✅ | ✅ | ✅ | ✅ | | @ 文件引用 | ✅ | ✅ | ✅ | ✅ | | / 命令菜单 | ✅ | ✅ | ✅ | ✅ | | ! Shell | ✅ | ✅ | ✅ | ✅ | | 多行输入 | ✅ | ✅ | ✅ | ✅ | | /add /drop | ✅ | ✅ | ✅ | ✅ | | /web URL | ✅ | ✅ | ✅ | ✅ | | Git 集成 | ✅ | ✅ | ✅ | ✅ | | Token 统计 | ✅ | ✅ | ✅ | ✅ | | 上下文压缩 | ✅ | ✅ | ✅ | ✅ | | 自定义命令 | ✅ | ✅ | ✅ | ✅ | | .ignore | ✅ | ✅ | ✅ | ✅ | | 会话管理 | ✅ | ✅ | ✅ | ✅ |
CLI 参数
Usage: ai-chat [options] [message]
Options:
-V, --version 版本号
-p, --print 非交互式打印模式
-c, --continue 继续上次对话
-r, --resume <id> 恢复指定会话
-m, --model <model> 指定模型
--mode <mode> 对话模式 (ask/agent)
--tui 使用 TUI 界面(默认)
--classic 使用经典 readline 界面
--search 启用 Web 搜索
--think 启用深度思考
--json JSON 格式输出
--no-instructions 禁用项目指令
-h, --help 帮助信息
Commands:
chat 会话管理
config 配置管理
models 列出可用模型License
MIT
