autoclaw 1.0.39 → 1.1.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/LICENSE +21 -21
- package/README.md +10 -0
- package/README.zh-CN.md +191 -191
- package/dist/agent.js +146 -25
- package/dist/index.js +76 -16
- package/dist/tools/search.js +8 -8
- package/package.json +1 -1
- package/dist/tools.js +0 -130
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 AutoClaw Contributor
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 AutoClaw Contributor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -189,3 +189,13 @@ Contributions are welcome! Please feel free to submit a Pull Request.
|
|
|
189
189
|
|
|
190
190
|
---
|
|
191
191
|
GitHub: [https://github.com/tsingliuwin/autoclaw](https://github.com/tsingliuwin/autoclaw)
|
|
192
|
+
|
|
193
|
+
## Star History
|
|
194
|
+
|
|
195
|
+
<a href="https://www.star-history.com/?repos=tsingliuwin%2Fautoclaw&type=date&legend=top-left">
|
|
196
|
+
<picture>
|
|
197
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/chart?repos=tsingliuwin/autoclaw&type=date&theme=dark&legend=top-left" />
|
|
198
|
+
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/chart?repos=tsingliuwin/autoclaw&type=date&legend=top-left" />
|
|
199
|
+
<img alt="Star History Chart" src="https://api.star-history.com/chart?repos=tsingliuwin/autoclaw&type=date&legend=top-left" />
|
|
200
|
+
</picture>
|
|
201
|
+
</a>
|
package/README.zh-CN.md
CHANGED
|
@@ -1,192 +1,192 @@
|
|
|
1
|
-
# AutoClaw 🦞
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/autoclaw)
|
|
4
|
-
[](https://www.npmjs.com/package/autoclaw)
|
|
5
|
-
[](https://github.com/tsingliuwin/autoclaw)
|
|
6
|
-
[](https://github.com/tsingliuwin/autoclaw/blob/main/LICENSE)
|
|
7
|
-
[](http://makeapullrequest.com)
|
|
8
|
-
|
|
9
|
-
**稳定、高工程化、易规模化:专为无界面系统设计的高效自动化 Agent 框架。**
|
|
10
|
-
|
|
11
|
-
[English](./README.md) | 简体中文
|
|
12
|
-
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
🔗 **GitHub 仓库**: [https://github.com/tsingliuwin/autoclaw](https://github.com/tsingliuwin/autoclaw)
|
|
16
|
-
|
|
17
|
-
---
|
|
18
|
-
|
|
19
|
-
AutoClaw 是一款针对 **“无界面系统” (Headless Systems)** 的高稳定性自动化 Agent 开源框架。
|
|
20
|
-
|
|
21
|
-
相比于 OpenClaw 等需要“看屏幕”的 Agent(如视觉解析),AutoClaw 采用纯指令驱动,具有更强的**工程化**属性、更高的**稳定性**,以及极易**规模化**的特点。它专为在各种复杂环境中执行确定性的自动化任务而设计——无论是本地服务器、CI/CD 流水线,还是成千上万个容器节点。
|
|
22
|
-
|
|
23
|
-
## 为什么选择 AutoClaw?
|
|
24
|
-
|
|
25
|
-
- 🐳 **Docker 友好**: 专为容器化环境设计,无 GUI 依赖,极致轻量(Node.js/Alpine 友好)。
|
|
26
|
-
- 🚀 **更强工程化 (Better Engineering)**: 并非依赖不稳定的视觉识别,而是通过系统 API 和 Shell 指令精准操作,确保任务执行的确定性。
|
|
27
|
-
- 🛡️ **高稳定性 (Superior Stability)**: 摆脱了图形界面渲染、屏幕分辨率、网络延迟对视觉识别的影响,即便在极端的 Headless 环境下也能稳定运行。
|
|
28
|
-
- 📈 **易于规模化 (Massive Scalability)**: 低资源占用使得你可以同时编排成千上万个 Agent 实例(如在 Kubernetes 集群中),实现真正的自动化蜂群。
|
|
29
|
-
- 🔌 **集群就绪 (Swarm Ready)**: 无状态设计,支持通过 K8s、Docker Swarm 或简单的 Shell 脚本进行大规模调度。
|
|
30
|
-
- 🧩 **可扩展集成**: 内置支持网页搜索 (Tavily)、邮件发送 (SMTP) 以及通知钩子 (飞书、钉钉、企业微信)。
|
|
31
|
-
|
|
32
|
-
## 特性
|
|
33
|
-
|
|
34
|
-
- 📜 **无头执行 (Headless Execution)**: 真正的无头模式,无需浏览器或图形化界面。
|
|
35
|
-
- 🤖 **非交互模式**: 支持自动化标志(`-y`, `--no-interactive`),完美适配零干预的自动化流程。
|
|
36
|
-
- 📂 **全方位控制 (Universal Control)**: 从基础的文件 I/O 到复杂的系统管理与代码重构。
|
|
37
|
-
- 🧠 **上下文感知 (Context Aware)**: 自动识别操作系统与容器环境,并提供精确的系统时间以处理相对时间查询。
|
|
38
|
-
- 🌐 **网页搜索**: 集成 Tavily,支持实时信息检索。
|
|
39
|
-
- 🕒 **时间精准**: 内置工具获取精确系统日期和时间,确保正确的时间上下文。
|
|
40
|
-
- 📧 **通讯能力**: 自动发送电子邮件并将通知推送至聊天群组。
|
|
41
|
-
|
|
42
|
-
## 技术栈
|
|
43
|
-
- **运行时**: Node.js
|
|
44
|
-
- **语言**: TypeScript
|
|
45
|
-
- **框架**: Commander.js
|
|
46
|
-
- **UI**: Inquirer (交互), Chalk (样式), Ora (加载动画)
|
|
47
|
-
- **AI**: OpenAI SDK (兼容 DeepSeek, LocalLLM 等)
|
|
48
|
-
|
|
49
|
-
## 安装
|
|
50
|
-
|
|
51
|
-
### 用户安装
|
|
52
|
-
通过 npm 全局安装:
|
|
53
|
-
```bash
|
|
54
|
-
npm install -g autoclaw
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
### 开发安装
|
|
58
|
-
1. 克隆仓库:
|
|
59
|
-
```bash
|
|
60
|
-
git clone https://github.com/tsingliuwin/autoclaw.git
|
|
61
|
-
cd autoclaw
|
|
62
|
-
```
|
|
63
|
-
2. 安装依赖:
|
|
64
|
-
```bash
|
|
65
|
-
npm install
|
|
66
|
-
```
|
|
67
|
-
3. 构建项目:
|
|
68
|
-
```bash
|
|
69
|
-
npm run build
|
|
70
|
-
```
|
|
71
|
-
4. 全局链接 (可选):
|
|
72
|
-
```bash
|
|
73
|
-
npm link
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## 快速上手
|
|
77
|
-
|
|
78
|
-
1. **配置**: 运行交互式设置向导以配置您的 API 密钥和集成插件。
|
|
79
|
-
```bash
|
|
80
|
-
autoclaw setup
|
|
81
|
-
```
|
|
82
|
-
2. **运行**: 在交互模式下启动 Agent。
|
|
83
|
-
```bash
|
|
84
|
-
autoclaw
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## 使用方法
|
|
88
|
-
|
|
89
|
-
### 交互模式
|
|
90
|
-
直接运行 `autoclaw` 进入对话循环。
|
|
91
|
-
```bash
|
|
92
|
-
autoclaw
|
|
93
|
-
> 列出 src 文件夹中所有的 TypeScript 文件。
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### 无头模式 (一次性任务)
|
|
97
|
-
执行单个指令后立即退出。
|
|
98
|
-
```bash
|
|
99
|
-
autoclaw "检查磁盘使用情况并将报告保存到 usage.txt" --no-interactive
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### 自动确认 (CI/CD)
|
|
103
|
-
自动批准所有工具执行(危险操作,请谨慎使用或在沙箱环境下运行)。
|
|
104
|
-
```bash
|
|
105
|
-
autoclaw "将 src/index.ts 重构为使用 ES 模块" -y
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### CLI 选项
|
|
109
|
-
- `-m, --model <model>`: 指定 LLM 模型 (默认: `gpt-4o`)。
|
|
110
|
-
- `-n, --no-interactive`: 处理完初始查询后退出 (无头模式)。
|
|
111
|
-
- `-y, --yes`: 自动确认所有工具执行 (例如 Shell 命令)。
|
|
112
|
-
|
|
113
|
-
## 配置
|
|
114
|
-
|
|
115
|
-
AutoClaw 使用层级配置系统。
|
|
116
|
-
|
|
117
|
-
**优先级排序 (从高到低):**
|
|
118
|
-
1. **CLI 参数**: (例如 `-m gpt-4o`)
|
|
119
|
-
2. **环境变量**: (`OPENAI_API_KEY`, `.env` 文件)
|
|
120
|
-
3. **项目配置**: (当前目录下的 `./.autoclaw/setting.json`)
|
|
121
|
-
4. **全局配置**: (`~/.autoclaw/setting.json`)
|
|
122
|
-
|
|
123
|
-
### 支持的配置键 (JSON)
|
|
124
|
-
- `apiKey`: 您的 OpenAI API 密钥。
|
|
125
|
-
- `baseUrl`: 自定义 API 基础地址 (例如 DeepSeek 或本地 LLM)。
|
|
126
|
-
- `model`: 默认使用的模型。
|
|
127
|
-
- `tavilyApiKey`: Tavily 网页搜索的 API 密钥。
|
|
128
|
-
- `smtpHost`, `smtpPort`, `smtpUser`, `smtpPass`, `smtpFrom`: SMTP 邮件设置。
|
|
129
|
-
- `feishuWebhook`, `dingtalkWebhook`, `wecomWebhook`: 通知钩子地址。
|
|
130
|
-
|
|
131
|
-
### 项目级配置示例
|
|
132
|
-
在 `.autoclaw/setting.json` 创建文件:
|
|
133
|
-
```json
|
|
134
|
-
{
|
|
135
|
-
"model": "gpt-3.5-turbo",
|
|
136
|
-
"baseUrl": "https://api.deepseek.com/v1"
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
> **⚠️ 安全警告**: 如果您在 `.autoclaw/setting.json` 中存储了 `apiKey` 或机密信息,请务必将 `.autoclaw/` 添加到您的 `.gitignore` 文件中,以防泄露!
|
|
141
|
-
|
|
142
|
-
## 集成功能
|
|
143
|
-
|
|
144
|
-
### 网页搜索 (Tavily)
|
|
145
|
-
如果您在设置中提供了 Tavily API 密钥,AutoClaw 可以搜索网页。
|
|
146
|
-
- **示例**: "搜索最新的 Node.js 发布说明。"
|
|
147
|
-
|
|
148
|
-
### 邮件 (SMTP)
|
|
149
|
-
配置 SMTP 设置以允许 Agent 发送邮件。
|
|
150
|
-
- **示例**: "向 user@example.com 发送一封包含日志文件摘要的邮件。"
|
|
151
|
-
|
|
152
|
-
### 通知 (飞书/钉钉/企业微信)
|
|
153
|
-
配置 Webhook 以在团队聊天应用中接收警报或报告。
|
|
154
|
-
- **示例**: "在飞书上通知团队构建已完成。"
|
|
155
|
-
|
|
156
|
-
### 日期与时间
|
|
157
|
-
内置工具为 Agent 提供当前系统时间,确保准确处理相对时间请求。
|
|
158
|
-
- **示例**: "今天是几号?" 或 "提醒我下周一检查日志。"
|
|
159
|
-
|
|
160
|
-
## Docker 支持
|
|
161
|
-
|
|
162
|
-
### 截图中的中文显示问题
|
|
163
|
-
在 Docker 容器(尤其是 Alpine 或 Debian Slim)中运行时,网页截图中的中文可能会显示为方块("豆腐块")。表情符号(如 🔥)也可能显示为方块。
|
|
164
|
-
|
|
165
|
-
**解决方案:** 在容器中安装 CJK(中日韩)和 Emoji 字体。
|
|
166
|
-
|
|
167
|
-
**Debian/Ubuntu:**
|
|
168
|
-
```bash
|
|
169
|
-
apt-get update && apt-get install -y fonts-noto-cjk fonts-wqy-zenhei fonts-noto-color-emoji
|
|
170
|
-
```
|
|
171
|
-
|
|
172
|
-
**Alpine Linux:**
|
|
173
|
-
```bash
|
|
174
|
-
apk add font-noto-cjk font-noto-emoji
|
|
175
|
-
```
|
|
176
|
-
|
|
177
|
-
## 开源协议
|
|
178
|
-
|
|
179
|
-
MIT
|
|
180
|
-
|
|
181
|
-
## 贡献指南
|
|
182
|
-
|
|
183
|
-
欢迎贡献!请随时提交 Pull Request。
|
|
184
|
-
|
|
185
|
-
1. Fork 本项目
|
|
186
|
-
2. 创建您的特性分支 (`git checkout -b feature/AmazingFeature`)
|
|
187
|
-
3. 提交您的更改 (`git commit -m 'Add some AmazingFeature'`)
|
|
188
|
-
4. 推送至分支 (`git push origin feature/AmazingFeature`)
|
|
189
|
-
5. 开启一个 Pull Request
|
|
190
|
-
|
|
191
|
-
---
|
|
1
|
+
# AutoClaw 🦞
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/autoclaw)
|
|
4
|
+
[](https://www.npmjs.com/package/autoclaw)
|
|
5
|
+
[](https://github.com/tsingliuwin/autoclaw)
|
|
6
|
+
[](https://github.com/tsingliuwin/autoclaw/blob/main/LICENSE)
|
|
7
|
+
[](http://makeapullrequest.com)
|
|
8
|
+
|
|
9
|
+
**稳定、高工程化、易规模化:专为无界面系统设计的高效自动化 Agent 框架。**
|
|
10
|
+
|
|
11
|
+
[English](./README.md) | 简体中文
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
🔗 **GitHub 仓库**: [https://github.com/tsingliuwin/autoclaw](https://github.com/tsingliuwin/autoclaw)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
AutoClaw 是一款针对 **“无界面系统” (Headless Systems)** 的高稳定性自动化 Agent 开源框架。
|
|
20
|
+
|
|
21
|
+
相比于 OpenClaw 等需要“看屏幕”的 Agent(如视觉解析),AutoClaw 采用纯指令驱动,具有更强的**工程化**属性、更高的**稳定性**,以及极易**规模化**的特点。它专为在各种复杂环境中执行确定性的自动化任务而设计——无论是本地服务器、CI/CD 流水线,还是成千上万个容器节点。
|
|
22
|
+
|
|
23
|
+
## 为什么选择 AutoClaw?
|
|
24
|
+
|
|
25
|
+
- 🐳 **Docker 友好**: 专为容器化环境设计,无 GUI 依赖,极致轻量(Node.js/Alpine 友好)。
|
|
26
|
+
- 🚀 **更强工程化 (Better Engineering)**: 并非依赖不稳定的视觉识别,而是通过系统 API 和 Shell 指令精准操作,确保任务执行的确定性。
|
|
27
|
+
- 🛡️ **高稳定性 (Superior Stability)**: 摆脱了图形界面渲染、屏幕分辨率、网络延迟对视觉识别的影响,即便在极端的 Headless 环境下也能稳定运行。
|
|
28
|
+
- 📈 **易于规模化 (Massive Scalability)**: 低资源占用使得你可以同时编排成千上万个 Agent 实例(如在 Kubernetes 集群中),实现真正的自动化蜂群。
|
|
29
|
+
- 🔌 **集群就绪 (Swarm Ready)**: 无状态设计,支持通过 K8s、Docker Swarm 或简单的 Shell 脚本进行大规模调度。
|
|
30
|
+
- 🧩 **可扩展集成**: 内置支持网页搜索 (Tavily)、邮件发送 (SMTP) 以及通知钩子 (飞书、钉钉、企业微信)。
|
|
31
|
+
|
|
32
|
+
## 特性
|
|
33
|
+
|
|
34
|
+
- 📜 **无头执行 (Headless Execution)**: 真正的无头模式,无需浏览器或图形化界面。
|
|
35
|
+
- 🤖 **非交互模式**: 支持自动化标志(`-y`, `--no-interactive`),完美适配零干预的自动化流程。
|
|
36
|
+
- 📂 **全方位控制 (Universal Control)**: 从基础的文件 I/O 到复杂的系统管理与代码重构。
|
|
37
|
+
- 🧠 **上下文感知 (Context Aware)**: 自动识别操作系统与容器环境,并提供精确的系统时间以处理相对时间查询。
|
|
38
|
+
- 🌐 **网页搜索**: 集成 Tavily,支持实时信息检索。
|
|
39
|
+
- 🕒 **时间精准**: 内置工具获取精确系统日期和时间,确保正确的时间上下文。
|
|
40
|
+
- 📧 **通讯能力**: 自动发送电子邮件并将通知推送至聊天群组。
|
|
41
|
+
|
|
42
|
+
## 技术栈
|
|
43
|
+
- **运行时**: Node.js
|
|
44
|
+
- **语言**: TypeScript
|
|
45
|
+
- **框架**: Commander.js
|
|
46
|
+
- **UI**: Inquirer (交互), Chalk (样式), Ora (加载动画)
|
|
47
|
+
- **AI**: OpenAI SDK (兼容 DeepSeek, LocalLLM 等)
|
|
48
|
+
|
|
49
|
+
## 安装
|
|
50
|
+
|
|
51
|
+
### 用户安装
|
|
52
|
+
通过 npm 全局安装:
|
|
53
|
+
```bash
|
|
54
|
+
npm install -g autoclaw
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 开发安装
|
|
58
|
+
1. 克隆仓库:
|
|
59
|
+
```bash
|
|
60
|
+
git clone https://github.com/tsingliuwin/autoclaw.git
|
|
61
|
+
cd autoclaw
|
|
62
|
+
```
|
|
63
|
+
2. 安装依赖:
|
|
64
|
+
```bash
|
|
65
|
+
npm install
|
|
66
|
+
```
|
|
67
|
+
3. 构建项目:
|
|
68
|
+
```bash
|
|
69
|
+
npm run build
|
|
70
|
+
```
|
|
71
|
+
4. 全局链接 (可选):
|
|
72
|
+
```bash
|
|
73
|
+
npm link
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## 快速上手
|
|
77
|
+
|
|
78
|
+
1. **配置**: 运行交互式设置向导以配置您的 API 密钥和集成插件。
|
|
79
|
+
```bash
|
|
80
|
+
autoclaw setup
|
|
81
|
+
```
|
|
82
|
+
2. **运行**: 在交互模式下启动 Agent。
|
|
83
|
+
```bash
|
|
84
|
+
autoclaw
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 使用方法
|
|
88
|
+
|
|
89
|
+
### 交互模式
|
|
90
|
+
直接运行 `autoclaw` 进入对话循环。
|
|
91
|
+
```bash
|
|
92
|
+
autoclaw
|
|
93
|
+
> 列出 src 文件夹中所有的 TypeScript 文件。
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### 无头模式 (一次性任务)
|
|
97
|
+
执行单个指令后立即退出。
|
|
98
|
+
```bash
|
|
99
|
+
autoclaw "检查磁盘使用情况并将报告保存到 usage.txt" --no-interactive
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
### 自动确认 (CI/CD)
|
|
103
|
+
自动批准所有工具执行(危险操作,请谨慎使用或在沙箱环境下运行)。
|
|
104
|
+
```bash
|
|
105
|
+
autoclaw "将 src/index.ts 重构为使用 ES 模块" -y
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### CLI 选项
|
|
109
|
+
- `-m, --model <model>`: 指定 LLM 模型 (默认: `gpt-4o`)。
|
|
110
|
+
- `-n, --no-interactive`: 处理完初始查询后退出 (无头模式)。
|
|
111
|
+
- `-y, --yes`: 自动确认所有工具执行 (例如 Shell 命令)。
|
|
112
|
+
|
|
113
|
+
## 配置
|
|
114
|
+
|
|
115
|
+
AutoClaw 使用层级配置系统。
|
|
116
|
+
|
|
117
|
+
**优先级排序 (从高到低):**
|
|
118
|
+
1. **CLI 参数**: (例如 `-m gpt-4o`)
|
|
119
|
+
2. **环境变量**: (`OPENAI_API_KEY`, `.env` 文件)
|
|
120
|
+
3. **项目配置**: (当前目录下的 `./.autoclaw/setting.json`)
|
|
121
|
+
4. **全局配置**: (`~/.autoclaw/setting.json`)
|
|
122
|
+
|
|
123
|
+
### 支持的配置键 (JSON)
|
|
124
|
+
- `apiKey`: 您的 OpenAI API 密钥。
|
|
125
|
+
- `baseUrl`: 自定义 API 基础地址 (例如 DeepSeek 或本地 LLM)。
|
|
126
|
+
- `model`: 默认使用的模型。
|
|
127
|
+
- `tavilyApiKey`: Tavily 网页搜索的 API 密钥。
|
|
128
|
+
- `smtpHost`, `smtpPort`, `smtpUser`, `smtpPass`, `smtpFrom`: SMTP 邮件设置。
|
|
129
|
+
- `feishuWebhook`, `dingtalkWebhook`, `wecomWebhook`: 通知钩子地址。
|
|
130
|
+
|
|
131
|
+
### 项目级配置示例
|
|
132
|
+
在 `.autoclaw/setting.json` 创建文件:
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"model": "gpt-3.5-turbo",
|
|
136
|
+
"baseUrl": "https://api.deepseek.com/v1"
|
|
137
|
+
}
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
> **⚠️ 安全警告**: 如果您在 `.autoclaw/setting.json` 中存储了 `apiKey` 或机密信息,请务必将 `.autoclaw/` 添加到您的 `.gitignore` 文件中,以防泄露!
|
|
141
|
+
|
|
142
|
+
## 集成功能
|
|
143
|
+
|
|
144
|
+
### 网页搜索 (Tavily)
|
|
145
|
+
如果您在设置中提供了 Tavily API 密钥,AutoClaw 可以搜索网页。
|
|
146
|
+
- **示例**: "搜索最新的 Node.js 发布说明。"
|
|
147
|
+
|
|
148
|
+
### 邮件 (SMTP)
|
|
149
|
+
配置 SMTP 设置以允许 Agent 发送邮件。
|
|
150
|
+
- **示例**: "向 user@example.com 发送一封包含日志文件摘要的邮件。"
|
|
151
|
+
|
|
152
|
+
### 通知 (飞书/钉钉/企业微信)
|
|
153
|
+
配置 Webhook 以在团队聊天应用中接收警报或报告。
|
|
154
|
+
- **示例**: "在飞书上通知团队构建已完成。"
|
|
155
|
+
|
|
156
|
+
### 日期与时间
|
|
157
|
+
内置工具为 Agent 提供当前系统时间,确保准确处理相对时间请求。
|
|
158
|
+
- **示例**: "今天是几号?" 或 "提醒我下周一检查日志。"
|
|
159
|
+
|
|
160
|
+
## Docker 支持
|
|
161
|
+
|
|
162
|
+
### 截图中的中文显示问题
|
|
163
|
+
在 Docker 容器(尤其是 Alpine 或 Debian Slim)中运行时,网页截图中的中文可能会显示为方块("豆腐块")。表情符号(如 🔥)也可能显示为方块。
|
|
164
|
+
|
|
165
|
+
**解决方案:** 在容器中安装 CJK(中日韩)和 Emoji 字体。
|
|
166
|
+
|
|
167
|
+
**Debian/Ubuntu:**
|
|
168
|
+
```bash
|
|
169
|
+
apt-get update && apt-get install -y fonts-noto-cjk fonts-wqy-zenhei fonts-noto-color-emoji
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
**Alpine Linux:**
|
|
173
|
+
```bash
|
|
174
|
+
apk add font-noto-cjk font-noto-emoji
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## 开源协议
|
|
178
|
+
|
|
179
|
+
MIT
|
|
180
|
+
|
|
181
|
+
## 贡献指南
|
|
182
|
+
|
|
183
|
+
欢迎贡献!请随时提交 Pull Request。
|
|
184
|
+
|
|
185
|
+
1. Fork 本项目
|
|
186
|
+
2. 创建您的特性分支 (`git checkout -b feature/AmazingFeature`)
|
|
187
|
+
3. 提交您的更改 (`git commit -m 'Add some AmazingFeature'`)
|
|
188
|
+
4. 推送至分支 (`git push origin feature/AmazingFeature`)
|
|
189
|
+
5. 开启一个 Pull Request
|
|
190
|
+
|
|
191
|
+
---
|
|
192
192
|
GitHub: [https://github.com/tsingliuwin/autoclaw](https://github.com/tsingliuwin/autoclaw)
|
package/dist/agent.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import OpenAI from 'openai';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import ora from 'ora';
|
|
4
|
+
import * as fs from 'fs';
|
|
4
5
|
import * as os from 'os';
|
|
6
|
+
import * as path from 'path';
|
|
5
7
|
import { getToolDefinitions, executeToolHandler } from './tools/index.js';
|
|
6
8
|
export class Agent {
|
|
7
9
|
client;
|
|
8
10
|
messages;
|
|
9
11
|
model;
|
|
10
12
|
config;
|
|
13
|
+
lastOutputFile = null;
|
|
11
14
|
constructor(apiKey, baseURL, model = 'gpt-4-turbo-preview', config = {}) {
|
|
12
15
|
this.client = new OpenAI({
|
|
13
16
|
apiKey: apiKey,
|
|
@@ -28,23 +31,28 @@ System Information:
|
|
|
28
31
|
this.messages = [
|
|
29
32
|
{
|
|
30
33
|
role: "system",
|
|
31
|
-
content: `You are AutoClaw, a
|
|
32
|
-
|
|
34
|
+
content: `You are AutoClaw, a lightweight AI agent that operates directly in the terminal. You accomplish tasks by executing shell commands, reading and writing files, and using integrated tools — no GUI, no guesswork, deterministic results.
|
|
35
|
+
|
|
36
|
+
You may be running on a developer workstation, a headless server, inside a Docker container, or in a CI/CD pipeline. Adapt accordingly.
|
|
33
37
|
|
|
34
|
-
CONTEXT:
|
|
35
38
|
${systemInfo}
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
WHAT YOU CAN DO:
|
|
41
|
+
- Shell: execute_shell_command — run scripts, install packages, manage processes, interact with the OS
|
|
42
|
+
- Files: read_file / write_file — inspect logs, generate configs, produce reports
|
|
43
|
+
- Web: web_search — real-time information lookup; read_website — extract article content; take_screenshot — capture page visuals
|
|
44
|
+
- Communication: send_email — SMTP email delivery; send_notification — push to Feishu/DingTalk/WeCom
|
|
45
|
+
- Creation: generate_image — AI image generation (DALL-E compatible); optimize_prompt — refine raw prompts for creative/complex tasks
|
|
46
|
+
- Utility: get_current_datetime — accurate system time for temporal reasoning
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
1.
|
|
44
|
-
2.
|
|
45
|
-
3.
|
|
46
|
-
4.
|
|
47
|
-
5.
|
|
48
|
+
RULES OF ENGAGEMENT:
|
|
49
|
+
1. One shot, not one chat. Produce working results, not conversation. Be terse.
|
|
50
|
+
2. Use the right tool for the job. Shell for system ops. Files for content. Web tools for external info.
|
|
51
|
+
3. Always pass non-interactive flags: --yes for npx, -y for apt/apk, -f for rm, etc. Assume no human is watching.
|
|
52
|
+
4. Container-friendly: stick to standard Unix tools available in Alpine/Debian slim images. No GUI apps, no browser-based debug tools.
|
|
53
|
+
5. For creative or complex tasks (image prompts, long-form writing, intricate scripts): call optimize_prompt first. It significantly raises output quality.
|
|
54
|
+
6. If a command fails, diagnose and try one alternative. Don't retry the same thing, don't give up on first error.
|
|
55
|
+
7. Read before write. When modifying a file, read it first. When installing a package, check if it's already there.
|
|
48
56
|
`
|
|
49
57
|
}
|
|
50
58
|
];
|
|
@@ -55,27 +63,140 @@ GUIDELINES:
|
|
|
55
63
|
while (active) {
|
|
56
64
|
const spinner = ora('Thinking...').start();
|
|
57
65
|
try {
|
|
58
|
-
const
|
|
66
|
+
const stream = await this.client.chat.completions.create({
|
|
59
67
|
model: this.model,
|
|
60
68
|
messages: this.messages,
|
|
61
69
|
tools: getToolDefinitions(),
|
|
62
|
-
tool_choice: "auto"
|
|
70
|
+
tool_choice: "auto",
|
|
71
|
+
stream: true
|
|
63
72
|
});
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
73
|
+
let content = '';
|
|
74
|
+
let reasoningContent = '';
|
|
75
|
+
let toolCalls = [];
|
|
76
|
+
let contentStarted = false;
|
|
77
|
+
let reasoningStarted = false;
|
|
78
|
+
const toolNamesSeen = new Set();
|
|
79
|
+
for await (const chunk of stream) {
|
|
80
|
+
const delta = chunk.choices[0]?.delta;
|
|
81
|
+
// Handle reasoning/thinking content (e.g., DeepSeek)
|
|
82
|
+
if (delta?.reasoning_content) {
|
|
83
|
+
if (!reasoningStarted) {
|
|
84
|
+
spinner.stop();
|
|
85
|
+
process.stdout.write(chalk.dim('\n[Thinking] '));
|
|
86
|
+
reasoningStarted = true;
|
|
87
|
+
}
|
|
88
|
+
process.stdout.write(chalk.dim(delta.reasoning_content));
|
|
89
|
+
reasoningContent += delta.reasoning_content;
|
|
90
|
+
}
|
|
91
|
+
// Handle regular content
|
|
92
|
+
if (delta?.content) {
|
|
93
|
+
if (!contentStarted) {
|
|
94
|
+
spinner.stop();
|
|
95
|
+
if (reasoningStarted)
|
|
96
|
+
process.stdout.write('\n');
|
|
97
|
+
process.stdout.write(chalk.blue("AutoClaw: "));
|
|
98
|
+
contentStarted = true;
|
|
99
|
+
}
|
|
100
|
+
process.stdout.write(delta.content);
|
|
101
|
+
content += delta.content;
|
|
102
|
+
}
|
|
103
|
+
// Handle tool calls - show name as soon as available
|
|
104
|
+
if (delta?.tool_calls) {
|
|
105
|
+
for (const tc of delta.tool_calls) {
|
|
106
|
+
const idx = tc.index;
|
|
107
|
+
if (!toolCalls[idx]) {
|
|
108
|
+
toolCalls[idx] = { id: tc.id || '', type: 'function', function: { name: '', arguments: '' } };
|
|
109
|
+
}
|
|
110
|
+
if (tc.id)
|
|
111
|
+
toolCalls[idx].id = tc.id;
|
|
112
|
+
if (tc.function?.name)
|
|
113
|
+
toolCalls[idx].function.name += tc.function.name;
|
|
114
|
+
if (tc.function?.arguments)
|
|
115
|
+
toolCalls[idx].function.arguments += tc.function.arguments;
|
|
116
|
+
// Show tool name as soon as it's complete
|
|
117
|
+
if (tc.function?.name && !toolNamesSeen.has(idx)) {
|
|
118
|
+
toolNamesSeen.add(idx);
|
|
119
|
+
spinner.stop();
|
|
120
|
+
if (contentStarted)
|
|
121
|
+
process.stdout.write('\n');
|
|
122
|
+
if (reasoningStarted && !contentStarted)
|
|
123
|
+
process.stdout.write('\n');
|
|
124
|
+
process.stdout.write(chalk.cyan(`[Calling] ${tc.function.name}\n`));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
69
128
|
}
|
|
70
|
-
if (
|
|
71
|
-
|
|
129
|
+
if (reasoningStarted) {
|
|
130
|
+
console.log(); // newline after reasoning
|
|
131
|
+
}
|
|
132
|
+
if (contentStarted) {
|
|
133
|
+
console.log(); // newline after streamed content
|
|
134
|
+
}
|
|
135
|
+
if (!reasoningStarted && !contentStarted) {
|
|
136
|
+
spinner.stop();
|
|
137
|
+
}
|
|
138
|
+
// Build the full message for history
|
|
139
|
+
const message = { role: "assistant" };
|
|
140
|
+
if (content)
|
|
141
|
+
message.content = content;
|
|
142
|
+
if (reasoningContent)
|
|
143
|
+
message.reasoning_content = reasoningContent;
|
|
144
|
+
if (toolCalls.length > 0) {
|
|
145
|
+
message.tool_calls = toolCalls;
|
|
146
|
+
message.content = message.content || null;
|
|
147
|
+
}
|
|
148
|
+
this.messages.push(message);
|
|
149
|
+
if (toolCalls.length > 0) {
|
|
150
|
+
for (const toolCall of toolCalls) {
|
|
72
151
|
if (toolCall.type !== 'function')
|
|
73
152
|
continue;
|
|
74
153
|
const functionName = toolCall.function.name;
|
|
75
154
|
const functionArgs = JSON.parse(toolCall.function.arguments);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
155
|
+
// Display tool call info
|
|
156
|
+
console.log(chalk.cyan(`\n[Tool] ${functionName}`));
|
|
157
|
+
const argsStr = JSON.stringify(functionArgs, null, 2);
|
|
158
|
+
const argsLines = argsStr.split('\n');
|
|
159
|
+
if (argsLines.length > 8) {
|
|
160
|
+
console.log(chalk.dim(argsLines.slice(0, 8).join('\n')));
|
|
161
|
+
console.log(chalk.dim(` ... (${argsLines.length - 8} more lines)`));
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
console.log(chalk.dim(argsStr));
|
|
165
|
+
}
|
|
166
|
+
const execSpinner = ora('Executing...').start();
|
|
167
|
+
let toolResult;
|
|
168
|
+
try {
|
|
169
|
+
toolResult = await executeToolHandler(functionName, functionArgs, this.config);
|
|
170
|
+
execSpinner.stop();
|
|
171
|
+
}
|
|
172
|
+
catch (err) {
|
|
173
|
+
execSpinner.fail('Tool execution failed');
|
|
174
|
+
toolResult = `Error: ${err.message}`;
|
|
175
|
+
}
|
|
176
|
+
// Display result with folding for long output
|
|
177
|
+
const MAX_PREVIEW_LINES = 20;
|
|
178
|
+
const resultLines = toolResult.split('\n');
|
|
179
|
+
console.log(chalk.green(`[Result]`));
|
|
180
|
+
if (resultLines.length > MAX_PREVIEW_LINES) {
|
|
181
|
+
// Show preview
|
|
182
|
+
console.log(resultLines.slice(0, MAX_PREVIEW_LINES).join('\n'));
|
|
183
|
+
const remaining = resultLines.length - MAX_PREVIEW_LINES;
|
|
184
|
+
console.log(chalk.dim(`\n ... ${remaining} more lines (${resultLines.length} lines total)`));
|
|
185
|
+
// Save full output to file
|
|
186
|
+
const outputDir = path.join(os.homedir(), '.autoclaw', 'output');
|
|
187
|
+
if (!fs.existsSync(outputDir)) {
|
|
188
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
189
|
+
}
|
|
190
|
+
const ts = new Date().toISOString().replace(/[:.]/g, '-');
|
|
191
|
+
const outputFile = path.join(outputDir, `${functionName}_${ts}.txt`);
|
|
192
|
+
fs.writeFileSync(outputFile, toolResult, 'utf-8');
|
|
193
|
+
this.lastOutputFile = outputFile;
|
|
194
|
+
console.log(chalk.dim(` Type '/view' to see full output`));
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
console.log(toolResult);
|
|
198
|
+
this.lastOutputFile = null;
|
|
199
|
+
}
|
|
79
200
|
this.messages.push({
|
|
80
201
|
role: "tool",
|
|
81
202
|
tool_call_id: toolCall.id,
|
package/dist/index.js
CHANGED
|
@@ -9,6 +9,7 @@ import * as path from 'path';
|
|
|
9
9
|
import * as os from 'os';
|
|
10
10
|
import * as readline from 'node:readline/promises';
|
|
11
11
|
import { fileURLToPath } from 'url';
|
|
12
|
+
import { spawn } from 'child_process';
|
|
12
13
|
// Handle Ctrl+C gracefully
|
|
13
14
|
function handleExit() {
|
|
14
15
|
console.log(chalk.cyan("\n\nGoodbye! (Interrupted)"));
|
|
@@ -23,6 +24,7 @@ process.on('SIGTERM', handleExit);
|
|
|
23
24
|
const GLOBAL_CONFIG_DIR = path.join(os.homedir(), '.autoclaw');
|
|
24
25
|
const GLOBAL_CONFIG_FILE = path.join(GLOBAL_CONFIG_DIR, 'setting.json');
|
|
25
26
|
const LOCAL_CONFIG_FILE = path.join(process.cwd(), '.autoclaw', 'setting.json');
|
|
27
|
+
const GLOBAL_ENV_FILE = path.join(GLOBAL_CONFIG_DIR, '.env');
|
|
26
28
|
function loadJsonConfig(filePath) {
|
|
27
29
|
if (fs.existsSync(filePath)) {
|
|
28
30
|
try {
|
|
@@ -34,8 +36,9 @@ function loadJsonConfig(filePath) {
|
|
|
34
36
|
}
|
|
35
37
|
return {};
|
|
36
38
|
}
|
|
37
|
-
// Load
|
|
38
|
-
|
|
39
|
+
// Load env vars only from AutoClaw's own config directory to avoid
|
|
40
|
+
// unrelated project/home .env files overriding API settings.
|
|
41
|
+
dotenv.config({ path: GLOBAL_ENV_FILE });
|
|
39
42
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
40
43
|
// In dist/index.js, package.json is usually up one level in the root
|
|
41
44
|
const pkgPath = path.join(__dirname, '..', 'package.json');
|
|
@@ -120,31 +123,43 @@ async function runSetup(options = {}) {
|
|
|
120
123
|
{
|
|
121
124
|
type: 'confirm',
|
|
122
125
|
name: 'configureImage',
|
|
123
|
-
message:
|
|
124
|
-
|
|
126
|
+
message: currentConfig.imageApiKey
|
|
127
|
+
? `Do you want to reconfigure Image Generation (DALL-E)? (current: ${maskSecret(currentConfig.imageApiKey)})`
|
|
128
|
+
: 'Do you want to configure a separate Image Generation Service (DALL-E)?',
|
|
129
|
+
default: false
|
|
125
130
|
},
|
|
126
131
|
{
|
|
127
132
|
type: 'confirm',
|
|
128
133
|
name: 'configureEmail',
|
|
129
|
-
message:
|
|
130
|
-
|
|
134
|
+
message: currentConfig.smtpHost
|
|
135
|
+
? `Do you want to reconfigure Email (SMTP)? (current: ${currentConfig.smtpUser}@${currentConfig.smtpHost})`
|
|
136
|
+
: 'Do you want to configure the Email Tool (SMTP)?',
|
|
137
|
+
default: false
|
|
131
138
|
},
|
|
132
139
|
{
|
|
133
140
|
type: 'confirm',
|
|
134
141
|
name: 'configureSearch',
|
|
135
|
-
message:
|
|
136
|
-
|
|
142
|
+
message: currentConfig.tavilyApiKey
|
|
143
|
+
? `Do you want to reconfigure Web Search (Tavily)? (current: ${maskSecret(currentConfig.tavilyApiKey)})`
|
|
144
|
+
: 'Do you want to configure Web Search (Tavily)?',
|
|
145
|
+
default: false
|
|
137
146
|
},
|
|
138
147
|
{
|
|
139
148
|
type: 'confirm',
|
|
140
149
|
name: 'configureNotify',
|
|
141
|
-
message:
|
|
142
|
-
|
|
150
|
+
message: (currentConfig.feishuWebhook || currentConfig.dingtalkWebhook || currentConfig.wecomWebhook)
|
|
151
|
+
? 'Do you want to reconfigure Group Bots (Feishu/DingTalk/WeCom)?'
|
|
152
|
+
: 'Do you want to configure Group Bots (Feishu/DingTalk/WeCom)?',
|
|
153
|
+
default: false
|
|
143
154
|
}
|
|
144
155
|
]);
|
|
145
156
|
// Resolve sensitive values (Keep old if empty)
|
|
146
157
|
const finalApiKey = answers.apiKey || currentConfig.apiKey;
|
|
147
|
-
let imageConfig = {
|
|
158
|
+
let imageConfig = {
|
|
159
|
+
imageApiKey: currentConfig.imageApiKey,
|
|
160
|
+
imageBaseUrl: currentConfig.imageBaseUrl,
|
|
161
|
+
imageModel: currentConfig.imageModel
|
|
162
|
+
};
|
|
148
163
|
if (answers.configureImage) {
|
|
149
164
|
const imageAnswers = await inquirer.prompt([
|
|
150
165
|
{
|
|
@@ -174,7 +189,13 @@ async function runSetup(options = {}) {
|
|
|
174
189
|
imageModel: imageAnswers.imageModel
|
|
175
190
|
};
|
|
176
191
|
}
|
|
177
|
-
let emailConfig = {
|
|
192
|
+
let emailConfig = {
|
|
193
|
+
smtpHost: currentConfig.smtpHost,
|
|
194
|
+
smtpPort: currentConfig.smtpPort,
|
|
195
|
+
smtpUser: currentConfig.smtpUser,
|
|
196
|
+
smtpPass: currentConfig.smtpPass,
|
|
197
|
+
smtpFrom: currentConfig.smtpFrom
|
|
198
|
+
};
|
|
178
199
|
if (answers.configureEmail) {
|
|
179
200
|
const emailAnswers = await inquirer.prompt([
|
|
180
201
|
{
|
|
@@ -216,7 +237,9 @@ async function runSetup(options = {}) {
|
|
|
216
237
|
emailConfig.smtpFrom = emailConfig.smtpUser;
|
|
217
238
|
}
|
|
218
239
|
}
|
|
219
|
-
let searchConfig = {
|
|
240
|
+
let searchConfig = {
|
|
241
|
+
tavilyApiKey: currentConfig.tavilyApiKey
|
|
242
|
+
};
|
|
220
243
|
if (answers.configureSearch) {
|
|
221
244
|
const searchAnswers = await inquirer.prompt([
|
|
222
245
|
{
|
|
@@ -230,7 +253,14 @@ async function runSetup(options = {}) {
|
|
|
230
253
|
]);
|
|
231
254
|
searchConfig = { tavilyApiKey: searchAnswers.tavilyApiKey || currentConfig.tavilyApiKey };
|
|
232
255
|
}
|
|
233
|
-
let notifyConfig = {
|
|
256
|
+
let notifyConfig = {
|
|
257
|
+
feishuWebhook: currentConfig.feishuWebhook,
|
|
258
|
+
feishuKeyword: currentConfig.feishuKeyword,
|
|
259
|
+
dingtalkWebhook: currentConfig.dingtalkWebhook,
|
|
260
|
+
dingtalkKeyword: currentConfig.dingtalkKeyword,
|
|
261
|
+
wecomWebhook: currentConfig.wecomWebhook,
|
|
262
|
+
wecomKeyword: currentConfig.wecomKeyword
|
|
263
|
+
};
|
|
234
264
|
if (answers.configureNotify) {
|
|
235
265
|
const notifyAnswers = await inquirer.prompt([
|
|
236
266
|
{
|
|
@@ -406,6 +436,32 @@ async function runChat(queryParts, options) {
|
|
|
406
436
|
console.log(chalk.cyan("Goodbye!"));
|
|
407
437
|
break;
|
|
408
438
|
}
|
|
439
|
+
if (userInput.toLowerCase() === '/view') {
|
|
440
|
+
if (agent.lastOutputFile && fs.existsSync(agent.lastOutputFile)) {
|
|
441
|
+
rl.pause();
|
|
442
|
+
try {
|
|
443
|
+
await new Promise((resolve, reject) => {
|
|
444
|
+
const isWin = process.platform === 'win32';
|
|
445
|
+
const cmd = isWin ? 'more' : (process.env.PAGER || 'less');
|
|
446
|
+
const args = isWin ? [agent.lastOutputFile] : ['-R', agent.lastOutputFile];
|
|
447
|
+
const child = spawn(cmd, args, { stdio: 'inherit' });
|
|
448
|
+
child.on('close', () => resolve());
|
|
449
|
+
child.on('error', (err) => {
|
|
450
|
+
console.error(chalk.red(`Failed to open pager: ${err.message}`));
|
|
451
|
+
console.log(chalk.dim(`You can manually view: ${agent.lastOutputFile}`));
|
|
452
|
+
resolve();
|
|
453
|
+
});
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
finally {
|
|
457
|
+
rl.resume();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
else {
|
|
461
|
+
console.log(chalk.yellow("No tool output to view."));
|
|
462
|
+
}
|
|
463
|
+
continue;
|
|
464
|
+
}
|
|
409
465
|
if (userInput.trim() === '')
|
|
410
466
|
continue;
|
|
411
467
|
rl.pause();
|
|
@@ -418,7 +474,7 @@ async function runChat(queryParts, options) {
|
|
|
418
474
|
}
|
|
419
475
|
}
|
|
420
476
|
catch (err) {
|
|
421
|
-
if (
|
|
477
|
+
if (isUserAbort(err)) {
|
|
422
478
|
console.log(chalk.cyan("\nGoodbye!"));
|
|
423
479
|
}
|
|
424
480
|
else {
|
|
@@ -429,9 +485,13 @@ async function runChat(queryParts, options) {
|
|
|
429
485
|
rl.close();
|
|
430
486
|
}
|
|
431
487
|
}
|
|
488
|
+
function isUserAbort(err) {
|
|
489
|
+
return err.code === 'ABORT_ERR'
|
|
490
|
+
|| (err.message && (err.message.includes('User force closed') || err.message.includes('Prompt was canceled')));
|
|
491
|
+
}
|
|
432
492
|
// Global error handler
|
|
433
493
|
main().catch(err => {
|
|
434
|
-
if (
|
|
494
|
+
if (isUserAbort(err)) {
|
|
435
495
|
console.log(chalk.cyan("\nGoodbye!"));
|
|
436
496
|
process.exit(0);
|
|
437
497
|
}
|
package/dist/tools/search.js
CHANGED
|
@@ -49,22 +49,22 @@ export const SearchTool = {
|
|
|
49
49
|
}
|
|
50
50
|
const data = await response.json();
|
|
51
51
|
// Format the results beautifully for the LLM
|
|
52
|
-
let output = `Search Results for "${args.query}":
|
|
53
|
-
|
|
52
|
+
let output = `Search Results for "${args.query}":
|
|
53
|
+
|
|
54
54
|
`;
|
|
55
55
|
if (data.answer) {
|
|
56
|
-
output += `💡 **Direct Answer**: ${data.answer}
|
|
57
|
-
|
|
56
|
+
output += `💡 **Direct Answer**: ${data.answer}
|
|
57
|
+
|
|
58
58
|
`;
|
|
59
59
|
}
|
|
60
60
|
if (data.results && Array.isArray(data.results)) {
|
|
61
61
|
data.results.forEach((result, index) => {
|
|
62
|
-
output += `### ${index + 1}. ${result.title}
|
|
62
|
+
output += `### ${index + 1}. ${result.title}
|
|
63
63
|
`;
|
|
64
|
-
output += `🔗 ${result.url}
|
|
64
|
+
output += `🔗 ${result.url}
|
|
65
65
|
`;
|
|
66
|
-
output += `📝 ${result.content}
|
|
67
|
-
|
|
66
|
+
output += `📝 ${result.content}
|
|
67
|
+
|
|
68
68
|
`;
|
|
69
69
|
});
|
|
70
70
|
}
|
package/package.json
CHANGED
package/dist/tools.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import { exec } from 'child_process';
|
|
2
|
-
import * as fs from 'fs/promises';
|
|
3
|
-
import * as path from 'path';
|
|
4
|
-
import inquirer from 'inquirer';
|
|
5
|
-
import chalk from 'chalk';
|
|
6
|
-
import util from 'util';
|
|
7
|
-
const execAsync = util.promisify(exec);
|
|
8
|
-
export const tools = [
|
|
9
|
-
{
|
|
10
|
-
type: "function",
|
|
11
|
-
function: {
|
|
12
|
-
name: "execute_shell_command",
|
|
13
|
-
description: "Execute a shell command on the host machine. Use this to run scripts, list files, or interact with the system.",
|
|
14
|
-
parameters: {
|
|
15
|
-
type: "object",
|
|
16
|
-
properties: {
|
|
17
|
-
command: {
|
|
18
|
-
type: "string",
|
|
19
|
-
description: "The shell command to execute (e.g., 'ls -la', 'npm install')."
|
|
20
|
-
},
|
|
21
|
-
rationale: {
|
|
22
|
-
type: "string",
|
|
23
|
-
description: "Explain why you are running this command."
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
required: ["command", "rationale"]
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
type: "function",
|
|
32
|
-
function: {
|
|
33
|
-
name: "read_file",
|
|
34
|
-
description: "Read the content of a file.",
|
|
35
|
-
parameters: {
|
|
36
|
-
type: "object",
|
|
37
|
-
properties: {
|
|
38
|
-
path: {
|
|
39
|
-
type: "string",
|
|
40
|
-
description: "The path to the file to read."
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
required: ["path"]
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
type: "function",
|
|
49
|
-
function: {
|
|
50
|
-
name: "write_file",
|
|
51
|
-
description: "Write content to a file. Overwrites existing files.",
|
|
52
|
-
parameters: {
|
|
53
|
-
type: "object",
|
|
54
|
-
properties: {
|
|
55
|
-
path: {
|
|
56
|
-
type: "string",
|
|
57
|
-
description: "The path to the file to write."
|
|
58
|
-
},
|
|
59
|
-
content: {
|
|
60
|
-
type: "string",
|
|
61
|
-
description: "The content to write to the file."
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
required: ["path", "content"]
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
];
|
|
69
|
-
export async function executeTool(name, args) {
|
|
70
|
-
try {
|
|
71
|
-
switch (name) {
|
|
72
|
-
case 'execute_shell_command':
|
|
73
|
-
return await executeShellCommand(args.command, args.rationale);
|
|
74
|
-
case 'read_file':
|
|
75
|
-
return await readFile(args.path);
|
|
76
|
-
case 'write_file':
|
|
77
|
-
return await writeFile(args.path, args.content);
|
|
78
|
-
default:
|
|
79
|
-
return `Error: Unknown tool ${name}`;
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
return `Error executing ${name}: ${error.message}`;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
async function executeShellCommand(command, rationale) {
|
|
87
|
-
console.log(chalk.yellow(`
|
|
88
|
-
AI wants to execute: `) + chalk.bold(command));
|
|
89
|
-
console.log(chalk.dim(`Reason: ${rationale}`));
|
|
90
|
-
const { confirm } = await inquirer.prompt([
|
|
91
|
-
{
|
|
92
|
-
type: 'confirm',
|
|
93
|
-
name: 'confirm',
|
|
94
|
-
message: 'Do you want to run this command?',
|
|
95
|
-
default: false
|
|
96
|
-
}
|
|
97
|
-
]);
|
|
98
|
-
if (!confirm) {
|
|
99
|
-
return "User denied command execution.";
|
|
100
|
-
}
|
|
101
|
-
try {
|
|
102
|
-
const { stdout, stderr } = await execAsync(command);
|
|
103
|
-
return stdout + (stderr ? `
|
|
104
|
-
Stderr: ${stderr}` : '');
|
|
105
|
-
}
|
|
106
|
-
catch (error) {
|
|
107
|
-
return `Command failed: ${error.message}
|
|
108
|
-
Stdout: ${error.stdout}
|
|
109
|
-
Stderr: ${error.stderr}`;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
async function readFile(filePath) {
|
|
113
|
-
try {
|
|
114
|
-
const content = await fs.readFile(filePath, 'utf-8');
|
|
115
|
-
return content;
|
|
116
|
-
}
|
|
117
|
-
catch (error) {
|
|
118
|
-
return `Error reading file: ${error.message}`;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
async function writeFile(filePath, content) {
|
|
122
|
-
try {
|
|
123
|
-
await fs.mkdir(path.dirname(filePath), { recursive: true });
|
|
124
|
-
await fs.writeFile(filePath, content, 'utf-8');
|
|
125
|
-
return `Successfully wrote to ${filePath}`;
|
|
126
|
-
}
|
|
127
|
-
catch (error) {
|
|
128
|
-
return `Error writing file: ${error.message}`;
|
|
129
|
-
}
|
|
130
|
-
}
|