@tencent-ai/agent-sdk 0.3.169 → 0.3.171
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/cli/CHANGELOG.md +50 -18
- package/cli/builtin/workflows/deep-research.workflow.js +429 -0
- package/cli/dist/codebuddy-headless.js +208 -135
- package/cli/dist/web-ui/assets/{index-CiYuiLTV.js → index-i12Tc2lJ.js} +20 -20
- package/cli/dist/web-ui/docs/cn/cli/permission-modes.md +260 -0
- package/cli/dist/web-ui/docs/cn/cli/permissions.md +380 -0
- package/cli/dist/web-ui/docs/cn/cli/release-notes/README.md +3 -0
- package/cli/dist/web-ui/docs/cn/cli/release-notes/v2.103.2.md +21 -0
- package/cli/dist/web-ui/docs/cn/cli/release-notes/v2.103.3.md +15 -0
- package/cli/dist/web-ui/docs/cn/cli/release-notes/v2.103.4.md +13 -0
- package/cli/dist/web-ui/docs/cn/cli/workflows.md +281 -0
- package/cli/dist/web-ui/docs/en/cli/permission-modes.md +260 -0
- package/cli/dist/web-ui/docs/en/cli/permissions.md +380 -0
- package/cli/dist/web-ui/docs/en/cli/release-notes/README.md +3 -0
- package/cli/dist/web-ui/docs/en/cli/release-notes/v2.103.2.md +21 -0
- package/cli/dist/web-ui/docs/en/cli/release-notes/v2.103.3.md +15 -0
- package/cli/dist/web-ui/docs/en/cli/release-notes/v2.103.4.md +13 -0
- package/cli/dist/web-ui/docs/en/cli/workflows.md +281 -0
- package/cli/dist/web-ui/docs/search-index-en.json +1 -1
- package/cli/dist/web-ui/docs/search-index-zh.json +1 -1
- package/cli/dist/web-ui/docs/sidebar-en.json +1 -1
- package/cli/dist/web-ui/docs/sidebar-zh.json +1 -1
- package/cli/dist/web-ui/index.html +1 -1
- package/cli/dist/web-ui/sw.js +1 -1
- package/cli/package.json +2 -1
- package/cli/product.cloudhosted.json +5 -3
- package/cli/product.internal.json +27 -3
- package/cli/product.ioa.json +31 -3
- package/cli/product.json +46 -3
- package/cli/product.selfhosted.json +5 -3
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/types.d.ts +9 -1
- package/lib/types.d.ts.map +1 -1
- package/lib/utils/type-guards.d.ts.map +1 -1
- package/lib/utils/type-guards.js +1 -0
- package/lib/utils/type-guards.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# 🚀 CodeBuddy Code v2.103.3 发布
|
|
2
|
+
|
|
3
|
+
## 📦 版本信息
|
|
4
|
+
|
|
5
|
+
| 组件 | 版本 |
|
|
6
|
+
|------|------|
|
|
7
|
+
| CodeBuddy Code CLI | v2.103.3 |
|
|
8
|
+
| Agent SDK JS | v0.3.168 |
|
|
9
|
+
| Agent SDK Python | v0.3.167 |
|
|
10
|
+
|
|
11
|
+
## 🐛 问题修复
|
|
12
|
+
|
|
13
|
+
- **自定义模型认证错误识别**:自定义模型 API key 失效(401/403)不再被误判为平台登录失效,避免出现"重新登录"弹窗中断会话
|
|
14
|
+
- **会话历史重放稳定性**:会话被中断(如强退、崩溃)后再打开,未收尾的工具调用现在正确渲染为「已取消」状态,而非消失或显示为不可本地化的文本;仍存活的待答问题不再被误判为孤儿调用,保留正常交互能力
|
|
15
|
+
- **OTel metrics 稳定性**:回滚此前的 metrics 修复改动,恢复稳定的遥测行为,避免主线回归
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# 🚀 CodeBuddy Code v2.103.4 发布
|
|
2
|
+
|
|
3
|
+
## 📦 版本信息
|
|
4
|
+
|
|
5
|
+
| 组件 | 版本 |
|
|
6
|
+
|------|------|
|
|
7
|
+
| CodeBuddy Code CLI | v2.103.4 |
|
|
8
|
+
| Agent SDK JS | v0.3.169 |
|
|
9
|
+
| Agent SDK Python | v0.3.168 |
|
|
10
|
+
|
|
11
|
+
## 🔧 改进优化
|
|
12
|
+
|
|
13
|
+
- **帮助优化模型开关**:新增 `enableModelOptimization` 全局设置项,可控制是否参与模型优化。开启后请求会携带相应标识,自定义模型不发送该标识,让你对数据使用范围拥有更明确的掌控。
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# Dynamic Workflows:用脚本编排成规模的子代理
|
|
2
|
+
|
|
3
|
+
> Dynamic Workflows 让 CodeBuddy 写一段 JavaScript 编排脚本,由运行时在后台调度数十甚至数百个子代理协作完成任务。脚本本身可读、可改、可重跑,适合代码库审计、大型迁移、需要交叉验证的研究类任务。
|
|
4
|
+
|
|
5
|
+
<Note>
|
|
6
|
+
Dynamic Workflows 目前为研究预览阶段,要求 CodeBuddy Code v2.1.154 或更高版本。在 `/config` 中通过 "Dynamic workflows" 开关启用。
|
|
7
|
+
</Note>
|
|
8
|
+
|
|
9
|
+
Dynamic Workflow 是一段由 CodeBuddy 为你的任务现场编写的 JavaScript 脚本,运行时在后台执行它,你的会话保持响应。脚本里包含一个或多个 [`agent()`](#脚本-api) 调用,每次调用都派出一个独立的子代理工作;脚本拿到中间结果后,可以分支、可以并行、可以再投递给下一批子代理。
|
|
10
|
+
|
|
11
|
+
当一项任务大到一个会话装不下,或者你希望编排逻辑被记录成"可重跑的脚本"时,就该用 Workflow。典型场景:
|
|
12
|
+
|
|
13
|
+
- 全代码库的 Bug 巡检
|
|
14
|
+
- 跨 500 个文件的迁移
|
|
15
|
+
- 一个需要从多源交叉印证的研究问题
|
|
16
|
+
- 一个值得从多个独立角度先草拟、再对比择优的复杂方案
|
|
17
|
+
|
|
18
|
+
本页介绍:
|
|
19
|
+
|
|
20
|
+
- [何时该用 Workflow](#何时该用-workflow)(与子代理 / Skills / Agent Teams 的取舍)
|
|
21
|
+
- [运行内置 Workflow](#运行内置-workflow):`/deep-research`
|
|
22
|
+
- [让 CodeBuddy 为你的任务写一个 Workflow](#让-codebuddy-写-workflow),并保存复用
|
|
23
|
+
- [Workflow 的运行机制](#workflow-的运行机制) 与 [运行管理](#运行管理)
|
|
24
|
+
|
|
25
|
+
## 何时该用 Workflow
|
|
26
|
+
|
|
27
|
+
[子代理](sub-agents.md)、[Skills](skills.md)、[Agent Teams](agent-teams.md) 与 Workflows 都能跑多步任务,差别在于"谁握着计划":
|
|
28
|
+
|
|
29
|
+
| | 子代理 | Skills | Agent Teams | Workflows |
|
|
30
|
+
| :-------------------- | :--------------------------- | :------------------------ | :-------------------------------- | :------------------------------ |
|
|
31
|
+
| 本质 | CodeBuddy 派出去的工人 | CodeBuddy 遵循的指令 | 一个领导监管一组同侪会话 | 运行时执行的一段脚本 |
|
|
32
|
+
| 谁决定下一步做什么 | CodeBuddy,逐轮决策 | CodeBuddy,按提示执行 | 领导代理,逐轮决策 | 脚本 |
|
|
33
|
+
| 中间结果存在哪 | CodeBuddy 的上下文窗口 | CodeBuddy 的上下文窗口 | 共享任务列表 | 脚本变量 |
|
|
34
|
+
| 可重复的是什么 | 工人定义 | 指令本身 | 团队定义 | 编排过程本身 |
|
|
35
|
+
| 规模 | 每轮少量委派 | 同子代理 | 几位长任务的同侪 | 单次运行数十到数百个代理 |
|
|
36
|
+
| 中断 | 重新开一轮 | 重新开一轮 | 队友继续跑 | 在同一会话内可恢复 |
|
|
37
|
+
|
|
38
|
+
Workflow 把"计划"挪进了代码。子代理 / Skills / Agent Teams 的编排者都是 CodeBuddy,每一轮它都要决定下一步派谁、做什么,所有结果都落进上下文窗口;而 Workflow 把循环、分支、中间结果都交给脚本本身管理,CodeBuddy 的上下文里只剩**最终答案**。
|
|
39
|
+
|
|
40
|
+
把计划变成代码还有第二个好处:你可以让脚本应用一种**重复可执行的质量模式**,而不只是单纯多派代理。比如让若干代理对彼此的发现做对抗式互评再上报、或者从多个角度同时起草方案再相互对比择优 —— 单次结果的可信度会比"一遍过"高得多。
|
|
41
|
+
|
|
42
|
+
## 运行内置 Workflow
|
|
43
|
+
|
|
44
|
+
最快感受 Workflow 的方式是跑 `/deep-research`,这是 CodeBuddy Code 内置的"多源交叉印证研究"工作流。会话里你会看到代理在后台分阶段推进,跑完后只拿到一份合成报告,而不是一长串逐轮对话。
|
|
45
|
+
|
|
46
|
+
### 步骤
|
|
47
|
+
|
|
48
|
+
1. **发起 Workflow**
|
|
49
|
+
|
|
50
|
+
带一个想调研的问题运行 `/deep-research`。它会从多个角度并行搜索、抓取并交叉印证来源,最终合成一份带引用的报告。
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
/deep-research Node.js 的 permission model 在 v20 到 v22 之间有什么变化?
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
2. **批准运行**
|
|
57
|
+
|
|
58
|
+
CodeBuddy Code 会询问是否允许此 Workflow 运行。选择 **Yes** 继续。具体提示取决于你的[权限模式](iam.md#权限系统)。详见 [运行前批准计划](#运行前批准计划)。
|
|
59
|
+
|
|
60
|
+
3. **观察进度**
|
|
61
|
+
|
|
62
|
+
运行在后台启动。`/workflows` 打开 Workflows 视图,方向键选中本次 run,回车进入进度页:
|
|
63
|
+
|
|
64
|
+
```text
|
|
65
|
+
/workflows
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
进度页按"阶段(phase)"展示,每个阶段标注代理数量、Token 总量与已耗时。下钻进任意阶段可以看每个代理的提示与产出。完整快捷键见 [观察运行](#观察运行)。
|
|
69
|
+
|
|
70
|
+
你也可以从输入框下方的任务面板里直接看到一行进度摘要。按方向键 ↓ 把焦点切到任务面板,回车展开。
|
|
71
|
+
|
|
72
|
+
4. **阅读报告**
|
|
73
|
+
|
|
74
|
+
运行结束后,报告自动落回会话。每一条主张都标注了引用来源,未通过交叉印证的主张会被剔除。
|
|
75
|
+
|
|
76
|
+
要把 Workflow 应用到你自己的任务,先 [让 CodeBuddy 写一个](#让-codebuddy-写-workflow);当某次运行结果令人满意,可以把它[保存为命令](#保存-workflow-以便复用)。
|
|
77
|
+
|
|
78
|
+
### 内置 Workflow
|
|
79
|
+
|
|
80
|
+
CodeBuddy Code 内置如下 Workflow:
|
|
81
|
+
|
|
82
|
+
| 命令 | 作用 |
|
|
83
|
+
| :---------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
84
|
+
| `/deep-research <问题>` | 多角度并行搜索、抓取并交叉印证来源,对每条主张投票,剔除未通过印证的部分,输出一份带引用的报告。需要 [WebSearch 工具](tools-reference.md#websearch-tool-behavior) 可用。 |
|
|
85
|
+
|
|
86
|
+
[你自己保存的 Workflow](#保存-workflow-以便复用) 会以同样方式注册成命令,在 `/` 自动补全里与内置 Workflow 一同出现。
|
|
87
|
+
|
|
88
|
+
### 观察运行
|
|
89
|
+
|
|
90
|
+
Workflow 在后台运行,会话保持响应。任何时候 `/workflows` 都能列出活跃 / 已完成的 run,选中后进入进度视图。
|
|
91
|
+
|
|
92
|
+
```text
|
|
93
|
+
/workflows
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
进度视图按阶段展示,每个阶段标注代理数量、Token 总量、已耗时。底部状态栏列出全部快捷键:
|
|
97
|
+
|
|
98
|
+
| 按键 | 作用 |
|
|
99
|
+
| :------------ | :------------------------------------------------------------------------------------------------ |
|
|
100
|
+
| `↑` / `↓` | 选中阶段或代理 |
|
|
101
|
+
| `Enter` 或 `→` | 下钻到所选阶段,再下钻到代理可读其提示、最近的工具调用与最终结果 |
|
|
102
|
+
| `Esc` | 回退一级 |
|
|
103
|
+
| `j` / `k` | 在代理详情溢出时滚动 |
|
|
104
|
+
| `p` | 暂停或恢复运行 |
|
|
105
|
+
| `x` | 中止所选代理;焦点在 run 上时中止整个 Workflow |
|
|
106
|
+
| `r` | 重启所选的运行中代理 |
|
|
107
|
+
| `s` | 把当前 run 的脚本[保存](#保存-workflow-以便复用)为命令 |
|
|
108
|
+
|
|
109
|
+
## 让 CodeBuddy 写 Workflow
|
|
110
|
+
|
|
111
|
+
让 CodeBuddy 为你的任务写 Workflow,有两种方式:
|
|
112
|
+
|
|
113
|
+
- [在提示里直接要 Workflow](#在提示里要-workflow):用自然语言或者关键词 `ultracode`,CodeBuddy 会为这个任务写一份。
|
|
114
|
+
- [让 CodeBuddy 自己决定(ultracode 模式)](#ultracode-模式让-codebuddy-自己决定):`/effort ultracode` 把 effort 等级设到 ultracode,会话里的每一个有分量的任务 CodeBuddy 都会先规划成 Workflow。
|
|
115
|
+
|
|
116
|
+
也可以直接运行已有的 Workflow 命令:内置如 `/deep-research`,或你[保存](#保存-workflow-以便复用)过的。
|
|
117
|
+
|
|
118
|
+
### 在提示里要 Workflow
|
|
119
|
+
|
|
120
|
+
不想改会话整体 effort 等级,只想让某次任务走 Workflow,在提示里加上关键词 `ultracode`。用自然语言说"用一个 workflow 跑这个"或者 "use a workflow",效果一样:CodeBuddy 把直接请求当作同等的显式 opt-in。
|
|
121
|
+
|
|
122
|
+
```text
|
|
123
|
+
ultracode:审计 src/routes/ 下每个 API 端点是否漏了鉴权检查
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
CodeBuddy Code 会高亮你输入里的关键词,CodeBuddy 收到这个提示后,会为该任务写一段 Workflow 脚本,而不是逐轮地展开工作。如果你不想触发 Workflow,按 macOS 的 `Option+W`、Windows / Linux 的 `Alt+W` 取消本次提示的高亮;或者光标停在关键词后面按 Backspace 删掉它即可。要彻底关闭关键词触发,到 `/config` 关掉 "Ultracode keyword trigger"。
|
|
127
|
+
|
|
128
|
+
如果运行结果满足需要,事后可以把它[保存为命令](#保存-workflow-以便复用)。
|
|
129
|
+
|
|
130
|
+
如果你已经有用其他方式搭好的编排器(一个子代理提示词文件夹、或一个分发任务的 Skill),可以让 CodeBuddy 看一下并写一段等价的 Workflow。
|
|
131
|
+
|
|
132
|
+
### Ultracode 模式:让 CodeBuddy 自己决定
|
|
133
|
+
|
|
134
|
+
Ultracode 是 CodeBuddy Code 的一个组合配置:把 [推理强度](models.md#调整推理强度) 推到 `xhigh`,并叠加自动 Workflow 编排。开启后,CodeBuddy 会主动判断哪些任务值得走 Workflow,不必你每次提醒。
|
|
135
|
+
|
|
136
|
+
```text
|
|
137
|
+
/effort ultracode
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
进入 ultracode 后,一个请求可能被拆成连续多个 Workflow:先一个 run 摸代码现状、再一个 run 实施改动、再一个 run 验证。会话里**每个**任务都按这个模式跑,每条请求消耗的 Token 会比低 effort 等级显著更多、耗时也更长。
|
|
141
|
+
|
|
142
|
+
ultracode 仅在当前会话生效,新开会话自动重置。回到日常工作时用 `/effort high` 回退即可。它仅在支持 `xhigh` [推理强度](models.md#调整推理强度) 的模型上可用;不支持的模型上 `/effort` 菜单不会展示该选项。
|
|
143
|
+
|
|
144
|
+
### 运行前批准计划
|
|
145
|
+
|
|
146
|
+
CLI 里,每次启动都会弹出运行前确认:
|
|
147
|
+
|
|
148
|
+
- **Yes, run it**:开始运行
|
|
149
|
+
- **Yes, and don't ask again for `<name>` in `<path>`**:开始运行,并对该项目内同名 Workflow 不再询问
|
|
150
|
+
- **View raw script**:先读脚本再决定
|
|
151
|
+
- **No**:取消
|
|
152
|
+
|
|
153
|
+
`Ctrl+G` 在你的编辑器里打开脚本;`Tab` 可以在运行前调整提示。
|
|
154
|
+
|
|
155
|
+
是否会出现这个询问,取决于你的 [权限模式](permission-modes.md):
|
|
156
|
+
|
|
157
|
+
| 权限模式 | 何时询问 |
|
|
158
|
+
| :----------------------------------------- | :-------------------------------------------------------------------------------------------------------------------------------- |
|
|
159
|
+
| Default、Accept edits | 每次都询问;除非你为该 Workflow 在该项目下选过 **Yes, and don't ask again** |
|
|
160
|
+
| Auto | 只在首次启动时询问;任何 **Yes** 都会写入用户设置,后续直接启动。ultracode 开启时整个询问被跳过 |
|
|
161
|
+
| Bypass permissions、`codebuddy -p`、Agent SDK | 永不询问,运行直接开始 |
|
|
162
|
+
|
|
163
|
+
权限模式只影响**启动前**这个询问。Workflow 派出去的子代理始终在 `acceptEdits` 模式下跑,并继承你的[工具白名单](settings.md#permission-settings),与你会话当前模式无关。文件改动是自动批准的。
|
|
164
|
+
|
|
165
|
+
不在白名单里的 Shell 命令、Web Fetch、MCP 工具调用,仍可能在运行中弹询问。要避免长任务被打断,启动前把代理需要的命令加进白名单。
|
|
166
|
+
|
|
167
|
+
`codebuddy -p` 与 Agent SDK 没有人机交互入口,工具调用按你配置的权限规则执行,没有交互式确认。
|
|
168
|
+
|
|
169
|
+
### 保存 Workflow 以便复用
|
|
170
|
+
|
|
171
|
+
当一段 Workflow 是你会反复跑的(比如每个分支都要做一遍的 review 流程),可以把它的脚本保存为命令。
|
|
172
|
+
|
|
173
|
+
`/workflows` 选中要保留的 run,按 `s`,在保存对话里 `Tab` 切换两个保存位置:
|
|
174
|
+
|
|
175
|
+
- 项目下 `.codebuddy/workflows/`:随仓库分发,团队所有人都看得到
|
|
176
|
+
- 用户目录 `~/.codebuddy/workflows/`:在所有项目都可用,仅你可见
|
|
177
|
+
|
|
178
|
+
回车保存。之后在任意会话里通过 `/<name>` 调用。
|
|
179
|
+
|
|
180
|
+
如果项目级和用户级 Workflow 重名,**项目级**优先。
|
|
181
|
+
|
|
182
|
+
### 给已保存的 Workflow 传参
|
|
183
|
+
|
|
184
|
+
保存的 Workflow 通过 `args` 接收输入。脚本里它是一个名为 `args` 的全局变量。这样不必每次改脚本就能传研究问题、目标路径列表、配置对象等。
|
|
185
|
+
|
|
186
|
+
下面这段提示触发一个保存的 Workflow,并把 issue 列表作为参数传入:
|
|
187
|
+
|
|
188
|
+
```text
|
|
189
|
+
> 用 /triage-issues 跑一下 issue 1024、1025、1030
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
CodeBuddy 把列表作为结构化数据传入,脚本可以直接对 `args` 用数组 / 对象方法,无需自己解析。如果调用方没传 `args`,脚本里 `args` 是 `undefined`。
|
|
193
|
+
|
|
194
|
+
## Workflow 的运行机制
|
|
195
|
+
|
|
196
|
+
运行时在一个隔离环境里执行脚本,与你的会话完全分离。中间结果留在脚本变量里,不会落进 CodeBuddy 的上下文。
|
|
197
|
+
|
|
198
|
+
每次 run 都会把脚本写到会话目录(`~/.codebuddy/projects/<session>/`)下的一个文件里。CodeBuddy 在 run 启动时拿到该路径,所以你可以问它"脚本在哪"。打开它可以读 CodeBuddy 写的编排逻辑、和上一次 run 做 diff、或者编辑后让 CodeBuddy 用编辑后的版本重新启动。
|
|
199
|
+
|
|
200
|
+
运行时持续记录每个代理的结果,这就是同一会话内 run [可恢复](#恢复-pause-后的-run) 的基础。
|
|
201
|
+
|
|
202
|
+
### 行为与限制
|
|
203
|
+
|
|
204
|
+
运行时施加以下约束:
|
|
205
|
+
|
|
206
|
+
| 约束 | 原因 |
|
|
207
|
+
| :------------------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------------------- |
|
|
208
|
+
| 运行中不接受用户输入 | 唯一能让 run 暂停的是代理的权限询问。若需要阶段间签字确认,把每个阶段拆成独立 Workflow |
|
|
209
|
+
| Workflow 自身没有直接的文件系统 / Shell 访问能力 | 文件读写、执行命令一律由代理完成;脚本只负责协调代理 |
|
|
210
|
+
| 同时最多 16 个并发代理(CPU 核数少的机器上更少) | 限制本地资源消耗 |
|
|
211
|
+
| 单次 run 最多 1000 个代理 | 防止脚本失控的循环 |
|
|
212
|
+
|
|
213
|
+
### 确定性沙箱
|
|
214
|
+
|
|
215
|
+
运行时强制确定性,避免同一脚本两次跑出不同结果(也是 [resume 缓存命中](#恢复-pause-后的-run) 的前提)。沙箱拒绝以下不确定性 / 任意代码生成 API(编译期扫描 + 运行时拦截):
|
|
216
|
+
|
|
217
|
+
- 时间相关:`Date.now()`、`new Date()`、`performance.now()`
|
|
218
|
+
- 随机数:`Math.random()`
|
|
219
|
+
- 任意代码生成:动态字符串求值与动态 Function 构造(沙箱关闭了 `codeGeneration.strings`)
|
|
220
|
+
- Node 全局:沙箱里看不到 `require` / `process` / `__dirname` / `Buffer`
|
|
221
|
+
|
|
222
|
+
需要时间戳或随机数时,用 `agent()` 让子代理拉取真实信息(搜索、读文件、调 API),把不确定性"装进"代理的结果里。
|
|
223
|
+
|
|
224
|
+
### 脚本 API
|
|
225
|
+
|
|
226
|
+
脚本是一个自包含的 JavaScript 模块,可以使用以下全局函数:
|
|
227
|
+
|
|
228
|
+
| 全局 | 作用 |
|
|
229
|
+
| :---------------------------- | :------------------------------------------------------------------------------------------------------------------------------------ |
|
|
230
|
+
| `agent(prompt, options?)` | 派一个子代理执行 `prompt`;返回它的结果。`options` 可指定 `tools` / `maxTurns` / `schema`(结构化输出)/ `model` 等 |
|
|
231
|
+
| `parallel(items, options?)` | 对 `items` 并行 fan-out,等同于 `Promise.all`,但受 16 个并发上限约束 |
|
|
232
|
+
| `pipeline(items, options?)` | 顺序串联,前一段的结果传给下一段;任一段失败时其余段返回 `null` |
|
|
233
|
+
| `phase(name, body)` | 把一段编排标注成一个阶段,进度视图里会按阶段聚合显示。`body` 可以是同步或异步函数 |
|
|
234
|
+
| `log(...)` | 写一条带时间戳的日志,会出现在进度视图的 Run log 里 |
|
|
235
|
+
| `args` | 调用方传入的参数(见 [给已保存的 Workflow 传参](#给已保存的-workflow-传参)) |
|
|
236
|
+
| `workflow(name, args?)` | 嵌套调用一个**已保存**的 Workflow(仅父级可调用,子级不再暴露此 hook,禁止深度嵌套) |
|
|
237
|
+
|
|
238
|
+
更多模式见 [`build/patches/cli-saas/templates/workflow-tool-description.tpl`](../../../build/patches/cli-saas/templates/workflow-tool-description.tpl) 与 [`workflow-subagent-system-preamble.tpl`](../../../build/patches/cli-saas/templates/workflow-subagent-system-preamble.tpl)。
|
|
239
|
+
|
|
240
|
+
## 运行管理
|
|
241
|
+
|
|
242
|
+
run 一旦启动,从 `/workflows` 视图管理;也可以展开输入框下方任务面板里的进度行。
|
|
243
|
+
|
|
244
|
+
### 恢复 pause 后的 run
|
|
245
|
+
|
|
246
|
+
如果你停下了一个 run,可以再恢复:已经完成的代理直接返回缓存结果,剩余部分继续跑。`/workflows` 选中已暂停的 run 按 `p` 恢复;也可以让 CodeBuddy 用同一脚本重启 run。
|
|
247
|
+
|
|
248
|
+
恢复仅限**同一 CodeBuddy Code 会话内**。如果你退出了 CodeBuddy Code 时 Workflow 还在跑,下次会话会从头开始。
|
|
249
|
+
|
|
250
|
+
### 成本
|
|
251
|
+
|
|
252
|
+
Workflow 会派出大量代理,因此一次 run 的 Token 消耗可能远高于以对话方式做同样的任务。这些消耗按你套餐的限额计入。
|
|
253
|
+
|
|
254
|
+
要在动手做大任务前估成本,先在小切片上跑一遍:一个目录而不是整个 repo,一个具体问题而不是宽泛主题。`/workflows` 视图里每个代理的 Token 用量实时可见,随时可以 `x` 中止 run 而不丢已完成的结果。运行时的 [代理上限](#行为与限制) 也限制了一次 run 能消耗的最大代价,避免脚本写错时跑飞。
|
|
255
|
+
|
|
256
|
+
每个代理默认沿用会话当前的模型;如果脚本显式给某阶段路由到了别的模型则不同。控制成本可以从几个方面入手:
|
|
257
|
+
|
|
258
|
+
- 大任务前 `/model` 检查一遍当前模型,如果你平时切到便宜模型,注意切回来或维持
|
|
259
|
+
- 描述任务时主动告诉 CodeBuddy:"对不需要最强模型的阶段用更便宜的模型"
|
|
260
|
+
|
|
261
|
+
### 关闭 Workflow
|
|
262
|
+
|
|
263
|
+
Workflow 在 CLI、桌面端、IDE 扩展、`codebuddy -p` 非交互模式与 [Agent SDK](sdk.md) 都可用,关闭方式在所有形态下一致。
|
|
264
|
+
|
|
265
|
+
仅对自己关闭:
|
|
266
|
+
|
|
267
|
+
- `/config` 里把 "Dynamic workflows" 关掉。会持久化到设置
|
|
268
|
+
- `~/.codebuddy/settings.json` 设 `"disableWorkflows": true`,会持久化
|
|
269
|
+
- 设环境变量 `CODEBUDDY_DISABLE_WORKFLOWS=1`,启动时读取,在哪儿设就在哪儿生效
|
|
270
|
+
|
|
271
|
+
为整个组织关闭:在 [托管设置](settings.md#enterprise-managed-policy-settings) 里设 `"disableWorkflows": true`。
|
|
272
|
+
|
|
273
|
+
关闭后,内置 Workflow 命令不可用,关键词 `ultracode` 不再触发,`/effort` 菜单也不再展示 ultracode 选项。
|
|
274
|
+
|
|
275
|
+
## 相关资源
|
|
276
|
+
|
|
277
|
+
- [子代理](sub-agents.md):Workflow 编排的底层"工人"原语
|
|
278
|
+
- [Agent Teams](agent-teams.md):另一种多代理协作形态,由领导代理管计划
|
|
279
|
+
- [Skills 技能系统](skills.md):把"指令"沉淀成可复用 Skill
|
|
280
|
+
- [推理强度调整(含 ultracode)](models.md#调整推理强度)
|
|
281
|
+
- [Hooks 钩子系统](hooks-guide.md):在工具调用与会话事件上挂钩子
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# Permission Modes
|
|
2
|
+
|
|
3
|
+
> Controls whether CodeBuddy should stop and ask before editing files, running commands, or making network requests. The mode determines the pace of the entire session: conservative modes require approval step by step, while more permissive modes let CodeBuddy continue for longer without interruption and report back at the end. Use strict modes for sensitive operations, and permissive modes when you trust the direction.
|
|
4
|
+
|
|
5
|
+
## Available Modes
|
|
6
|
+
|
|
7
|
+
All modes actually defined by CodeBuddy Code in the `src/node/settings/settings-protocol.ts::PermissionMode` enum are listed below. The first four are directly exposed to CLI users, and the remaining modes are for programmatic or integration scenarios.
|
|
8
|
+
|
|
9
|
+
### Modes You Can Switch Manually
|
|
10
|
+
|
|
11
|
+
| Mode | What can run without asking | Use case |
|
|
12
|
+
| :----------------------------------------------------------- | :------------------------------------------------------------------------------------------------------------ | :---------------------------------------------------------- |
|
|
13
|
+
| `default` | Read tool inside trusted directories | Default; suitable for sensitive work / getting started |
|
|
14
|
+
| [`acceptEdits`](#acceptedits-auto-approve-file-edits) | Read + Edit-family tools inside trusted directories | Keep writing, then review with git diff |
|
|
15
|
+
| [`plan`](#plan-explore-before-changing) | Delegates to the mode active before entering plan (default = `default`); additionally allows writing session plan files | Explore the code before deciding what to change |
|
|
16
|
+
| [`bypassPermissions`](#bypasspermissions-skip-all-checks) | All tools, without asking | Use only in sandbox containers / VMs / offline dev containers |
|
|
17
|
+
| [`delegate`](#delegate-multi-agent-coordination-mode) | Coordination tools only (such as Agent / TaskCreate / SendMessage / team management); implementation tools are blocked by the assembly layer | The main agent only decomposes and delegates work to subagents |
|
|
18
|
+
|
|
19
|
+
### Programmatic / Integration Modes (Not in the Shift+Tab Cycle)
|
|
20
|
+
|
|
21
|
+
| Mode | When it appears |
|
|
22
|
+
| :-------------- | :-------------------------------------------------------------------------------------------------------------------------------- |
|
|
23
|
+
| `fullAccess` | Passed by an ACP client (IDE integration) through the protocol; semantically equivalent to globally allowing everything like `bypassPermissions` (see `sandbox-orchestrator.ts:946`) |
|
|
24
|
+
| `work` | Passed by an ACP client. Read is allowed directly (without checking trusted directories), Edit always asks, Bash allows only safe commands directly, and other tools ask |
|
|
25
|
+
| `ignore` | Only takes effect for subagents / teammates. It means “use the main session’s mode; do not let the subagent’s own frontmatter override it”. Main sessions do not use it |
|
|
26
|
+
|
|
27
|
+
## Switching Permission Modes
|
|
28
|
+
|
|
29
|
+
You do not switch modes by telling CodeBuddy in chat. Set them through the following three entry points instead.
|
|
30
|
+
|
|
31
|
+
### Switch During a Session: Shift+Tab
|
|
32
|
+
|
|
33
|
+
In the CLI, press `Shift+Tab` to cycle through the following five modes (order defined in `input-hint-box.tsx:72`):
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
default → bypassPermissions → acceptEdits → plan → delegate → default → ...
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
After switching, the current mode is shown in the lower-left status bar:
|
|
40
|
+
|
|
41
|
+
| Mode | Status bar text | Color |
|
|
42
|
+
| :------------------- | :------------------------------------------- | :----------------------------------- |
|
|
43
|
+
| `default` | Not shown | — |
|
|
44
|
+
| `bypassPermissions` | `⏵⏵ bypass permissions on (shift+tab to cycle)` | warning |
|
|
45
|
+
| `acceptEdits` | `⏵⏵ accept edits on (shift+tab to cycle)` | info |
|
|
46
|
+
| `plan` | `⏸ plan mode on (shift+tab to cycle)` | planMode |
|
|
47
|
+
| `plan` + pre-mode | `⏸ plan + accept edits (shift+tab to cycle)` and similar | planMode |
|
|
48
|
+
| `delegate` | `⇢ delegate mode on (shift+tab to cycle)` | delegateMode |
|
|
49
|
+
|
|
50
|
+
### Specify at Startup: `--permission-mode`
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
codebuddy --permission-mode plan
|
|
54
|
+
codebuddy --permission-mode acceptEdits
|
|
55
|
+
codebuddy --permission-mode bypassPermissions
|
|
56
|
+
codebuddy --permission-mode default
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The CLI option `--permission-mode` accepts only these four literals (see `cli-provider.ts:36`). Other modes (`delegate` / `work` / `fullAccess` / `ignore`) cannot be passed on the command line.
|
|
60
|
+
|
|
61
|
+
It also works under `-p` ([headless mode](headless.md)):
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
codebuddy -p --permission-mode acceptEdits "refactor src/utils/foo.ts"
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
You can also add the following at startup:
|
|
68
|
+
|
|
69
|
+
- `-y` / `--dangerously-skip-permissions`: equivalent to `--permission-mode bypassPermissions`; skips all permission checks (see `cli-provider.ts:35`)
|
|
70
|
+
|
|
71
|
+
### Persistent Default: `defaultMode`
|
|
72
|
+
|
|
73
|
+
Write it to `~/.codebuddy/settings.json` or repository `.codebuddy/settings.json`:
|
|
74
|
+
|
|
75
|
+
```json
|
|
76
|
+
{
|
|
77
|
+
"permissions": {
|
|
78
|
+
"defaultMode": "acceptEdits"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
If `--permission-mode` is also provided at startup, the CLI argument takes precedence (see the fallback chain in `stream-json-view.ts:525`: `current session value → permissions.defaultMode → PermissionMode.Default`).
|
|
84
|
+
|
|
85
|
+
### Automatic Memory of the “Pre-Plan Mode”
|
|
86
|
+
|
|
87
|
+
When entering `plan`, CodeBuddy saves the current mode to `session.meta.prePlanPermissionMode` and restores it when leaving plan. This means:
|
|
88
|
+
|
|
89
|
+
- If you press `Shift+Tab` from `acceptEdits` into `plan`, the approval strategy for Read/Edit/Bash during plan still follows `acceptEdits` rules (except for the plan file, which never asks)
|
|
90
|
+
- When leaving plan, you return to `acceptEdits`; it will not be forcibly dropped to `default`
|
|
91
|
+
|
|
92
|
+
The implementation is `delegateToPrePlanStrategy` in `tool-permission-strategy.ts:92`.
|
|
93
|
+
|
|
94
|
+
## Detailed Semantics by Mode
|
|
95
|
+
|
|
96
|
+
### default (Default)
|
|
97
|
+
|
|
98
|
+
A step-by-step approval mode. This is the safe option for beginners and for sensitive work.
|
|
99
|
+
|
|
100
|
+
| Tool type | Decision |
|
|
101
|
+
| :-------- | :-------------------------------------------------------------------------------------------------- |
|
|
102
|
+
| Read | Path is inside a trusted directory (cwd + `permissions.additionalDirectories` + user-added `addDir`) → allow; otherwise ask |
|
|
103
|
+
| Edit | Always ask |
|
|
104
|
+
| Bash | Always ask |
|
|
105
|
+
| Other | Always ask |
|
|
106
|
+
|
|
107
|
+
### acceptEdits (Auto-Approve File Edits)
|
|
108
|
+
|
|
109
|
+
Suitable when you want to keep writing and review the diff later, without being interrupted by every Edit approval prompt.
|
|
110
|
+
|
|
111
|
+
| Tool type | Decision |
|
|
112
|
+
| :-------- | :-------------------------------------------------------------------------------------------------- |
|
|
113
|
+
| Read | Inside trusted directories → allow; otherwise ask |
|
|
114
|
+
| Edit | **Always allow** |
|
|
115
|
+
| Bash | Always ask |
|
|
116
|
+
| Other | Always ask |
|
|
117
|
+
|
|
118
|
+
Notes:
|
|
119
|
+
|
|
120
|
+
- Only **Edit-family tools** are auto-approved (Edit / Write / NotebookEdit, etc.). This does not affect Bash — Bash always follows a separate safety classification (`command-utils.ts::checkCommandSafety`)
|
|
121
|
+
- “Trusted directories” are based on the workspace root + user-configured `permissions.additionalDirectories` + startup `--add-dir` (see `permission-utils.ts:561`)
|
|
122
|
+
- Writes to [protected files](#protected-critical-files) still ask according to the original mode and do not use automatic allow
|
|
123
|
+
|
|
124
|
+
### plan (Explore Before Changing)
|
|
125
|
+
|
|
126
|
+
In plan mode, CodeBuddy focuses on reading code and running read-only Bash commands to investigate, writes the proposal as a plan, and then comes back for your approval. It does not apply changes to your source code.
|
|
127
|
+
|
|
128
|
+
See `tool-permission-strategy.ts:75` for the implementation idea — plan mode is not an independent “fully read-only block”; it **delegates to the pre-plan mode**:
|
|
129
|
+
|
|
130
|
+
- Read: delegates the decision to the pre-plan mode (default is `default`)
|
|
131
|
+
- Edit: first checks whether the target path is the current session’s **plan file** (`PlanStorageService.getPlanFilePath`) → if yes, allow; otherwise delegate to the pre-plan mode
|
|
132
|
+
- Bash: delegates to the pre-plan mode
|
|
133
|
+
- Enter plan through `Shift+Tab` or the `EnterPlanMode` tool; exit through another `Shift+Tab` or `ExitPlanMode` (see `enter-planmode-tool.ts:94` and `exit-planmode-tool.ts:73`)
|
|
134
|
+
|
|
135
|
+
Start directly in plan mode:
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
codebuddy --permission-mode plan
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### bypassPermissions (Skip All Checks)
|
|
142
|
+
|
|
143
|
+
Literally: **skip all approvals**. All Bash, Edit, network, and MCP operations execute immediately. Use only in the following scenarios:
|
|
144
|
+
|
|
145
|
+
- Isolated containers / VMs / dev containers
|
|
146
|
+
- Sandboxes with no external network access
|
|
147
|
+
- Scripted scenarios where you fully understand the consequences
|
|
148
|
+
|
|
149
|
+
Startup methods:
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
codebuddy --permission-mode bypassPermissions
|
|
153
|
+
# Equivalent
|
|
154
|
+
codebuddy -y
|
|
155
|
+
codebuddy --dangerously-skip-permissions
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
#### Disable Channel (Administrators)
|
|
159
|
+
|
|
160
|
+
Write `permissions.disableBypassPermissionsMode: "disable"` to settings at any layer:
|
|
161
|
+
|
|
162
|
+
```json
|
|
163
|
+
{
|
|
164
|
+
"permissions": {
|
|
165
|
+
"disableBypassPermissionsMode": "disable"
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
After this is written, even if the session switches to `bypassPermissions`, the permission strategy will **fall back to `default` decisions** (see `tool-permission-strategy.ts:192`). If any layer of settings disables it, it takes effect (user / project / local / cli flagSettings with any layer set to `"disable"`; see `tool-permission-service.ts:670`).
|
|
171
|
+
|
|
172
|
+
### delegate (Multi-Agent Coordination Mode)
|
|
173
|
+
|
|
174
|
+
In `delegate` mode, the main agent can **only coordinate**: assign tasks, start subagents, and communicate across members. It does not edit files or run commands itself.
|
|
175
|
+
|
|
176
|
+
Implementation idea:
|
|
177
|
+
|
|
178
|
+
- The assembly layer (tool-manager) removes “implementation tools” (Read/Write/Edit/Bash, etc.) from the main agent’s available tool set
|
|
179
|
+
- By the time execution reaches the `delegate` strategy layer (`tool-permission-strategy.ts:244`), only coordination tools remain (Agent / TaskCreate / SendMessage, etc.), and they are all allowed automatically
|
|
180
|
+
|
|
181
|
+
This is suitable when you explicitly want the main agent to “plan only, with specialized subagents doing the implementation” ([Agent Teams](agent-teams.md) / [Subagents](sub-agents.md)).
|
|
182
|
+
|
|
183
|
+
Press `Shift+Tab` until `delegate` appears to enter it.
|
|
184
|
+
|
|
185
|
+
### work (IDE Integration)
|
|
186
|
+
|
|
187
|
+
Set by the ACP client (IDE extension) through the protocol (see `acp-agent.ts:3407`), and not directly exposed to CLI users. Semantics:
|
|
188
|
+
|
|
189
|
+
| Tool type | Decision |
|
|
190
|
+
| :-------- | :---------------------------------------------------------------------------------- |
|
|
191
|
+
| Read | **Allow directly** (does not check trusted directories) |
|
|
192
|
+
| Edit | Always ask |
|
|
193
|
+
| Bash | Safe commands (marked by `checkCommandSafety` as `isSafe && !requiresApproval`) are allowed; others ask |
|
|
194
|
+
| Other | Allow |
|
|
195
|
+
|
|
196
|
+
### fullAccess (IDE Integration)
|
|
197
|
+
|
|
198
|
+
Only passed through the ACP protocol; same semantics as `bypassPermissions` (the sandbox orchestrator short-circuits it together with `BypassPermissions`, see `sandbox-orchestrator.ts:946`).
|
|
199
|
+
|
|
200
|
+
### ignore (Subagent Only)
|
|
201
|
+
|
|
202
|
+
Only used by subagent frontmatter / options. When a subagent writes `permissionMode: ignore` in its metadata, agent-task assembly treats it as “do not override the parent agent’s mode” and continues using the parent session’s current mode (see `agent-task.ts:1009`). This value does not appear in main sessions.
|
|
203
|
+
|
|
204
|
+
## Protected Critical Files
|
|
205
|
+
|
|
206
|
+
Write operations to the following paths retain special handling even under `acceptEdits` / `bypassPermissions` (aligned with cc):
|
|
207
|
+
|
|
208
|
+
- Repository itself: `.git`, `.gitconfig`, `.gitmodules`
|
|
209
|
+
- Shell config: `.bashrc` / `.bash_profile` / `.zshrc` / `.zprofile` / `.envrc`, etc.
|
|
210
|
+
- Package management: `.npmrc` / `.yarnrc` / `.pnpmfile.cjs` / `bunfig.toml`, etc.
|
|
211
|
+
- IDE / tools: `.vscode` / `.idea` / `.husky` / `.devcontainer` / `.cargo` / `.yarn` / `.mvn`
|
|
212
|
+
- CodeBuddy itself: `.codebuddy` (except `.codebuddy/worktrees`)
|
|
213
|
+
- MCP / config: `.mcp.json` / `.codebuddy.json`
|
|
214
|
+
|
|
215
|
+
The exact list and decision logic are defined by `tool-permission-service.ts`.
|
|
216
|
+
|
|
217
|
+
## Permission Mode Inheritance for Subagents
|
|
218
|
+
|
|
219
|
+
Subagents ([Agent](sub-agents.md) tool calls and [Agent Teams](agent-teams.md) members) inherit the main session’s permission mode by default. To force an override at the team / project layer:
|
|
220
|
+
|
|
221
|
+
```json
|
|
222
|
+
{
|
|
223
|
+
"permissions": {
|
|
224
|
+
"subagentPermissionMode": "bypassPermissions"
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
After this is written, all subagents run under `bypassPermissions` (implementation priority chain in `agent-task.ts:1009`). Notes:
|
|
230
|
+
|
|
231
|
+
- Passing the `mode` parameter explicitly in an Agent tool call → **highest priority**, overrides this setting
|
|
232
|
+
- Writing `permissionMode: ignore` in subagent frontmatter → still runs under the main session mode (not affected by this setting)
|
|
233
|
+
|
|
234
|
+
## Working with Permission Rules
|
|
235
|
+
|
|
236
|
+
Permission modes define the “baseline”. You can layer additional rules under `permissions` in `~/.codebuddy/settings.json` or repository `.codebuddy/settings.json`:
|
|
237
|
+
|
|
238
|
+
```json
|
|
239
|
+
{
|
|
240
|
+
"permissions": {
|
|
241
|
+
"defaultMode": "default",
|
|
242
|
+
"allow": ["Bash(npm test)", "Read(/etc/hosts)"],
|
|
243
|
+
"ask": ["WebFetch"],
|
|
244
|
+
"deny": ["Bash(rm -rf *)", "Edit(.git/**)"]
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
- The `allow` / `ask` / `deny` layers have higher priority than mode decisions (except that `bypassPermissions` skips the entire permission layer)
|
|
250
|
+
- For detailed rule syntax, see [Settings](settings.md), [Security](security.md), and [IAM](iam.md)
|
|
251
|
+
|
|
252
|
+
## Related Resources
|
|
253
|
+
|
|
254
|
+
- [Agent Teams: Multi-Agent Collaboration](agent-teams.md): let the main agent focus on coordination in `delegate` mode
|
|
255
|
+
- [Subagents](sub-agents.md): subagent tools and permission mode inheritance
|
|
256
|
+
- [Hooks](hooks-guide.md): use `PreToolUse` hooks for custom allow / block behavior
|
|
257
|
+
- [Bash sandboxing](bash-sandboxing.md): add filesystem / network isolation at the Bash command layer
|
|
258
|
+
- [Settings](settings.md): complete fields for permission rules, trusted directories, `disableBypassPermissionsMode`, and more
|
|
259
|
+
- [CLI reference](cli-reference.md): startup parameters such as `--permission-mode` / `-y` / `--add-dir`
|
|
260
|
+
- [Headless mode](headless.md): use permission modes under the `-p` flow
|