@zqagent/core 0.1.30 → 0.2.5

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.
Files changed (86) hide show
  1. package/CONTRIBUTING.md +65 -0
  2. package/LICENSE +190 -0
  3. package/README.md +102 -146
  4. package/README.oss.en.md +161 -0
  5. package/README.oss.md +165 -0
  6. package/README.oss.zh-TW.md +165 -0
  7. package/SECURITY.md +51 -0
  8. package/dist/{ToolRegistry-BmvPxgMr.d.cts → ToolRegistry-C3pTFiaJ.d.cts} +13 -4
  9. package/dist/{ToolRegistry-BmvPxgMr.d.ts → ToolRegistry-C3pTFiaJ.d.ts} +13 -4
  10. package/dist/cli/index.cjs +17799 -2062
  11. package/dist/cli/index.cjs.map +1 -1
  12. package/dist/cli/index.js +16729 -985
  13. package/dist/cli/index.js.map +1 -1
  14. package/dist/{explore-OI6htHN1.d.cts → explore-D4lCKXbA.d.ts} +160 -19
  15. package/dist/{explore-Pmhyk4gv.d.ts → explore-Dj1j_GyN.d.cts} +160 -19
  16. package/dist/index.cjs +3626 -453
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +337 -27
  19. package/dist/index.d.ts +337 -27
  20. package/dist/index.js +3617 -452
  21. package/dist/index.js.map +1 -1
  22. package/dist/server/index.cjs +14029 -1482
  23. package/dist/server/index.cjs.map +1 -1
  24. package/dist/server/index.js +14036 -1482
  25. package/dist/server/index.js.map +1 -1
  26. package/dist/tools/ask.cjs +14 -0
  27. package/dist/tools/ask.cjs.map +1 -1
  28. package/dist/tools/ask.d.cts +8 -2
  29. package/dist/tools/ask.d.ts +8 -2
  30. package/dist/tools/ask.js +13 -0
  31. package/dist/tools/ask.js.map +1 -1
  32. package/dist/tools/diff.cjs +59 -30
  33. package/dist/tools/diff.cjs.map +1 -1
  34. package/dist/tools/diff.d.cts +1 -1
  35. package/dist/tools/diff.d.ts +1 -1
  36. package/dist/tools/diff.js +59 -30
  37. package/dist/tools/diff.js.map +1 -1
  38. package/dist/tools/directories.d.cts +1 -1
  39. package/dist/tools/directories.d.ts +1 -1
  40. package/dist/tools/explore.cjs +1050 -309
  41. package/dist/tools/explore.cjs.map +1 -1
  42. package/dist/tools/explore.d.cts +2 -2
  43. package/dist/tools/explore.d.ts +2 -2
  44. package/dist/tools/explore.js +1057 -309
  45. package/dist/tools/explore.js.map +1 -1
  46. package/dist/tools/files.cjs +58 -43
  47. package/dist/tools/files.cjs.map +1 -1
  48. package/dist/tools/files.d.cts +10 -4
  49. package/dist/tools/files.d.ts +10 -4
  50. package/dist/tools/files.js +56 -42
  51. package/dist/tools/files.js.map +1 -1
  52. package/dist/tools/git.cjs +816 -63
  53. package/dist/tools/git.cjs.map +1 -1
  54. package/dist/tools/git.d.cts +200 -2
  55. package/dist/tools/git.d.ts +200 -2
  56. package/dist/tools/git.js +788 -62
  57. package/dist/tools/git.js.map +1 -1
  58. package/dist/tools/media.cjs +1191 -0
  59. package/dist/tools/media.cjs.map +1 -0
  60. package/dist/tools/media.d.cts +31 -0
  61. package/dist/tools/media.d.ts +31 -0
  62. package/dist/tools/media.js +1159 -0
  63. package/dist/tools/media.js.map +1 -0
  64. package/dist/tools/plan.d.cts +1 -1
  65. package/dist/tools/plan.d.ts +1 -1
  66. package/dist/tools/search.cjs +513 -33
  67. package/dist/tools/search.cjs.map +1 -1
  68. package/dist/tools/search.d.cts +12 -1
  69. package/dist/tools/search.d.ts +12 -1
  70. package/dist/tools/search.js +508 -33
  71. package/dist/tools/search.js.map +1 -1
  72. package/dist/tools/shell.cjs +631 -41
  73. package/dist/tools/shell.cjs.map +1 -1
  74. package/dist/tools/shell.d.cts +37 -4
  75. package/dist/tools/shell.d.ts +37 -4
  76. package/dist/tools/shell.js +626 -40
  77. package/dist/tools/shell.js.map +1 -1
  78. package/dist/tools/todo.d.cts +1 -1
  79. package/dist/tools/todo.d.ts +1 -1
  80. package/dist/tools/web.cjs +51 -18
  81. package/dist/tools/web.cjs.map +1 -1
  82. package/dist/tools/web.d.cts +1 -1
  83. package/dist/tools/web.d.ts +1 -1
  84. package/dist/tools/web.js +51 -18
  85. package/dist/tools/web.js.map +1 -1
  86. package/package.json +43 -8
