@ktkid/kmh-subagent-team 0.0.0-stage → 0.1.0
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 +38 -2
- package/cordis.patch.yml +4 -0
- package/lib/src/acp/client.d.ts +35 -0
- package/lib/src/acp/client.js +327 -0
- package/lib/src/acp/process.d.ts +15 -0
- package/lib/src/acp/process.js +102 -0
- package/lib/src/acp/protocol.d.ts +66 -0
- package/lib/src/acp/protocol.js +193 -0
- package/lib/src/adapters/agy.d.ts +2 -0
- package/lib/src/adapters/agy.js +99 -0
- package/lib/src/adapters/codex.d.ts +14 -0
- package/lib/src/adapters/codex.js +168 -0
- package/lib/src/adapters/grok.d.ts +2 -0
- package/lib/src/adapters/grok.js +147 -0
- package/lib/src/adapters/registry.d.ts +3 -0
- package/lib/src/adapters/registry.js +64 -0
- package/lib/src/adapters/types.d.ts +59 -0
- package/lib/src/adapters/types.js +141 -0
- package/lib/src/adapters/workbuddy-auth.d.ts +6 -0
- package/lib/src/adapters/workbuddy-auth.js +116 -0
- package/lib/src/adapters/workbuddy.d.ts +9 -0
- package/lib/src/adapters/workbuddy.js +179 -0
- package/lib/src/adapters/zcode.d.ts +51 -0
- package/lib/src/adapters/zcode.js +226 -0
- package/lib/src/config.d.ts +46 -0
- package/lib/src/config.js +82 -0
- package/lib/src/index.d.ts +10 -0
- package/lib/src/index.js +184 -0
- package/lib/src/prompt.d.ts +4 -0
- package/lib/src/prompt.js +30 -0
- package/lib/src/runtime/approval.d.ts +29 -0
- package/lib/src/runtime/approval.js +88 -0
- package/lib/src/runtime/manager.d.ts +65 -0
- package/lib/src/runtime/manager.js +270 -0
- package/package.json +56 -4
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { asRecord, nonEmptyString } from "../acp/protocol.js";
|
|
2
|
+
const ZCODE_LOGIN_HINT = "请在 KMH 设置中登录 ZCode CLI(GLM 账号),或确认 @kmh/zcode-cli 插件已启用。";
|
|
3
|
+
/** 探测宿主中 zcode-cli 的可用模型与就绪状态。 */
|
|
4
|
+
export async function probeZcodeHost(ctx, member) {
|
|
5
|
+
const llm = ctx.get("llm");
|
|
6
|
+
const subagents = ctx.get("subagents");
|
|
7
|
+
if (llm?.listModels === undefined || subagents?.startActivation === undefined) {
|
|
8
|
+
return {
|
|
9
|
+
id: member.id,
|
|
10
|
+
name: member.name,
|
|
11
|
+
adapter: member.adapter,
|
|
12
|
+
status: "not-installed",
|
|
13
|
+
detail: "当前宿主未加载 @kmh/zcode-cli 或 DSH subagents 服务。",
|
|
14
|
+
loginHint: ZCODE_LOGIN_HINT,
|
|
15
|
+
models: [],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const rawModels = await llm.listModels("zcode-cli");
|
|
20
|
+
const models = rawModels.map((m) => ({
|
|
21
|
+
id: m.id,
|
|
22
|
+
name: m.name ?? m.id,
|
|
23
|
+
}));
|
|
24
|
+
if (models.length === 0) {
|
|
25
|
+
return {
|
|
26
|
+
id: member.id,
|
|
27
|
+
name: member.name,
|
|
28
|
+
adapter: member.adapter,
|
|
29
|
+
status: "not-logged-in",
|
|
30
|
+
detail: "zcode-cli 当前未返回可用模型,可能尚未完成登录。",
|
|
31
|
+
loginHint: ZCODE_LOGIN_HINT,
|
|
32
|
+
models: [],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
const preferredDefault = models.find((m) => m.id.toLowerCase().includes("flash"))?.id ??
|
|
36
|
+
models[0]?.id;
|
|
37
|
+
return {
|
|
38
|
+
id: member.id,
|
|
39
|
+
name: member.name,
|
|
40
|
+
adapter: member.adapter,
|
|
41
|
+
status: "ready",
|
|
42
|
+
detail: `已就绪(复用宿主 zcode-cli),发现 ${String(models.length)} 个可用模型。`,
|
|
43
|
+
models,
|
|
44
|
+
...(preferredDefault === undefined ? {} : { defaultModel: preferredDefault }),
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (err) {
|
|
48
|
+
return {
|
|
49
|
+
id: member.id,
|
|
50
|
+
name: member.name,
|
|
51
|
+
adapter: member.adapter,
|
|
52
|
+
status: "error",
|
|
53
|
+
detail: err instanceof Error ? err.message : String(err),
|
|
54
|
+
models: [],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** 通过宿主 DSH subagents + zcode-cli 执行一轮异步任务并返回统一 AcpRunResult。 */
|
|
59
|
+
export async function runZcodeViaHost(params) {
|
|
60
|
+
const { ctx, parentAgent, cwd, prompt, model, signal } = params;
|
|
61
|
+
if (signal.aborted) {
|
|
62
|
+
return {
|
|
63
|
+
ok: false,
|
|
64
|
+
stage: "cancelled",
|
|
65
|
+
text: "",
|
|
66
|
+
reasoning: "",
|
|
67
|
+
tools: [],
|
|
68
|
+
error: "任务已被显式取消。",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const llm = ctx.get("llm");
|
|
72
|
+
const subagents = ctx.get("subagents");
|
|
73
|
+
if (llm?.listModels === undefined || subagents?.startActivation === undefined) {
|
|
74
|
+
return {
|
|
75
|
+
ok: false,
|
|
76
|
+
stage: "spawn",
|
|
77
|
+
text: "",
|
|
78
|
+
reasoning: "",
|
|
79
|
+
tools: [],
|
|
80
|
+
error: `当前宿主未就绪 zcode-cli。${ZCODE_LOGIN_HINT}`,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const available = await llm.listModels("zcode-cli").catch(() => []);
|
|
84
|
+
if (available.length === 0) {
|
|
85
|
+
return {
|
|
86
|
+
ok: false,
|
|
87
|
+
stage: "initialize",
|
|
88
|
+
text: "",
|
|
89
|
+
reasoning: "",
|
|
90
|
+
tools: [],
|
|
91
|
+
error: `zcode-cli 尚未登录或无可用模型。${ZCODE_LOGIN_HINT}`,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const chosenModel = model ??
|
|
95
|
+
available.find((m) => m.id.toLowerCase().includes("flash"))?.id ??
|
|
96
|
+
available[0].id;
|
|
97
|
+
if (model !== undefined && !available.some((m) => m.id === model)) {
|
|
98
|
+
return {
|
|
99
|
+
ok: false,
|
|
100
|
+
stage: "configure",
|
|
101
|
+
text: "",
|
|
102
|
+
reasoning: "",
|
|
103
|
+
tools: [],
|
|
104
|
+
error: `zcode-acp 不支持模型 "${model}"。可用模型:${available.map((m) => m.id).join(", ")}`,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
let activation;
|
|
108
|
+
const onAbort = () => {
|
|
109
|
+
void activation?.dispose().catch(() => undefined);
|
|
110
|
+
};
|
|
111
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
112
|
+
try {
|
|
113
|
+
// 依次尝试常见内置本地 subagent provider 名(DSH 默认为 "in-process" 或 "local")。
|
|
114
|
+
const candidates = ["in-process", "local", "default"];
|
|
115
|
+
let lastErr;
|
|
116
|
+
for (const provider of candidates) {
|
|
117
|
+
try {
|
|
118
|
+
activation = await subagents.startActivation({
|
|
119
|
+
provider,
|
|
120
|
+
label: "zcode-acp",
|
|
121
|
+
signal,
|
|
122
|
+
delivery: "caller",
|
|
123
|
+
request: {
|
|
124
|
+
cwd,
|
|
125
|
+
prompt: [{ type: "text", text: prompt }],
|
|
126
|
+
parent: parentAgent,
|
|
127
|
+
agentOptions: {
|
|
128
|
+
model: { provider: "zcode-cli", model: chosenModel },
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
catch (err) {
|
|
135
|
+
lastErr = err;
|
|
136
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
137
|
+
if (!/unknown.*provider|not registered/i.test(msg)) {
|
|
138
|
+
throw err;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (activation === undefined) {
|
|
143
|
+
throw lastErr ?? new Error("未找到可用的本地 subagent provider");
|
|
144
|
+
}
|
|
145
|
+
const res = await activation.result;
|
|
146
|
+
const text = (res.output ?? [])
|
|
147
|
+
.filter((b) => b.type === "text" && typeof b.text === "string")
|
|
148
|
+
.map((b) => b.text)
|
|
149
|
+
.join("");
|
|
150
|
+
if (signal.aborted || res.stopReason === "aborted") {
|
|
151
|
+
return {
|
|
152
|
+
ok: false,
|
|
153
|
+
stage: "cancelled",
|
|
154
|
+
sessionId: activation.childId,
|
|
155
|
+
text,
|
|
156
|
+
reasoning: "",
|
|
157
|
+
tools: [],
|
|
158
|
+
stopReason: "cancelled",
|
|
159
|
+
error: "任务已被显式取消。",
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
if (res.stopReason !== "completed" && res.stopReason !== "max-tokens") {
|
|
163
|
+
const diag = nonEmptyString(asRecord(res)?.["diagnostic"]);
|
|
164
|
+
return {
|
|
165
|
+
ok: false,
|
|
166
|
+
stage: "prompt",
|
|
167
|
+
sessionId: activation.childId,
|
|
168
|
+
text,
|
|
169
|
+
reasoning: "",
|
|
170
|
+
tools: [],
|
|
171
|
+
stopReason: res.stopReason,
|
|
172
|
+
error: diag ?? `zcode-acp 执行失败(${res.stopReason})。`,
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
ok: true,
|
|
177
|
+
stage: "prompt",
|
|
178
|
+
sessionId: activation.childId,
|
|
179
|
+
text,
|
|
180
|
+
reasoning: "",
|
|
181
|
+
tools: [],
|
|
182
|
+
stopReason: res.stopReason,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
if (signal.aborted) {
|
|
187
|
+
return {
|
|
188
|
+
ok: false,
|
|
189
|
+
stage: "cancelled",
|
|
190
|
+
text: "",
|
|
191
|
+
reasoning: "",
|
|
192
|
+
tools: [],
|
|
193
|
+
error: "任务已被显式取消。",
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
return {
|
|
197
|
+
ok: false,
|
|
198
|
+
stage: "prompt",
|
|
199
|
+
text: "",
|
|
200
|
+
reasoning: "",
|
|
201
|
+
tools: [],
|
|
202
|
+
error: err instanceof Error ? err.message : String(err),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
finally {
|
|
206
|
+
signal.removeEventListener("abort", onAbort);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export const zcodeAdapter = {
|
|
210
|
+
async probe(member) {
|
|
211
|
+
return {
|
|
212
|
+
id: member.id,
|
|
213
|
+
name: member.name,
|
|
214
|
+
adapter: member.adapter,
|
|
215
|
+
status: "error",
|
|
216
|
+
detail: "需要通过宿主上下文探测 zcode-cli。",
|
|
217
|
+
models: [],
|
|
218
|
+
};
|
|
219
|
+
},
|
|
220
|
+
buildArgs(member, _options) {
|
|
221
|
+
return member.args;
|
|
222
|
+
},
|
|
223
|
+
extractUsage() {
|
|
224
|
+
return undefined;
|
|
225
|
+
},
|
|
226
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** 插件配置 schema 与默认内置成员定义(agy-acp 与 grok-acp)。 */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export declare const acpMemberSchema: z.ZodObject<{
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
name: z.ZodString;
|
|
6
|
+
command: z.ZodString;
|
|
7
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
8
|
+
adapter: z.ZodDefault<z.ZodEnum<{
|
|
9
|
+
agy: "agy";
|
|
10
|
+
grok: "grok";
|
|
11
|
+
codex: "codex";
|
|
12
|
+
workbuddy: "workbuddy";
|
|
13
|
+
zcode: "zcode";
|
|
14
|
+
generic: "generic";
|
|
15
|
+
}>>;
|
|
16
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
17
|
+
aliases: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
18
|
+
description: z.ZodOptional<z.ZodString>;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
export type AcpMemberConfig = z.infer<typeof acpMemberSchema>;
|
|
21
|
+
export declare const pluginConfigSchema: z.ZodObject<{
|
|
22
|
+
members: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
23
|
+
id: z.ZodString;
|
|
24
|
+
name: z.ZodString;
|
|
25
|
+
command: z.ZodString;
|
|
26
|
+
args: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
27
|
+
adapter: z.ZodDefault<z.ZodEnum<{
|
|
28
|
+
agy: "agy";
|
|
29
|
+
grok: "grok";
|
|
30
|
+
codex: "codex";
|
|
31
|
+
workbuddy: "workbuddy";
|
|
32
|
+
zcode: "zcode";
|
|
33
|
+
generic: "generic";
|
|
34
|
+
}>>;
|
|
35
|
+
env: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
36
|
+
aliases: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
37
|
+
description: z.ZodOptional<z.ZodString>;
|
|
38
|
+
}, z.core.$strip>>>;
|
|
39
|
+
probeTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
40
|
+
shutdownGraceMs: z.ZodDefault<z.ZodNumber>;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
export type PluginConfig = z.infer<typeof pluginConfigSchema>;
|
|
43
|
+
/** 1 期默认内置成员:官方原生 agy acp 与 grok agent stdio。 */
|
|
44
|
+
export declare const DEFAULT_ACP_MEMBERS: readonly AcpMemberConfig[];
|
|
45
|
+
/** 解析最终生效的成员列表(配置未覆盖时使用默认双成员)。 */
|
|
46
|
+
export declare function resolveMembers(configured?: readonly AcpMemberConfig[]): readonly AcpMemberConfig[];
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/** 插件配置 schema 与默认内置成员定义(agy-acp 与 grok-acp)。 */
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
export const acpMemberSchema = z.object({
|
|
4
|
+
id: z.string().min(1),
|
|
5
|
+
name: z.string().min(1),
|
|
6
|
+
command: z.string().min(1),
|
|
7
|
+
args: z.array(z.string()).default([]),
|
|
8
|
+
adapter: z
|
|
9
|
+
.enum(["agy", "grok", "codex", "workbuddy", "zcode", "generic"])
|
|
10
|
+
.default("generic"),
|
|
11
|
+
env: z.record(z.string(), z.string()).default({}),
|
|
12
|
+
aliases: z.array(z.string()).default([]),
|
|
13
|
+
description: z.string().optional(),
|
|
14
|
+
});
|
|
15
|
+
export const pluginConfigSchema = z.object({
|
|
16
|
+
/** 已注册的 ACP 成员列表;默认内置 agy-acp 与 grok-acp。 */
|
|
17
|
+
members: z.array(acpMemberSchema).optional(),
|
|
18
|
+
/** 每次探测目录的超时毫秒数。 */
|
|
19
|
+
probeTimeoutMs: z.number().int().positive().default(15_000),
|
|
20
|
+
/** 显式取消或结束时等待进程优雅退出的毫秒数。 */
|
|
21
|
+
shutdownGraceMs: z.number().int().nonnegative().default(2_000),
|
|
22
|
+
});
|
|
23
|
+
/** 1 期默认内置成员:官方原生 agy acp 与 grok agent stdio。 */
|
|
24
|
+
export const DEFAULT_ACP_MEMBERS = [
|
|
25
|
+
{
|
|
26
|
+
id: "agy-acp",
|
|
27
|
+
name: "Antigravity ACP",
|
|
28
|
+
command: "agy",
|
|
29
|
+
args: ["acp"],
|
|
30
|
+
adapter: "agy",
|
|
31
|
+
env: {},
|
|
32
|
+
aliases: ["agy大臣", "Antigravity大臣"],
|
|
33
|
+
description: "Google Antigravity 原生 ACP Agent,擅长深度分析与长文写作(Gemini 4 系列为主;Claude 系列额度极少,非用户指定勿用)。",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: "grok-acp",
|
|
37
|
+
name: "Grok ACP",
|
|
38
|
+
command: "grok",
|
|
39
|
+
args: ["agent", "stdio"],
|
|
40
|
+
adapter: "grok",
|
|
41
|
+
env: {},
|
|
42
|
+
aliases: ["grok大臣", "X情报大臣"],
|
|
43
|
+
description: "xAI Grok Build 原生 ACP Agent,直连 X 平台检索(x_thread_fetch / x_keyword_search / x_semantic_search / x_user_search)与代码任务。",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "codex-acp",
|
|
47
|
+
name: "Codex ACP",
|
|
48
|
+
command: "codex-acp",
|
|
49
|
+
args: [],
|
|
50
|
+
adapter: "codex",
|
|
51
|
+
env: {},
|
|
52
|
+
aliases: ["codex大臣", "创意大臣", "建模大臣"],
|
|
53
|
+
description: "OpenAI Codex ACP Agent,擅长生成图片、Blender 建模(有审美)及工程编码;非编程杂活优先用 gpt-6.1-sol。",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: "workbuddy-acp",
|
|
57
|
+
name: "WorkBuddy ACP",
|
|
58
|
+
command: "workbuddy-acp",
|
|
59
|
+
args: [],
|
|
60
|
+
adapter: "workbuddy",
|
|
61
|
+
env: {},
|
|
62
|
+
aliases: ["workbuddy大臣", "工蜂大臣"],
|
|
63
|
+
description: "WorkBuddy 原生 ACP Agent(codebuddy-lite-wb),支持桌面工作区与通用办公/编码协作。",
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
id: "zcode-acp",
|
|
67
|
+
name: "ZCode 大臣",
|
|
68
|
+
command: "zcode",
|
|
69
|
+
args: [],
|
|
70
|
+
adapter: "zcode",
|
|
71
|
+
env: {},
|
|
72
|
+
aliases: ["zcode大臣", "智谱大臣"],
|
|
73
|
+
description: "ZCode 智谱 Agent(复用宿主 zcode-cli,支持 GLM-5.3 / GLM-5.3-Flash),适合非编程杂活与中文长文本协作。",
|
|
74
|
+
},
|
|
75
|
+
];
|
|
76
|
+
/** 解析最终生效的成员列表(配置未覆盖时使用默认双成员)。 */
|
|
77
|
+
export function resolveMembers(configured) {
|
|
78
|
+
if (configured === undefined || configured.length === 0) {
|
|
79
|
+
return DEFAULT_ACP_MEMBERS;
|
|
80
|
+
}
|
|
81
|
+
return configured;
|
|
82
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Cordis 插件入口:向所有 DSH 会话注册外部 ACP 团队调度工具。 */
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import { type PluginConfig } from "./config.ts";
|
|
4
|
+
export declare const name = "kmh-subagent-team";
|
|
5
|
+
export declare const inject: readonly ["agents", "tools"];
|
|
6
|
+
export declare function apply(ctx: Context, rawConfig?: Partial<PluginConfig>): void;
|
|
7
|
+
export { AcpTeamManager } from "./runtime/manager.ts";
|
|
8
|
+
export { DEFAULT_ACP_MEMBERS, pluginConfigSchema, resolveMembers, type AcpMemberConfig, type PluginConfig, } from "./config.ts";
|
|
9
|
+
export type { AcpRunResult } from "./acp/client.ts";
|
|
10
|
+
export type { MemberProbeResult } from "./adapters/types.ts";
|
package/lib/src/index.js
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
2
|
+
import { pluginConfigSchema, resolveMembers, } from "./config.js";
|
|
3
|
+
import { buildTeamSystemPrompt } from "./prompt.js";
|
|
4
|
+
import { AcpTeamManager } from "./runtime/manager.js";
|
|
5
|
+
export const name = "kmh-subagent-team";
|
|
6
|
+
export const inject = ["agents", "tools"];
|
|
7
|
+
export function apply(ctx, rawConfig = {}) {
|
|
8
|
+
const parsed = pluginConfigSchema.safeParse(rawConfig);
|
|
9
|
+
const config = parsed.success
|
|
10
|
+
? parsed.data
|
|
11
|
+
: pluginConfigSchema.parse({});
|
|
12
|
+
const members = resolveMembers(config.members);
|
|
13
|
+
const manager = new AcpTeamManager(ctx, members, {
|
|
14
|
+
probeTimeoutMs: config.probeTimeoutMs,
|
|
15
|
+
shutdownGraceMs: config.shutdownGraceMs,
|
|
16
|
+
});
|
|
17
|
+
const offList = ctx.tools.register(defineTool({
|
|
18
|
+
name: "acp_list_members",
|
|
19
|
+
description: "List available external ACP team members (such as agy-acp and grok-acp), their readiness/login status, login instructions if unauthenticated, and available models/modes.",
|
|
20
|
+
parameters: {},
|
|
21
|
+
output: {
|
|
22
|
+
schema: { type: "string" },
|
|
23
|
+
render: (_args, value) => [{ type: "text", text: value }],
|
|
24
|
+
},
|
|
25
|
+
async execute(_args, { agent, signal }) {
|
|
26
|
+
signal.throwIfAborted();
|
|
27
|
+
const cwd = agent?.session.header.cwd || process.cwd();
|
|
28
|
+
const results = await manager.probeAll(cwd);
|
|
29
|
+
return JSON.stringify(results, null, 2);
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
const offDispatch = ctx.tools.register(defineTool({
|
|
33
|
+
name: "acp_dispatch",
|
|
34
|
+
description: "Asynchronously dispatch a task to an external ACP agent (e.g. agy-acp or grok-acp), or resume an existing external session with sessionId. " +
|
|
35
|
+
"Returns immediately with taskId while you keep chatting; the completed output, external sessionId, tool summary, and usage arrive later as a follow-up.",
|
|
36
|
+
parameters: {
|
|
37
|
+
member: {
|
|
38
|
+
type: "string",
|
|
39
|
+
required: true,
|
|
40
|
+
description: "Target ACP member ID from acp_list_members (e.g. agy-acp or grok-acp).",
|
|
41
|
+
},
|
|
42
|
+
prompt: {
|
|
43
|
+
type: "string",
|
|
44
|
+
required: true,
|
|
45
|
+
description: "Task prompt sent to the external ACP agent.",
|
|
46
|
+
},
|
|
47
|
+
cwd: {
|
|
48
|
+
type: "string",
|
|
49
|
+
description: "Optional working directory; defaults to the current session cwd.",
|
|
50
|
+
},
|
|
51
|
+
model: {
|
|
52
|
+
type: "string",
|
|
53
|
+
description: "Optional exact model ID supported by the target ACP member.",
|
|
54
|
+
},
|
|
55
|
+
effort: {
|
|
56
|
+
type: "string",
|
|
57
|
+
description: "Optional reasoning effort (e.g. low, medium, high, xhigh).",
|
|
58
|
+
},
|
|
59
|
+
mode: {
|
|
60
|
+
type: "string",
|
|
61
|
+
description: "Optional execution mode (e.g. default, accept-edits, auto, plan for agy-acp).",
|
|
62
|
+
},
|
|
63
|
+
sessionId: {
|
|
64
|
+
type: "string",
|
|
65
|
+
description: "Optional external sessionId returned by a previous run to continue the same conversation.",
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
output: {
|
|
69
|
+
schema: { type: "string" },
|
|
70
|
+
render: (_args, value) => [{ type: "text", text: value }],
|
|
71
|
+
},
|
|
72
|
+
async execute(args, { agent, signal }) {
|
|
73
|
+
signal.throwIfAborted();
|
|
74
|
+
if (agent === undefined) {
|
|
75
|
+
throw new Error("acp_dispatch 只能在有效的会话 Agent 上下文中调用。");
|
|
76
|
+
}
|
|
77
|
+
const dispatched = manager.dispatch(agent, {
|
|
78
|
+
memberId: args.member,
|
|
79
|
+
prompt: args.prompt,
|
|
80
|
+
...(args.cwd === undefined ? {} : { cwd: args.cwd }),
|
|
81
|
+
...(args.model === undefined ? {} : { model: args.model }),
|
|
82
|
+
...(args.effort === undefined ? {} : { effort: args.effort }),
|
|
83
|
+
...(args.mode === undefined ? {} : { mode: args.mode }),
|
|
84
|
+
...(args.sessionId === undefined ? {} : { sessionId: args.sessionId }),
|
|
85
|
+
});
|
|
86
|
+
if (!dispatched.ok) {
|
|
87
|
+
throw new Error(dispatched.error);
|
|
88
|
+
}
|
|
89
|
+
return JSON.stringify(dispatched);
|
|
90
|
+
},
|
|
91
|
+
}));
|
|
92
|
+
const offStatus = ctx.tools.register(defineTool({
|
|
93
|
+
name: "acp_status",
|
|
94
|
+
description: "List background ACP tasks spawned by this session, including running status, external sessionId, and any pending approval requests.",
|
|
95
|
+
parameters: {},
|
|
96
|
+
output: {
|
|
97
|
+
schema: { type: "string" },
|
|
98
|
+
render: (_args, value) => [{ type: "text", text: value }],
|
|
99
|
+
},
|
|
100
|
+
async execute(_args, { agent, signal }) {
|
|
101
|
+
signal.throwIfAborted();
|
|
102
|
+
if (agent === undefined)
|
|
103
|
+
return "[]";
|
|
104
|
+
return JSON.stringify(manager.listTasks(agent.session.id), null, 2);
|
|
105
|
+
},
|
|
106
|
+
}));
|
|
107
|
+
const offApprove = ctx.tools.register(defineTool({
|
|
108
|
+
name: "acp_approve",
|
|
109
|
+
description: "Submit an approval decision (allow, reject, or cancel) for a background ACP task currently waiting for permission.",
|
|
110
|
+
parameters: {
|
|
111
|
+
taskId: {
|
|
112
|
+
type: "string",
|
|
113
|
+
required: true,
|
|
114
|
+
description: "Background task ID waiting for approval.",
|
|
115
|
+
},
|
|
116
|
+
decision: {
|
|
117
|
+
type: "string",
|
|
118
|
+
enum: ["allow", "reject", "cancel"],
|
|
119
|
+
required: true,
|
|
120
|
+
description: "Permission decision to return to the child ACP agent.",
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
output: {
|
|
124
|
+
schema: { type: "string" },
|
|
125
|
+
render: (_args, value) => [{ type: "text", text: value }],
|
|
126
|
+
},
|
|
127
|
+
async execute(args, { agent, signal }) {
|
|
128
|
+
signal.throwIfAborted();
|
|
129
|
+
if (agent === undefined) {
|
|
130
|
+
throw new Error("acp_approve 只能在有效的会话上下文中调用。");
|
|
131
|
+
}
|
|
132
|
+
const res = manager.approve(agent.session.id, args.taskId, args.decision);
|
|
133
|
+
if (!res.ok)
|
|
134
|
+
throw new Error(res.message);
|
|
135
|
+
return res.message;
|
|
136
|
+
},
|
|
137
|
+
}));
|
|
138
|
+
const offCancel = ctx.tools.register(defineTool({
|
|
139
|
+
name: "acp_cancel",
|
|
140
|
+
description: "Explicitly cancel a running background ACP task spawned by this session.",
|
|
141
|
+
parameters: {
|
|
142
|
+
taskId: {
|
|
143
|
+
type: "string",
|
|
144
|
+
required: true,
|
|
145
|
+
description: "Background task ID to cancel.",
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
output: {
|
|
149
|
+
schema: { type: "string" },
|
|
150
|
+
render: (_args, value) => [{ type: "text", text: value }],
|
|
151
|
+
},
|
|
152
|
+
async execute(args, { agent, signal }) {
|
|
153
|
+
signal.throwIfAborted();
|
|
154
|
+
if (agent === undefined) {
|
|
155
|
+
throw new Error("acp_cancel 只能在有效的会话上下文中调用。");
|
|
156
|
+
}
|
|
157
|
+
const res = manager.cancel(agent.session.id, args.taskId);
|
|
158
|
+
if (!res.ok)
|
|
159
|
+
throw new Error(res.message);
|
|
160
|
+
return res.message;
|
|
161
|
+
},
|
|
162
|
+
}));
|
|
163
|
+
ctx.inject(["systemPrompt"], (scope) => {
|
|
164
|
+
const offPrompt = scope.systemPrompt.section({
|
|
165
|
+
name: "kmh-subagent-team:guide",
|
|
166
|
+
order: scope.systemPrompt.getSectionOrder("DEPLOYMENT_PERSONA_SUFFIX"),
|
|
167
|
+
text: buildTeamSystemPrompt(members),
|
|
168
|
+
interpolate: false,
|
|
169
|
+
});
|
|
170
|
+
scope.effect(() => offPrompt, "kmh-subagent-team: prompt");
|
|
171
|
+
});
|
|
172
|
+
ctx.effect(() => {
|
|
173
|
+
return () => {
|
|
174
|
+
offList();
|
|
175
|
+
offDispatch();
|
|
176
|
+
offStatus();
|
|
177
|
+
offApprove();
|
|
178
|
+
offCancel();
|
|
179
|
+
manager.disposeAll();
|
|
180
|
+
};
|
|
181
|
+
}, "kmh-subagent-team");
|
|
182
|
+
}
|
|
183
|
+
export { AcpTeamManager } from "./runtime/manager.js";
|
|
184
|
+
export { DEFAULT_ACP_MEMBERS, pluginConfigSchema, resolveMembers, } from "./config.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** 生成静态系统提示词段落,避免每轮变动破坏 KV Cache 前缀。 */
|
|
2
|
+
export function buildTeamSystemPrompt(members) {
|
|
3
|
+
const memberLines = members.map((m) => {
|
|
4
|
+
const aliasText = m.aliases.length > 0 ? `(别名:${m.aliases.join("、")})` : "";
|
|
5
|
+
const desc = m.description ?? m.name;
|
|
6
|
+
return `- \`${m.id}\`${aliasText}:${desc}`;
|
|
7
|
+
});
|
|
8
|
+
return [
|
|
9
|
+
"## 外部 ACP 团队(大臣子 Agent)调度规范",
|
|
10
|
+
"",
|
|
11
|
+
"当用户提到“大臣”“ACP 团队”“agy/grok/codex/workbuddy/zcode 大臣”或需要外部专项 Agent 协助时,**必须使用 `acp_*` 工具**,不要误调内置的 `list_subagent_models` 或 `subagent` 工具(`subagent` 仅用于 DSH 内置普通子会话)。",
|
|
12
|
+
"",
|
|
13
|
+
"### 1. 可用大臣与分工",
|
|
14
|
+
...memberLines,
|
|
15
|
+
"",
|
|
16
|
+
"### 2. 选型与额度约束",
|
|
17
|
+
"- **额度保护(agy-acp)**:`agy-acp` 下的 Claude 系列模型(如 `claude-opus-*`、`claude-sonnet-*`)额度极少,**除非用户明确点名要求,否则禁止选用**,优先使用 Gemini 4 系列。",
|
|
18
|
+
"- **审美与创意(codex-acp)**:生成图片、Blender 建模、视觉审美类任务优先派给 `codex-acp`。",
|
|
19
|
+
"- **非编程杂活分流**:日常总结、格式整理、轻量检索等非编程杂活,优先派给 `codex-acp` 的 `gpt-6.1-sol` 或 `zcode-acp` 的 `GLM-5.3-Flash` 模型,节省高阶模型额度。",
|
|
20
|
+
"- **X 情报检索(grok-acp)**:凡涉及 X/Twitter 帖子抓取、实时热点或用户动态检索,优先派给 `grok-acp`。",
|
|
21
|
+
"",
|
|
22
|
+
"### 3. 用户意图与工具映射",
|
|
23
|
+
"- 查询有哪些大臣 / 检查登录与可用模型 → 调用 `acp_list_members`。",
|
|
24
|
+
"- 派大臣干活 → 调用 `acp_dispatch`(传入 `member`、`prompt`,按需传 `model`/`effort`/`mode`/`cwd`),**派发后立即简短告知用户并继续正常聊天**,不要阻塞等待。",
|
|
25
|
+
"- 让刚才的大臣接着做 / 追问 → 调用 `acp_dispatch` 并传入上一次回传的外部 `sessionId`。",
|
|
26
|
+
"- 查看后台大臣进度 → 调用 `acp_status`。",
|
|
27
|
+
"- 允许或拒绝大臣的权限请求 → 调用 `acp_approve`。",
|
|
28
|
+
"- 显式叫停某个后台大臣 → 调用 `acp_cancel`。",
|
|
29
|
+
].join("\n");
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** 父会话权限等级读取与子 ACP 审批透传(支持前端弹窗 + 空闲会话挂起回传)。 */
|
|
2
|
+
import type { Context } from "@deepseek-ai/cordis";
|
|
3
|
+
import type { Agent } from "@deepseek-ai/dsh-agent";
|
|
4
|
+
import type { AcpPermissionRequest, PermissionDecision } from "../acp/protocol.ts";
|
|
5
|
+
export type ParentApprovalMode = "auto-allow" | "ask";
|
|
6
|
+
export interface PendingApprovalEntry {
|
|
7
|
+
readonly taskId: string;
|
|
8
|
+
readonly memberId: string;
|
|
9
|
+
readonly request: AcpPermissionRequest;
|
|
10
|
+
resolve(decision: PermissionDecision): void;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 读取父会话当前的权限等级(D3):
|
|
14
|
+
* 仅当明确处于 `danger-full-access`(不限制)时返回 `auto-allow`;
|
|
15
|
+
* 其余情况一律返回 `ask`(避免把 DSH 内部的 `approval: 'never'` 误判成不限制)。
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveParentApprovalMode(ctx: Context, agent: Agent): ParentApprovalMode;
|
|
18
|
+
/** 将父会话审批决策请求转发给宿主或挂起等待主 Agent 应答(feat04)。 */
|
|
19
|
+
export declare function forwardPermissionToParent(params: {
|
|
20
|
+
readonly ctx: Context;
|
|
21
|
+
readonly parentAgent: Agent;
|
|
22
|
+
readonly taskId: string;
|
|
23
|
+
readonly memberId: string;
|
|
24
|
+
readonly request: AcpPermissionRequest;
|
|
25
|
+
readonly signal: AbortSignal;
|
|
26
|
+
readonly registerPending: (entry: PendingApprovalEntry) => void;
|
|
27
|
+
readonly clearPending: (taskId: string) => void;
|
|
28
|
+
readonly onWaitingChange: (waiting: boolean) => void;
|
|
29
|
+
}): Promise<PermissionDecision>;
|