@zqagent/core 0.1.30 → 0.2.4
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/CONTRIBUTING.md +65 -0
- package/LICENSE +190 -0
- package/README.md +42 -165
- package/README.oss.en.md +161 -0
- package/README.oss.md +165 -0
- package/README.oss.zh-TW.md +165 -0
- package/SECURITY.md +51 -0
- package/dist/{ToolRegistry-BmvPxgMr.d.cts → ToolRegistry-C3pTFiaJ.d.cts} +13 -4
- package/dist/{ToolRegistry-BmvPxgMr.d.ts → ToolRegistry-C3pTFiaJ.d.ts} +13 -4
- package/dist/cli/index.cjs +17799 -2062
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +16729 -985
- package/dist/cli/index.js.map +1 -1
- package/dist/{explore-OI6htHN1.d.cts → explore-D4lCKXbA.d.ts} +160 -19
- package/dist/{explore-Pmhyk4gv.d.ts → explore-Dj1j_GyN.d.cts} +160 -19
- package/dist/index.cjs +3626 -453
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +337 -27
- package/dist/index.d.ts +337 -27
- package/dist/index.js +3617 -452
- package/dist/index.js.map +1 -1
- package/dist/server/index.cjs +14029 -1482
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.js +14036 -1482
- package/dist/server/index.js.map +1 -1
- package/dist/tools/ask.cjs +14 -0
- package/dist/tools/ask.cjs.map +1 -1
- package/dist/tools/ask.d.cts +8 -2
- package/dist/tools/ask.d.ts +8 -2
- package/dist/tools/ask.js +13 -0
- package/dist/tools/ask.js.map +1 -1
- package/dist/tools/diff.cjs +59 -30
- package/dist/tools/diff.cjs.map +1 -1
- package/dist/tools/diff.d.cts +1 -1
- package/dist/tools/diff.d.ts +1 -1
- package/dist/tools/diff.js +59 -30
- package/dist/tools/diff.js.map +1 -1
- package/dist/tools/directories.d.cts +1 -1
- package/dist/tools/directories.d.ts +1 -1
- package/dist/tools/explore.cjs +1050 -309
- package/dist/tools/explore.cjs.map +1 -1
- package/dist/tools/explore.d.cts +2 -2
- package/dist/tools/explore.d.ts +2 -2
- package/dist/tools/explore.js +1057 -309
- package/dist/tools/explore.js.map +1 -1
- package/dist/tools/files.cjs +58 -43
- package/dist/tools/files.cjs.map +1 -1
- package/dist/tools/files.d.cts +10 -4
- package/dist/tools/files.d.ts +10 -4
- package/dist/tools/files.js +56 -42
- package/dist/tools/files.js.map +1 -1
- package/dist/tools/git.cjs +816 -63
- package/dist/tools/git.cjs.map +1 -1
- package/dist/tools/git.d.cts +200 -2
- package/dist/tools/git.d.ts +200 -2
- package/dist/tools/git.js +788 -62
- package/dist/tools/git.js.map +1 -1
- package/dist/tools/media.cjs +1191 -0
- package/dist/tools/media.cjs.map +1 -0
- package/dist/tools/media.d.cts +31 -0
- package/dist/tools/media.d.ts +31 -0
- package/dist/tools/media.js +1159 -0
- package/dist/tools/media.js.map +1 -0
- package/dist/tools/plan.d.cts +1 -1
- package/dist/tools/plan.d.ts +1 -1
- package/dist/tools/search.cjs +513 -33
- package/dist/tools/search.cjs.map +1 -1
- package/dist/tools/search.d.cts +12 -1
- package/dist/tools/search.d.ts +12 -1
- package/dist/tools/search.js +508 -33
- package/dist/tools/search.js.map +1 -1
- package/dist/tools/shell.cjs +631 -41
- package/dist/tools/shell.cjs.map +1 -1
- package/dist/tools/shell.d.cts +37 -4
- package/dist/tools/shell.d.ts +37 -4
- package/dist/tools/shell.js +626 -40
- package/dist/tools/shell.js.map +1 -1
- package/dist/tools/todo.d.cts +1 -1
- package/dist/tools/todo.d.ts +1 -1
- package/dist/tools/web.cjs +51 -18
- package/dist/tools/web.cjs.map +1 -1
- package/dist/tools/web.d.cts +1 -1
- package/dist/tools/web.d.ts +1 -1
- package/dist/tools/web.js +51 -18
- package/dist/tools/web.js.map +1 -1
- package/package.json +43 -8
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# 贡献指南
|
|
2
|
+
|
|
3
|
+
感谢你愿意改进 ZQAgent。这个项目能执行真实命令、修改真实文件,所以我们对变更的要求比一般项目更严格。
|
|
4
|
+
|
|
5
|
+
## 开始之前
|
|
6
|
+
|
|
7
|
+
- 小改动(错别字、文档、明显的 bug 修复)可以直接提 PR。
|
|
8
|
+
- **大改动请先开 issue 讨论**,尤其是:新增工具、修改权限/审批逻辑、改动线协议(`proto/`)、改动对外 API。未经讨论的大 PR 很可能被拒绝,避免你的时间被浪费。
|
|
9
|
+
- 涉及安全的问题请看 [SECURITY.md](./SECURITY.md),不要开公开 issue。
|
|
10
|
+
|
|
11
|
+
## 开发环境
|
|
12
|
+
|
|
13
|
+
要求 Node.js >= 18.17,包管理器使用 pnpm。
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm install
|
|
17
|
+
pnpm --filter @zqagent/core test # 单元测试
|
|
18
|
+
pnpm --filter @zqagent/core typecheck # 类型检查
|
|
19
|
+
pnpm --filter @zqagent/core dev # 本地启动 CLI
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
提交前请确保 `test` 与 `typecheck` 都通过。
|
|
23
|
+
|
|
24
|
+
## 代码约定
|
|
25
|
+
|
|
26
|
+
- 使用 TypeScript,保持 `strict` 通过;不要用 `any` 掩盖类型问题。
|
|
27
|
+
- 注释用中文,只解释「为什么」,不复述代码在做什么。
|
|
28
|
+
- 新增工具体现在 `src/tools/`,并在工具注册处声明风险等级(`read` / `write` / `exec`)。**风险等级标错会导致审批被绕过,属于阻断性问题。**
|
|
29
|
+
- 任何写文件、起进程、发网络请求的逻辑都必须走 `PermissionEngine`,不要自己直接调用 `fs.writeFile` 或 `child_process`。
|
|
30
|
+
- 改动线协议时同步更新 `proto/` 与 `docs/wire-protocol.md`,并跑 `pnpm --filter @zqagent/core exec tsx scripts/gen_wire_vectors.ts` 重新生成向量。
|
|
31
|
+
|
|
32
|
+
## 双语文档
|
|
33
|
+
|
|
34
|
+
`docs/architecture.md` 与 `docs/wire-protocol.md` 有英文版(`docs/en/`)。
|
|
35
|
+
修改这两篇时请**同一次提交里同步更新英文版**,否则英文读者会看到过期内容。
|
|
36
|
+
其余文档目前只有中文,新增时不必强制翻译,但请在 README 的文档表中保持链接有效
|
|
37
|
+
(导出脚本会校验所有相对链接,失效会直接失败)。
|
|
38
|
+
|
|
39
|
+
## 测试
|
|
40
|
+
|
|
41
|
+
- 修 bug 请附带一个能复现该 bug 的测试。
|
|
42
|
+
- 新增工具需要覆盖:正常路径、审批被拒绝、参数非法。
|
|
43
|
+
- 不要提交依赖真实网络的测试;需要外部服务时用本地 stub。
|
|
44
|
+
|
|
45
|
+
## 提交信息
|
|
46
|
+
|
|
47
|
+
采用 Conventional Commits:
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
feat(cli): 支持 /model 切换时保留会话
|
|
51
|
+
fix(permissions): 修复 auto 模式下命令白名单失效
|
|
52
|
+
docs: 补充 MCP http 传输示例
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## PR 检查清单
|
|
56
|
+
|
|
57
|
+
- [ ] `test` 与 `typecheck` 通过
|
|
58
|
+
- [ ] 新增/修改的行为有测试覆盖
|
|
59
|
+
- [ ] 没有提交密钥、真实账号、内部地址或 `dist/`、`node_modules/`
|
|
60
|
+
- [ ] 涉及权限、审批、命令执行的改动,在 PR 描述中说明了安全影响
|
|
61
|
+
- [ ] 面向用户的变更已同步文档(`packages/site/docs/` 或 `docs/`)
|
|
62
|
+
|
|
63
|
+
## 许可
|
|
64
|
+
|
|
65
|
+
提交 PR 即表示你同意以 [Apache-2.0](./LICENSE) 许可贡献你的代码,并确认你有权这样做。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Chengdu Zhiqian Technology Co., Ltd.
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,183 +1,60 @@
|
|
|
1
|
-
# zqagent
|
|
1
|
+
# @zqagent/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
zqagent 的引擎核心:`TurnEngine`(异步事件循环)、`ToolRegistry`、`PermissionEngine`、
|
|
4
|
+
`OpenAIProvider`,以及 CLI 与**多租户云端 Server**(含 MQTT 节点管理 v2 节点桥)。
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
- **ToolRegistry** — 工具注册 / 执行 / 元数据管理
|
|
7
|
-
- **PermissionEngine** — 工具风险分类 + 运行模式门控 + Y/N 交互审批
|
|
8
|
-
- **OpenAIProvider** — 基于 OpenAI SDK 的流式 LLM 调用
|
|
6
|
+
依赖 `@zqagent/shared`(经 tsconfig `paths` 引用其源码,构建期打进 bundle)。
|
|
9
7
|
|
|
10
|
-
##
|
|
11
|
-
|
|
12
|
-
### 全局安装(推荐)
|
|
13
|
-
|
|
14
|
-
```bash
|
|
15
|
-
# 从私有仓库全局安装(其它机器需先配置该 registry,或加 --registry 参数)
|
|
16
|
-
npm i -g @zqagent/core --registry=https://npm2.cd-zq.com/
|
|
17
|
-
|
|
18
|
-
# 启动 CLI
|
|
19
|
-
zqagent
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
启动后无需手动写 `.env`,输入 `/connect` 即可交互式配置 LLM 连接:
|
|
23
|
-
选择 provider(DeepSeek / OpenAI / 自定义)→ 输入 API Key → 自动刷新模型列表并选择 →
|
|
24
|
-
设置推理强度。API Key 会 AES-256-GCM 加密保存到本机 `~/.config/zqagent/`。
|
|
25
|
-
|
|
26
|
-
### 本地开发
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
# 安装依赖
|
|
30
|
-
npm install
|
|
31
|
-
|
|
32
|
-
# 配置环境变量(复制为 .env 后填写),或启动后直接 /connect
|
|
33
|
-
# OPENAI_API_KEY=sk-... # 必填(未用 /connect 时)
|
|
34
|
-
# OPENAI_MODEL=gpt-4o # 可选,默认 gpt-4o
|
|
35
|
-
# OPENAI_BASE_URL=... # 可选,自定义端点
|
|
36
|
-
# WORKSPACE=./ # 可选,工作区根目录,默认当前目录
|
|
37
|
-
cp .env.example .env
|
|
38
|
-
|
|
39
|
-
# 启动 CLI
|
|
40
|
-
npm run dev
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
## 使用
|
|
44
|
-
|
|
45
|
-
启动后进入交互式 CLI,直接输入自然语言任务即可。内置命令:
|
|
46
|
-
|
|
47
|
-
| 命令 | 说明 |
|
|
48
|
-
| --- | --- |
|
|
49
|
-
| `/plan` | 切换为计划模式(只读探索 + 计划提案) |
|
|
50
|
-
| `/interactive` | 切换为交互式审批模式(默认) |
|
|
51
|
-
| `/auto` | 切换为全自动模式(无需审批,高风险) |
|
|
52
|
-
| `/discuss` | 切换为讨论模式(只读对话) |
|
|
53
|
-
| `/mode` | 显示当前模式 |
|
|
54
|
-
| `/connect` | 连接 LLM(选 provider → key → 刷新模型列表 → 推理强度) |
|
|
55
|
-
| `/connect rm` | 清除连接配置(回退到环境变量) |
|
|
56
|
-
| `/sessions` | 列出已保存会话并选择恢复(切换后回显最近消息) |
|
|
57
|
-
| `/history` | 列出当前会话的用户指令 |
|
|
58
|
-
| `/model <id>` | 切换 LLM 模型 |
|
|
59
|
-
| `/agent <name>` | 切换 agent(Prompt + 可选模型同步) |
|
|
60
|
-
| `/agents` | 列出所有 agent(当前高亮) |
|
|
61
|
-
| `/agent add <name> <prompt...>` | 新增自定义 agent |
|
|
62
|
-
| `/agent edit <name> <prompt...>` | 修改 agent 的 Prompt(当前 agent 即时热更新) |
|
|
63
|
-
| `/agent rm <name>` | 删除 agent |
|
|
64
|
-
| `/agent show [name]` | 查看 agent 详情 |
|
|
65
|
-
| `/mcp` | 列出 MCP 服务器与连接状态 |
|
|
66
|
-
| `/mcp add <name> stdio <cmd...>\|http <url>` | 添加并连接 MCP 服务器(工具自动注入) |
|
|
67
|
-
| `/mcp rm\|enable\|disable\|refresh [name]` | 移除 / 启用 / 禁用 / 刷新工具列表 |
|
|
68
|
-
| `/tools` | 列出所有工具(来源、风险、禁用状态) |
|
|
69
|
-
| `/tool add <name> <cmd...>` | 添加命令工具(执行 shell 命令) |
|
|
70
|
-
| `/tool rm\|disable\|enable <name>` | 移除 / 禁用 / 启用工具 |
|
|
71
|
-
| `/clear` | 清空会话,重建引擎 |
|
|
72
|
-
| `quit` / `exit` | 退出 |
|
|
73
|
-
| `reset` | 重置会话 |
|
|
74
|
-
|
|
75
|
-
> **Agent 机制**:内置 `code`(编程助手)/ `cowork`(通用协作)两个 agent。
|
|
76
|
-
> 通过 `/agent add / edit / rm` 可运行时维护任意数量的 agent(名称 + Prompt + 可选模型);
|
|
77
|
-
> 定义持久化到项目内 `.agent/agents.json`(可提交 git,随项目共享)。
|
|
78
|
-
> 切换 agent 时若其配置了 `model`,LLM 模型会同步切换;否则沿用当前模型。
|
|
79
|
-
> 提示符以 `[模式][agent名] > ` 形式展示当前状态,如 `[plan][code] > `。
|
|
80
|
-
|
|
81
|
-
> **MCP 与工具管理**:运行时可通过 `/mcp add` 注入外部 MCP 服务器
|
|
82
|
-
> (stdio 本地进程或 http 远程端点),其工具自动以 `mcp__<server>__<tool>`
|
|
83
|
-
> 前缀注册到工具表;`/tool add` 可创建执行 shell 命令的命令工具。
|
|
84
|
-
> 引擎每次请求都实时拉取工具 schema,因此工具的新增 / 移除 / 禁用 / 替换
|
|
85
|
-
> 对下一次 LLM 调用立即生效,无需重启。
|
|
86
|
-
> MCP 服务器配置持久化到 `.agent/mcp.json`,命令工具到 `.agent/tools.json`
|
|
87
|
-
> (均随项目走,可提交 git);MCP 注入工具默认按高风险归类,交互模式下需逐次审批。
|
|
88
|
-
|
|
89
|
-
### 运行模式
|
|
90
|
-
|
|
91
|
-
| 模式 | 行为 |
|
|
92
|
-
| --- | --- |
|
|
93
|
-
| `discuss` | 只读,禁止一切写入与执行 |
|
|
94
|
-
| `plan` | 只读,禁止一切写入与执行,面向计划提案 |
|
|
95
|
-
| `interactive` | 有副作用的操作需用户逐次审批(默认) |
|
|
96
|
-
| `auto` | 有副作用的操作全部放行(高风险,需自行承担) |
|
|
97
|
-
|
|
98
|
-
交互模式下,审批卡片支持:`Y` 允许一次 / `A` 总是允许此工具 / `D` 拒绝;
|
|
99
|
-
`run_shell` 额外支持 `C` 总是允许此命令(按具体命令白名单,比放行整个工具更安全)。
|
|
100
|
-
|
|
101
|
-
## 内置工具(18 个)
|
|
102
|
-
|
|
103
|
-
| 类别 | 工具 |
|
|
104
|
-
| --- | --- |
|
|
105
|
-
| 文件 | `read_file`, `write_file`, `replace_in_file`, `list_files`, `grep` |
|
|
106
|
-
| Shell | `run_shell`(持久化 shell,命令白名单在 Auto 模式下自动放行) |
|
|
107
|
-
| 网络 | `web_search`, `web_fetch` |
|
|
108
|
-
| Git | `git_log`, `git_status`, `git_diff`(只读) |
|
|
109
|
-
| 补丁 | `apply_patch`, `apply_unified_diff` |
|
|
110
|
-
| 协作 | `ask_user`, `propose_plan`, `request_directory` |
|
|
111
|
-
| 任务 | `todo_write`(共享进度状态) |
|
|
112
|
-
| 子代理 | `explore`(独立 TurnEngine 实例,只读研究) |
|
|
113
|
-
|
|
114
|
-
## 项目结构
|
|
8
|
+
## 目录
|
|
115
9
|
|
|
116
10
|
```
|
|
117
11
|
src/
|
|
118
|
-
├── index.ts
|
|
119
|
-
├──
|
|
120
|
-
|
|
121
|
-
├── mcp/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
├──
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
│ └── OpenAIProvider.ts # 流式 LLM 调用
|
|
132
|
-
├── prompts/
|
|
133
|
-
│ └── index.ts # 中文系统提示词模板
|
|
134
|
-
└── tools/
|
|
135
|
-
├── ToolRegistry.ts # 工具注册表(注册/移除/禁用/替换)
|
|
136
|
-
├── files.ts shell.ts search.ts web.ts
|
|
137
|
-
├── git.ts diff.ts todo.ts explore.ts
|
|
138
|
-
└── ask.ts plan.ts directories.ts
|
|
139
|
-
test/ # Vitest 单元测试
|
|
12
|
+
├── index.ts # 库入口(re-export)
|
|
13
|
+
├── cli/ # CLI(index.ts 入口 / 连接向导 / 输入 / 会话元数据 …)
|
|
14
|
+
├── agents/ # Agent 注册表(运行时维护 agent)
|
|
15
|
+
├── mcp/ # MCP 客户端与管理(stdio / http)
|
|
16
|
+
├── engine/ # TurnEngine / events / compaction / hooks / renderer
|
|
17
|
+
├── permissions/ # 风险分类 + 模式门控 + 审批
|
|
18
|
+
├── providers/ # OpenAI 兼容 provider(流式 / chat)
|
|
19
|
+
├── prompts/ # 中文系统提示词
|
|
20
|
+
├── tools/ # 19 个内置工具(文件/shell/搜索/web/git/补丁/协作/子代理/媒体)
|
|
21
|
+
└── server/ # 多租户 API + 项目/节点 + MQTT 节点管理 v2 桥(FleetNodeBridge/FleetCommands)
|
|
22
|
+
bin/zqagent # CLI 可执行入口
|
|
23
|
+
scripts/ # SEA 单文件构建 / 冒烟 / 探针 / busybox 下载
|
|
24
|
+
test/ # Vitest(492 用例,覆盖引擎/server/hub/web 协议)
|
|
140
25
|
```
|
|
141
26
|
|
|
142
|
-
##
|
|
27
|
+
## 使用
|
|
143
28
|
|
|
144
29
|
```bash
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
30
|
+
# 库
|
|
31
|
+
import { TurnEngine, ToolRegistry, PermissionEngine, OpenAIProvider } from "@zqagent/core";
|
|
32
|
+
import { ... } from "@zqagent/core/server"; // 服务端 API
|
|
33
|
+
import { ... } from "@zqagent/core/tools/fs"; // 单个工具
|
|
148
34
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
支持审批与提问的**挂起 → 持久化 → 超时回收 → resume 恢复**完整链路。
|
|
153
|
-
|
|
154
|
-
```bash
|
|
155
|
-
npm run server # 启动(默认端口 8787,首次启动自动创建演示租户 demo/demo-key)
|
|
35
|
+
# CLI(全局安装)
|
|
36
|
+
npm i -g @zqagent/core --registry=https://npm2.cd-zq.com/
|
|
37
|
+
zqagent
|
|
156
38
|
```
|
|
157
39
|
|
|
158
|
-
|
|
159
|
-
- 一键测试:`bash scripts/test-server.sh`(无需 Key 的烟雾测试,18 项);模型配置
|
|
160
|
-
(`OPENAI_API_KEY` 等)未显式设置时自动从项目 `.env` 读取,此时为完整链路测试
|
|
161
|
-
(真实对话 + 提问挂起 + 超时回收 + resume 恢复,24 项)
|
|
162
|
-
|
|
163
|
-
## 桌面应用(macOS / Windows)
|
|
164
|
-
|
|
165
|
-
`desktop/` 把 Server 打包成桌面应用:Tauri 2 外壳 + 内嵌 Node sidecar,前端复用
|
|
166
|
-
`test_web/` 的 React 页面(本地引擎自动连接、托盘常驻、自动更新)。
|
|
40
|
+
## 开发与构建(在仓库根 ts/ 或本目录)
|
|
167
41
|
|
|
168
42
|
```bash
|
|
169
|
-
#
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
#
|
|
173
|
-
|
|
174
|
-
|
|
43
|
+
pnpm run dev # CLI(tsx packages/core/src/cli/index.ts)
|
|
44
|
+
pnpm run server # 多租户 Server :8787
|
|
45
|
+
pnpm run build # tsup → dist/(含 dts)
|
|
46
|
+
pnpm run test # Vitest
|
|
47
|
+
pnpm run typecheck # tsc --noEmit
|
|
48
|
+
pnpm run build:sea # 单 CJS bundle(供 SEA)
|
|
49
|
+
pnpm run build:cli-bin # SEA 单文件可执行 → release/cli/
|
|
50
|
+
pnpm run probes:sea # 生成对照探针
|
|
51
|
+
pnpm run fetch:busybox # 下载 BusyBox-w32(Windows)
|
|
175
52
|
```
|
|
176
53
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
## 测试 Web 界面(test_web/)
|
|
54
|
+
## 相关文档
|
|
180
55
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
56
|
+
- 系统架构与构建:[../../docs/architecture.md](../../docs/architecture.md)
|
|
57
|
+
- CLI 使用/工具/Agent/MCP:[../../packages/site/docs/guide/](../../packages/site/docs/guide/)
|
|
58
|
+
- Server REST API:[../../docs/server-api.md](../../docs/server-api.md)
|
|
59
|
+
- 线协议规范(帧/信封/消息/签名):[../../docs/wire-protocol.md](../../docs/wire-protocol.md)
|
|
60
|
+
- CLI SEA 故障排查:[../../docs/cli-sea-troubleshooting.md](../../docs/cli-sea-troubleshooting.md)
|
package/README.oss.en.md
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
# ZQAgent
|
|
2
|
+
|
|
3
|
+
**English** · [简体中文](./README.md) · [繁體中文](./README.zh-TW.md)
|
|
4
|
+
|
|
5
|
+
**Your AI assistant in the terminal, on the desktop, or on your phone — write code, edit files, run commands. Anything with side effects asks you first.**
|
|
6
|
+
|
|
7
|
+
[](https://github.com/__OSS_REPO__/actions/workflows/ci.yml)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](https://nodejs.org/)
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
ZQAgent is a self-hostable AI coding agent. It reads code, edits files, and runs commands on its own — but **every side-effecting action asks for your approval first**.
|
|
14
|
+
|
|
15
|
+
- **Bring your own model key** — DeepSeek, OpenAI, or any OpenAI-compatible endpoint. Pay for what you use instead of a subscription.
|
|
16
|
+
- **Approval by default** — four modes (discuss / plan / interactive / auto); file writes and shell commands are confirmed one by one.
|
|
17
|
+
- **Works everywhere** — terminal CLI, desktop app, and remote task dispatch from your phone or QQ.
|
|
18
|
+
- **Extensible** — plug in MCP servers, or add command tools and custom agents; changes take effect immediately.
|
|
19
|
+
|
|
20
|
+
> This repository is the **open-source part**: the agent engine, built-in tools, permission system, CLI, and node service.
|
|
21
|
+
> Cloud accounts, subscriptions, and billing (Hub) are closed source, and are not required for local use.
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
**Linux (no dependencies, recommended)**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
curl -fsSL https://agent.cd-zq.com/install.sh | sh
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The script downloads a single-file executable for your architecture, verifies its SHA-256, and puts it on your `PATH`. No Node.js required.
|
|
34
|
+
|
|
35
|
+
**Other platforms / npm** (requires Node.js >= 18.17)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm i -g @zqagent/core
|
|
39
|
+
zqagent
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
On first launch, run `/connect` and follow the prompts: pick a provider (OpenAI / DeepSeek / Qwen / Zhipu GLM / Kimi / custom) → enter your API key → choose a model → set reasoning effort. Keys are encrypted with AES-256-GCM and stored locally in `~/.config/zqagent/`; they are never uploaded.
|
|
43
|
+
|
|
44
|
+
To run from source instead:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pnpm install
|
|
48
|
+
pnpm build
|
|
49
|
+
node packages/core/bin/zqagent
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Quick start
|
|
53
|
+
|
|
54
|
+
```text
|
|
55
|
+
$ zqagent
|
|
56
|
+
[interactive][code] > read this project and tell me what it does
|
|
57
|
+
|
|
58
|
+
● list_files .
|
|
59
|
+
● read_file README.md
|
|
60
|
+
● read_file package.json
|
|
61
|
+
✓ This is a TypeScript AI agent engine...
|
|
62
|
+
|
|
63
|
+
[interactive][code] > change the default port in src/config.ts to 8788, then run the tests
|
|
64
|
+
|
|
65
|
+
● read_file src/config.ts
|
|
66
|
+
⏵ replace_in_file 1 change, waiting for approval
|
|
67
|
+
[Y] allow once [A] always allow [D] deny
|
|
68
|
+
> Y
|
|
69
|
+
● run_shell pnpm test
|
|
70
|
+
✓ 42 passed
|
|
71
|
+
✓ Changed the default port; tests pass
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Common commands:
|
|
75
|
+
|
|
76
|
+
| Command | Description |
|
|
77
|
+
| --- | --- |
|
|
78
|
+
| `/connect` | Configure the model connection (provider / key / model / reasoning effort) |
|
|
79
|
+
| `/plan` | Plan mode: read-only exploration, proposes a plan and waits |
|
|
80
|
+
| `/interactive` | Interactive mode: every side-effecting action needs approval (default) |
|
|
81
|
+
| `/auto` | Auto mode: allow everything (risky — use in isolated environments only) |
|
|
82
|
+
| `/discuss` | Discuss mode: read-only conversation |
|
|
83
|
+
| `/sessions` | List and resume previous sessions |
|
|
84
|
+
| `/agent` | Switch or maintain custom agents |
|
|
85
|
+
| `/mcp` | Manage MCP servers |
|
|
86
|
+
| `/tools` | Show all tools and their risk levels |
|
|
87
|
+
|
|
88
|
+
While a task is running you can type additional instructions at any time — no need to wait for it to finish. Press `ESC` twice to interrupt.
|
|
89
|
+
|
|
90
|
+
## How it works
|
|
91
|
+
|
|
92
|
+

|
|
93
|
+
|
|
94
|
+
`TurnEngine` drives each task: the model thinks → calls a tool → observes the result → next round,
|
|
95
|
+
until the task is done or the turn limit is reached.
|
|
96
|
+
|
|
97
|
+
Every tool call goes through `PermissionEngine`: each tool declares a risk level (read / write / exec),
|
|
98
|
+
and the current mode decides whether it runs directly or requires approval.
|
|
99
|
+
|
|
100
|
+
## Built-in tools
|
|
101
|
+
|
|
102
|
+
| Category | Tools |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| Files | `read_file` `write_file` `replace_in_file` `list_files` `grep` |
|
|
105
|
+
| Shell | `run_shell` `shell_task_output` `shell_task_kill` (persistent shell, background tasks) |
|
|
106
|
+
| Web | `web_search` `web_fetch` |
|
|
107
|
+
| Git | `git_log` `git_status` `git_diff` |
|
|
108
|
+
| Patches | `apply_patch` `apply_unified_diff` |
|
|
109
|
+
| Collaboration | `ask_user` `propose_plan` `request_directory` `todo_write` |
|
|
110
|
+
| Exploration | `explore` (sub-agent for cross-file research; returns conclusions only) |
|
|
111
|
+
| Media | `media` `ffmpeg` `ffprobe` (audio/video; requires ffmpeg on the host) |
|
|
112
|
+
|
|
113
|
+
Tools can be added, removed, or disabled at runtime; the next model call picks up the change immediately.
|
|
114
|
+
|
|
115
|
+
## Security model
|
|
116
|
+
|
|
117
|
+
ZQAgent assumes **model output is untrusted**:
|
|
118
|
+
|
|
119
|
+
- File writes, command execution, and network access require approval by default.
|
|
120
|
+
- API keys are encrypted locally and never appear in the repository or logs.
|
|
121
|
+
- The workspace is the permission boundary: the agent has exactly the permissions of the user and directory it was started in.
|
|
122
|
+
- Do not expose the node service directly to the internet.
|
|
123
|
+
|
|
124
|
+
Please **do not open a public issue** for security problems — follow [SECURITY.md](./SECURITY.md) instead.
|
|
125
|
+
|
|
126
|
+
## Documentation
|
|
127
|
+
|
|
128
|
+
| Topic | Document |
|
|
129
|
+
| --- | --- |
|
|
130
|
+
| Architecture and event flow | [docs/en/architecture.md](./docs/en/architecture.md) |
|
|
131
|
+
| Wire protocol (frames / messages / signatures) | [docs/en/wire-protocol.md](./docs/en/wire-protocol.md) |
|
|
132
|
+
| Node service REST API | [docs/en/server-api.md](./docs/en/server-api.md) |
|
|
133
|
+
| Shared library (protocol / crypto / approvals / notifications) | [docs/en/shared.md](./docs/en/shared.md) |
|
|
134
|
+
| Context compaction | [docs/en/context-compaction.md](./docs/en/context-compaction.md) |
|
|
135
|
+
| LLM connection errors | [docs/en/llm-connection-troubleshooting.md](./docs/en/llm-connection-troubleshooting.md) |
|
|
136
|
+
| QQ bot integration | [docs/qq-bot.md](./docs/qq-bot.md) *(Chinese)* |
|
|
137
|
+
| Windows tool compatibility | [docs/windows-tool-compat.md](./docs/windows-tool-compat.md) *(Chinese)* |
|
|
138
|
+
| CLI single-file (SEA) packaging and troubleshooting | [docs/cli-sea-troubleshooting.md](./docs/cli-sea-troubleshooting.md) *(Chinese)* |
|
|
139
|
+
|
|
140
|
+
Every document except the QQ bot, Windows compatibility, and CLI-packaging notes is available
|
|
141
|
+
in English; those three are currently Chinese only.
|
|
142
|
+
|
|
143
|
+
User-facing guides (installation, CLI usage, agents, MCP): <https://agent.cd-zq.com/en/>
|
|
144
|
+
|
|
145
|
+
## Development
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
pnpm install
|
|
149
|
+
pnpm typecheck # tsc --noEmit
|
|
150
|
+
pnpm test # vitest
|
|
151
|
+
pnpm build # tsup → dist/
|
|
152
|
+
pnpm dev # run the CLI from source
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Please read [CONTRIBUTING.md](./CONTRIBUTING.md) before submitting a pull request. Changes touching permissions,
|
|
156
|
+
approval, or command execution get extra scrutiny.
|
|
157
|
+
|
|
158
|
+
## License
|
|
159
|
+
|
|
160
|
+
[Apache-2.0](./LICENSE). `@zqagent` and the ZQAgent name are trademarks of this project;
|
|
161
|
+
redistributions and hosted services must not imply official endorsement.
|