@@ -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,139 @@
1
- # zqagent TS
1
+ # @zqagent/core
2
2
 
3
- TypeScript 实现的 zqagent Agent 引擎核心(CLI),复刻 Python 版的核心机制:
3
+ **在终端、桌面或手机上,让 AI 帮你写代码、改文件、跑命令——有副作用的操作先问你。**
4
4
 
5
- - **TurnEngine** — 异步生成器事件循环,驱动"思考 → 工具调用 → 观察"的迭代
6
- - **ToolRegistry** — 工具注册 / 执行 / 元数据管理
7
- - **PermissionEngine** — 工具风险分类 + 运行模式门控 + Y/N 交互审批
8
- - **OpenAIProvider** — 基于 OpenAI SDK 的流式 LLM 调用
5
+ [![CI](https://github.com/zqagent/zqagent/actions/workflows/ci.yml/badge.svg)](https://github.com/zqagent/zqagent/actions/workflows/ci.yml)
6
+ [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://github.com/zqagent/zqagent/blob/main/LICENSE)
9
7
 
10
- ## 快速开始
8
+ ZQAgent 是可自托管的 AI 编码 Agent。它自己读代码、改文件、跑命令,但**每一个有副作用的动作都会先问你**。
11
9
 
12
- ### 全局安装(推荐)
10
+ - **自带模型 Key**:DeepSeek、OpenAI 或任意 OpenAI 兼容端点,用多少花多少。
11
+ - **审批可控**:讨论 / 计划 / 交互 / 自动四种模式,写文件、执行命令逐次确认。
12
+ - **多端可用**:终端 CLI、桌面应用,以及手机或 QQ 远程派任务。
13
+ - **可扩展**:接入 MCP 外部工具,或用命令工具、自定义 Agent 扩展能力。
13
14
 
14
- ```bash
15
- # 从私有仓库全局安装(其它机器需先配置该 registry,或加 --registry 参数)
16
- npm i -g @zqagent/core --registry=https://npm2.cd-zq.com/
15
+ ## 安装
17
16
 
18
- # 启动 CLI
17
+ 需要 **Node.js >= 18.17**。
18
+
19
+ ```bash
20
+ npm i -g @zqagent/core
19
21
  zqagent
20
22
  ```
21
23
 
22
- 启动后无需手动写 `.env`,输入 `/connect` 即可交互式配置 LLM 连接:
23
- 选择 provider(DeepSeek / OpenAI / 自定义)→ 输入 API Key → 自动刷新模型列表并选择 →
24
- 设置推理强度。API Key 会 AES-256-GCM 加密保存到本机 `~/.config/zqagent/`。
25
-
26
- ### 本地开发
24
+ Linux 也可以零依赖安装(下载单文件可执行程序,无需 Node):
27
25
 
28
26
  ```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
27
+ curl -fsSL https://agent.cd-zq.com/install.sh | sh
41
28
  ```
42
29
 
43
- ## 使用
30
+ 首次启动输入 `/connect`,按提示选择 provider(OpenAI / DeepSeek / 通义千问 / 智谱 GLM / Kimi / 自定义)→
31
+ 填写 API Key → 选择模型 → 设置推理强度。Key 使用 AES-256-GCM 加密保存在本机
32
+ `~/.config/zqagent/`,不会上传。
33
+
34
+ ## 快速开始
44
35
 
45
- 启动后进入交互式 CLI,直接输入自然语言任务即可。内置命令:
36
+ ```text
37
+ $ zqagent
38
+ [interactive][code] > 读一下这个项目,告诉我它是做什么的
39
+
40
+ ● list_files .
41
+ ● read_file README.md
42
+ ✓ 这是一个 TypeScript 实现的 AI Agent 引擎……
43
+
44
+ [interactive][code] > 把 src/config.ts 里的默认端口改成 8788,然后跑测试
45
+
46
+ ● read_file src/config.ts
47
+ ⏵ replace_in_file 1 处修改,等待审批
48
+ [Y] 允许一次 [A] 总是允许 [D] 拒绝
49
+ > Y
50
+ ● run_shell pnpm test
51
+ ✓ 42 passed
52
+ ✓ 已修改默认端口,测试通过
53
+ ```
54
+
55
+ 常用命令:
46
56
 
47
57
  | 命令 | 说明 |
48
58
  | --- | --- |
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` | 有副作用的操作全部放行(高风险,需自行承担) |
59
+ | `/connect` | 配置模型连接(provider / Key / 模型 / 推理强度) |
60
+ | `/plan` | 计划模式:只读探索,输出方案后等待确认 |
61
+ | `/interactive` | 交互模式:有副作用的操作逐次审批(默认) |
62
+ | `/auto` | 自动模式:全部放行(高风险,建议只在隔离环境使用) |
63
+ | `/discuss` | 讨论模式:纯只读对话 |
64
+ | `/sessions` | 列出并恢复历史会话 |
65
+ | `/agent` | 切换或维护自定义 Agent |
66
+ | `/mcp` | 管理 MCP 服务器 |
67
+ | `/tools` | 查看全部工具及其风险等级 |
97
68
 
98
- 交互模式下,审批卡片支持:`Y` 允许一次 / `A` 总是允许此工具 / `D` 拒绝;
99
- `run_shell` 额外支持 `C` 总是允许此命令(按具体命令白名单,比放行整个工具更安全)。
69
+ 任务执行过程中可以直接输入文字追加指示,无需等它跑完;连按两次 `ESC` 中断。
100
70
 
101
- ## 内置工具(18 个)
71
+ ## 内置能力
102
72
 
103
73
  | 类别 | 工具 |
104
74
  | --- | --- |
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
- ## 项目结构
115
-
116
- ```
117
- src/
118
- ├── index.ts # CLI 入口:装配组件、命令行审批器、事件渲染
119
- ├── agents/
120
- │ └── AgentRegistry.ts # Agent 注册表(运行时增删改查 / 切换 agent)
121
- ├── mcp/
122
- │ ├── McpClient.ts # 单个 MCP 服务器客户端(stdio / http)
123
- │ └── McpManager.ts # 多服务器管理 + 工具动态注入 ToolRegistry
124
- ├── engine/
125
- │ ├── TurnEngine.ts # 异步生成器事件循环
126
- │ ├── events.ts # 事件类型定义
127
- │ └── types.ts
128
- ├── permissions/
129
- │ └── PermissionEngine.ts # 风险分类 + 模式门控 + 审批决策
130
- ├── providers/
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 单元测试
75
+ | 文件 | `read_file` `write_file` `replace_in_file` `list_files` `grep` |
76
+ | Shell | `run_shell` `shell_task_output` `shell_task_kill`(持久化 shell,支持后台任务) |
77
+ | 网络 | `web_search` `web_fetch` |
78
+ | Git | `git_log` `git_status` `git_diff` |
79
+ | 补丁 | `apply_patch` `apply_unified_diff` |
80
+ | 协作 | `ask_user` `propose_plan` `request_directory` `todo_write` |
81
+ | 探索 | `explore`(子代理:跨文件调研,只返回结论) |
82
+ | 媒体 | `media`,检测到本机 ffmpeg 时另有 `ffmpeg` `ffprobe` |
83
+
84
+ 共 21 个内置工具。工具可在运行时新增、删除、禁用,下一次模型调用立即生效。
85
+
86
+ ## 作为库使用
87
+
88
+ ```ts
89
+ import { TurnEngine, ToolRegistry, PermissionEngine, OpenAIProvider } from "@zqagent/core";
90
+ import { ... } from "@zqagent/core/server"; // 多租户 HTTP 服务
91
+ import { ... } from "@zqagent/core/tools/fs"; // 单个工具
140
92
  ```
141
93
 
142
- ## 开发
94
+ ## 安全模型
143
95
 
144
- ```bash
145
- npm run build # tsc 类型检查与构建
146
- npm test # Vitest 运行测试
147
- ```
96
+ ZQAgent 的前提是**模型输出不可信**:
148
97
 
149
- ## 云端多租户 Server
98
+ - 写文件、执行命令、访问网络默认需要审批。
99
+ - API Key 加密存储在本机,仓库与日志中不会出现明文。
100
+ - 工作区就是权限边界:以哪个用户、在哪个目录启动,就拥有该用户对该目录的权限。
101
+ - 不要把节点服务直接暴露到公网。
150
102
 
151
- `src/server/` 提供多租户云端化 API(独立于 CLI):每租户独立工作区/模型配置/状态存储,
152
- 支持审批与提问的**挂起 → 持久化 → 超时回收 → resume 恢复**完整链路。
103
+ 发现安全问题请**不要开公开 issue**,按
104
+ [SECURITY.md](https://github.com/zqagent/zqagent/blob/main/SECURITY.md) 私下报告。
153
105
 
154
- ```bash
155
- npm run server # 启动(默认端口 8787,首次启动自动创建演示租户 demo/demo-key)
156
- ```
106
+ ## 文档
107
+
108
+ | 主题 | 文档 |
109
+ | --- | --- |
110
+ | 系统架构 | [docs/architecture.md](https://github.com/zqagent/zqagent/blob/main/docs/architecture.md) |
111
+ | 线协议(帧 / 消息 / 签名) | [docs/wire-protocol.md](https://github.com/zqagent/zqagent/blob/main/docs/wire-protocol.md) |
112
+ | 上下文压缩 | [docs/context-compaction.md](https://github.com/zqagent/zqagent/blob/main/docs/context-compaction.md) |
113
+ | 节点服务 REST API | [docs/server-api.md](https://github.com/zqagent/zqagent/blob/main/docs/server-api.md) |
114
+ | 共享库 | [docs/shared.md](https://github.com/zqagent/zqagent/blob/main/docs/shared.md) |
115
+ | LLM 连接排查 | [docs/llm-connection-troubleshooting.md](https://github.com/zqagent/zqagent/blob/main/docs/llm-connection-troubleshooting.md) |
116
+ | QQ 机器人 | [docs/qq-bot.md](https://github.com/zqagent/zqagent/blob/main/docs/qq-bot.md) |
157
117
 
158
- - 完整 curl 教程(审批/提问/超时回收/多租户隔离):[docs/server-api.md](docs/server-api.md)
159
- - 一键测试:`bash scripts/test-server.sh`(无需 Key 的烟雾测试,18 项);模型配置
160
- (`OPENAI_API_KEY` 等)未显式设置时自动从项目 `.env` 读取,此时为完整链路测试
161
- (真实对话 + 提问挂起 + 超时回收 + resume 恢复,24 项)
118
+ 上述文档同时提供英文版(`docs/en/`)。使用者指南见 <https://agent.cd-zq.com/>。
162
119
 
163
- ## 桌面应用(macOS / Windows)
120
+ ## 开发
164
121
 
165
- `desktop/` 把 Server 打包成桌面应用:Tauri 2 外壳 + 内嵌 Node sidecar,前端复用
166
- `test_web/` 的 React 页面(本地引擎自动连接、托盘常驻、自动更新)。
122
+ 本包是 monorepo 的一部分(与 `@zqagent/shared` 同源构建):
167
123
 
168
124
  ```bash
169
- # 开发调试
170
- cd desktop && npm install && npm run tauri dev
171
-
172
- # 一键构建
173
- ./desktop/scripts/build_macos.sh # macOS → DMG
174
- .\desktop\scripts\build_windows.ps1 # Windows → NSIS + MSI
125
+ pnpm install
126
+ pnpm --filter @zqagent/core typecheck
127
+ pnpm --filter @zqagent/core test
128
+ pnpm --filter @zqagent/core build
129
+ pnpm --filter @zqagent/core dev # 以源码方式启动 CLI
175
130
  ```
176
131
 
177
- 详见 [desktop/README.md](desktop/README.md)。
132
+ 贡献前请阅读
133
+ [CONTRIBUTING.md](https://github.com/zqagent/zqagent/blob/main/CONTRIBUTING.md)。
134
+ 涉及权限、审批、命令执行的改动会被重点审查。
178
135
 
179
- ## 测试 Web 界面(test_web/)
136
+ ## 许可
180
137
 
181
- `test_web/` 是 Server 的 React 测试页:多租户 profile 管理、会话/审批/提问全链路。
182
- 桌面壳会注入 `window.__ZQ_HTTP__/__ZQ_API_KEY__` 并自动注册「本地引擎」profile,
183
- 浏览器模式(`npm run dev`)行为不变。
138
+ [Apache-2.0](https://github.com/zqagent/zqagent/blob/main/LICENSE)。
139
+ `@zqagent` 与 ZQAgent 名称为本项目商标,二次分发或托管服务请勿暗示官方背书。