@zqagent/core 0.0.0-stage → 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 +59 -2
- 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/bin/zqagent +2 -0
- package/dist/ToolRegistry-C3pTFiaJ.d.cts +218 -0
- package/dist/ToolRegistry-C3pTFiaJ.d.ts +218 -0
- package/dist/cli/index.cjs +22054 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +2 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +22037 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/explore-D4lCKXbA.d.ts +735 -0
- package/dist/explore-Dj1j_GyN.d.cts +735 -0
- package/dist/index.cjs +8226 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +752 -0
- package/dist/index.d.ts +752 -0
- package/dist/index.js +8142 -0
- package/dist/index.js.map +1 -0
- package/dist/server/index.cjs +17945 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +2 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +17928 -0
- package/dist/server/index.js.map +1 -0
- package/dist/tools/ask.cjs +95 -0
- package/dist/tools/ask.cjs.map +1 -0
- package/dist/tools/ask.d.cts +20 -0
- package/dist/tools/ask.d.ts +20 -0
- package/dist/tools/ask.js +68 -0
- package/dist/tools/ask.js.map +1 -0
- package/dist/tools/diff.cjs +453 -0
- package/dist/tools/diff.cjs.map +1 -0
- package/dist/tools/diff.d.cts +6 -0
- package/dist/tools/diff.d.ts +6 -0
- package/dist/tools/diff.js +418 -0
- package/dist/tools/diff.js.map +1 -0
- package/dist/tools/directories.cjs +86 -0
- package/dist/tools/directories.cjs.map +1 -0
- package/dist/tools/directories.d.cts +16 -0
- package/dist/tools/directories.d.ts +16 -0
- package/dist/tools/directories.js +60 -0
- package/dist/tools/directories.js.map +1 -0
- package/dist/tools/explore.cjs +3174 -0
- package/dist/tools/explore.cjs.map +1 -0
- package/dist/tools/explore.d.cts +4 -0
- package/dist/tools/explore.d.ts +4 -0
- package/dist/tools/explore.js +3142 -0
- package/dist/tools/explore.js.map +1 -0
- package/dist/tools/files.cjs +312 -0
- package/dist/tools/files.cjs.map +1 -0
- package/dist/tools/files.d.cts +17 -0
- package/dist/tools/files.d.ts +17 -0
- package/dist/tools/files.js +276 -0
- package/dist/tools/files.js.map +1 -0
- package/dist/tools/git.cjs +926 -0
- package/dist/tools/git.cjs.map +1 -0
- package/dist/tools/git.d.cts +204 -0
- package/dist/tools/git.d.ts +204 -0
- package/dist/tools/git.js +874 -0
- package/dist/tools/git.js.map +1 -0
- 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.cjs +84 -0
- package/dist/tools/plan.cjs.map +1 -0
- package/dist/tools/plan.d.cts +17 -0
- package/dist/tools/plan.d.ts +17 -0
- package/dist/tools/plan.js +58 -0
- package/dist/tools/plan.js.map +1 -0
- package/dist/tools/search.cjs +575 -0
- package/dist/tools/search.cjs.map +1 -0
- package/dist/tools/search.d.cts +17 -0
- package/dist/tools/search.d.ts +17 -0
- package/dist/tools/search.js +545 -0
- package/dist/tools/search.js.map +1 -0
- package/dist/tools/shell.cjs +706 -0
- package/dist/tools/shell.cjs.map +1 -0
- package/dist/tools/shell.d.cts +39 -0
- package/dist/tools/shell.d.ts +39 -0
- package/dist/tools/shell.js +667 -0
- package/dist/tools/shell.js.map +1 -0
- package/dist/tools/todo.cjs +89 -0
- package/dist/tools/todo.cjs.map +1 -0
- package/dist/tools/todo.d.cts +27 -0
- package/dist/tools/todo.d.ts +27 -0
- package/dist/tools/todo.js +63 -0
- package/dist/tools/todo.js.map +1 -0
- package/dist/tools/web.cjs +500 -0
- package/dist/tools/web.cjs.map +1 -0
- package/dist/tools/web.d.cts +35 -0
- package/dist/tools/web.d.ts +35 -0
- package/dist/tools/web.js +465 -0
- package/dist/tools/web.js.map +1 -0
- package/package.json +217 -4
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,3 +1,60 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zqagent/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
zqagent 的引擎核心:`TurnEngine`(异步事件循环)、`ToolRegistry`、`PermissionEngine`、
|
|
4
|
+
`OpenAIProvider`,以及 CLI 与**多租户云端 Server**(含 MQTT 节点管理 v2 节点桥)。
|
|
5
|
+
|
|
6
|
+
依赖 `@zqagent/shared`(经 tsconfig `paths` 引用其源码,构建期打进 bundle)。
|
|
7
|
+
|
|
8
|
+
## 目录
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
src/
|
|
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 协议)
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 使用
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# 库
|
|
31
|
+
import { TurnEngine, ToolRegistry, PermissionEngine, OpenAIProvider } from "@zqagent/core";
|
|
32
|
+
import { ... } from "@zqagent/core/server"; // 服务端 API
|
|
33
|
+
import { ... } from "@zqagent/core/tools/fs"; // 单个工具
|
|
34
|
+
|
|
35
|
+
# CLI(全局安装)
|
|
36
|
+
npm i -g @zqagent/core --registry=https://npm2.cd-zq.com/
|
|
37
|
+
zqagent
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 开发与构建(在仓库根 ts/ 或本目录)
|
|
41
|
+
|
|
42
|
+
```bash
|
|
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)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 相关文档
|
|
55
|
+
|
|
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.
|
package/README.oss.md
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# ZQAgent
|
|
2
|
+
|
|
3
|
+
**简体中文** · [English](./README.en.md) · [繁體中文](./README.zh-TW.md)
|
|
4
|
+
|
|
5
|
+
**在终端、桌面或手机上,让 AI 帮你写代码、改文件、跑命令——有副作用的操作先问你。**
|
|
6
|
+
|
|
7
|
+
[](https://github.com/__OSS_REPO__/actions/workflows/ci.yml)
|
|
8
|
+
[](./LICENSE)
|
|
9
|
+
[](https://nodejs.org/)
|
|
10
|
+
|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
ZQAgent 是一个可自托管的 AI 编码 Agent。它自己读代码、改文件、跑命令,但**每一个有副作用的动作都会先问你**。
|
|
14
|
+
|
|
15
|
+
- **自带模型 Key**:DeepSeek、OpenAI 或任意 OpenAI 兼容端点,用多少花多少,不被订阅制绑定。
|
|
16
|
+
- **审批可控**:讨论 / 计划 / 交互 / 自动四种模式,写文件、执行命令逐次确认。
|
|
17
|
+
- **多端可用**:终端 CLI、桌面应用,以及手机或 QQ 远程派任务。
|
|
18
|
+
- **可扩展**:接入 MCP 外部工具,或用命令工具、自定义 Agent 扩展能力,改完即生效。
|
|
19
|
+
|
|
20
|
+
> 本仓库是**开源部分**:Agent 引擎、内置工具、权限系统、CLI 与节点服务。
|
|
21
|
+
> 云端账号、订阅与计费(Hub)为闭源,但不影响本地完整使用。
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 安装
|
|
26
|
+
|
|
27
|
+
**Linux(零依赖,推荐)**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
curl -fsSL https://agent.cd-zq.com/install.sh | sh
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
脚本下载对应架构的单文件可执行程序、校验 SHA-256,并装进 `PATH`,无需预先安装 Node。
|
|
34
|
+
|
|
35
|
+
**其它平台 / 用 npm 管理版本**(需要 Node.js >= 18.17)
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm i -g @zqagent/core
|
|
39
|
+
zqagent
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
首次启动输入 `/connect`,按提示选择 provider(DeepSeek / OpenAI / 自定义)→ 填写 API Key →
|
|
43
|
+
选择模型 → 设置推理强度。Key 使用 AES-256-GCM 加密保存在本机 `~/.config/zqagent/`,
|
|
44
|
+
不会上传到任何服务器。
|
|
45
|
+
|
|
46
|
+
不想全局安装,也可以直接从源码运行:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
pnpm install
|
|
50
|
+
pnpm build
|
|
51
|
+
node packages/core/bin/zqagent
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## 快速开始
|
|
55
|
+
|
|
56
|
+
```text
|
|
57
|
+
$ zqagent
|
|
58
|
+
[interactive][code] > 读一下这个项目,告诉我它是做什么的
|
|
59
|
+
|
|
60
|
+
● list_files .
|
|
61
|
+
● read_file README.md
|
|
62
|
+
● read_file package.json
|
|
63
|
+
✓ 这是一个 TypeScript 实现的 AI Agent 引擎……
|
|
64
|
+
|
|
65
|
+
[interactive][code] > 把 src/config.ts 里的默认端口改成 8788,然后跑测试
|
|
66
|
+
|
|
67
|
+
● read_file src/config.ts
|
|
68
|
+
⏵ replace_in_file 1 处修改,等待审批
|
|
69
|
+
[Y] 允许一次 [A] 总是允许 [D] 拒绝
|
|
70
|
+
> Y
|
|
71
|
+
● run_shell pnpm test
|
|
72
|
+
✓ 42 passed
|
|
73
|
+
✓ 已修改默认端口,测试通过
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
常用命令:
|
|
77
|
+
|
|
78
|
+
| 命令 | 说明 |
|
|
79
|
+
| --- | --- |
|
|
80
|
+
| `/connect` | 配置模型连接(provider / Key / 模型 / 推理强度) |
|
|
81
|
+
| `/plan` | 计划模式:只读探索,输出方案后等待确认 |
|
|
82
|
+
| `/interactive` | 交互模式:有副作用的操作逐次审批(默认) |
|
|
83
|
+
| `/auto` | 自动模式:全部放行(高风险,建议只在隔离环境使用) |
|
|
84
|
+
| `/discuss` | 讨论模式:纯只读对话 |
|
|
85
|
+
| `/sessions` | 列出并恢复历史会话 |
|
|
86
|
+
| `/agent` | 切换或维护自定义 Agent |
|
|
87
|
+
| `/mcp` | 管理 MCP 服务器 |
|
|
88
|
+
| `/tools` | 查看全部工具及其风险等级 |
|
|
89
|
+
|
|
90
|
+
任务执行过程中可以直接输入文字追加指示,无需等它跑完;连按两次 `ESC` 中断。
|
|
91
|
+
|
|
92
|
+
## 它是怎么工作的
|
|
93
|
+
|
|
94
|
+

