@oh-my-dsh/dsh-better-subagent 0.5.1 → 0.5.3
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/README.md +5 -5
- package/docs/DEVELOPMENT.md +10 -7
- package/package.json +16 -16
- package/src/child-exit-guard.js +3 -1
- package/src/client.js +10 -0
- package/src/config.js +17 -5
- package/src/prompt.js +8 -16
- package/src/subagents.js +19 -15
- package/src/wait-subagent.js +39 -15
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
<p align="center">
|
|
13
13
|
<a href="https://www.npmjs.com/package/@oh-my-dsh/dsh-better-subagent"><img src="https://img.shields.io/npm/v/%40oh-my-dsh%2Fdsh-better-subagent.svg" alt="npm 版本"></a>
|
|
14
14
|
<a href="LICENSE"><img alt="Apache-2.0" src="https://img.shields.io/github/license/omdsh-dev/dsh-better-subagent?color=blue"></a>
|
|
15
|
-
<a href="package.json"><img alt="DSH 0.2.2-rc.
|
|
15
|
+
<a href="package.json"><img alt="DSH 0.2.2-rc.2" src="https://img.shields.io/badge/DSH-0.2.2--rc.2-4B32C3"></a>
|
|
16
16
|
<a href="https://github.com/omdsh-dev/dsh-better-dsh"><img alt="Part of Better DSH" src="https://img.shields.io/badge/part%20of-dsh--better--dsh-2F80B7"></a>
|
|
17
17
|
</p>
|
|
18
18
|
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
|
|
43
43
|
```sh
|
|
44
44
|
# 只安装这个插件
|
|
45
|
-
dsh plugin --profile <profile> add @oh-my-dsh/dsh-better-subagent@0.5.
|
|
45
|
+
dsh plugin --profile <profile> add @oh-my-dsh/dsh-better-subagent@0.5.3
|
|
46
46
|
|
|
47
47
|
# 或安装 Better DSH(会自动带上所有独立插件)
|
|
48
|
-
dsh plugin --profile <profile> add dsh-better-dsh@0.10.
|
|
48
|
+
dsh plugin --profile <profile> add dsh-better-dsh@0.10.1
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
> 安装 / 升级 / 换包后必须重启对应 profile;只刷新网页不够。
|
|
@@ -56,8 +56,8 @@ dsh plugin --profile <profile> add dsh-better-dsh@0.10.0
|
|
|
56
56
|
|---|---|
|
|
57
57
|
| 稳定行 id | `dsh-better-subagent` |
|
|
58
58
|
| 入口 / 工具 | `wait_subagent` · `/better-subagent/api/*` · 子代理设置页 |
|
|
59
|
-
| 设置 | `childExitGuard`、`tiers.*`、两个 CLI 后端、`trustedHosts` |
|
|
60
|
-
| npm 包 | `@oh-my-dsh/dsh-better-subagent@0.5.
|
|
59
|
+
| 设置 | `childExitGuard`、`delegation.prompt`、`tiers.*`、两个 CLI 后端、`trustedHosts` |
|
|
60
|
+
| npm 包 | `@oh-my-dsh/dsh-better-subagent@0.5.3` |
|
|
61
61
|
| 仓库 | https://github.com/omdsh-dev/dsh-better-subagent |
|
|
62
62
|
|
|
63
63
|
## 设置
|
package/docs/DEVELOPMENT.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
- 纯 ESM、无构建步骤;宿主入口 `src/index.js`,浏览器入口 `src/client.js`。
|
|
8
8
|
- `package.json` 的 `dsh.bundle.patch` 指向 `cordis.patch.yml`;`dsh.client.platform = "web"`。
|
|
9
9
|
- `files` 白名单:`src`、`docs`、`cordis.patch.yml`、`README.md`、`LICENSE`、`third-party`。测试、脚本、设计 Spec、凭据、临时 profile 都不进发布包。
|
|
10
|
-
- 依赖:运行时只直接 import `@deepseek-ai/schemastery`;其余 DSH 包是精确 peer(`0.2.2-rc.
|
|
10
|
+
- 依赖:运行时只直接 import `@deepseek-ai/schemastery`;其余 DSH 包是精确 peer(`0.2.2-rc.2`),由宿主运行环境提供,服务全部经 `ctx` 获取。
|
|
11
11
|
- 浏览器半边只 `require('react')`,不 import 任何 DSH client 包;样式全部使用宿主主题 token(`--dsw-alias-*`),不写 DOM。
|
|
12
12
|
|
|
13
13
|
## 2. 宿主行与配置
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
|
|
23
23
|
- 行 `name` 必须是 scoped npm 名:Loader 把它当模块 specifier 解析,`dsh-client-modules` 还要求 manifest 的 `name` 与行完全一致才能发现 `./client`。
|
|
24
24
|
- 不允许再插入 agent preset 行;本插件不提供 preset。
|
|
25
|
-
- 行 `Config` 在 `src/config.js`,由 `src/index.js` 重新导出。全部字段 volatile:`childExitGuard`、`tiers.fast/quality`、`subagents.eng/global`、`subagents.codex.*`、`subagents.claude.*`、`trustedHosts`(信任边界按请求重读活配置,保存即生效不重挂)。
|
|
25
|
+
- 行 `Config` 在 `src/config.js`,由 `src/index.js` 重新导出。全部字段 volatile:`childExitGuard`、`delegation.prompt`、`tiers.fast/quality`、`subagents.eng/global`、`subagents.codex.*`、`subagents.claude.*`、`trustedHosts`(信任边界按请求重读活配置,保存即生效不重挂)。
|
|
26
|
+
- `delegation.prompt`(默认 `true`)只决定 `better-subagent:delegation` 提示词段是否渲染,**对所有预设生效**;`subagents.eng/global` 只管 CLI 后端路由与 CLI 目录段。两者互不影响:把 CLI 范围全关掉,委派纪律照样渲染。
|
|
26
27
|
- `normalizeConfig` 会把任意来源(volatile 引用、旧 JSON、残缺对象)规整成精确默认形状;非法值回退默认、绝不抛错。`currentConfig(ctx, fallback)` 经 `configEditor` 找**活**行配置;找不到时回退 `fallback`。
|
|
27
28
|
- **命名**:S1 Spec 的 unscoped 名 `dsh-better-subagent` 已被他人占用,现使用 scoped 包名 `@oh-my-dsh/dsh-better-subagent`;行 id 仍是 `dsh-better-subagent`,行 name 与 client closure id 必须是 scoped 包名,短键 `dsh-better-subagent#dsh-better-subagent` 只作兼容别名保留。旧 `@menghuan1918/dsh-better-subagent` 作为 legacy 键保留。
|
|
28
29
|
- 行配置键(浏览器半边 `plugins.row.config`)六份,全部指向同一行:
|
|
@@ -49,13 +50,13 @@
|
|
|
49
50
|
|
|
50
51
|
## 4. CLI 桥(`src/subagents.js` + `src/cli-adapter.js` + `src/cli/*`)
|
|
51
52
|
|
|
52
|
-
- 不注册第二个 spawn/fork registry;CLI 子代理仍是原生 `subagents.startActivation({provider:'spawn', childId, ...})`,只是 `agentOptions.provider` 是内部 synthetic route。
|
|
53
|
+
- 不注册第二个 spawn/fork registry;CLI 子代理仍是原生 `subagents.startActivation({provider:'spawn', childId, parent, prompt, ...})`,只是 `agentOptions.provider` 是内部 synthetic route。rc.2 的 spec 是扁平对象,返回 `{childId, name}`;工具结果只回传 `{kind:'activation', name}`。
|
|
53
54
|
- 内部 route 历史固定为 `apollo-cli-codex` / `apollo-cli-claude`;不要为新包名重命名,否则旧会话不可续接。
|
|
54
55
|
- 拦截点:
|
|
55
56
|
- `ctx.tools.guard`:内部 route 保留、禁用范围明确拒绝、fork 拒绝;
|
|
56
57
|
- `ctx.tools.execute`:`subagent` + `provider=codex|claude` 短路创建;`list_subagent_models` 合并 CLI 目录;
|
|
57
58
|
- `ctx.on('tools/result')`:未被调用方接受的 child 回收(drain + 删 KV)。
|
|
58
|
-
- 创建流程:模型/effort 白名单校验 → 父当前目录解析(`workingDirectory.ensure`)→ `resolveExecutable` 预检 → `<executable> --version` 版本预检(`src/cli/version.js`:Codex 基线 `0.162.1`,Claude 基线 `2.1.300`;无法执行/无法识别/过旧都给出点名可执行文件与安装/升级方式的可操作错误)→ 先落 KV 再 `startActivation` →
|
|
59
|
+
- 创建流程:模型/effort 白名单校验 → 父当前目录解析(`workingDirectory.ensure`)→ `resolveExecutable` 预检 → `<executable> --version` 版本预检(`src/cli/version.js`:Codex 基线 `0.162.1`,Claude 基线 `2.1.300`;无法执行/无法识别/过旧都给出点名可执行文件与安装/升级方式的可操作错误)→ 先落 KV 再 `startActivation` → 已发布 activation 在失败/取消时 `dispose()`,再删记录;预发布失败由 rc.2 manager 回滚。`ctx.cliVersionProbe` 是测试 seam;真实运行时用 `execFile`,无 shell。
|
|
59
60
|
- 每个 adapter:一轮一个子进程;`delivered` 在 spawn 前落 KV;`remoteId` 第一行事件即落盘;`parse` 失败/非零退出/缺完成标志都抛错且不自动重试;`dispose()` 等待进程句柄退出。没有 `subprocess` 服务或 spawn 未发布时回滚 `started/delivered`。
|
|
60
61
|
- 身份 KV(`src/cli-sessions.js`):命名空间前缀 `apollo_cli_` + `sha256(profile.dir)[:16]`,version 1,`sessions` 表,`per-record`。**包名变化不重命名/复制/清空**。
|
|
61
62
|
- 权限/模型/effort 与父子归属在启动前失败;缺 CLI 或版本不兼容给可操作诊断,不回退到另一后端。
|
|
@@ -64,6 +65,8 @@
|
|
|
64
65
|
|
|
65
66
|
旧实现的缺陷:`settled` 只按 childId 缓存 `subagent/end`,当同一 child 被续接(新 activation 或 resident 新回合)时会把旧 end 当成本轮完成。
|
|
66
67
|
|
|
68
|
+
参数先经 `ctx.subagents.resolveName(parent, ref, signal)` 解析:rc.2 的 `list_agents` 和原生 `subagent` 结果都以树内名字为句柄,单个无法匹配的 token 仍按 durable id 处理。解析后再校验是否为当前 Agent 的直接子代理,输出行回显调用方给的名字。
|
|
69
|
+
|
|
67
70
|
现实现只依据宿主可证明的事实:
|
|
68
71
|
|
|
69
72
|
1. 监听 `subagent/start` / `subagent/end`,记录每个 child 最近的 activation `runId`;
|
|
@@ -84,7 +87,7 @@
|
|
|
84
87
|
## 6. 子代理退出守卫(`src/child-exit-guard.js`)
|
|
85
88
|
|
|
86
89
|
- 只由 volatile `childExitGuard`(默认 false)控制;
|
|
87
|
-
- 只听 `agent/turn-stopping`,只收集 `subagents.
|
|
90
|
+
- 只听 `agent/turn-stopping`,只收集 `subagents.listDescendants(agent.id)` 中 `depth === 1` 且 **live status === running** 的直接子代理;
|
|
88
91
|
- 只做一次 `agent.steer(buildChildGuardMessage(children))`;
|
|
89
92
|
- 查询/注入异常 → 告警并放行(fail open);`payload.signal.aborted` 直接返回;
|
|
90
93
|
- 不看 jobs、不 import Apollo、不扩大权限。
|
|
@@ -95,7 +98,7 @@
|
|
|
95
98
|
|
|
96
99
|
| 名称 | order | 出现条件 | 内容 |
|
|
97
100
|
|---|---|---|---|
|
|
98
|
-
| `better-subagent:delegation` | 60 | `
|
|
101
|
+
| `better-subagent:delegation` | 60 | `delegation.prompt` | 委派纪律(含等待纪律)+ fast/quality 分档;preset 以 `ptc` 结尾时追加 run_code fanout 规则 |
|
|
99
102
|
| `better-subagent:child-guard` | 70 | `childExitGuard` | 运行中子代理退出守卫措辞 |
|
|
100
103
|
| `better-subagent:cli-subagents` | 80 | 路由范围 + 至少一个后端 enabled | 旧 CLI 目录内容(provider、后台、send_message/wait_subagent/list_agents/interrupt_agent、模型/effort 目录) |
|
|
101
104
|
|
|
@@ -115,7 +118,7 @@ preset 解析优先 `agentPresets.composedPreset(agent.ctx)`,回退 `sessionPr
|
|
|
115
118
|
- 使用 `form.state`(`{status, value, revision, writable, mode}`)与 `form.mutate(ops, revision)`;只在保存时提交与宿主快照的差异 `set` ops。
|
|
116
119
|
- 可写字段只包含 volatile 路径;`writable === false` / `mode === 'memory'` 禁用配置写入控件,保留页签导航与只读探测刷新;冲突(mutate 返回 false)回退宿主值并提示;异常保留草稿。
|
|
117
120
|
- 六份 `plugins.row.config` 键注册同一个组件;locale 命名空间 `better-subagent`(zh/en 字典键一致)。
|
|
118
|
-
- 表单分为概览、CLI(Codex / Claude)、模型分档、连接;覆盖 scope(eng/global)、fast/quality(路由 + effort)、两个后端(enabled/executable/profile/permission/defaultModel/models + 自动发现)、childExitGuard 与 trustedHosts。页签支持方向键 / Home / End,切换保留草稿和未输入完的 effort 文本。说明使用标签旁的原生信息折叠控件,保留 aria-describedby 与控件关联。
|
|
121
|
+
- 表单分为概览、CLI(Codex / Claude)、模型分档、连接;覆盖 scope(eng/global)、fast/quality(路由 + effort)、两个后端(enabled/executable/profile/permission/defaultModel/models + 自动发现)、delegationPrompt、childExitGuard 与 trustedHosts。页签支持方向键 / Home / End,切换保留草稿和未输入完的 effort 文本。说明使用标签旁的原生信息折叠控件,保留 aria-describedby 与控件关联。
|
|
119
122
|
- 依赖:重命名默认模型会同步默认选择,删除时清空;effort 列表变更会清空失效默认 effort。后端停用时仍可提前编辑配置;scope 全关闭时提示路由不可见。未保存 executable / profile 时禁用模型发现,保存 revision 变更后重读探针;请求期间路径 / profile 改变、放弃改动或 revision 更新都会丢弃旧目录。失效请求会结束自己的加载状态,旧请求不会覆盖新一次发现的状态。
|
|
120
123
|
- 校验:模型 id 非空且唯一;启用的后端必须有模型、默认模型与默认 effort;白名单读到时已存分档路由必须在白名单内,已选 effort 必须属于模型提供的候选列表;trustedHosts 接受不含协议和路径的主机名或 host:port。已存但不在候选中的值保留并标注,不静默改值。分档本身只是提示词建议,实际子代理路由仍由宿主模型选择策略决定。
|
|
121
124
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oh-my-dsh/dsh-better-subagent",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.3",
|
|
4
4
|
"description": "Standalone DSH plugin: Codex/Claude continuable CLI subagents, wait_subagent, child exit guard and model tiers. Pure ESM, no build step.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"engines": {
|
|
18
18
|
"node": ">=24.9.0",
|
|
19
|
-
"dsh": "0.2.2-rc.
|
|
19
|
+
"dsh": "0.2.2-rc.2"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
22
|
"test": "node --test",
|
|
@@ -46,23 +46,23 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@deepseek-ai/schemastery": "~3.19.0",
|
|
49
|
-
"dsh-better-ptc": "0.2.
|
|
49
|
+
"dsh-better-ptc": "0.2.1"
|
|
50
50
|
},
|
|
51
51
|
"peerDependencies": {
|
|
52
52
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
53
|
-
"@deepseek-ai/dsh-agent": "0.2.2-rc.
|
|
54
|
-
"@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.
|
|
55
|
-
"@deepseek-ai/dsh-llm": "0.2.2-rc.
|
|
56
|
-
"@deepseek-ai/dsh-session": "0.2.2-rc.
|
|
57
|
-
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.
|
|
58
|
-
"@deepseek-ai/dsh-session-query": "0.2.2-rc.
|
|
59
|
-
"@deepseek-ai/dsh-storage": "0.2.2-rc.
|
|
60
|
-
"@deepseek-ai/dsh-storage-json": "0.2.2-rc.
|
|
61
|
-
"@deepseek-ai/dsh-subagent": "0.2.2-rc.
|
|
62
|
-
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.
|
|
63
|
-
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.
|
|
64
|
-
"@deepseek-ai/dsh-tools": "0.2.2-rc.
|
|
65
|
-
"@deepseek-ai/dsh-working-directory": "0.2.2-rc.
|
|
53
|
+
"@deepseek-ai/dsh-agent": "0.2.2-rc.2",
|
|
54
|
+
"@deepseek-ai/dsh-agent-preset-registry": "0.2.2-rc.2",
|
|
55
|
+
"@deepseek-ai/dsh-llm": "0.2.2-rc.2",
|
|
56
|
+
"@deepseek-ai/dsh-session": "0.2.2-rc.2",
|
|
57
|
+
"@deepseek-ai/dsh-session-projection": "0.2.2-rc.2",
|
|
58
|
+
"@deepseek-ai/dsh-session-query": "0.2.2-rc.2",
|
|
59
|
+
"@deepseek-ai/dsh-storage": "0.2.2-rc.2",
|
|
60
|
+
"@deepseek-ai/dsh-storage-json": "0.2.2-rc.2",
|
|
61
|
+
"@deepseek-ai/dsh-subagent": "0.2.2-rc.2",
|
|
62
|
+
"@deepseek-ai/dsh-subprocess": "0.2.2-rc.2",
|
|
63
|
+
"@deepseek-ai/dsh-system-prompt": "0.2.2-rc.2",
|
|
64
|
+
"@deepseek-ai/dsh-tools": "0.2.2-rc.2",
|
|
65
|
+
"@deepseek-ai/dsh-working-directory": "0.2.2-rc.2",
|
|
66
66
|
"react": "^18.2.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
package/src/child-exit-guard.js
CHANGED
|
@@ -62,7 +62,9 @@ export function buildChildGuardMessage(children) {
|
|
|
62
62
|
*/
|
|
63
63
|
export async function collectRunningChildren(ctx, agent) {
|
|
64
64
|
const running = []
|
|
65
|
-
|
|
65
|
+
// rc.2 removed listChildren; depth-one descendants are this Agent's direct
|
|
66
|
+
// children in the same stable catalog order.
|
|
67
|
+
for (const entry of (await ctx.subagents.listDescendants(agent.id)).filter((candidate) => candidate.depth === 1)) {
|
|
66
68
|
if (ctx.agents.get(entry.id)?.status === 'running') running.push(entry)
|
|
67
69
|
}
|
|
68
70
|
return running
|
package/src/client.js
CHANGED
|
@@ -137,6 +137,8 @@ window.__ModuleLoader__.load({
|
|
|
137
137
|
readonly: "当前连接仅供查看,无法保存设置。",
|
|
138
138
|
childExitGuardLabel: "等待子代理完成",
|
|
139
139
|
childExitGuardHint: "子代理仍在运行时继续等待;按 Esc 仍可中断。",
|
|
140
|
+
delegationPromptLabel: "委派提示词",
|
|
141
|
+
delegationPromptHint: "把委派纪律与模型分档写进系统提示词,对所有预设生效;与 CLI 接入范围无关。",
|
|
140
142
|
tiersTitle: "子代理模型选择",
|
|
141
143
|
tiersIntro: "为工程预设推荐子代理模型;实际调用仍需符合允许使用的模型范围。",
|
|
142
144
|
tierFast: '快速档',
|
|
@@ -298,6 +300,8 @@ window.__ModuleLoader__.load({
|
|
|
298
300
|
readonly: "This connection is view-only. Settings cannot be saved.",
|
|
299
301
|
childExitGuardLabel: "Wait for subagents to finish",
|
|
300
302
|
childExitGuardHint: "Keep waiting while subagents run. You can still interrupt with Esc.",
|
|
303
|
+
delegationPromptLabel: "Delegation prompt",
|
|
304
|
+
delegationPromptHint: "Adds the delegation rules and model tiers to the system prompt for every preset; independent of the CLI scope.",
|
|
301
305
|
tiersTitle: "Subagent model selection",
|
|
302
306
|
tiersIntro: "Recommend subagent models in engineering presets; calls must still use a permitted model.",
|
|
303
307
|
tierFast: 'Fast tier',
|
|
@@ -603,6 +607,7 @@ window.__ModuleLoader__.load({
|
|
|
603
607
|
const tiers = isRecord(source.tiers) ? source.tiers : {};
|
|
604
608
|
const result = {
|
|
605
609
|
childExitGuard: source.childExitGuard === true,
|
|
610
|
+
delegationPrompt: !isRecord(source.delegation) || source.delegation.prompt !== false,
|
|
606
611
|
trustedHosts: Array.isArray(source.trustedHosts) ? [...new Set(source.trustedHosts.filter((item) => typeof item === 'string').map((item) => item.trim()).filter(Boolean))] : [],
|
|
607
612
|
tiers: {},
|
|
608
613
|
subagents: {
|
|
@@ -635,6 +640,9 @@ window.__ModuleLoader__.load({
|
|
|
635
640
|
if (host.childExitGuard !== current.childExitGuard) {
|
|
636
641
|
ops.push({ op: 'set', path: ['childExitGuard'], value: current.childExitGuard });
|
|
637
642
|
}
|
|
643
|
+
if (host.delegationPrompt !== current.delegationPrompt) {
|
|
644
|
+
ops.push({ op: 'set', path: ['delegation', 'prompt'], value: current.delegationPrompt });
|
|
645
|
+
}
|
|
638
646
|
for (const tier of TIERS) {
|
|
639
647
|
if (JSON.stringify(host.tiers[tier]) === JSON.stringify(current.tiers[tier])) continue;
|
|
640
648
|
ops.push({ op: 'set', path: ['tiers', tier], value: tierShape(current.tiers[tier]) });
|
|
@@ -1462,6 +1470,8 @@ window.__ModuleLoader__.load({
|
|
|
1462
1470
|
!scopeActive ? h('p', { className: 'bs-note', 'data-tone': 'warn' }, translate('scopeNone')) : null),
|
|
1463
1471
|
h('section', { className: 'bs-section' },
|
|
1464
1472
|
h('div', { className: 'bs-sectionHead' }, h('h3', { className: 'bs-sectionTitle' }, translate('behaviorTitle'))),
|
|
1473
|
+
h(SwitchRow, { id: 'bs-delegation-prompt', label: translate('delegationPromptLabel'), hint: translate('delegationPromptHint'),
|
|
1474
|
+
checked: live.delegationPrompt, disabled: !writable || busy, onChange: (delegationPrompt) => edit((current) => ({ ...current, delegationPrompt })) }),
|
|
1465
1475
|
h(SwitchRow, { id: 'bs-child-exit-guard', label: translate('childExitGuardLabel'), hint: translate('childExitGuardHint'),
|
|
1466
1476
|
checked: live.childExitGuard, disabled: !writable || busy, onChange: (childExitGuard) => edit((current) => ({ ...current, childExitGuard })) })),
|
|
1467
1477
|
h('section', { className: 'bs-section', 'aria-label': translate('readonlyDiagnostics') },
|
package/src/config.js
CHANGED
|
@@ -14,8 +14,13 @@
|
|
|
14
14
|
* `src/panel.js`),改完即时生效、不重挂。
|
|
15
15
|
*
|
|
16
16
|
* 可编辑范围(volatile,即 dsh-settings 投影出的行配置表单字段):
|
|
17
|
-
* `childExitGuard`、`tiers.fast`、`tiers.quality
|
|
18
|
-
* `subagents.global`、`subagents.codex.*`、`subagents.claude
|
|
17
|
+
* `childExitGuard`、`delegation.prompt`、`tiers.fast`、`tiers.quality`、
|
|
18
|
+
* `subagents.eng`、`subagents.global`、`subagents.codex.*`、`subagents.claude.*`、
|
|
19
|
+
* `trustedHosts`。
|
|
20
|
+
*
|
|
21
|
+
* `delegation.prompt` 只决定 `better-subagent:delegation` 提示词段是否渲染(默认
|
|
22
|
+
* 开启、对所有预设生效);`subagents.eng/global` 只管 CLI 后端路由与 CLI 目录段,
|
|
23
|
+
* 两者互不影响。
|
|
19
24
|
* 表单写入只能落在 volatile 路径上(dsh-settings 会拒绝其他路径)。
|
|
20
25
|
*
|
|
21
26
|
* 读取入口:
|
|
@@ -116,12 +121,17 @@ export const TIER_NAMES = Object.freeze(['fast', 'quality'])
|
|
|
116
121
|
/**
|
|
117
122
|
* 本插件行的正式配置 schema。
|
|
118
123
|
*
|
|
119
|
-
* `childExitGuard`、`subagents.{eng,global}
|
|
120
|
-
* `trustedHosts` 全部标 volatile(即时生效、不重挂):信任边界按请求重读活配置。
|
|
124
|
+
* `childExitGuard`、`delegation.prompt`、`subagents.{eng,global}`、
|
|
125
|
+
* `subagents.{codex,claude}`、`trustedHosts` 全部标 volatile(即时生效、不重挂):信任边界按请求重读活配置。
|
|
121
126
|
*/
|
|
122
127
|
export const Config = z.object({
|
|
123
128
|
/** 运行中子代理退出拦截总开关(默认关闭,显式开启才拦回合结束)。 */
|
|
124
129
|
childExitGuard: z.boolean().default(false).volatile(),
|
|
130
|
+
/** 委派提示词段(`better-subagent:delegation`);与 CLI 路由范围 `subagents.*` 无关。 */
|
|
131
|
+
delegation: z.object({
|
|
132
|
+
/** 是否把委派纪律与模型分档渲染进系统提示词(默认开启,对所有预设生效)。 */
|
|
133
|
+
prompt: z.boolean().default(true).volatile(),
|
|
134
|
+
}),
|
|
125
135
|
/** 子代理模型分档(工程模式提示词按此渲染;路由须在 allowedModels 白名单内)。 */
|
|
126
136
|
tiers: z.object({
|
|
127
137
|
fast: TierSchema,
|
|
@@ -248,15 +258,17 @@ function tierOf(value) {
|
|
|
248
258
|
* 输入可以是 `entry.fiber.config`(volatile 字段是引用对象)、旧 JSON 文档、
|
|
249
259
|
* 残缺对象或 `undefined`;返回值总是全新的、可安全改写的普通对象。
|
|
250
260
|
* @param config - 任意配置值。
|
|
251
|
-
* @returns `{ childExitGuard, tiers: { fast, quality }, subagents: { eng, global, codex, claude }, trustedHosts }`。
|
|
261
|
+
* @returns `{ childExitGuard, delegation: { prompt }, tiers: { fast, quality }, subagents: { eng, global, codex, claude }, trustedHosts }`。
|
|
252
262
|
*/
|
|
253
263
|
export function normalizeConfig(config) {
|
|
254
264
|
const projected = plain(config)
|
|
255
265
|
const source = isRecord(projected) ? projected : {}
|
|
256
266
|
const subagents = isRecord(source.subagents) ? source.subagents : {}
|
|
257
267
|
const tiers = isRecord(source.tiers) ? source.tiers : {}
|
|
268
|
+
const delegation = isRecord(source.delegation) ? source.delegation : {}
|
|
258
269
|
return {
|
|
259
270
|
childExitGuard: booleanOf(source.childExitGuard, false),
|
|
271
|
+
delegation: { prompt: booleanOf(delegation.prompt, true) },
|
|
260
272
|
tiers: { fast: tierOf(tiers.fast), quality: tierOf(tiers.quality) },
|
|
261
273
|
subagents: {
|
|
262
274
|
eng: booleanOf(subagents.eng, true),
|
package/src/prompt.js
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* with the session header/projection as fallback.
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
import { currentConfig
|
|
18
|
+
import { currentConfig } from './config.js'
|
|
19
19
|
import { enabledIn } from './cli-adapter.js'
|
|
20
20
|
import { cliCatalog } from './subagents.js'
|
|
21
21
|
|
|
@@ -28,9 +28,6 @@ export const DELEGATION_ORDER = 60
|
|
|
28
28
|
export const CHILD_GUARD_ORDER = 70
|
|
29
29
|
export const CLI_CATALOG_ORDER = 80
|
|
30
30
|
|
|
31
|
-
/** Presets that opt into the eng-scope subagent behavior. */
|
|
32
|
-
export const ENG_PRESETS = Object.freeze(['eng', 'eng-ptc'])
|
|
33
|
-
|
|
34
31
|
const DELEGATION_HEAD = `## Delegation
|
|
35
32
|
- Subagents cannot see this conversation: state the goal, write scope, deliverable, and verification, and give real file paths for prior outputs.
|
|
36
33
|
- Opening reconnaissance: when starting non-trivial work in an unfamiliar or large codebase, immediately dispatch fast-tier scouts in parallel (structure, relevant modules, conventions, test entry points), all in one message; the main agent reads only the instruction files that define the task. A scout prompt needs only goal, boundaries, and deliverable.
|
|
@@ -39,8 +36,9 @@ const DELEGATION_HEAD = `## Delegation
|
|
|
39
36
|
|
|
40
37
|
const FANOUT_PTC = '- For repeated same-shaped work, dispatch all subagents inside one run_code program, then collect them with wait_subagent.'
|
|
41
38
|
|
|
42
|
-
const DELEGATION_TAIL = `-
|
|
43
|
-
-
|
|
39
|
+
const DELEGATION_TAIL = `- Waiting for delegated subagents is done with wait_subagent only: do independent work first, then pass every subagent name (or durable id) you need to a single wait_subagent call and let it block. Do not end the turn to wait for a notification unless nothing else is left to do.
|
|
40
|
+
- list_agents shows the tree with names; send_message targets a name, and wait_subagent accepts the name returned by subagent.
|
|
41
|
+
- send_message is for new information or a correction, never for asking about progress, nudging, or checking in. Do not poll list_agents in place of waiting, and do not interrupt_agent a normally running subagent; intervene only for substantive new information, a clear failure or blockage, or a user request to stop.
|
|
44
42
|
- A wait_subagent timeout while a subagent is still running is not a failure: wait again or do independent work. Do not re-dispatch or take over solely because it is taking a long time.
|
|
45
43
|
- The main agent owns integration, review, and final verification. Subagent reports are leads, not evidence: check the actual changes yourself.
|
|
46
44
|
- When a subagent ends in an error or empty result, read why, fix the cause, and re-dispatch once; take over in the main thread only if it fails again without an external blocker, and say why.`
|
|
@@ -57,7 +55,8 @@ export function renderTier(tier) {
|
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
/**
|
|
60
|
-
* Render the delegation + model-tier section.
|
|
58
|
+
* Render the delegation + model-tier section. Scope gating (the
|
|
59
|
+
* `delegation.prompt` switch) happens in the caller, not here.
|
|
61
60
|
* @param config - normalized Better Subagent config (`tiers`).
|
|
62
61
|
* @param options - `{ ptc }` (true for the eng-ptc preset).
|
|
63
62
|
* @returns the section markdown; never empty (scope gating happens outside).
|
|
@@ -83,7 +82,7 @@ export function renderCliCatalog(config) {
|
|
|
83
82
|
return [
|
|
84
83
|
'Better Subagent CLI subagents: subagent also accepts provider="codex" or provider="claude"; model and reasoning_effort default to Better Subagent settings (list_subagent_models with that provider shows allowed values).',
|
|
85
84
|
'They always run in the background, start in cwd (default: current directory) with permissions from Better Subagent settings; subagent_fork and agent_preset are unsupported.',
|
|
86
|
-
'Control them
|
|
85
|
+
'Control them through list_agents names with send_message; wait_subagent accepts the name returned by subagent, and interrupt_agent is disabled in the engineering presets.',
|
|
87
86
|
catalog,
|
|
88
87
|
].join('\n')
|
|
89
88
|
}
|
|
@@ -110,13 +109,6 @@ export function presetOf(ctx, agent) {
|
|
|
110
109
|
return preset
|
|
111
110
|
}
|
|
112
111
|
|
|
113
|
-
/** Whether the preset participates in the subagent scope. */
|
|
114
|
-
export function scopeEnabled(config, agent, preset) {
|
|
115
|
-
if (normalizeConfig(config).subagents.global) return true
|
|
116
|
-
if (!normalizeConfig(config).subagents.eng) return false
|
|
117
|
-
return ENG_PRESETS.includes(preset)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
112
|
/**
|
|
121
113
|
* Register the per-agent prompt sections.
|
|
122
114
|
* @param ctx - context with systemPrompt + agents.
|
|
@@ -138,8 +130,8 @@ export function installPromptSections(ctx, config) {
|
|
|
138
130
|
interpolate: false,
|
|
139
131
|
text: () => {
|
|
140
132
|
const live = currentConfig(ctx, config)
|
|
133
|
+
if (!live.delegation.prompt) return ''
|
|
141
134
|
const preset = currentPreset()
|
|
142
|
-
if (!scopeEnabled(live, agent, preset)) return ''
|
|
143
135
|
return renderDelegation(live, { ptc: typeof preset === 'string' && preset.endsWith('ptc') })
|
|
144
136
|
},
|
|
145
137
|
})
|
package/src/subagents.js
CHANGED
|
@@ -122,24 +122,28 @@ export async function startCliSubagent(ctx, config, sessions, args, exec) {
|
|
|
122
122
|
model: selected.model, effort: selected.effort, delivered: [], started: false,
|
|
123
123
|
}
|
|
124
124
|
await sessions.put(record)
|
|
125
|
+
let created
|
|
125
126
|
try {
|
|
126
127
|
exec.signal.throwIfAborted()
|
|
127
128
|
const maxDepth = ctx.subagents.resolveMaxDepth()
|
|
128
|
-
|
|
129
|
+
created = await ctx.subagents.startActivation({
|
|
129
130
|
provider: 'spawn', label: args.description, childId: id, signal: exec.signal,
|
|
130
131
|
delivery: 'parent',
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
...(maxDepth === undefined ? {} : { maxDepth }),
|
|
135
|
-
},
|
|
132
|
+
parent, prompt: [{ type: 'text', text: args.prompt }], cwd,
|
|
133
|
+
agentOptions: { provider: CLI_ROUTES[cli], model: selected.model, reasoningEffort: selected.effort },
|
|
134
|
+
...(maxDepth === undefined ? {} : { maxDepth }),
|
|
136
135
|
})
|
|
137
136
|
exec.signal.throwIfAborted()
|
|
138
|
-
|
|
137
|
+
// rc.2's native subagent tool returns the tree name, not the durable id.
|
|
138
|
+
return { kind: 'activation', name: created.name ?? created.childId, childId: created.childId, activation: created }
|
|
139
139
|
} catch (error) {
|
|
140
|
-
//
|
|
141
|
-
//
|
|
142
|
-
|
|
140
|
+
// rc.2 rolls back pre-admission failures in the manager. A published
|
|
141
|
+
// activation still needs explicit disposal for the post-admission abort race.
|
|
142
|
+
if (created !== undefined) {
|
|
143
|
+
try { await created.dispose() } catch (disposeError) {
|
|
144
|
+
ctx.logger?.warn?.(`Better Subagent could not dispose canceled CLI child ${id}: ${disposeError.message}`)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
143
147
|
await sessions.delete(id)
|
|
144
148
|
throw error
|
|
145
149
|
}
|
|
@@ -154,8 +158,7 @@ export function installCliRouting(ctx, config, sessions) {
|
|
|
154
158
|
const reclaim = (entry) => {
|
|
155
159
|
if (entry.cleanup) return entry.cleanup
|
|
156
160
|
const task = (async () => {
|
|
157
|
-
await
|
|
158
|
-
await sessions.delete(entry.id)
|
|
161
|
+
try { await entry.activation?.dispose() } finally { await sessions.delete(entry.id) }
|
|
159
162
|
})()
|
|
160
163
|
entry.cleanup = task
|
|
161
164
|
cleanups.add(task)
|
|
@@ -168,7 +171,7 @@ export function installCliRouting(ctx, config, sessions) {
|
|
|
168
171
|
const entry = unpublished.get(key)
|
|
169
172
|
if (!entry) return
|
|
170
173
|
unpublished.delete(key)
|
|
171
|
-
if (!result.isError && result.value?.kind === 'activation' && result.value.
|
|
174
|
+
if (!result.isError && result.value?.kind === 'activation' && result.value.name === entry.name) return
|
|
172
175
|
void reclaim(entry)
|
|
173
176
|
})
|
|
174
177
|
ctx.tools.guard((exec) => {
|
|
@@ -191,8 +194,9 @@ export function installCliRouting(ctx, config, sessions) {
|
|
|
191
194
|
if (exec.name === 'subagent' && cliName(args.provider)) {
|
|
192
195
|
const signal = AbortSignal.any([exec.signal, lifetime.signal])
|
|
193
196
|
const creation = (async () => {
|
|
194
|
-
const
|
|
195
|
-
|
|
197
|
+
const created = await startCliSubagent(ctx, config, sessions, args, { ...exec, signal })
|
|
198
|
+
const { activation, childId, ...value } = created
|
|
199
|
+
unpublished.set(exec.token ?? exec, { parent: exec.agent, id: childId, name: value.name, activation })
|
|
196
200
|
return success(value)
|
|
197
201
|
})()
|
|
198
202
|
creating.add(creation)
|
package/src/wait-subagent.js
CHANGED
|
@@ -201,7 +201,7 @@ export function installWaitTool(ctx) {
|
|
|
201
201
|
type: 'array',
|
|
202
202
|
items: { type: 'string' },
|
|
203
203
|
minItems: 1,
|
|
204
|
-
description: '
|
|
204
|
+
description: 'Names returned by subagent/list_agents, or durable ids.',
|
|
205
205
|
},
|
|
206
206
|
timeout_ms: {
|
|
207
207
|
type: 'integer',
|
|
@@ -218,43 +218,67 @@ export function installWaitTool(ctx) {
|
|
|
218
218
|
async execute(args, exec) {
|
|
219
219
|
// Dedupe preserving input order; the schema already enforces a
|
|
220
220
|
// non-empty array, the guard below only covers malformed direct calls.
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
221
|
+
const refs = [...new Set(Array.isArray(args.subagent_id) ? args.subagent_id : [])]
|
|
222
|
+
if (refs.length === 0) return 'subagent_id must be a non-empty array of subagent names or ids.'
|
|
223
223
|
const parent = exec.agent
|
|
224
224
|
if (parent === undefined) throw new Error('wait_subagent requires a calling agent (exec.agent was undefined)')
|
|
225
225
|
|
|
226
|
-
// Verify every
|
|
227
|
-
// waiting for nobody (the contract the single-id version had).
|
|
226
|
+
// Verify every reference resolves to one of this agent's direct children —
|
|
227
|
+
// fail fast, waiting for nobody (the contract the single-id version had).
|
|
228
228
|
let entries
|
|
229
229
|
try {
|
|
230
|
-
|
|
230
|
+
// rc.2 removed listChildren; a depth-one slice of the descendant walk
|
|
231
|
+
// is the same direct-child catalog without loading child Agents.
|
|
232
|
+
entries = (await ctx.subagents.listDescendants(parent.id, exec.signal))
|
|
233
|
+
.filter((entry) => entry.depth === 1)
|
|
231
234
|
} catch (error) {
|
|
232
|
-
return '
|
|
235
|
+
return 'subagent listing failed: ' + (error && error.message ? error.message : String(error))
|
|
233
236
|
}
|
|
234
237
|
const known = new Set(entries.map((entry) => entry.id))
|
|
235
|
-
const
|
|
238
|
+
const resolved = []
|
|
239
|
+
const unknown = []
|
|
240
|
+
for (const ref of refs) {
|
|
241
|
+
let id
|
|
242
|
+
try {
|
|
243
|
+
// rc.2 names are the model-facing handles; a single token that is not
|
|
244
|
+
// a tree name is returned as a durable id, so both continue to work.
|
|
245
|
+
id = await ctx.subagents.resolveName(parent, ref, exec.signal)
|
|
246
|
+
} catch {
|
|
247
|
+
unknown.push(ref)
|
|
248
|
+
continue
|
|
249
|
+
}
|
|
250
|
+
if (!known.has(id)) {
|
|
251
|
+
unknown.push(ref)
|
|
252
|
+
continue
|
|
253
|
+
}
|
|
254
|
+
if (!resolved.some((entry) => entry.id === id)) resolved.push({ ref, id })
|
|
255
|
+
}
|
|
236
256
|
if (unknown.length > 0) {
|
|
237
|
-
return `unknown subagent ${unknown.map((
|
|
257
|
+
return `unknown subagent ${unknown.map((ref) => `"${ref}"`).join(', ')}: not a direct child of this agent (list_agents shows your children; only depth-1 children can be awaited).`
|
|
238
258
|
}
|
|
259
|
+
const ids = resolved.map((entry) => entry.id)
|
|
260
|
+
const labels = new Map(resolved.map((entry) => [entry.id, entry.ref]))
|
|
261
|
+
const displayOf = (id) => labels.get(id) ?? id
|
|
239
262
|
|
|
240
263
|
const startedAt = Date.now()
|
|
241
264
|
const capMs = typeof args.timeout_ms === 'number' && args.timeout_ms > 0 ? Math.max(args.timeout_ms, MIN_TIMEOUT_MS) : undefined
|
|
242
265
|
|
|
243
266
|
const lineOf = (id, outcome) => {
|
|
244
|
-
|
|
245
|
-
if (outcome.kind === '
|
|
267
|
+
const display = displayOf(id)
|
|
268
|
+
if (outcome.kind === 'aborted') return `wait for subagent ${display} was aborted by user interruption; the child may still be running.`
|
|
269
|
+
if (outcome.kind === 'timedOut') return `timed out waiting for subagent ${display}; it is still running. You will be notified when it finishes — you can wait_subagent it again or continue with other work.`
|
|
246
270
|
if (outcome.kind === 'notStarted') {
|
|
247
|
-
return `subagent ${
|
|
271
|
+
return `subagent ${display} has not started after ${Math.round(START_GRACE_MS / 1000)}s (status: ${statusOf(id)}). It may still be spinning up — call wait_subagent again, or continue with other work; you will be notified when it finishes.`
|
|
248
272
|
}
|
|
249
273
|
if (outcome.kind === 'unconfirmed') {
|
|
250
|
-
return `subagent ${
|
|
274
|
+
return `subagent ${display} is not running, but its current turn state could not be confirmed (session state unavailable). Call wait_subagent again, or inspect it with list_agents before continuing.`
|
|
251
275
|
}
|
|
252
276
|
if (outcome.kind === 'endedEarlier') {
|
|
253
|
-
return `subagent ${
|
|
277
|
+
return `subagent ${display} already finished its last turn (${outcome.reason?.kind ?? 'completed'}) and has no queued input; no new settlement was observed during this wait (its earlier notice was delivered before it). Use send_message to continue it if needed.`
|
|
254
278
|
}
|
|
255
279
|
// Real settlement: short done line; the framework's settlement notice
|
|
256
280
|
// carries the closing message — nothing to consume or deduplicate.
|
|
257
|
-
return DONE(
|
|
281
|
+
return DONE(display, outcome.info && outcome.info.stopReason)
|
|
258
282
|
}
|
|
259
283
|
|
|
260
284
|
/**
|