xiaozhou-chat 1.0.0 → 1.0.1-0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -20
- package/bin/cli.js +399 -110
- package/lib/chat.js +376 -0
- package/lib/config.js +158 -0
- package/lib/history.js +68 -0
- package/lib/mcp-lite.js +128 -0
- package/lib/tools.js +178 -0
- package/lib/ui.js +114 -0
- package/lib/utils.js +21 -0
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -1,28 +1,124 @@
|
|
|
1
|
-
#
|
|
1
|
+
# xiaozhou-chat
|
|
2
2
|
|
|
3
|
-
CLI chatbot based on NewAPI.
|
|
3
|
+
CLI chatbot based on NewAPI with advanced features like Project Context, Multi-Profiles, and AI Tools.
|
|
4
|
+
基于 NewAPI 的高级命令行聊天工具,支持项目上下文感知、多环境配置及 AI 自动化工具。
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
npm i -g my-newapi-chat
|
|
6
|
+
---
|
|
7
7
|
|
|
8
|
-
##
|
|
9
|
-
export NEWAPI_API_KEY="你的Key"
|
|
8
|
+
## ✨ 特性 (Features)
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
- **🤖 多模型/多环境管理**:支持通过 `/profile` (或 `/切换模型`) 快速切换不同的 API Key 和模型配置。
|
|
11
|
+
- **📂 项目感知**:通过 `/scan` 自动扫描项目结构、读取 `package.json` 和 `README.md` (智能大文件摘要),让 AI 理解你的项目。
|
|
12
|
+
- **🛠️ AI 编程助手**:内置文件读写 (`read_file`, `write_file`) 和命令执行 (`run_command`) 工具,AI 可以帮你重构代码、运行测试。
|
|
13
|
+
- **🛡️ 安全机制**:`write_file` 覆盖文件前自动创建 `.bak` 备份;敏感文件自动排除;网络请求失败自动指数退避重试。
|
|
14
|
+
- **🚀 效率工具**:`/commit` 自动分析代码变更并生成 Git Commit Message;`/token` 实时监控上下文消耗。
|
|
15
|
+
- **🎨 交互优化**:
|
|
16
|
+
- **Ctrl+C 中断**:生成过程中按 `Ctrl+C` 仅中断当前输出,不退出程序。
|
|
17
|
+
- **Markdown 渲染**:终端内完美渲染 Markdown(代码高亮、表格、粗体等)。
|
|
18
|
+
- **Esc 快捷键**:按 `Esc` 清除当前输入,空行时按 `Esc` 退出程序。
|
|
19
|
+
- **⚙️ 灵活配置**:支持全局配置及项目级配置文件 (`.newapi-chat-config.json`),可随项目隔离环境。
|
|
20
|
+
- **🔌 MCP 支持**:集成 Model Context Protocol,可连接外部 MCP Server 扩展能力。
|
|
14
21
|
|
|
15
|
-
|
|
16
|
-
newapi-chat
|
|
22
|
+
---
|
|
17
23
|
|
|
18
|
-
##
|
|
19
|
-
newapi-chat --model gpt-4 --base-url https://api.newapi.pro/v1
|
|
24
|
+
## 📦 安装与使用 (Installation & Usage)
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
~/.newapi-chat-history.json
|
|
26
|
+
### 方式一:在当前项目中使用 (推荐)
|
|
27
|
+
无需全局安装,直接在你的项目中添加并初始化配置:
|
|
24
28
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
npm
|
|
28
|
-
|
|
29
|
+
1. **安装依赖**
|
|
30
|
+
```bash
|
|
31
|
+
npm install xiaozhou-chat
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. **初始化配置** (自动在当前目录生成配置文件)
|
|
35
|
+
```bash
|
|
36
|
+
npx xiaozhou-chat init
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
3. **启动聊天**
|
|
40
|
+
```bash
|
|
41
|
+
npx xiaozhou-chat
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### 方式二:全局安装
|
|
45
|
+
如果你希望在任何目录下都能使用:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
npm i -g xiaozhou-chat
|
|
49
|
+
xiaozhou-chat
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 💬 常用命令 (Commands)
|
|
55
|
+
|
|
56
|
+
在对话中输入 `/` 开头的命令即可触发功能。支持中文别名。
|
|
57
|
+
|
|
58
|
+
### 🔧 配置管理
|
|
59
|
+
| 命令 | 中文别名 | 说明 |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| `/init` | `/初始化配置` | (交互式) 在当前目录生成 `.newapi-chat-config.json` |
|
|
62
|
+
| `/config` | `/配置` | 查看或修改当前配置 (如 `/config set model gpt-4`) |
|
|
63
|
+
| `/profile` | `/切换模型` | 管理多套配置 (详情见下文) |
|
|
64
|
+
| `/system` | - | 设置系统提示词 (System Prompt) |
|
|
65
|
+
|
|
66
|
+
### 🧠 上下文与文件
|
|
67
|
+
| 命令 | 中文别名 | 说明 |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `/scan` | `/当前项目结构` | 扫描当前目录结构并加载关键文件到上下文 |
|
|
70
|
+
| `/load <file>` | - | 加载指定文件内容给 AI (支持大文件行号选择) |
|
|
71
|
+
| `/save <file>` | - | 将 AI 回复中的代码块保存为本地文件 |
|
|
72
|
+
| `/paste` | - | 进入多行粘贴模式 (避免回车直接发送) |
|
|
73
|
+
|
|
74
|
+
### 🛠️ 工具与扩展
|
|
75
|
+
| 命令 | 说明 |
|
|
76
|
+
|---|---|
|
|
77
|
+
| `/commit` | 自动执行 `git add -A` 并利用 AI 生成提交信息 |
|
|
78
|
+
| `/token` | 查看当前会话 Token 估算与预警 |
|
|
79
|
+
| `/compress` | 智能压缩对话历史,节省 Token |
|
|
80
|
+
| `/mcp` | 管理 MCP 服务器连接 (如连接外部数据库工具) |
|
|
81
|
+
| `/clear` | 清空当前对话历史 (保留 System Prompt) |
|
|
82
|
+
| `/history` | 查看历史记录 (支持 Markdown 渲染) |
|
|
83
|
+
| `/export` | 导出对话记录为 Markdown |
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## ⚙️ 配置文件 (Configuration)
|
|
88
|
+
|
|
89
|
+
工具会按以下优先级读取配置:
|
|
90
|
+
1. **项目级配置**:`./.newapi-chat-config.json` (推荐,由 `init` 生成)
|
|
91
|
+
2. **用户级配置**:`~/.newapi-chat-config.json`
|
|
92
|
+
|
|
93
|
+
**配置文件示例 (`.newapi-chat-config.json`):**
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"apiKey": "sk-xxxx",
|
|
97
|
+
"baseUrl": "https://api.newapi.pro/v1",
|
|
98
|
+
"model": "claude-3-5-sonnet",
|
|
99
|
+
"profiles": {
|
|
100
|
+
"default": { "model": "claude-3-5-sonnet" },
|
|
101
|
+
"gpt4": { "model": "gpt-4", "apiKey": "sk-special..." }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
> **注意**:建议将 `.newapi-chat-config.json` 添加到 `.gitignore` 中,防止 API Key 泄露。
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## 🛠️ 本地开发 (Development)
|
|
111
|
+
|
|
112
|
+
### 依赖安装
|
|
113
|
+
```bash
|
|
114
|
+
npm install
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### 构建与打包
|
|
118
|
+
- **Windows**: `npm run build:win` -> `dist/newapi-chat.exe`
|
|
119
|
+
- **macOS**: `npm run build:mac` -> `dist/xiaozhou-chat`
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## 📄 许可证
|
|
124
|
+
MIT
|