|
|
95
|
+
|
|
96
|
+
一次任务由 `TurnEngine` 驱动:模型思考 → 调用工具 → 观察结果 → 进入下一轮,
|
|
97
|
+
直到任务完成或达到轮次上限。
|
|
98
|
+
|
|
99
|
+
所有工具调用都经过 `PermissionEngine`:每个工具声明风险等级(读 / 写 / 执行),
|
|
100
|
+
再由当前运行模式决定是直接放行、还是弹出审批。
|
|
101
|
+
|
|
102
|
+
## 内置工具
|
|
103
|
+
|
|
104
|
+
| 类别 | 工具 |
|
|
105
|
+
| --- | --- |
|
|
106
|
+
| 文件 | `read_file` `write_file` `replace_in_file` `list_files` `grep` |
|
|
107
|
+
| Shell | `run_shell` `shell_task_output` `shell_task_kill`(持久化 shell,支持后台任务) |
|
|
108
|
+
| 网络 | `web_search` `web_fetch` |
|
|
109
|
+
| Git | `git_log` `git_status` `git_diff` |
|
|
110
|
+
| 补丁 | `apply_patch` `apply_unified_diff` |
|
|
111
|
+
| 协作 | `ask_user` `propose_plan` `request_directory` `todo_write` |
|
|
112
|
+
| 探索 | `explore`(子代理:跨文件调研,只返回结论) |
|
|
113
|
+
| 媒体 | `media` `ffmpeg` `ffprobe`(音视频处理,需本机有 ffmpeg) |
|
|
114
|
+
|
|
115
|
+
工具可在运行时新增、删除、禁用,下一次模型调用立即生效。
|
|
116
|
+
|
|
117
|
+
## 安全模型
|
|
118
|
+
|
|
119
|
+
ZQAgent 的前提是**模型输出不可信**:
|
|
120
|
+
|
|
121
|
+
- 写文件、执行命令、访问网络默认需要审批。
|
|
122
|
+
- API Key 加密存储在本机,仓库与日志中不会出现明文。
|
|
123
|
+
- 工作区就是权限边界:以哪个用户、在哪个目录启动,就拥有该用户对该目录的权限。
|
|
124
|
+
- 不要把节点服务直接暴露到公网。
|
|
125
|
+
|
|
126
|
+
发现安全问题请**不要开公开 issue**,按 [SECURITY.md](./SECURITY.md) 私下报告。
|
|
127
|
+
|
|
128
|
+
## 文档
|
|
129
|
+
|
|
130
|
+
| 主题 | 文档 |
|
|
131
|
+
| --- | --- |
|
|
132
|
+
| 架构与事件流 | [docs/architecture.md](./docs/architecture.md) |
|
|
133
|
+
| 线协议(帧 / 消息 / 签名) | [docs/wire-protocol.md](./docs/wire-protocol.md) |
|
|
134
|
+
| 上下文压缩 | [docs/context-compaction.md](./docs/context-compaction.md) |
|
|
135
|
+
| 节点服务 REST API | [docs/server-api.md](./docs/server-api.md) |
|
|
136
|
+
| QQ 机器人 | [docs/qq-bot.md](./docs/qq-bot.md) |
|
|
137
|
+
| 共享库(协议 / 加密 / 审批 / 通知) | [docs/shared.md](./docs/shared.md) |
|
|
138
|
+
| Windows 终端兼容 | [docs/windows-tool-compat.md](./docs/windows-tool-compat.md) |
|
|
139
|
+
| 单文件可执行(SEA)排错 | [docs/cli-sea-troubleshooting.md](./docs/cli-sea-troubleshooting.md) |
|
|
140
|
+
| LLM 连接错误排查 | [docs/llm-connection-troubleshooting.md](./docs/llm-connection-troubleshooting.md) |
|
|
141
|
+
|
|
142
|
+
面向使用者的指南(安装、CLI 用法、Agent、MCP):<https://agent.cd-zq.com/>
|
|
143
|
+
|
|
144
|
+
架构、线协议、REST API、共享库、上下文压缩与连接排错另有英文版:
|
|
145
|
+
[architecture](./docs/en/architecture.md) · [wire-protocol](./docs/en/wire-protocol.md) ·
|
|
146
|
+
[server-api](./docs/en/server-api.md) · [shared](./docs/en/shared.md) ·
|
|
147
|
+
[context-compaction](./docs/en/context-compaction.md) ·
|
|
148
|
+
[llm-connection](./docs/en/llm-connection-troubleshooting.md)
|
|
149
|
+
|
|
150
|
+
## 开发
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
pnpm install
|
|
154
|
+
pnpm typecheck # tsc --noEmit
|
|
155
|
+
pnpm test # vitest
|
|
156
|
+
pnpm build # tsup → dist/
|
|
157
|
+
pnpm dev # 源码方式启动 CLI
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
提交前请阅读 [CONTRIBUTING.md](./CONTRIBUTING.md)。涉及权限、审批、命令执行的改动会被重点审查。
|
|
161
|
+
|
|
162
|
+
## 许可
|
|
163
|
+
|
|
164
|
+
[Apache-2.0](./LICENSE)。`@zqagent` 与 ZQAgent 名称为本项目商标,
|
|
165
|
+
二次分发或托管服务请勿暗示官方背书。
|