dsh-team-control 0.2.7 → 0.3.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 +23 -22
- package/index.js +890 -163
- package/package.json +3 -3
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
// 工具用普通 ToolDefinition 对象注册(JSON Schema 参数),不依赖 defineTool。
|
|
7
7
|
// - sidecar 未运行时,autoStart=true 会在首次工具调用时拉起 `dsh-team up`;
|
|
8
8
|
// 插件卸载时只回收「自己拉起」的进程,不影响用户手工起的服务。
|
|
9
|
-
import { spawn } from 'node:child_process';
|
|
9
|
+
import { spawn, execFileSync } from 'node:child_process';
|
|
10
10
|
import { randomUUID } from 'node:crypto';
|
|
11
11
|
import fs from 'node:fs';
|
|
12
12
|
import { createRequire } from 'node:module';
|
|
@@ -84,15 +84,20 @@ function resolveConfig(config) {
|
|
|
84
84
|
forceStopPollMs: Number(c.forceStopPollMs) || 1000,
|
|
85
85
|
// 任务投递后成员会话迟迟没有任何事件(模型路由报错、会话没启动)就判定失败并交回 sidecar 重试
|
|
86
86
|
agentStartTimeoutMs: Number(c.agentStartTimeoutMs) || 120000,
|
|
87
|
-
// 成员触发权限审批(permission preset 的 approval=ask)后,等待 Lead 调
|
|
87
|
+
// 成员触发权限审批(permission preset 的 approval=ask)后,等待 Lead 调 dsh_team_approve 的上限
|
|
88
88
|
approvalTimeoutMs: Number(c.approvalTimeoutMs) || 600000,
|
|
89
|
-
// 审批降噪:命令明确是「已知安全程序 +
|
|
89
|
+
// 审批降噪:命令明确是「已知安全程序 + 无重定向/命令替换/脚本块」时直接 allowed-once,
|
|
90
90
|
// 不打扰 Lead;敏感命令(见 DEFAULT_SENSITIVE_COMMAND_PATTERNS)仍转 Lead 审批
|
|
91
91
|
autoApproveLowRisk: c.autoApproveLowRisk !== false,
|
|
92
92
|
// 追加的敏感命令正则(字符串数组):命中即视为敏感,仍走 Lead 审批
|
|
93
93
|
sensitiveCommandPatterns: Array.isArray(c.sensitiveCommandPatterns)
|
|
94
94
|
? c.sensitiveCommandPatterns.map((p) => String(p)).filter(Boolean)
|
|
95
95
|
: [],
|
|
96
|
+
// 工具级自动放行白名单(字符串数组,支持 `*` 通配):命中工具名的审批直接 allowed-once。
|
|
97
|
+
// 默认空;用于把「非 shell 但明确安全」的工具(如只读 MCP 发现类工具)从审批流里摘出去。
|
|
98
|
+
autoApproveTools: Array.isArray(c.autoApproveTools)
|
|
99
|
+
? c.autoApproveTools.map((p) => String(p).trim()).filter(Boolean)
|
|
100
|
+
: [],
|
|
96
101
|
// spawnTeammate 的 provider:默认与 dsh-experimental-tool-agent-team 一致
|
|
97
102
|
freshProvider: String(c.freshProvider || 'spawn'),
|
|
98
103
|
forkProvider: String(c.forkProvider || 'fork'),
|
|
@@ -196,10 +201,10 @@ const qs = (obj) => {
|
|
|
196
201
|
// (spawnTeammate / sendMessage / interrupt)和派发,因为只有 Host 进程能创建 DSH agent。
|
|
197
202
|
//
|
|
198
203
|
// 流程:
|
|
199
|
-
//
|
|
200
|
-
//
|
|
204
|
+
// dsh_team_spawn(runtime=agent)→ spawnTeammate → POST /api/agents/register 绑定 session
|
|
205
|
+
// dsh_team_task 建任务 → sidecar 置 ready → POST /api/agents/dispatch 原子认领(running)
|
|
201
206
|
// → sendMessage(lead → member) 把任务说明投进成员信箱
|
|
202
|
-
// 成员跑完 →
|
|
207
|
+
// 成员跑完 → dsh_team_report_task(精确摘要)/ agent/status=idle(兜底)→ 任务 done → evaluate 推进依赖
|
|
203
208
|
// → 再跑一轮 dispatch,把新 ready 的任务投给 idle 成员
|
|
204
209
|
|
|
205
210
|
/** teamId → 最近一次调用 team_* 工具的 Lead Agent(发消息必须由 live Lead 发出)。 */
|
|
@@ -223,8 +228,87 @@ const memberOfCaller = (agent) => {
|
|
|
223
228
|
return sid != null ? (sessionMember.get(String(sid)) || null) : null;
|
|
224
229
|
};
|
|
225
230
|
const subagentsOf = (ctx) => { try { return ctx.get('subagents'); } catch { return undefined; } };
|
|
231
|
+
/** DSH `agents` 注册表:`subagents.sendMessage` 要求 sender 是「精确的活跃 Agent」,必须从注册表取。 */
|
|
232
|
+
const agentsOf = (ctx) => { try { return ctx.get('agents'); } catch { return undefined; } };
|
|
226
233
|
const subagentNames = (ctx) => { const svc = subagentsOf(ctx); return svc && typeof svc.list === 'function' ? svc.list() : []; };
|
|
227
234
|
|
|
235
|
+
/**
|
|
236
|
+
* 原生 agent 消息工具:DSH 0.2.2 起把「给另一个 agent 发消息」收敛成工具,
|
|
237
|
+
* 工具名是下划线版 `send_message`;连字符 `send-message` 作为别名一起探测,防止宿主改名。
|
|
238
|
+
*/
|
|
239
|
+
const NATIVE_SEND_TOOLS = ['send_message', 'send-message'];
|
|
240
|
+
const toolsOf = (ctx) => ctx?.tools || (() => { try { return ctx.get('tools'); } catch { return undefined; } })();
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* 探测宿主是否提供原生消息工具(高版本 DSH),返回 `{ tools, name }`。
|
|
244
|
+
*
|
|
245
|
+
* 查可见性时要带发送者作用域:工具可能注册在 agent preset 的 scope 里,只查全局会漏;
|
|
246
|
+
* 低版本没有这个工具(或没有 `tools.execute`)时返回 undefined,调用方继续走 `subagents.sendMessage`。
|
|
247
|
+
*/
|
|
248
|
+
function nativeSendTools(ctx, sender) {
|
|
249
|
+
const tools = toolsOf(ctx);
|
|
250
|
+
if (!tools || typeof tools.get !== 'function' || typeof tools.execute !== 'function') return undefined;
|
|
251
|
+
for (const name of NATIVE_SEND_TOOLS) {
|
|
252
|
+
try {
|
|
253
|
+
if (tools.get(name, sender)) return { tools, name };
|
|
254
|
+
} catch { /* 查不到就继续试下一个名字 */ }
|
|
255
|
+
}
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/** 还有没有可用的投递通道:原生工具,或低版本的 `subagents.sendMessage`。 */
|
|
260
|
+
function canDeliverTo(ctx, sender) {
|
|
261
|
+
if (!sender) return false;
|
|
262
|
+
if (nativeSendTools(ctx, sender)) return true;
|
|
263
|
+
const subs = subagentsOf(ctx);
|
|
264
|
+
return !!subs && typeof subs.sendMessage === 'function';
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* 把一条文本消息投进某个 agent 会话(成员与 Lead 一视同仁)。
|
|
269
|
+
*
|
|
270
|
+
* - 高版本 DSH 提供原生 `send_message` 工具:走工具层调用,接收方由宿主 `resolveName` 解析
|
|
271
|
+
* (传 sessionId 时它会被原样当作会话 id),消息来源标记、空闲唤醒、后续语义变化都交给宿主;
|
|
272
|
+
* - 低版本没有该工具:保持原来的 `subagents.sendMessage(sender, sessionId, content, { signal })`。
|
|
273
|
+
*
|
|
274
|
+
* `sender` 必须是精确的活跃 Agent(两代实现都这么要求),调用方负责从 `agents` 注册表或缓存的
|
|
275
|
+
* Lead 句柄里取。
|
|
276
|
+
*/
|
|
277
|
+
async function sendAgentMessage(ctx, sender, targetSessionId, text, opts = {}) {
|
|
278
|
+
const native = nativeSendTools(ctx, sender);
|
|
279
|
+
if (native) {
|
|
280
|
+
const callId = `team-send-${randomUUID()}`;
|
|
281
|
+
const batch = await native.tools.execute({
|
|
282
|
+
calls: [{
|
|
283
|
+
type: 'tool-call',
|
|
284
|
+
id: callId,
|
|
285
|
+
name: native.name,
|
|
286
|
+
arguments: JSON.stringify({ agent: String(targetSessionId), message: String(text) }),
|
|
287
|
+
}],
|
|
288
|
+
signal: opts.signal || AbortSignal.timeout(60000),
|
|
289
|
+
agent: sender,
|
|
290
|
+
});
|
|
291
|
+
const results = Array.isArray(batch?.results) ? batch.results : [];
|
|
292
|
+
const result = (results.find((r) => r && r.callId === callId) || results[0])?.result;
|
|
293
|
+
if (!result) throw new Error('send_message 工具没有返回执行结果');
|
|
294
|
+
if (result.isError) {
|
|
295
|
+
const failure = result.error || {};
|
|
296
|
+
throw new Error(`send_message 工具投递失败:${failure.message || failure.code || '未知错误'}`);
|
|
297
|
+
}
|
|
298
|
+
const messageId = result.value && result.value.messageId;
|
|
299
|
+
return { via: 'tool', messageId: messageId != null ? String(messageId) : undefined };
|
|
300
|
+
}
|
|
301
|
+
const subs = subagentsOf(ctx);
|
|
302
|
+
if (!subs || typeof subs.sendMessage !== 'function') throw new Error('subagents 服务不可用,无法投递消息');
|
|
303
|
+
const messageId = await subs.sendMessage(
|
|
304
|
+
sender,
|
|
305
|
+
String(targetSessionId),
|
|
306
|
+
[{ type: 'text', text: String(text) }],
|
|
307
|
+
opts.signal ? { signal: opts.signal } : {},
|
|
308
|
+
);
|
|
309
|
+
return { via: 'service', messageId: messageId != null ? String(messageId) : undefined };
|
|
310
|
+
}
|
|
311
|
+
|
|
228
312
|
/** `sessions` / `workspaceChanges`:读成员自己会话里的交付文件(都是可选依赖)。 */
|
|
229
313
|
const sessionsOf = (ctx) => { try { return ctx.get('sessions'); } catch { return undefined; } };
|
|
230
314
|
const workspaceChangesOf = (ctx) => { try { return ctx.get('workspaceChanges'); } catch { return undefined; } };
|
|
@@ -567,10 +651,17 @@ function providerFor(ctx, s, context) {
|
|
|
567
651
|
return names[0];
|
|
568
652
|
}
|
|
569
653
|
|
|
654
|
+
// subagents.startActivation 的 delegation request 形状在 DSH 0.2.2 变了:
|
|
655
|
+
// 旧宿主从 spec.request 读 prompt/parent/cwd/agentOptions/agentPreset,新宿主直接读 spec 顶层。
|
|
656
|
+
// 两种形状一起带:新宿主忽略 request,旧宿主忽略摊平字段,一份调用同时兼容。
|
|
657
|
+
function activationSpec(request, base) {
|
|
658
|
+
return { ...base, ...request, request };
|
|
659
|
+
}
|
|
660
|
+
|
|
570
661
|
// ---------- 模型路由:DSH ctx.llm 目录 → sidecar 映射 ----------
|
|
571
662
|
//
|
|
572
663
|
// 目录的唯一来源是 Host 的 ctx.llm;这里只把 provider/model 的映射、展示名和
|
|
573
|
-
// 模态同步给 sidecar。sidecar 保存用户勾选的子集与备注,
|
|
664
|
+
// 模态同步给 sidecar。sidecar 保存用户勾选的子集与备注,dsh_team_spawn 只接受
|
|
574
665
|
// 启用项。本插件不代理 LLM 请求、不保存任何凭据。
|
|
575
666
|
const llmOf = (ctx) => { try { return ctx.get('llm'); } catch { return undefined; } };
|
|
576
667
|
|
|
@@ -599,7 +690,7 @@ async function effortsOfRoute(llm, provider, model) {
|
|
|
599
690
|
]);
|
|
600
691
|
const reasoning = info && info.reasoning;
|
|
601
692
|
if (!reasoning || !Array.isArray(reasoning.efforts)) return undefined;
|
|
602
|
-
// 「off」等于关思考,不是可派发的强度:既不进面板胶囊,也不进
|
|
693
|
+
// 「off」等于关思考,不是可派发的强度:既不进面板胶囊,也不进 dsh_team_models,
|
|
603
694
|
// 否则用户能「允许派发 off」而实际语义相反。
|
|
604
695
|
const efforts = reasoning.efforts
|
|
605
696
|
.filter((e) => e && e.id && String(e.id) !== 'off')
|
|
@@ -663,7 +754,7 @@ async function syncLlmCatalog(s, ctx) {
|
|
|
663
754
|
}
|
|
664
755
|
}
|
|
665
756
|
// 只上报真正能列出模型的 provider;没模型的(含未配置的 dormant)不进目录,
|
|
666
|
-
// 面板与
|
|
757
|
+
// 面板与 dsh_team_models 就不会出现空分组。
|
|
667
758
|
const withModels = providers.filter((p) => models.some((m) => m.provider === p.id));
|
|
668
759
|
if (!withModels.length) return { ok: true, providers: 0, models: 0, empty: true };
|
|
669
760
|
await request(s, '/api/llm/catalog', { method: 'POST', body: { providers: withModels, models, partial } });
|
|
@@ -692,12 +783,20 @@ async function assertRouteEnabled(s, ctx, provider, model, effort = null) {
|
|
|
692
783
|
// 目录里查不到的 route(例如适配器临时提供、未在 listModels 中声明)不拦,避免误伤;
|
|
693
784
|
// 能查到但被停用的,无论是显式指定还是继承 Lead,都拒绝。
|
|
694
785
|
const known = all.filter((m) => (!provider || m.provider === provider) && (!model || m.model === model));
|
|
695
|
-
if (!known.length)
|
|
786
|
+
if (!known.length) {
|
|
787
|
+
// 常见错法:agentProvider 填了模型名(如 "glm-5.3")。这会在成员回合里才炸成
|
|
788
|
+
// `no adapter registered for provider "glm-5.3"`,白起一轮;这里提前拦。
|
|
789
|
+
const owners = [...new Set(all.filter((m) => !model || m.model === model).map((m) => m.provider))];
|
|
790
|
+
if (provider && model && owners.length && !owners.includes(provider)) {
|
|
791
|
+
throw new Error(`agentProvider「${provider}」不是模型「${model}」所属的 provider:应填 ${owners.join(' 或 ')}。agentProvider 要的是 provider id(见 dsh_team_models),不是模型名。`);
|
|
792
|
+
}
|
|
793
|
+
return;
|
|
794
|
+
}
|
|
696
795
|
const enabled = all.filter((m) => m.enabled);
|
|
697
|
-
if (!enabled.length) throw new Error('所有模型路由都已停用:请先在面板「模型路由」页启用,或调用
|
|
796
|
+
if (!enabled.length) throw new Error('所有模型路由都已停用:请先在面板「模型路由」页启用,或调用 dsh_team_models 查看。');
|
|
698
797
|
if (!known.some((m) => m.enabled)) {
|
|
699
798
|
const sample = enabled.slice(0, 8).map((m) => `${m.provider}/${m.model}`).join(', ');
|
|
700
|
-
throw new Error(`模型路由未启用:${[provider, model].filter(Boolean).join('/')}。可用(前 8 条):${sample}。完整列表见
|
|
799
|
+
throw new Error(`模型路由未启用:${[provider, model].filter(Boolean).join('/')}。可用(前 8 条):${sample}。完整列表见 dsh_team_models,或在面板「模型路由」页启用。`);
|
|
701
800
|
}
|
|
702
801
|
// effort 闸门:只有该 route 声明了 efforts 才校验;allowedEfforts=null 表示全部允许。
|
|
703
802
|
if (!effort) return;
|
|
@@ -730,14 +829,14 @@ function rememberMember(sessionId, teamId, memberId, cwd, permissionPreset = nul
|
|
|
730
829
|
|
|
731
830
|
async function teamOf(s, teamId, { refresh = false, sessionId = null } = {}) {
|
|
732
831
|
// 模型偶尔会漏掉必填的 teamId。先显式挡住,避免 /api/teams/undefined 被误报成「团队不存在」;
|
|
733
|
-
// 同一会话内
|
|
832
|
+
// 同一会话内 dsh_team_create 过的团队可以直接兜底(DSH 对直接注册的工具不做 required 运行时校验)。
|
|
734
833
|
const missing = teamId == null || String(teamId).trim() === '' || String(teamId) === 'undefined' || String(teamId) === 'null';
|
|
735
834
|
if (missing && sessionId) {
|
|
736
835
|
const bound = sessionMember.get(String(sessionId))?.teamId || teamBySession.get(String(sessionId));
|
|
737
836
|
if (bound) teamId = bound;
|
|
738
837
|
}
|
|
739
838
|
if (teamId == null || String(teamId).trim() === '' || String(teamId) === 'undefined' || String(teamId) === 'null') {
|
|
740
|
-
throw new Error('缺少 teamId:请把
|
|
839
|
+
throw new Error('缺少 teamId:请把 dsh_team_create 返回的 result.team.id(形如 team_xxx)作为 teamId 参数传入后重试。');
|
|
741
840
|
}
|
|
742
841
|
const key = String(teamId);
|
|
743
842
|
if (!refresh && teamCache.has(key)) return teamCache.get(key);
|
|
@@ -747,7 +846,7 @@ async function teamOf(s, teamId, { refresh = false, sessionId = null } = {}) {
|
|
|
747
846
|
return team;
|
|
748
847
|
} catch (err) {
|
|
749
848
|
if (err && err.status === 404) {
|
|
750
|
-
throw new Error(`团队不存在或 teamId 无效: ${key}(teamId 来自
|
|
849
|
+
throw new Error(`团队不存在或 teamId 无效: ${key}(teamId 来自 dsh_team_create 返回值,请核对后重试)`);
|
|
751
850
|
}
|
|
752
851
|
throw err;
|
|
753
852
|
}
|
|
@@ -777,6 +876,13 @@ async function resolveAgentPreset(ctx, requested, fallback, store = null) {
|
|
|
777
876
|
if (ids.length && !ids.includes(preset)) {
|
|
778
877
|
throw new Error(`agentPreset「${preset}」不存在;可用预设:${ids.join(', ')}`);
|
|
779
878
|
}
|
|
879
|
+
// 宿主挂载失败的预设会在 startActivation 才抛出「xxx: never started」,看不出原因,
|
|
880
|
+
// 也看不出该换哪个;用 list() 的 broken 提前给可操作提示。
|
|
881
|
+
const row = Array.isArray(rows) ? rows.find((r) => r && r.id === preset) : null;
|
|
882
|
+
if (row && row.broken) {
|
|
883
|
+
const usable = (Array.isArray(rows) ? rows : []).filter((r) => r && r.id && !r.broken).map((r) => r.id);
|
|
884
|
+
throw new Error(`agentPreset「${preset}」在宿主里启动失败:${String(row.broken).split('\n')[0]}${usable.length ? `。可用预设:${usable.join('、')}(显式传 agentPreset 绕过)` : ''}`);
|
|
885
|
+
}
|
|
780
886
|
return preset;
|
|
781
887
|
}
|
|
782
888
|
|
|
@@ -784,7 +890,7 @@ async function resolveAgentPreset(ctx, requested, fallback, store = null) {
|
|
|
784
890
|
* 宿主默认 agentPreset 的 id。
|
|
785
891
|
*
|
|
786
892
|
* DSH 的 subagent 在 request 里省略 agentPreset 时,会继承父会话的实时组合
|
|
787
|
-
* (`composeFrom(parent)`),并不会自动套用宿主默认。因此
|
|
893
|
+
* (`composeFrom(parent)`),并不会自动套用宿主默认。因此 dsh_team_spawn 必须显式
|
|
788
894
|
* 把默认预设传下去,否则成员就只能拿到 Lead 根组合里的宿主级工具(比如没有 shell)。
|
|
789
895
|
*/
|
|
790
896
|
async function hostDefaultAgentPreset(ctx) {
|
|
@@ -806,7 +912,7 @@ async function hostDefaultAgentPreset(ctx) {
|
|
|
806
912
|
// ---------------------------------------------------------------------------
|
|
807
913
|
// Leader 自建 agentPreset
|
|
808
914
|
//
|
|
809
|
-
// 内置 preset 不满足时,Lead 用
|
|
915
|
+
// 内置 preset 不满足时,Lead 用 dsh_team_preset({action:'save'}) 把一份组合定义写到固定目录,
|
|
810
916
|
// 并立刻调用宿主 `agentPresets.register()` 生效(无需重启 DSH)。目录里的 JSON 文档
|
|
811
917
|
// (JSON 是合法 YAML)在插件启动时也会被重新注册,因此跨会话可复用。
|
|
812
918
|
// ---------------------------------------------------------------------------
|
|
@@ -1044,18 +1150,17 @@ function taskBrief(teamId, task, member) {
|
|
|
1044
1150
|
'',
|
|
1045
1151
|
'执行要求:',
|
|
1046
1152
|
'1) 直接在本会话里做这件事(用你自己的工具,不要委派给别的 agent)。',
|
|
1047
|
-
'2) 每开始或完成一步、以及验收通过后,调用
|
|
1048
|
-
'3) 收工前,如果这次任务产生了对后续任务可复用的结论(接口约定、坑、决策理由、未决问题),调用
|
|
1049
|
-
'4) 完成或失败后必须调用
|
|
1050
|
-
`
|
|
1051
|
-
'5) 需要 Lead 决策或补充信息时用
|
|
1153
|
+
'2) 每开始或完成一步、以及验收通过后,调用 dsh_team_todo 更新该任务的计划清单(teamId/taskId 同上)。',
|
|
1154
|
+
'3) 收工前,如果这次任务产生了对后续任务可复用的结论(接口约定、坑、决策理由、未决问题),调用 dsh_team_memory_write 存一条简短 handoff(scope="member",kind="handoff",value 不超过 300 字);没有可复用结论就跳过,不要为了留记忆而写。只有 Lead 明确要求上传时才写 scope="team"。',
|
|
1155
|
+
'4) 完成或失败后必须调用 dsh_team_report_task,例如:',
|
|
1156
|
+
` dsh_team_report_task({ teamId: "${teamId}", taskId: "${task.id}", status: "done", summary: "一句话结果 + 关键产物路径" })`,
|
|
1157
|
+
'5) 需要 Lead 决策或补充信息时用 dsh_team_send(teamId 同上,to: "lead"),不要自己猜测。',
|
|
1052
1158
|
].join('\n');
|
|
1053
1159
|
}
|
|
1054
1160
|
|
|
1055
1161
|
/** 把任务投递给成员:由 Lead 发一条消息进成员信箱(running 时在最近 step 边界送达)。 */
|
|
1056
1162
|
async function deliverTask(s, ctx, lead, teamId, task, member) {
|
|
1057
|
-
|
|
1058
|
-
if (!subs || typeof subs.sendMessage !== 'function') throw new Error('subagents 服务不可用,无法派发给 agent 成员');
|
|
1163
|
+
if (!canDeliverTo(ctx, lead)) throw new Error('subagents 服务不可用,无法派发给 agent 成员');
|
|
1059
1164
|
if (!member.agentSessionId) throw new Error(`成员 ${member.name} 还没有绑定 sub-agent 会话`);
|
|
1060
1165
|
const brief = taskBrief(teamId, task, member);
|
|
1061
1166
|
// 简报本身就是一条 Lead→成员的消息:先落信箱,面板【消息与回执】才有「提问 → 回复」可配对;
|
|
@@ -1068,8 +1173,9 @@ async function deliverTask(s, ctx, lead, teamId, task, member) {
|
|
|
1068
1173
|
});
|
|
1069
1174
|
messageId = recorded?.message?.id || null;
|
|
1070
1175
|
} catch { messageId = null; }
|
|
1071
|
-
|
|
1072
|
-
|
|
1176
|
+
await sendAgentMessage(ctx, lead, String(member.agentSessionId), brief, {
|
|
1177
|
+
signal: AbortSignal.timeout(s.requestTimeoutMs),
|
|
1178
|
+
});
|
|
1073
1179
|
await markDelivered(s, messageId);
|
|
1074
1180
|
}
|
|
1075
1181
|
|
|
@@ -1125,7 +1231,7 @@ async function dispatchLoop(s, ctx, teamId) {
|
|
|
1125
1231
|
}
|
|
1126
1232
|
}
|
|
1127
1233
|
|
|
1128
|
-
// ---------- 权限审批转发:成员 preset 触发 approval/request → Lead 用
|
|
1234
|
+
// ---------- 权限审批转发:成员 preset 触发 approval/request → Lead 用 dsh_team_approve 决定 ----------
|
|
1129
1235
|
const pendingApprovals = new Map();
|
|
1130
1236
|
|
|
1131
1237
|
// 审批分类:approval/request 只带 toolName 与 callId,不带命令参数;
|
|
@@ -1141,6 +1247,14 @@ const SAFE_COMMAND_PROGRAMS = new Set([
|
|
|
1141
1247
|
'cargo', 'rustc', 'go', 'dotnet', 'javac', 'java', 'mvn', 'gradle',
|
|
1142
1248
|
'ls', 'dir', 'cat', 'type', 'head', 'tail', 'rg', 'grep', 'find', 'fd', 'where', 'which',
|
|
1143
1249
|
'git', 'echo', 'cd', 'pwd', 'mkdir', 'touch',
|
|
1250
|
+
// PowerShell 只读命令:成员在 Windows 上排查时的大量噪声来自 Get-*/Select-*/Format-*。
|
|
1251
|
+
// ForEach-Object 等能执行脚本块的 cmdlet 故意不收录(脚本块另有 `{}` 拦截)。
|
|
1252
|
+
'get-childitem', 'get-content', 'get-item', 'get-itemproperty', 'get-location', 'get-command',
|
|
1253
|
+
'get-process', 'get-date', 'get-acl', 'get-help', 'get-member', 'get-module', 'get-variable',
|
|
1254
|
+
'select-string', 'select-object', 'where-object', 'measure-object', 'sort-object',
|
|
1255
|
+
'format-table', 'format-list', 'out-string', 'out-host', 'write-output',
|
|
1256
|
+
'test-path', 'resolve-path', 'join-path', 'split-path', 'compare-object', 'group-object',
|
|
1257
|
+
'convertto-json', 'convertfrom-json', 'get-filehash',
|
|
1144
1258
|
]);
|
|
1145
1259
|
// 解释器带 -e/-c 等价于任意代码执行,不自动放行。
|
|
1146
1260
|
const INTERPRETER_PROGRAMS = new Set(['node', 'python', 'python3', 'py', 'deno', 'bun']);
|
|
@@ -1199,28 +1313,48 @@ function cachedPreExecuteArgs(sessionId, callId) {
|
|
|
1199
1313
|
}
|
|
1200
1314
|
|
|
1201
1315
|
/**
|
|
1202
|
-
* 低风险命令判定:白名单程序 +
|
|
1316
|
+
* 低风险命令判定:白名单程序 + 禁止重定向/命令替换/脚本块 + 敏感规则。
|
|
1317
|
+
* 允许管道(每段都按白名单校验)与 `&&`/`||`/`;` 串联,覆盖 `git status | head`、
|
|
1318
|
+
* `Get-ChildItem | Where-Object` 这类只读排查命令。
|
|
1203
1319
|
* 这是启发式而非完整 shell 解析——宁可漏放行(转 Lead),也不误放行。
|
|
1204
1320
|
*/
|
|
1205
1321
|
function isLowRiskCommand(command, extraPatterns = []) {
|
|
1206
1322
|
const text = String(command || '').trim();
|
|
1207
1323
|
if (!text || text.length > 2000) return false;
|
|
1208
|
-
|
|
1324
|
+
// `<>` 重定向、反引号、$() 命令替换、换行、{} 脚本块(ForEach-Object/Where-Object 的代码)
|
|
1325
|
+
if (/[<>`{}]|\$\(|\n|\r/.test(text)) return false;
|
|
1209
1326
|
if (DEFAULT_SENSITIVE_COMMAND_PATTERNS.test(text)) return false;
|
|
1210
1327
|
for (const pattern of extraPatterns) {
|
|
1211
1328
|
try { if (new RegExp(pattern, 'i').test(text)) return false; } catch { /* 非法正则忽略 */ }
|
|
1212
1329
|
}
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
if (!
|
|
1216
|
-
const
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1330
|
+
// 先按命令分隔符切成简单命令,再按单管道切段;空段(尾随 `|`)视为异常,宁可转 Lead。
|
|
1331
|
+
for (const chain of text.split(/&&|\|\||;/)) {
|
|
1332
|
+
if (!chain.trim()) continue;
|
|
1333
|
+
for (const seg of chain.split('|')) {
|
|
1334
|
+
const part = seg.trim();
|
|
1335
|
+
if (!part) return false;
|
|
1336
|
+
const words = part.split(/\s+/);
|
|
1337
|
+
const prog = words[0].replace(/^.*[\\/]/, '').replace(/\.(exe|cmd|bat|ps1)$/i, '').toLowerCase();
|
|
1338
|
+
if (!SAFE_COMMAND_PROGRAMS.has(prog)) return false;
|
|
1339
|
+
if (INTERPRETER_PROGRAMS.has(prog) && words.slice(1).some((w) => /^(-e|-c|--eval|--command|\/c)$/i.test(w))) return false;
|
|
1340
|
+
}
|
|
1220
1341
|
}
|
|
1221
1342
|
return true;
|
|
1222
1343
|
}
|
|
1223
1344
|
|
|
1345
|
+
/** 工具名匹配:精确或 `*` 通配(大小写不敏感),用于 autoApproveTools 白名单。 */
|
|
1346
|
+
function toolNameMatches(pattern, name) {
|
|
1347
|
+
const target = String(name || '');
|
|
1348
|
+
if (!pattern || !target) return false;
|
|
1349
|
+
if (!pattern.includes('*')) return pattern.toLowerCase() === target.toLowerCase();
|
|
1350
|
+
const re = new RegExp(`^${pattern.split('*').map((p) => p.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')).join('.*')}$`, 'i');
|
|
1351
|
+
return re.test(target);
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
function isAutoApprovedTool(patterns, ...names) {
|
|
1355
|
+
return (patterns || []).some((pattern) => names.some((name) => toolNameMatches(pattern, name)));
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1224
1358
|
function settleApproval(s, requestId, decision, reason, decidedBy) {
|
|
1225
1359
|
const entry = pendingApprovals.get(requestId);
|
|
1226
1360
|
if (!entry) return null;
|
|
@@ -1249,8 +1383,7 @@ function cancelPendingApprovals() {
|
|
|
1249
1383
|
}
|
|
1250
1384
|
|
|
1251
1385
|
async function notifyLeadOfApproval(s, ctx, req, info) {
|
|
1252
|
-
|
|
1253
|
-
if (!subs || typeof subs.sendMessage !== 'function' || !req?.agent) return false;
|
|
1386
|
+
if (!req?.agent || !canDeliverTo(ctx, req.agent)) return false;
|
|
1254
1387
|
const team = await teamOf(s, info.teamId);
|
|
1255
1388
|
const leadId = leadByTeam.get(info.teamId)?.id != null
|
|
1256
1389
|
? String(leadByTeam.get(info.teamId).id)
|
|
@@ -1267,14 +1400,75 @@ async function notifyLeadOfApproval(s, ctx, req, info) {
|
|
|
1267
1400
|
`requestId=${info.requestId}`,
|
|
1268
1401
|
'',
|
|
1269
1402
|
`成员因 permissionPreset「${info.preset || 'unknown'}」的审批策略暂停,等待你决定。`,
|
|
1270
|
-
`批准本次操作:
|
|
1403
|
+
`批准本次操作:dsh_team_approve({ teamId: "${info.teamId}", requestId: "${info.requestId}", decision: "allow" })`,
|
|
1271
1404
|
`拒绝:把 decision 改成 "deny"(可加 reason)。`,
|
|
1272
1405
|
`超过 ${minutes} 分钟未决定将自动拒绝。`,
|
|
1273
1406
|
].join('\n');
|
|
1274
|
-
await
|
|
1407
|
+
await sendAgentMessage(ctx, req.agent, leadId, text, { signal: AbortSignal.timeout(s.requestTimeoutMs) });
|
|
1275
1408
|
return true;
|
|
1276
1409
|
}
|
|
1277
1410
|
|
|
1411
|
+
/** 已经通知过 Lead 的中断(recover 用 memberId:seq,回合失败用 sessionId:序号),避免同一次中断反复打扰。 */
|
|
1412
|
+
const interruptNotified = new Set();
|
|
1413
|
+
|
|
1414
|
+
/**
|
|
1415
|
+
* 成员意外中断时主动推给 Lead(sidecar 重启 recover、模型回合报错、会话被异常终止)。
|
|
1416
|
+
*
|
|
1417
|
+
* 审批有 notifyLeadOfApproval 这条唯一通道,中断却一条都没有:Lead 挂起(会话空闲/等消息)后
|
|
1418
|
+
* 成员断了,事件流里只有一行 recover 或 failed,Lead 永远不会被唤醒(task_mwgbawyif5cuwf 现场)。
|
|
1419
|
+
* `subagents.sendMessage` 要求 sender 是精确的活跃 Agent,所以从 `agents` 注册表按会话 id 取成员;
|
|
1420
|
+
* 会话已经回收时发不出去——那种情况事件流/面板里仍有记录,不阻塞其它泵。
|
|
1421
|
+
*/
|
|
1422
|
+
async function notifyLeadOfMemberInterrupt(s, ctx, info) {
|
|
1423
|
+
if (!info) return false;
|
|
1424
|
+
const sessionId = info.sessionId != null ? String(info.sessionId) : null;
|
|
1425
|
+
const teamId = info.teamId != null ? String(info.teamId) : null;
|
|
1426
|
+
if (!sessionId || !teamId) return false;
|
|
1427
|
+
const agents = agentsOf(ctx);
|
|
1428
|
+
const sender = agents && typeof agents.get === 'function' ? agents.get(sessionId) : undefined;
|
|
1429
|
+
if (!sender || !canDeliverTo(ctx, sender)) return false;
|
|
1430
|
+
let leadId = info.leadSessionId != null ? String(info.leadSessionId) : null;
|
|
1431
|
+
if (!leadId) {
|
|
1432
|
+
const cached = leadByTeam.get(teamId);
|
|
1433
|
+
leadId = cached?.id != null ? String(cached.id) : null;
|
|
1434
|
+
}
|
|
1435
|
+
if (!leadId) {
|
|
1436
|
+
const team = await teamOf(s, teamId).catch(() => null);
|
|
1437
|
+
leadId = team?.leadSessionId != null ? String(team.leadSessionId) : null;
|
|
1438
|
+
}
|
|
1439
|
+
if (!leadId || leadId === sessionId) return false;
|
|
1440
|
+
const key = info.dedupeKey || `${info.memberId || sessionId}:${info.status || 'interrupted'}`;
|
|
1441
|
+
if (interruptNotified.has(key)) return false;
|
|
1442
|
+
interruptNotified.add(key);
|
|
1443
|
+
const lines = [
|
|
1444
|
+
'【dsh-team 成员中断】',
|
|
1445
|
+
`teamId=${teamId}`,
|
|
1446
|
+
...(info.memberId ? [`memberId=${info.memberId}`] : []),
|
|
1447
|
+
...(info.memberName ? [`memberName=${info.memberName}`] : []),
|
|
1448
|
+
...(info.taskId ? [`taskId=${info.taskId}`] : []),
|
|
1449
|
+
`成员状态:${info.status || 'interrupted'}`,
|
|
1450
|
+
...(info.reason ? [`原因:${clip(String(info.reason), 500)}`] : []),
|
|
1451
|
+
'',
|
|
1452
|
+
info.status === 'failed'
|
|
1453
|
+
? '该成员的回合以错误结束,任务按失败重试策略处理(可能已重新派发);反复失败需要你介入。'
|
|
1454
|
+
: '该成员没有正常收工,任务不会被当成完成;中断后它需要你确认才能继续。',
|
|
1455
|
+
info.status === 'failed'
|
|
1456
|
+
? `下一步:dsh_team_status({ teamId: "${teamId}" }) 看进度;需要人工接手时用 dsh_team_task/dsh_team_member 调整。`
|
|
1457
|
+
: (info.memberId
|
|
1458
|
+
? `下一步:dsh_team_status({ teamId: "${teamId}" }) 看进度;确认后 dsh_team_control({ teamId: "${teamId}", memberId: "${info.memberId}", action: "resume" }) 继续。`
|
|
1459
|
+
: `下一步:dsh_team_status({ teamId: "${teamId}" }) 看进度;确认后 dsh_team_dispatch 重新派发。`),
|
|
1460
|
+
];
|
|
1461
|
+
try {
|
|
1462
|
+
await sendAgentMessage(ctx, sender, leadId, lines.join('\n'), {
|
|
1463
|
+
signal: AbortSignal.timeout(s.requestTimeoutMs),
|
|
1464
|
+
});
|
|
1465
|
+
return true;
|
|
1466
|
+
} catch {
|
|
1467
|
+
interruptNotified.delete(key); // 这次没送出去:下一跳重试
|
|
1468
|
+
return false;
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1278
1472
|
async function onApprovalRequest(s, ctx, req, next) {
|
|
1279
1473
|
const sessionId = req?.agent?.id != null ? String(req.agent.id) : null;
|
|
1280
1474
|
const binding = sessionId ? sessionMember.get(sessionId) : null;
|
|
@@ -1295,24 +1489,31 @@ async function onApprovalRequest(s, ctx, req, next) {
|
|
|
1295
1489
|
// 同一个请求重复进入(理论上不会)直接拒绝,避免两个 waiter 争同一个 id。
|
|
1296
1490
|
if (pendingApprovals.has(requestId)) return 'rejected';
|
|
1297
1491
|
|
|
1298
|
-
//
|
|
1299
|
-
//
|
|
1492
|
+
// 自动放行(两条独立通道,命中即 allowed-once,镜像 decidedBy:"auto",不打扰 Lead):
|
|
1493
|
+
// ① autoApproveTools:显式工具白名单(支持 *),不依赖参数;
|
|
1494
|
+
// ② autoApproveLowRisk:工具名像 shell、参数里带 command、且命令通过白名单校验。
|
|
1300
1495
|
const cached = sessionId && req?.callId != null ? cachedPreExecuteArgs(sessionId, String(req.callId)) : null;
|
|
1496
|
+
const cachedToolName = String(cached?.name || '');
|
|
1497
|
+
const autoApprove = (autoReason) => {
|
|
1498
|
+
void request(s, '/api/approvals', {
|
|
1499
|
+
method: 'POST',
|
|
1500
|
+
body: {
|
|
1501
|
+
id: requestId, teamId: info.teamId, memberId: info.memberId,
|
|
1502
|
+
sessionId, toolName: info.toolName, reason: autoReason,
|
|
1503
|
+
},
|
|
1504
|
+
}).then(() => request(s, `/api/approvals/${encodeURIComponent(requestId)}/decide`, {
|
|
1505
|
+
method: 'POST', body: { decision: 'allowed', decidedBy: 'auto', reason: autoReason },
|
|
1506
|
+
})).catch(() => { /* 镜像失败不影响放行 */ });
|
|
1507
|
+
return 'allowed-once';
|
|
1508
|
+
};
|
|
1509
|
+
if (isAutoApprovedTool(s.autoApproveTools, cachedToolName, info.toolName)) {
|
|
1510
|
+
return autoApprove(`工具白名单自动放行:${info.toolName || cachedToolName}`);
|
|
1511
|
+
}
|
|
1301
1512
|
if (s.autoApproveLowRisk && cached) {
|
|
1302
1513
|
const toolName = String(cached.name || info.toolName || '');
|
|
1303
1514
|
const command = cached.args?.command;
|
|
1304
1515
|
if (SHELL_TOOL_RE.test(toolName) && typeof command === 'string' && isLowRiskCommand(command, s.sensitiveCommandPatterns)) {
|
|
1305
|
-
|
|
1306
|
-
void request(s, '/api/approvals', {
|
|
1307
|
-
method: 'POST',
|
|
1308
|
-
body: {
|
|
1309
|
-
id: requestId, teamId: info.teamId, memberId: info.memberId,
|
|
1310
|
-
sessionId, toolName: info.toolName, reason: autoReason,
|
|
1311
|
-
},
|
|
1312
|
-
}).then(() => request(s, `/api/approvals/${encodeURIComponent(requestId)}/decide`, {
|
|
1313
|
-
method: 'POST', body: { decision: 'allowed', decidedBy: 'auto', reason: autoReason },
|
|
1314
|
-
})).catch(() => { /* 镜像失败不影响放行 */ });
|
|
1315
|
-
return 'allowed-once';
|
|
1516
|
+
return autoApprove(`低风险命令自动放行:${clip(command, 300)}`);
|
|
1316
1517
|
}
|
|
1317
1518
|
}
|
|
1318
1519
|
|
|
@@ -1463,6 +1664,8 @@ async function readStatus(s) {
|
|
|
1463
1664
|
|
|
1464
1665
|
/** sessionId → 最近一次从 sidecar 看到的成员状态;用于只强制中断一次。 */
|
|
1465
1666
|
const forceStopSeen = new Map();
|
|
1667
|
+
/** teamId → 最近一次已处理的停止时间戳:面板停团队时顺带取消 Lead 的当前回合。 */
|
|
1668
|
+
const leadStopSeen = new Map();
|
|
1466
1669
|
|
|
1467
1670
|
/**
|
|
1468
1671
|
* 面板/看板停止只走 sidecar(不经过 Host 插件),sidecar 改不了 DSH 会话。
|
|
@@ -1486,6 +1689,9 @@ async function forceStopPump(s, ctx) {
|
|
|
1486
1689
|
if (heldSessions.has(sid)) continue;
|
|
1487
1690
|
const parentSessionId = m.parentSessionId != null ? String(m.parentSessionId) : null;
|
|
1488
1691
|
if (!parentSessionId) continue;
|
|
1692
|
+
// recover(sidecar 重启恢复现场)不是 Lead 主动中断:必须主动通知 Lead,
|
|
1693
|
+
// 否则 Lead 挂起时只会看到成员「没声了」,永远等不到中断说明。
|
|
1694
|
+
const recover = (m.blockers || []).some((b) => b && b.kind === 'recover');
|
|
1489
1695
|
heldSessions.add(sid);
|
|
1490
1696
|
cancelIdleReport(sid);
|
|
1491
1697
|
cancelStartWatchdog(sid);
|
|
@@ -1497,15 +1703,43 @@ async function forceStopPump(s, ctx) {
|
|
|
1497
1703
|
heldSessions.delete(sid);
|
|
1498
1704
|
forceStopSeen.delete(sid);
|
|
1499
1705
|
}
|
|
1706
|
+
if (recover) {
|
|
1707
|
+
void notifyLeadOfMemberInterrupt(s, ctx, {
|
|
1708
|
+
teamId: m.teamId,
|
|
1709
|
+
memberId: m.id,
|
|
1710
|
+
memberName: m.name,
|
|
1711
|
+
taskId: m.currentTaskId ?? null,
|
|
1712
|
+
sessionId: sid,
|
|
1713
|
+
leadSessionId: parentSessionId,
|
|
1714
|
+
status: 'interrupted',
|
|
1715
|
+
reason: 'sidecar 重启恢复现场:成员会话的在途回合被判定为中断(recover)',
|
|
1716
|
+
dedupeKey: `recover:${m.id}:${m.seq}`,
|
|
1717
|
+
}).catch(() => { /* 通知尽力而为,不影响冻结 */ });
|
|
1718
|
+
}
|
|
1500
1719
|
}
|
|
1501
1720
|
for (const sid of forceStopSeen.keys()) if (!live.has(sid)) forceStopSeen.delete(sid);
|
|
1721
|
+
|
|
1722
|
+
// 停止团队不只是中断成员:Lead 会话(团队创建者)也必须在当前回合被停下,
|
|
1723
|
+
// 否则面板显示「已停止」而 Lead 仍在派发/写代码。sidecar 只记录停止时间戳,
|
|
1724
|
+
// 真正取消由 Host 做(canceling 等价于用户按停止键)。
|
|
1725
|
+
const agents = agentsOf(ctx);
|
|
1726
|
+
for (const t of status.teams || []) {
|
|
1727
|
+
const sid = t?.leadSessionId != null ? String(t.leadSessionId) : null;
|
|
1728
|
+
const stamp = t?.stopRequestedAt != null ? String(t.stopRequestedAt) : '';
|
|
1729
|
+
if (!sid || !stamp || leadStopSeen.get(t.id) === stamp) continue;
|
|
1730
|
+
const agent = agents && typeof agents.get === 'function' ? agents.get(sid) : null;
|
|
1731
|
+
if (!agent) continue; // 会话不归本进程管:留到下次轮询或由 DSH 自身收尾
|
|
1732
|
+
leadStopSeen.set(t.id, stamp);
|
|
1733
|
+
if (agent.status !== 'running') continue; // 已经空闲,没有可取消的回合
|
|
1734
|
+
try { agent.cancel({ kind: 'user' }); } catch { leadStopSeen.delete(t.id); }
|
|
1735
|
+
}
|
|
1502
1736
|
}
|
|
1503
1737
|
|
|
1504
1738
|
/** DSH 内置 todo 的状态 → sidecar 计划步骤的状态。 */
|
|
1505
1739
|
const TODO_TO_PLAN = { pending: 'open', in_progress: 'active', completed: 'done' };
|
|
1506
1740
|
|
|
1507
1741
|
/**
|
|
1508
|
-
* 成员没用
|
|
1742
|
+
* 成员没用 dsh_team_todo、而是用了内置 todo_write 时,把 DSH 的 `todos` 投影镜像成 sidecar 计划。
|
|
1509
1743
|
* todo_write 每次整份替换,这里也整份替换(POST /api/tasks/<taskId>/todos),
|
|
1510
1744
|
* 于是「todo 完成 → 计划步骤完成」自动同步,面板与团队校验都能看到成员的真实 plan。
|
|
1511
1745
|
*/
|
|
@@ -1577,14 +1811,12 @@ const steerInFlight = new Set();
|
|
|
1577
1811
|
|
|
1578
1812
|
async function steerPump(s, ctx) {
|
|
1579
1813
|
if (!sessionMember.size) return;
|
|
1580
|
-
const subs = subagentsOf(ctx);
|
|
1581
|
-
if (!subs || typeof subs.sendMessage !== 'function') return;
|
|
1582
1814
|
const teams = new Set();
|
|
1583
1815
|
for (const binding of sessionMember.values()) if (binding?.teamId) teams.add(binding.teamId);
|
|
1584
1816
|
|
|
1585
1817
|
for (const teamId of teams) {
|
|
1586
1818
|
const caller = leadByTeam.get(teamId);
|
|
1587
|
-
if (!caller) continue;
|
|
1819
|
+
if (!caller || !canDeliverTo(ctx, caller)) continue;
|
|
1588
1820
|
const res = await request(
|
|
1589
1821
|
s,
|
|
1590
1822
|
`/api/messages${qs({ team: teamId, status: 'queued', limit: 100 })}`,
|
|
@@ -1611,7 +1843,7 @@ async function steerPump(s, ctx) {
|
|
|
1611
1843
|
if (!text) { await markDelivered(s, message.id); continue; }
|
|
1612
1844
|
steerInFlight.add(message.id);
|
|
1613
1845
|
try {
|
|
1614
|
-
await
|
|
1846
|
+
await sendAgentMessage(ctx, caller, String(binding[0]), text, {
|
|
1615
1847
|
signal: AbortSignal.timeout(s.requestTimeoutMs),
|
|
1616
1848
|
});
|
|
1617
1849
|
await markDelivered(s, message.id);
|
|
@@ -1638,7 +1870,7 @@ function assistantReplyText(message) {
|
|
|
1638
1870
|
|
|
1639
1871
|
/**
|
|
1640
1872
|
* 把成员这一轮的结论作为 member→lead 的消息落库(kind=response)。
|
|
1641
|
-
* 成员用 send_message /
|
|
1873
|
+
* 成员用 send_message / dsh_team_report_task 回话都不经过消息总线,面板里只剩 Lead 单向提问;
|
|
1642
1874
|
* 收工时补一条回复,【消息与回执】才能配对成双向箭头并展示两条正文。
|
|
1643
1875
|
*/
|
|
1644
1876
|
async function flushMemberReply(s, sessionId) {
|
|
@@ -1708,6 +1940,7 @@ const textOutput = () => ({
|
|
|
1708
1940
|
// ---------------------------------------------------------------------------
|
|
1709
1941
|
const boardSessions = new Map(); // sessionId -> { taskId, phase, handle, sawRunning }
|
|
1710
1942
|
const boardSessionIds = new Set();
|
|
1943
|
+
const boardStopSeen = new Map(); // taskId -> 已处理的 stopRequestedAt(取消过一次就不再取消)
|
|
1711
1944
|
|
|
1712
1945
|
function boardUserMessage(text) {
|
|
1713
1946
|
return {
|
|
@@ -1762,15 +1995,243 @@ function boardSetPermission(ctx, agent, preset) {
|
|
|
1762
1995
|
}
|
|
1763
1996
|
}
|
|
1764
1997
|
|
|
1998
|
+
/**
|
|
1999
|
+
* 把同一个会话下一次请求的模型切到执行路由。
|
|
2000
|
+
*
|
|
2001
|
+
* 走 DSH 的会话级模型选择(`agent.model.select`,与 Web UI 里切换模型同一条链路):
|
|
2002
|
+
* 追加一条 durable `model/selection` 事件,下一步装配请求时生效,并自动补一条
|
|
2003
|
+
* "model changed" 通知;会话历史、工具结果、todo、已经改过的文件全部留在原地,
|
|
2004
|
+
* 不新建会话、也不改部署默认模型。失败时保持原模型继续执行,不阻断任务。
|
|
2005
|
+
*/
|
|
2006
|
+
function boardSelectionOf(route) {
|
|
2007
|
+
return {
|
|
2008
|
+
...(route?.provider ? { provider: route.provider } : {}),
|
|
2009
|
+
model: route?.model,
|
|
2010
|
+
...(route?.reasoningEffort ? { reasoningEffort: route.reasoningEffort } : {}),
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
function boardSameSelection(a, b) {
|
|
2015
|
+
return !!a && !!b
|
|
2016
|
+
&& a.model === b.model
|
|
2017
|
+
&& (a.provider || undefined) === (b.provider || undefined)
|
|
2018
|
+
&& (a.reasoningEffort || undefined) === (b.reasoningEffort || undefined);
|
|
2019
|
+
}
|
|
2020
|
+
|
|
2021
|
+
/**
|
|
2022
|
+
* 规划路由与执行路由是否不同:只看显式配置的执行路由(task.leadRoute / settings.lead),
|
|
2023
|
+
* 没有配置时不猜部署默认模型,保持原模型继续。
|
|
2024
|
+
*/
|
|
2025
|
+
function boardExecutionRouteDiffers(ctx, task, settings) {
|
|
2026
|
+
if (!task || task.executionMode !== 'same') return false;
|
|
2027
|
+
const exec = boardRoute(task, settings || {}, 'inprogress');
|
|
2028
|
+
if (!exec?.model) return false;
|
|
2029
|
+
const plan = boardRouteOrDefault(ctx, task, settings || {}, 'planning');
|
|
2030
|
+
return !boardSameSelection(boardSelectionOf(plan), boardSelectionOf(exec));
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
async function boardApplyExecutionModel(ctx, agent, task, settings) {
|
|
2034
|
+
const target = boardRoute(task, settings || {}, 'inprogress');
|
|
2035
|
+
if (!target?.model) return { switched: false, reason: '没有可用的执行模型' };
|
|
2036
|
+
const model = agent?.model;
|
|
2037
|
+
let current;
|
|
2038
|
+
if (model && typeof model.current === 'function') {
|
|
2039
|
+
try { current = model.current(); } catch { current = undefined; }
|
|
2040
|
+
}
|
|
2041
|
+
let selection = boardSelectionOf(target);
|
|
2042
|
+
// 只配了模型没配 provider 时沿用当前 provider,避免写入非法选择。
|
|
2043
|
+
if (!selection.provider && current?.provider) selection.provider = current.provider;
|
|
2044
|
+
if (!selection.provider) {
|
|
2045
|
+
try { selection.provider = ctx.get('agentDefaultModel')?.currentSelection?.()?.provider; } catch { /* ignore */ }
|
|
2046
|
+
}
|
|
2047
|
+
if (!selection.provider) return { switched: false, reason: '执行模型缺少 provider' };
|
|
2048
|
+
const llm = llmOf(ctx);
|
|
2049
|
+
if (llm && typeof llm.resolveCallConfig === 'function') {
|
|
2050
|
+
try {
|
|
2051
|
+
const resolved = await llm.resolveCallConfig(selection);
|
|
2052
|
+
selection = {
|
|
2053
|
+
...(resolved?.provider ? { provider: resolved.provider } : selection),
|
|
2054
|
+
model: resolved?.model || selection.model,
|
|
2055
|
+
...(resolved?.reasoningEffort ? { reasoningEffort: resolved.reasoningEffort } : {}),
|
|
2056
|
+
};
|
|
2057
|
+
} catch (err) {
|
|
2058
|
+
console.warn(`[dsh-team] prewalk: 执行模型不可用(${String(err?.message || err)}),保持规划模型继续执行`);
|
|
2059
|
+
return { switched: false, reason: '执行模型不可用' };
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
if (model && typeof model.select === 'function') {
|
|
2063
|
+
if (boardSameSelection(current, selection)) return { switched: false, reason: '已经是执行模型' };
|
|
2064
|
+
try {
|
|
2065
|
+
model.select(selection);
|
|
2066
|
+
} catch (err) {
|
|
2067
|
+
console.warn(`[dsh-team] prewalk: 切换模型失败(${String(err?.message || err)}),保持规划模型继续执行`);
|
|
2068
|
+
return { switched: false, reason: '切换模型失败' };
|
|
2069
|
+
}
|
|
2070
|
+
console.log(`[dsh-team] prewalk: 会话 ${String(agent.id)} 切到 ${selection.provider || '默认'}/${selection.model} 继续执行`);
|
|
2071
|
+
return { switched: true, selection };
|
|
2072
|
+
}
|
|
2073
|
+
// 兼容旧 Host:sessionController 的会话级选择(当前 DSH 已不提供)。
|
|
2074
|
+
let controller;
|
|
2075
|
+
try { controller = ctx.get('sessionController'); } catch { controller = undefined; }
|
|
2076
|
+
const sessions = controller?.agents;
|
|
2077
|
+
if (!sessions || typeof sessions.selectionFor !== 'function' || typeof sessions.selectForNextRequest !== 'function') {
|
|
2078
|
+
console.warn('[dsh-team] prewalk: 当前 Host 不支持会话内切换模型,保持规划模型继续执行');
|
|
2079
|
+
return { switched: false, reason: 'Host 不支持会话内切换模型' };
|
|
2080
|
+
}
|
|
2081
|
+
if (!current) {
|
|
2082
|
+
try { current = sessions.selectionFor(agent)?.current; } catch { current = undefined; }
|
|
2083
|
+
}
|
|
2084
|
+
if (boardSameSelection(current, selection)) return { switched: false, reason: '已经是执行模型' };
|
|
2085
|
+
try {
|
|
2086
|
+
sessions.selectForNextRequest(agent, selection);
|
|
2087
|
+
} catch (err) {
|
|
2088
|
+
console.warn(`[dsh-team] prewalk: 切换模型失败(${String(err?.message || err)}),保持规划模型继续执行`);
|
|
2089
|
+
return { switched: false, reason: '切换模型失败' };
|
|
2090
|
+
}
|
|
2091
|
+
console.log(`[dsh-team] prewalk: 会话 ${String(agent.id)} 切到 ${selection.provider || '默认'}/${selection.model} 继续执行`);
|
|
2092
|
+
return { switched: true, selection };
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
/**
|
|
2096
|
+
* 触发 prewalk 交接的「实现动作」。
|
|
2097
|
+
*
|
|
2098
|
+
* 对齐官方语义:不在计划提交时切换,而是等规划模型在同一条会话里落下第一笔实现
|
|
2099
|
+
* 动作之后(首个 edit/write 类工具结果;团队任务则是 Lead 的首次 dsh_team_task 派发),
|
|
2100
|
+
* 再把剩下的活交给执行模型,避免便宜模型接手后才发现计划不可执行。
|
|
2101
|
+
*/
|
|
2102
|
+
const PREWALK_EDIT_TOOLS = new Set(['write', 'edit', 'str_replace_editor']);
|
|
2103
|
+
const PREWALK_DISPATCH_TOOLS = new Set(['dsh_team_task']);
|
|
2104
|
+
|
|
2105
|
+
/** 执行阶段已武装、等待首次实现动作的会话:sessionId → { task, settings }。 */
|
|
2106
|
+
const prewalkArmed = new Map();
|
|
2107
|
+
|
|
2108
|
+
function boardPrewalkWantsTool(name) {
|
|
2109
|
+
return PREWALK_EDIT_TOOLS.has(name) || PREWALK_DISPATCH_TOOLS.has(name);
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
/** 会话里是否已经出现过实现动作(插件重启 / 会话恢复后据此立即补一次交接)。 */
|
|
2113
|
+
function boardSessionStartedImplementation(agent) {
|
|
2114
|
+
try {
|
|
2115
|
+
const session = agent?.session;
|
|
2116
|
+
if (!session || typeof session.eventAt !== 'function' || typeof session.seq !== 'number') return false;
|
|
2117
|
+
const callIds = new Set();
|
|
2118
|
+
for (let seq = 0; seq < session.seq; seq += 1) {
|
|
2119
|
+
const event = session.eventAt(seq);
|
|
2120
|
+
if (!event) continue;
|
|
2121
|
+
if (event.type === 'tool/call' && boardPrewalkWantsTool(String(event.data?.name || ''))) {
|
|
2122
|
+
callIds.add(String(event.data?.callId || ''));
|
|
2123
|
+
} else if (event.type === 'tool/result') {
|
|
2124
|
+
const ok = event.data?.message?.isError !== true;
|
|
2125
|
+
if (ok && callIds.has(String(event.data?.message?.toolCallId || ''))) return true;
|
|
2126
|
+
}
|
|
2127
|
+
}
|
|
2128
|
+
return false;
|
|
2129
|
+
} catch { return false; }
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
/**
|
|
2133
|
+
* 交接 steering:只说「继续」。
|
|
2134
|
+
* 计划、todo、已读文件与已做改动都在会话上下文里,任何附加清单都会诱导接手模型
|
|
2135
|
+
* 逐条核对、重新读文件;让它接着上文做完即可。规划刚提交时用「继续执行计划」,
|
|
2136
|
+
* 明确告诉接手模型规划阶段已经结束。
|
|
2137
|
+
*/
|
|
2138
|
+
function boardHandoffSteering(kind) {
|
|
2139
|
+
return kind === 'plan-submitted' ? '继续执行计划' : '继续';
|
|
2140
|
+
}
|
|
2141
|
+
|
|
2142
|
+
/** 交接:切到执行模型并注入一条简短的继续指令;一次任务只做一次。 */
|
|
2143
|
+
async function boardHandoffExecution(ctx, agent, task, settings, kind) {
|
|
2144
|
+
const sessionId = agent?.id != null ? String(agent.id) : null;
|
|
2145
|
+
if (sessionId) prewalkArmed.delete(sessionId);
|
|
2146
|
+
const result = await boardApplyExecutionModel(ctx, agent, task, settings || {});
|
|
2147
|
+
if (!result?.switched) return result;
|
|
2148
|
+
const steering = boardHandoffSteering(kind);
|
|
2149
|
+
try {
|
|
2150
|
+
if (typeof agent.steer === 'function') agent.steer(boardUserMessage(steering));
|
|
2151
|
+
else if (typeof agent.followup === 'function') agent.followup(boardUserMessage(steering));
|
|
2152
|
+
console.log(`[dsh-team] prewalk: 继续指令已注入会话 ${sessionId}`);
|
|
2153
|
+
} catch (err) {
|
|
2154
|
+
console.warn(`[dsh-team] prewalk: 注入继续指令失败(${String(err?.message || err)})`);
|
|
2155
|
+
}
|
|
2156
|
+
return result;
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
/**
|
|
2160
|
+
* 武装 prewalk:记录待交接,等首个实现动作再切模型。
|
|
2161
|
+
* 恢复/重启时如果实现动作已经发生过,直接交接,避免规划模型继续用着贵模型干完。
|
|
2162
|
+
*/
|
|
2163
|
+
async function armBoardPrewalk(ctx, agent, task, settings) {
|
|
2164
|
+
const sessionId = agent?.id != null ? String(agent.id) : null;
|
|
2165
|
+
if (!sessionId || !agent || !task?.prewalk) return false;
|
|
2166
|
+
if (boardSessionStartedImplementation(agent)) {
|
|
2167
|
+
await boardHandoffExecution(ctx, agent, task, settings);
|
|
2168
|
+
return true;
|
|
2169
|
+
}
|
|
2170
|
+
if (!prewalkArmed.has(sessionId)) prewalkArmed.set(sessionId, { task, settings: settings || {} });
|
|
2171
|
+
return false;
|
|
2172
|
+
}
|
|
2173
|
+
|
|
1765
2174
|
function boardPromptModels(task) {
|
|
1766
2175
|
return Array.isArray(task.teamModels) && task.teamModels.length
|
|
1767
2176
|
? task.teamModels.map((m) => (typeof m === 'string' ? m : `${m.provider ? m.provider + '/' : ''}${m.model}`)).join('\n')
|
|
1768
2177
|
: '不限制';
|
|
1769
2178
|
}
|
|
1770
2179
|
|
|
2180
|
+
// 看板任务的 git 分支:任务开启分支时,spawn 前先切好(不存在就从当前 HEAD 新建)。
|
|
2181
|
+
// git 是可选能力:目录不是仓库 / 没装 git / 切换失败都不阻断任务,只在 prompt 里降级说明。
|
|
2182
|
+
function gitRun(cwd, args) {
|
|
2183
|
+
return execFileSync('git', ['-C', cwd, ...args], { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
function ensureBoardGitBranch(task) {
|
|
2187
|
+
const branch = String(task?.gitBranch || '').trim();
|
|
2188
|
+
if (!branch) return { branch: null, ok: true };
|
|
2189
|
+
const cwd = String(task.workspacePath || '').trim();
|
|
2190
|
+
if (!cwd) return { branch, ok: false, reason: '工作区路径为空' };
|
|
2191
|
+
try {
|
|
2192
|
+
if (gitRun(cwd, ['rev-parse', '--is-inside-work-tree']).trim() !== 'true') {
|
|
2193
|
+
return { branch, ok: false, reason: '工作区不是 git 仓库' };
|
|
2194
|
+
}
|
|
2195
|
+
} catch {
|
|
2196
|
+
return { branch, ok: false, reason: '工作区不是 git 仓库,或本机没有 git' };
|
|
2197
|
+
}
|
|
2198
|
+
try {
|
|
2199
|
+
const cur = gitRun(cwd, ['rev-parse', '--abbrev-ref', 'HEAD']).trim();
|
|
2200
|
+
if (cur === branch) return { branch, ok: true };
|
|
2201
|
+
} catch { /* 空仓库没有 HEAD,继续尝试新建分支 */ }
|
|
2202
|
+
let exists = false;
|
|
2203
|
+
try {
|
|
2204
|
+
gitRun(cwd, ['rev-parse', '--verify', '--quiet', `refs/heads/${branch}`]);
|
|
2205
|
+
exists = true;
|
|
2206
|
+
} catch { exists = false; }
|
|
2207
|
+
try {
|
|
2208
|
+
gitRun(cwd, exists ? ['checkout', branch] : ['checkout', '-b', branch]);
|
|
2209
|
+
return { branch, ok: true, created: !exists };
|
|
2210
|
+
} catch (err) {
|
|
2211
|
+
const msg = String(err?.stderr || err?.message || err).trim().split(/\r?\n/).filter(Boolean).slice(-2).join(' ');
|
|
2212
|
+
console.warn(`[dsh-team] board git branch ${branch} checkout failed: ${msg}`);
|
|
2213
|
+
return { branch, ok: false, reason: msg || 'git 切分支失败' };
|
|
2214
|
+
}
|
|
2215
|
+
}
|
|
2216
|
+
|
|
2217
|
+
// prompt 里的分支说明:正常时一句话告知「已在目标分支上」;失败时允许自行补救但不强制。
|
|
2218
|
+
function boardBranchLines(task) {
|
|
2219
|
+
const branch = String(task?.gitBranch || '').trim();
|
|
2220
|
+
if (!branch) return [];
|
|
2221
|
+
const st = task.gitBranchState;
|
|
2222
|
+
if (!st || st.ok) {
|
|
2223
|
+
return [`git 分支:${branch}(会话开始前已切好,直接在该分支上改文件;不要自行 checkout 其他分支)`];
|
|
2224
|
+
}
|
|
2225
|
+
return [
|
|
2226
|
+
`git 分支:目标是 ${branch},但自动切分支失败(${st.reason || '未知原因'})。`
|
|
2227
|
+
+ `可以用 shell 执行 git checkout -b ${branch}(已存在则 git checkout ${branch})后继续;`
|
|
2228
|
+
+ '如果仍失败,就在当前分支继续完成工作,并在最终汇报里明确说明分支未切换。',
|
|
2229
|
+
];
|
|
2230
|
+
}
|
|
2231
|
+
|
|
1771
2232
|
function boardPlanningPrompt(task, settings) {
|
|
1772
2233
|
const useTeam = task.useTeam !== false;
|
|
1773
|
-
// 同会话模式:规划与执行是同一个会话,
|
|
2234
|
+
// 同会话模式:规划与执行是同一个会话,dsh_team_board_plan_submit 会直接领执行槽位,
|
|
1774
2235
|
// 所以执行规则从一开始就写进规划 prompt,提交后不再补发「现在开始执行」。
|
|
1775
2236
|
const sameSession = task.executionMode === 'same';
|
|
1776
2237
|
const models = boardPromptModels(task);
|
|
@@ -1780,10 +2241,11 @@ function boardPlanningPrompt(task, settings) {
|
|
|
1780
2241
|
? '这一轮先只做规划,不要写代码、不要修改文件、不要创建团队。'
|
|
1781
2242
|
: '只做规划,不写代码、不修改文件、不创建团队。',
|
|
1782
2243
|
sameSession
|
|
1783
|
-
? '计划提交后读取
|
|
2244
|
+
? '计划提交后读取 dsh_team_board_plan_submit 的返回:status 是 inprogress 就直接在同一会话里按计划开始执行(此时可以写文件、可以调用 team_*);status 是 planned 说明执行槽位已满,立刻停下等待调度器。'
|
|
1784
2245
|
: '规划完成后不要开始执行;调度器会在执行槽位空出后,在同一会话里让你继续。',
|
|
1785
2246
|
'',
|
|
1786
2247
|
`工作区:${task.workspacePath}`,
|
|
2248
|
+
...boardBranchLines(task),
|
|
1787
2249
|
'任务描述:',
|
|
1788
2250
|
task.description || '(无)',
|
|
1789
2251
|
'',
|
|
@@ -1813,7 +2275,7 @@ function boardPlanningPrompt(task, settings) {
|
|
|
1813
2275
|
...head,
|
|
1814
2276
|
...body,
|
|
1815
2277
|
'',
|
|
1816
|
-
'最后必须调用
|
|
2278
|
+
'最后必须调用 dsh_team_board_plan_submit({ plan: "<完整 markdown>", summary: "<一句话>" })。',
|
|
1817
2279
|
'不要只把计划写在回复里。',
|
|
1818
2280
|
...(sameSession
|
|
1819
2281
|
? ['', '提交后如果返回 inprogress,继续按下面的规则执行;返回 planned 则忽略这些规则并停下:', '', ...boardLeadRules(task)]
|
|
@@ -1825,32 +2287,45 @@ function boardLeadRules(task) {
|
|
|
1825
2287
|
const useTeam = task.useTeam !== false;
|
|
1826
2288
|
const models = boardPromptModels(task);
|
|
1827
2289
|
// 任务已有关联团队(重试、失败后继续、或完成后再次执行)时,在原团队上接着干,
|
|
1828
|
-
// 不要每轮都
|
|
2290
|
+
// 不要每轮都 dsh_team_create 出一个新团队。
|
|
1829
2291
|
const teams = Array.isArray(task.teams) ? task.teams.filter(Boolean).map(String) : [];
|
|
1830
2292
|
const teamRule = teams.length
|
|
1831
|
-
? `1. 本任务已关联团队:${teams.join('、')}。不要调用
|
|
1832
|
-
+ '在原团队里用
|
|
1833
|
-
+ '只有原团队已被删除或全部不可用时,才允许
|
|
1834
|
-
: '1. 先调用
|
|
2293
|
+
? `1. 本任务已关联团队:${teams.join('、')}。不要调用 dsh_team_create 新建团队:先 dsh_team_status 查看这些团队的现状,`
|
|
2294
|
+
+ '在原团队里用 dsh_team_task 追加剩余工作继续推进;已经完成的成员任务不要重复创建。'
|
|
2295
|
+
+ '只有原团队已被删除或全部不可用时,才允许 dsh_team_create 新团队(若既有团队需要继续保留、只是要并行新建,必须显式传 force: true)。'
|
|
2296
|
+
: '1. 先调用 dsh_team_create 创建团队;name 用任务标题,workspace 用上面的路径。需要多个团队就多次创建,所有团队都会自动绑定到本任务。';
|
|
2297
|
+
// 用户嘴里的「新任务」经常被 Lead 误当成当前团队的 DAG 节点:先强制做归属判断。
|
|
2298
|
+
const scopeRules = [
|
|
2299
|
+
'先判断用户这次说的事是不是「新任务」:',
|
|
2300
|
+
'- 同一目标 / 同一模块或文件 / 同一验收 / 同一分支 → 是本任务的一部分,在本任务(或本团队)里继续推进。',
|
|
2301
|
+
'- 交付物或验收不同、需要单独分支或单独规划、做完之后不再依赖本任务上下文 → 这是独立的一件事:调用 dsh_team_board_task_create 给它建一张看板卡(workspaceId / workspacePath 沿用本任务),不要用 dsh_team_task 塞进当前团队。',
|
|
2302
|
+
'- 用户明确说「建看板任务 / 加一张卡 / 单开一个会话」→ 一律 dsh_team_board_task_create,禁止 dsh_team_task。',
|
|
2303
|
+
'- 判断不清就先问用户一句「这算当前任务的一部分,还是另开一张卡?」,不要猜。',
|
|
2304
|
+
'记住:dsh_team_task 只拆解当前任务,它不会出现在用户的看板上;用户说的「任务」通常指看板卡片。',
|
|
2305
|
+
];
|
|
1835
2306
|
const teamRules = [
|
|
1836
2307
|
'开始执行前,先加载 `dsh-agent-team` 技能(调用 skill 工具,参数 {"name":"dsh-agent-team"}),按技能里的团队编排流程、工具字段与常见错法执行,不要凭记忆猜参数。',
|
|
1837
2308
|
'',
|
|
2309
|
+
...scopeRules,
|
|
2310
|
+
'',
|
|
1838
2311
|
'规则:',
|
|
1839
2312
|
teamRule,
|
|
1840
|
-
'2. 调用
|
|
2313
|
+
'2. 调用 dsh_team_models 查看可用路由;只能使用以下模型:',
|
|
1841
2314
|
models,
|
|
1842
|
-
'3. 用
|
|
1843
|
-
'4. 用户反馈 Bug 时,不要自己去读代码排查:先判断归属成员,用
|
|
1844
|
-
'5. 每轮结束前必须先调用
|
|
1845
|
-
'6. 用户再次发消息时,先调用
|
|
2315
|
+
'3. 用 dsh_team_task 拆解并派发;用 dsh_team_status / dsh_team_report 跟踪。不要自己写代码,不要重复成员的工作。成员按能力域分配:同一模块/相邻功能、或一个成员能顺手做完的多个条目,合并给同一个成员;成员数取能完成工作的最小值,不要按需求条目数量等量创建成员。',
|
|
2316
|
+
'4. 用户反馈 Bug 时,不要自己去读代码排查:先判断归属成员,用 dsh_team_send 把复现步骤与怀疑点派给对应成员定位、修复;你只做分派、汇总与状态汇报。',
|
|
2317
|
+
'5. 每轮结束前必须先调用 dsh_team_board_task_status 对齐状态:全部任务成功→done(附完成摘要),失败→failed(附原因),仍需继续或等待用户→inprogress。不能只在开始时调用一次。',
|
|
2318
|
+
'6. 用户再次发消息时,先调用 dsh_team_board_task_status({ status: "inprogress" }),再继续处理。',
|
|
1846
2319
|
];
|
|
1847
2320
|
const soloRules = [
|
|
1848
|
-
'本任务不开启团队:由你自己直接完成所有工作,不要调用
|
|
2321
|
+
'本任务不开启团队:由你自己直接完成所有工作,不要调用 dsh_team_create / dsh_team_spawn / dsh_team_task。',
|
|
2322
|
+
'',
|
|
2323
|
+
...scopeRules,
|
|
1849
2324
|
'',
|
|
1850
2325
|
'规则:',
|
|
1851
2326
|
'1. 按任务描述直接修改文件、运行命令并验证结果。',
|
|
1852
|
-
'2. 每轮结束前必须先调用
|
|
1853
|
-
'3. 用户再次发消息时,先调用
|
|
2327
|
+
'2. 每轮结束前必须先调用 dsh_team_board_task_status 对齐状态:全部完成→done(附完成摘要),失败→failed(附原因),仍需继续或等待用户→inprogress。不能只在开始时调用一次。',
|
|
2328
|
+
'3. 用户再次发消息时,先调用 dsh_team_board_task_status({ status: "inprogress" }),再继续处理。',
|
|
1854
2329
|
];
|
|
1855
2330
|
return useTeam ? teamRules : soloRules;
|
|
1856
2331
|
}
|
|
@@ -1863,12 +2338,14 @@ function boardLeadPrompt(task, sameSession) {
|
|
|
1863
2338
|
if (sameSession) {
|
|
1864
2339
|
return [
|
|
1865
2340
|
`现在开始执行「${task.title}」。计划就在同一会话的上文里,不要重复输出计划。`,
|
|
2341
|
+
...boardBranchLines(task),
|
|
1866
2342
|
'',
|
|
1867
2343
|
...rules,
|
|
1868
2344
|
].join('\n');
|
|
1869
2345
|
}
|
|
1870
2346
|
const lines = [
|
|
1871
2347
|
`你是任务「${task.title}」的${useTeam ? ' Lead' : '执行 Agent'}。工作区:${task.workspacePath}`,
|
|
2348
|
+
...boardBranchLines(task),
|
|
1872
2349
|
needPlan ? '以下是规划会话产出的计划,现在开始执行。' : '本任务不需要规划,直接开始执行。',
|
|
1873
2350
|
'',
|
|
1874
2351
|
'任务描述:',
|
|
@@ -1917,8 +2394,8 @@ async function guardBoardTeamReuse(s, sessionId, force) {
|
|
|
1917
2394
|
}
|
|
1918
2395
|
if (!alive.length) return;
|
|
1919
2396
|
throw new Error(
|
|
1920
|
-
`本任务已关联团队:${alive.join('、')}。重试/续跑请在原团队上继续:先用
|
|
1921
|
-
+ '确实需要与之并行新建团队时,调用
|
|
2397
|
+
`本任务已关联团队:${alive.join('、')}。重试/续跑请在原团队上继续:先用 dsh_team_status 查看现状,再用 dsh_team_task 追加剩余工作,不要重复 dsh_team_create。`
|
|
2398
|
+
+ '确实需要与之并行新建团队时,调用 dsh_team_create 并显式传 force: true。',
|
|
1922
2399
|
);
|
|
1923
2400
|
}
|
|
1924
2401
|
|
|
@@ -1951,6 +2428,10 @@ async function spawnBoardSession(s, ctx, item) {
|
|
|
1951
2428
|
// 以及 new 模式完成后用户追问,都不能再新建会话。
|
|
1952
2429
|
const sameSession = kind === 'inprogress' && !!task.leadSessionId;
|
|
1953
2430
|
|
|
2431
|
+
// 任务指定 git 分支时,在拉起/复用任何会话之前切好:分支是仓库级状态,会话 cwd 不变,
|
|
2432
|
+
// 同会话续跑也直接落在目标分支上。结果只挂到本地 task 供本轮 prompt 文案使用。
|
|
2433
|
+
task.gitBranchState = ensureBoardGitBranch(task);
|
|
2434
|
+
|
|
1954
2435
|
// 同会话执行:复用规划会话,只切权限 + 投执行 prompt。
|
|
1955
2436
|
if (sameSession) {
|
|
1956
2437
|
const sessionId = String(task.leadSessionId);
|
|
@@ -1974,6 +2455,15 @@ async function spawnBoardSession(s, ctx, item) {
|
|
|
1974
2455
|
rec.sawRunning = false;
|
|
1975
2456
|
boardSessions.set(sessionId, rec);
|
|
1976
2457
|
boardSessionIds.add(sessionId);
|
|
2458
|
+
// prewalk:只武装交接。规划模型先在同一会话里落下第一笔成功的实现动作,
|
|
2459
|
+
// 再由 tools/execute 钩子切模型并注入「继续」;实现动作已经发生(恢复/重启)
|
|
2460
|
+
// 则 armBoardPrewalk 会立即交接,不必等下一笔改动。
|
|
2461
|
+
if (task.prewalk) await armBoardPrewalk(ctx, agent, task, settings);
|
|
2462
|
+
// 规划模型 ≠ 执行模型:复用会话续跑前先静默切到执行模型,
|
|
2463
|
+
// 让紧随其后的执行 prompt(或用户追问)直接由执行模型处理。
|
|
2464
|
+
else if (boardExecutionRouteDiffers(ctx, task, settings)) {
|
|
2465
|
+
await boardApplyExecutionModel(ctx, agent, task, settings);
|
|
2466
|
+
}
|
|
1977
2467
|
// 用户追问触发 done→inprogress 时,真实用户消息已经在会话里;
|
|
1978
2468
|
// 这里只恢复状态与权限,不再注入重复的执行 prompt。
|
|
1979
2469
|
if (!task.resumed) agent.followup(boardUserMessage(boardLeadPrompt(task, true)));
|
|
@@ -2038,6 +2528,28 @@ async function boardPump(s, ctx) {
|
|
|
2038
2528
|
try {
|
|
2039
2529
|
const live = await request(s, '/api/board/live');
|
|
2040
2530
|
for (const task of live?.tasks || []) {
|
|
2531
|
+
// 用户在面板/看板停止任务:sidecar 已把 status 置 failed 并记 stop_requested_at,
|
|
2532
|
+
// 但会话里的回合不会自己停(solo 任务没有团队,连 stopTeam 都走不到)。
|
|
2533
|
+
// 这里对任务当前的 Lead/规划会话取消一次当前回合,语义同用户按停止键。
|
|
2534
|
+
const stopStamp = task?.stopRequestedAt != null ? String(task.stopRequestedAt) : '';
|
|
2535
|
+
if (stopStamp && boardStopSeen.get(task.id) !== stopStamp) {
|
|
2536
|
+
// 只在停止后 2 分钟内取消:插件重启后 boardStopSeen 是空的,旧停止戳不该
|
|
2537
|
+
// 再去打断用户后来对终态任务 Lead 的新追问。
|
|
2538
|
+
const age = Date.now() - Date.parse(stopStamp);
|
|
2539
|
+
if (!Number.isFinite(age) || age > 120_000) { boardStopSeen.set(task.id, stopStamp); continue; }
|
|
2540
|
+
const sid = String(task.leadSessionId || task.planningSessionId || '');
|
|
2541
|
+
const rec = sid ? boardSessions.get(sid) : null;
|
|
2542
|
+
let agent = rec?.handle?.agent || null;
|
|
2543
|
+
if (!agent && sid) {
|
|
2544
|
+
try { agent = agents.get(sid); } catch { agent = null; }
|
|
2545
|
+
}
|
|
2546
|
+
if (agent) {
|
|
2547
|
+
boardStopSeen.set(task.id, stopStamp);
|
|
2548
|
+
if (agent.status === 'running') {
|
|
2549
|
+
try { agent.cancel({ kind: 'user' }); } catch { boardStopSeen.delete(task.id); }
|
|
2550
|
+
}
|
|
2551
|
+
}
|
|
2552
|
+
}
|
|
2041
2553
|
// 插件重启后 boardSessions 是空的:能找回 live agent 就接管,找不回就把
|
|
2042
2554
|
// 永远不可能再推进的任务置 failed,避免占着槽位。
|
|
2043
2555
|
if (task.status === 'done' || task.status === 'failed') {
|
|
@@ -2120,16 +2632,16 @@ function buildTools(s, ctx) {
|
|
|
2120
2632
|
const tools = [];
|
|
2121
2633
|
|
|
2122
2634
|
tools.push({
|
|
2123
|
-
name: '
|
|
2124
|
-
description: 'START HERE to build a working team of agents. Order:
|
|
2635
|
+
name: 'dsh_team_create',
|
|
2636
|
+
description: 'START HERE to build a working team of agents. Order: dsh_team_create({name, workspace, permissionPreset?}) → dsh_team_models() to see the enabled provider/model routes → dsh_team_spawn({teamId, name, prompt, agentProvider?, model?, reasoningEffort?, permissionPreset?}) once per member, choosing a cheap/fast route for mechanical work and a strong-reasoning route for architecture, debugging, or review → dsh_team_task({teamId, subject, assignee?, plan, acceptance}) per DAG node → each member finishes by calling dsh_team_report_task → inspect with dsh_team_status / dsh_team_report. Every member is a real DSH sub-agent session (own model, tools, context, message inbox). `permissionPreset` decides the member sandbox + approval policy (DSH permission presets, e.g. workspace-write or danger-full-access); the team value is the default and dsh_team_spawn can override it per member. When a member hits an operation its preset requires approval for, the approval is forwarded to the Lead, who decides with dsh_team_approve. `workspace` is an absolute directory shared by the members and becomes their cwd. Keep teamId from this response (result.team.id): every later call needs it. Spawn members by capability domain, not one per requirement item: one member can own several related dsh_team_task items, so keep the member count at the minimum needed. For the full recipe with per-field pitfalls, load the skill "dsh-agent-team".',
|
|
2125
2637
|
parameters: {
|
|
2126
2638
|
type: 'object',
|
|
2127
2639
|
additionalProperties: false,
|
|
2128
2640
|
properties: {
|
|
2129
2641
|
name: { type: 'string', description: 'Team name.' },
|
|
2130
2642
|
workspace: { type: 'string', description: 'Absolute directory shared by members; created if missing.' },
|
|
2131
|
-
permissionPreset: { type: 'string', description: 'Default DSH permission preset for members (sandbox + approval policy). Default workspace-write.
|
|
2132
|
-
agentPreset: { type: 'string', description: 'Default DSH agent preset (composition: tools/skills/MCP + system prompt) for members. Omit to use the host default.
|
|
2643
|
+
permissionPreset: { type: 'string', description: 'Default DSH permission preset for members (sandbox + approval policy). Default workspace-write. dsh_team_spawn can override it per member.' },
|
|
2644
|
+
agentPreset: { type: 'string', description: 'Default DSH agent preset (composition: tools/skills/MCP + system prompt) for members. Omit to use the host default. dsh_team_spawn can override it per member.' },
|
|
2133
2645
|
maxMembers: { type: 'integer', description: 'Member cap, 0 means unlimited. Default 64. Extra members are queued, never errors.' },
|
|
2134
2646
|
maxConcurrency: { type: 'integer', description: 'Max simultaneously running tasks. Default 8.' },
|
|
2135
2647
|
failurePolicy: { type: 'string', enum: ['continue', 'abort'], description: 'Team-level default failure policy.' },
|
|
@@ -2159,7 +2671,7 @@ function buildTools(s, ctx) {
|
|
|
2159
2671
|
});
|
|
2160
2672
|
teamCache.set(team.id, team);
|
|
2161
2673
|
if (exec?.agent) leadByTeam.set(team.id, exec.agent);
|
|
2162
|
-
// 会话级粘性绑定:即使后续
|
|
2674
|
+
// 会话级粘性绑定:即使后续 dsh_team_spawn 漏传 teamId,也能解析到本会话刚建的团队。
|
|
2163
2675
|
if (exec?.agent?.id != null) teamBySession.set(String(exec.agent.id), String(team.id));
|
|
2164
2676
|
await bindBoardTeam(s, exec, team.id);
|
|
2165
2677
|
return { team, panel: panelUrl(s) };
|
|
@@ -2167,22 +2679,22 @@ function buildTools(s, ctx) {
|
|
|
2167
2679
|
});
|
|
2168
2680
|
|
|
2169
2681
|
tools.push({
|
|
2170
|
-
name: '
|
|
2171
|
-
description: "Add one member to a team; returns the member `id` you use as
|
|
2682
|
+
name: 'dsh_team_spawn',
|
|
2683
|
+
description: "Add one member to a team; returns the member `id` you use as dsh_team_task's `assignee`. This SPAWNS A REAL DSH SUB-AGENT session (`subagents.startActivation`, continuable child) that owns its own model, context, tools and message inbox; `prompt` is required and becomes the member's first instruction — the member cannot see your conversation, so state the team id, its job, the workspace, and end with: finish by calling dsh_team_report_task({teamId, taskId, status, summary}). Over the member cap the member becomes `queued` instead of failing. Members are reusable: they run one task at a time and return to `idle`. Model routing: call dsh_team_models first, then pass `agentProvider` + `model` to fit the task — a cheap/fast route for mechanical edits and lookups, a strong-reasoning route for architecture, debugging, or review. Pass `reasoningEffort` when the model exposes one; omitting it inherits the Lead's effort only while the route stays the same, otherwise the model's default applies. Omit agentProvider/model to inherit the Lead's route. `permissionPreset` overrides the team default for this member (sandbox + approval policy); approval-required operations are forwarded to the Lead via dsh_team_approve.",
|
|
2172
2684
|
parameters: {
|
|
2173
2685
|
type: 'object',
|
|
2174
2686
|
additionalProperties: false,
|
|
2175
2687
|
properties: {
|
|
2176
|
-
teamId: { type: 'string', description: '
|
|
2688
|
+
teamId: { type: 'string', description: 'dsh_team_create 返回的 result.team.id(形如 team_xxx)。漏传时自动使用当前会话刚创建的团队。' },
|
|
2177
2689
|
name: { type: 'string', description: 'Unique member name inside the team; this is the addressable target.' },
|
|
2178
2690
|
role: { type: 'string', description: 'Role label shown on the panel.' },
|
|
2179
2691
|
permissionPreset: { type: 'string', description: "DSH permission preset for this member (sandbox + approval policy). Defaults to the team's permissionPreset." },
|
|
2180
2692
|
agentPreset: { type: 'string', description: "DSH agent preset (composition: tools/skills/MCP + system prompt). Defaults to the team's agentPreset; omit both to join the host default. Only supported with contextMode 'fresh' (the fork provider inherits the Lead's composition)." },
|
|
2181
|
-
agentProvider: { type: 'string', description: 'LLM provider route id, as returned by
|
|
2182
|
-
model: { type: 'string', description: 'LLM model id, as returned by
|
|
2693
|
+
agentProvider: { type: 'string', description: 'LLM provider route id, as returned by dsh_team_models. Omit to inherit the Lead\'s provider. Must be an enabled route in the team panel.' },
|
|
2694
|
+
model: { type: 'string', description: 'LLM model id, as returned by dsh_team_models. Changing the route clears inherited reasoning effort unless reasoningEffort is set explicitly.' },
|
|
2183
2695
|
reasoningEffort: { type: 'string', description: 'Adapter-defined reasoning effort id (for example low / medium / high, when the model supports them). Omit to inherit the Lead\'s effort while the route is unchanged; a changed route falls back to the model default.' },
|
|
2184
2696
|
contextMode: { type: 'string', enum: ['isolated', 'fresh', 'fork'], description: 'Context isolation: `fresh` starts with no Lead history, `fork` inherits completed Lead turns. Default isolated/fresh.' },
|
|
2185
|
-
prompt: { type: 'string', description: 'The member’s first instruction. Tell it its role, workspace, and that it must call
|
|
2697
|
+
prompt: { type: 'string', description: 'The member’s first instruction. Tell it its role, workspace, and that it must call dsh_team_report_task when done.' },
|
|
2186
2698
|
description: { type: 'string', description: 'One-line description of what this member is responsible for.' },
|
|
2187
2699
|
},
|
|
2188
2700
|
required: ['teamId', 'name', 'prompt'],
|
|
@@ -2199,8 +2711,8 @@ function buildTools(s, ctx) {
|
|
|
2199
2711
|
throw new Error('subagents 服务不可用:无法创建 sub-agent 成员(需要宿主启用 dsh-subagent)。');
|
|
2200
2712
|
}
|
|
2201
2713
|
const caller = exec?.agent;
|
|
2202
|
-
if (!caller) throw new Error('
|
|
2203
|
-
if (!args.prompt) throw new Error('
|
|
2714
|
+
if (!caller) throw new Error('dsh_team_spawn 需要 Lead 会话上下文(exec.agent 缺失:不能在非 agent 调用里起成员)。');
|
|
2715
|
+
if (!args.prompt) throw new Error('dsh_team_spawn 需要 prompt(成员的初始指令)。');
|
|
2204
2716
|
|
|
2205
2717
|
const context = args.contextMode === 'fork' ? 'fork' : 'fresh';
|
|
2206
2718
|
// 省略 preset 时 DSH 继承 Lead 的实时组合,不会套宿主默认;
|
|
@@ -2249,21 +2761,20 @@ function buildTools(s, ctx) {
|
|
|
2249
2761
|
const memberName = String(args.name).trim();
|
|
2250
2762
|
const description = String(args.description || args.role || memberName).slice(0, 200);
|
|
2251
2763
|
const sessionId = randomUUID();
|
|
2252
|
-
const started = await subs.startActivation({
|
|
2764
|
+
const started = await subs.startActivation(activationSpec({
|
|
2765
|
+
prompt: [{ type: 'text', text: String(args.prompt) }],
|
|
2766
|
+
parent: caller,
|
|
2767
|
+
...(team && team.workspace ? { cwd: team.workspace } : {}),
|
|
2768
|
+
...(Object.keys(agentOptions).length ? { agentOptions } : {}),
|
|
2769
|
+
...(agentPreset ? { agentPreset } : {}),
|
|
2770
|
+
}, {
|
|
2253
2771
|
delivery: 'parent',
|
|
2254
2772
|
childId: sessionId,
|
|
2255
2773
|
provider,
|
|
2256
2774
|
label: memberLabel(memberName, description),
|
|
2257
|
-
request: {
|
|
2258
|
-
prompt: [{ type: 'text', text: String(args.prompt) }],
|
|
2259
|
-
parent: caller,
|
|
2260
|
-
...(team && team.workspace ? { cwd: team.workspace } : {}),
|
|
2261
|
-
...(Object.keys(agentOptions).length ? { agentOptions } : {}),
|
|
2262
|
-
...(agentPreset ? { agentPreset } : {}),
|
|
2263
|
-
},
|
|
2264
2775
|
signal: exec.signal || AbortSignal.timeout(s.requestTimeoutMs),
|
|
2265
|
-
});
|
|
2266
|
-
// 成员跑的是一整轮 agent loop,结果由
|
|
2776
|
+
}));
|
|
2777
|
+
// 成员跑的是一整轮 agent loop,结果由 dsh_team_report_task 汇报;这里只防止未处理的 rejection。
|
|
2267
2778
|
if (started && started.result && typeof started.result.catch === 'function') started.result.catch(() => {});
|
|
2268
2779
|
// 子会话发布后立刻把 preset 落到会话(会覆盖 subagent 继承来的 approval=never)。
|
|
2269
2780
|
const presetResult = applyPermissionPreset(ctx, sessionId, permissionPreset);
|
|
@@ -2313,27 +2824,32 @@ function buildTools(s, ctx) {
|
|
|
2313
2824
|
});
|
|
2314
2825
|
|
|
2315
2826
|
tools.push({
|
|
2316
|
-
name: '
|
|
2317
|
-
description: 'List the model routes enabled for this team: provider id, model id, display name, note, and modalities. Use it before
|
|
2827
|
+
name: 'dsh_team_models',
|
|
2828
|
+
description: 'List the model routes enabled for this team: provider id, model id, display name, note, providerNote (the vendor-level strength the user wrote, e.g. "适合逻辑处理" / "适合做设计"), and modalities. Use it before dsh_team_spawn when a task should run on a different model or reasoning effort than the Lead — a cheap/fast route for mechanical work, a strong-reasoning route for architecture, debugging, or review. Only the user-enabled subset is listed; the panel curates it. Pass a listed pair to dsh_team_spawn({ agentProvider, model, reasoningEffort }).',
|
|
2318
2829
|
parameters: {
|
|
2319
2830
|
type: 'object',
|
|
2320
2831
|
additionalProperties: false,
|
|
2321
2832
|
properties: {},
|
|
2322
2833
|
},
|
|
2323
|
-
output: jsonOutput('{ asOf, total, models: [{ provider, model, name, description, note, modalities, efforts?, defaultEffort? }], hint? }'),
|
|
2834
|
+
output: jsonOutput('{ asOf, total, models: [{ provider, model, name, description, note, providerNote, modalities, efforts?, defaultEffort? }], hint? }'),
|
|
2324
2835
|
isConcurrencySafe: () => true,
|
|
2325
2836
|
async execute() {
|
|
2326
2837
|
let cat = null;
|
|
2327
2838
|
try { cat = await request(s, '/api/llm/catalog'); } catch { /* catalog unavailable */ }
|
|
2839
|
+
// 厂商级备注(用户在面板分组头写的「这个厂商擅长什么」)随每个 route 一起下发,
|
|
2840
|
+
// 让模型在派活时能按「擅长逻辑 / 擅长设计」这类语义选厂商,而不只看模型 id。
|
|
2841
|
+
const providerNotes = new Map((cat?.providers || []).map((p) => [p.id, p.note || null]));
|
|
2328
2842
|
const all = cat ? (cat.providers || []).flatMap((p) => p.models || []) : [];
|
|
2329
2843
|
const models = all.filter((m) => m.enabled).map((m) => {
|
|
2330
2844
|
// 只报用户允许的 effort;allowedEfforts=null 表示全部允许。未声明 efforts 的 route 不报该字段。
|
|
2331
2845
|
const effortIds = Array.isArray(m.efforts) ? m.efforts.map((e) => e.id) : [];
|
|
2332
2846
|
const allowed = Array.isArray(m.allowedEfforts) ? effortIds.filter((id) => m.allowedEfforts.includes(id)) : effortIds;
|
|
2847
|
+
const providerNote = providerNotes.get(m.provider);
|
|
2333
2848
|
return {
|
|
2334
2849
|
provider: m.provider,
|
|
2335
2850
|
model: m.model,
|
|
2336
2851
|
name: m.name,
|
|
2852
|
+
...(providerNote ? { providerNote } : {}),
|
|
2337
2853
|
...(m.description ? { description: m.description } : {}),
|
|
2338
2854
|
...(m.note ? { note: m.note } : {}),
|
|
2339
2855
|
...(m.modalities ? { modalities: m.modalities } : {}),
|
|
@@ -2341,7 +2857,8 @@ function buildTools(s, ctx) {
|
|
|
2341
2857
|
};
|
|
2342
2858
|
});
|
|
2343
2859
|
const hint = models.length
|
|
2344
|
-
? '在
|
|
2860
|
+
? '在 dsh_team_spawn 里用 agentProvider + model;providerNote 是该厂商整体强项(用户填写的厂商备注),note 是单模型差异;'
|
|
2861
|
+
+ 'efforts 是该 route 允许派发的 reasoningEffort 列表(省略时只在 route 不变时继承 Lead 的 effort,被禁止的 effort 会被拒绝)。'
|
|
2345
2862
|
: '没有启用的模型路由:请让用户在面板「模型路由」页勾选需要的 provider/model。';
|
|
2346
2863
|
return {
|
|
2347
2864
|
asOf: cat?.asOf || new Date().toISOString(),
|
|
@@ -2353,8 +2870,8 @@ function buildTools(s, ctx) {
|
|
|
2353
2870
|
});
|
|
2354
2871
|
|
|
2355
2872
|
tools.push({
|
|
2356
|
-
name: '
|
|
2357
|
-
description: 'Create, inspect, list, or delete team-owned agent presets when the host built-ins do not fit. A preset decides what a member OWNS (tool plugins, skill providers, MCP clients, persona/system prompt); permissionPreset decides what it MAY DO. action:list lists host presets plus presets the team already created; action:save writes one JSON document to the fixed team preset directory and registers it with the host immediately (no DSH restart), then the id can be passed to
|
|
2873
|
+
name: 'dsh_team_preset',
|
|
2874
|
+
description: 'Create, inspect, list, or delete team-owned agent presets when the host built-ins do not fit. A preset decides what a member OWNS (tool plugins, skill providers, MCP clients, persona/system prompt); permissionPreset decides what it MAY DO. action:list lists host presets plus presets the team already created; action:save writes one JSON document to the fixed team preset directory and registers it with the host immediately (no DSH restart), then the id can be passed to dsh_team_create({agentPreset}) / dsh_team_spawn({agentPreset}); action:show prints the saved document; action:delete removes a team-owned preset file and unregisters it (host built-ins are read-only). plugins must be a non-empty Cordis entry list, e.g. [{name:"@deepseek-ai/dsh-tool-fs"},{name:"@deepseek-ai/dsh-persona",config:{prefix:"You are a reviewer."}}]. Prefer copying the shape of an existing host preset: call dsh_team_preset({action:"show", id:"standard"}) and swap rows.',
|
|
2358
2875
|
parameters: {
|
|
2359
2876
|
type: 'object',
|
|
2360
2877
|
additionalProperties: false,
|
|
@@ -2407,7 +2924,7 @@ function buildTools(s, ctx) {
|
|
|
2407
2924
|
});
|
|
2408
2925
|
|
|
2409
2926
|
tools.push({
|
|
2410
|
-
name: '
|
|
2927
|
+
name: 'dsh_team_status',
|
|
2411
2928
|
description: 'Read a live snapshot instead of guessing progress. detail=summary returns every member with status/step/seq/percent/next/blockers/stale and its permissionPreset; detail=dag returns the task DAG with dependencies, readiness, joins and the critical path. `asOf` marks the snapshot time.',
|
|
2412
2929
|
parameters: {
|
|
2413
2930
|
type: 'object',
|
|
@@ -2455,8 +2972,36 @@ function buildTools(s, ctx) {
|
|
|
2455
2972
|
});
|
|
2456
2973
|
|
|
2457
2974
|
tools.push({
|
|
2458
|
-
name: '
|
|
2459
|
-
description: '
|
|
2975
|
+
name: 'dsh_team_task_get',
|
|
2976
|
+
description: 'Read ONE DAG task of a team instead of the whole status: subject/status/assignee/attempts/maxAttempts/failurePolicy, its plan and acceptance, plus ledger node info (dependsOn, ready, blocked, blockers). Use it to confirm a task was dispatched, to check whether it is blocked on a dependency or a member, and to decide whether to retry or re-dispatch it. teamId is optional when the caller is already bound to that team.',
|
|
2977
|
+
parameters: {
|
|
2978
|
+
type: 'object',
|
|
2979
|
+
additionalProperties: false,
|
|
2980
|
+
properties: {
|
|
2981
|
+
taskId: { type: 'string', description: 'Task id returned by dsh_team_task (task_…).' },
|
|
2982
|
+
teamId: { type: 'string', description: 'Optional ownership check; inferred from the caller session when omitted.' },
|
|
2983
|
+
},
|
|
2984
|
+
required: ['taskId'],
|
|
2985
|
+
},
|
|
2986
|
+
output: jsonOutput('{ task, node }'),
|
|
2987
|
+
isConcurrencySafe: () => true,
|
|
2988
|
+
async execute(args) {
|
|
2989
|
+
const task = await request(s, `/api/tasks/${encodeURIComponent(args.taskId)}`);
|
|
2990
|
+
const teamId = String(args.teamId || task.teamId || '');
|
|
2991
|
+
if (!teamId) throw new Error('dsh_team_task_get 无法确定 teamId:请显式传入');
|
|
2992
|
+
if (args.teamId && String(task.teamId) !== String(args.teamId)) {
|
|
2993
|
+
throw new Error(`task ${task.id} 不属于 team ${args.teamId}`);
|
|
2994
|
+
}
|
|
2995
|
+
// DAG 节点提供依赖/就绪/阻塞信息,task 行本身不存这些派生状态。
|
|
2996
|
+
const dag = await request(s, `/api/dag${qs({ team: teamId })}`).catch(() => null);
|
|
2997
|
+
const node = dag?.nodes?.find((n) => n.taskId === task.id) || null;
|
|
2998
|
+
return { task, node };
|
|
2999
|
+
},
|
|
3000
|
+
});
|
|
3001
|
+
|
|
3002
|
+
tools.push({
|
|
3003
|
+
name: 'dsh_team_task',
|
|
3004
|
+
description: 'Only for decomposing the CURRENT task: declare one task (DAG node) and hand it to a member. When the user asks for a new, separate task card (own deliverable or acceptance, own branch/session), use dsh_team_board_task_create instead — dsh_team_task items never appear on the board. The plan is a BRIEF sent to the member’s own sub-agent session, which does the work with its own tools and calls dsh_team_report_task when finished — write it self-contained (the member does not see this conversation). `assignee` takes a member **id** from dsh_team_spawn, not its name; omit it to let the scheduler pick an idle member. `deps[].from` takes a **task** id returned by an earlier dsh_team_task (member ids are rejected). The scheduler satisfies dependencies itself — never poll. The task dispatches immediately to an idle member once dependencies are satisfied; pass dispatch:false to build the DAG first.',
|
|
2460
3005
|
parameters: {
|
|
2461
3006
|
type: 'object',
|
|
2462
3007
|
additionalProperties: false,
|
|
@@ -2472,7 +3017,7 @@ function buildTools(s, ctx) {
|
|
|
2472
3017
|
type: 'object',
|
|
2473
3018
|
additionalProperties: false,
|
|
2474
3019
|
properties: {
|
|
2475
|
-
from: { type: 'string', description: 'Upstream **task** id (starts with task_), taken from the
|
|
3020
|
+
from: { type: 'string', description: 'Upstream **task** id (starts with task_), taken from the dsh_team_task result — not a member id.' },
|
|
2476
3021
|
condition: { type: 'string', enum: ['all_success', 'any_success', 'on_failure', 'artifact_exists'] },
|
|
2477
3022
|
artifactPath: { type: 'string', description: 'Workspace-relative path for condition=artifact_exists.' },
|
|
2478
3023
|
},
|
|
@@ -2483,7 +3028,7 @@ function buildTools(s, ctx) {
|
|
|
2483
3028
|
priority: { type: 'integer', description: 'Smaller runs first. Default 0.' },
|
|
2484
3029
|
failurePolicy: { type: 'string', enum: ['continue', 'skip', 'abort_team', 'retry'] },
|
|
2485
3030
|
maxAttempts: { type: 'integer' },
|
|
2486
|
-
dispatch: { type: 'boolean', description: 'Dispatch immediately after creating (default true). Pass false to build the DAG first and dispatch later with
|
|
3031
|
+
dispatch: { type: 'boolean', description: 'Dispatch immediately after creating (default true). Pass false to build the DAG first and dispatch later with dsh_team_dispatch.' },
|
|
2487
3032
|
},
|
|
2488
3033
|
required: ['teamId', 'subject', 'plan'],
|
|
2489
3034
|
},
|
|
@@ -2512,8 +3057,8 @@ function buildTools(s, ctx) {
|
|
|
2512
3057
|
});
|
|
2513
3058
|
|
|
2514
3059
|
tools.push({
|
|
2515
|
-
name: '
|
|
2516
|
-
description: "Send a message that a member will actually read: the text is injected into the target sub-agent's message inbox. By default a running member's current turn is interrupted first, so the message immediately starts a fresh turn instead of waiting for the next step boundary; pass `interrupt: false` to keep the current turn and deliver at the next step boundary. An idle member is woken. `to` is a member NAME (member id also accepted) or '*' to broadcast; use to:'lead' to reply to the Lead. Every send is also recorded on the sidecar so the panel shows the conversation.",
|
|
3060
|
+
name: 'dsh_team_send',
|
|
3061
|
+
description: "Send a message that a member will actually read: the text is injected into the target sub-agent's message inbox. By default a running member's current turn is interrupted first, so the message immediately starts a fresh turn instead of waiting for the next step boundary; pass `interrupt: false` to keep the current turn and deliver at the next step boundary. An idle member is woken. `to` is a member NAME (member id also accepted) or '*' to broadcast; use to:'lead' to reply to the Lead. Every send is also recorded on the sidecar so the panel shows the conversation. Returns delivery status only, never the member's reply: the reply arrives asynchronously as a new message in a later turn. Never wait for it with sleep/Start-Sleep/delayed scripts, polling loops, or repeated dsh_team_status calls — after sending, continue independent work or end the turn.",
|
|
2517
3062
|
parameters: {
|
|
2518
3063
|
type: 'object',
|
|
2519
3064
|
additionalProperties: false,
|
|
@@ -2540,7 +3085,7 @@ function buildTools(s, ctx) {
|
|
|
2540
3085
|
const members = st?.members || [];
|
|
2541
3086
|
const resolve = (v) => members.find((m) => m.name === v || m.id === v) || null;
|
|
2542
3087
|
if (!toLead && args.to !== '*' && (members.length ? !resolve(args.to) : false)) {
|
|
2543
|
-
throw new Error(`
|
|
3088
|
+
throw new Error(`dsh_team_send: 找不到成员 ${args.to}(可用成员 name 或 memberId;广播用 '*';给 Lead 留言用 to:"lead")`);
|
|
2544
3089
|
}
|
|
2545
3090
|
const recorded = await request(s, '/api/messages', {
|
|
2546
3091
|
method: 'POST',
|
|
@@ -2558,8 +3103,7 @@ function buildTools(s, ctx) {
|
|
|
2558
3103
|
const subs = subagentsOf(ctx);
|
|
2559
3104
|
// 成员之间互通必须借 Lead 的 agent 句柄:成员会话都挂在 Lead 下,成员直发会「belongs to another parent session」。
|
|
2560
3105
|
const caller = leadByTeam.get(args.teamId) || exec?.agent;
|
|
2561
|
-
if (!
|
|
2562
|
-
const content = [{ type: 'text', text: String(args.message) }];
|
|
3106
|
+
if (!caller || !canDeliverTo(ctx, caller)) return { ...recorded, delivered: false };
|
|
2563
3107
|
const candidates = args.to === '*' ? members : [resolve(args.to)].filter(Boolean);
|
|
2564
3108
|
const targets = candidates.filter((m) => m.agentSessionId);
|
|
2565
3109
|
const delivered = [];
|
|
@@ -2581,7 +3125,9 @@ function buildTools(s, ctx) {
|
|
|
2581
3125
|
interruptErrors.push({ target: target.name, error: String(err?.message || err) });
|
|
2582
3126
|
}
|
|
2583
3127
|
}
|
|
2584
|
-
await
|
|
3128
|
+
await sendAgentMessage(ctx, caller, sid, String(args.message), {
|
|
3129
|
+
signal: AbortSignal.timeout(s.requestTimeoutMs),
|
|
3130
|
+
});
|
|
2585
3131
|
delivered.push(target.name);
|
|
2586
3132
|
// 投递成功才补记送达:这一条消息确实进了成员会话
|
|
2587
3133
|
const row = (recorded.messages || [recorded.message]).find((m) => m && String(m.to) === String(target.id));
|
|
@@ -2601,7 +3147,7 @@ function buildTools(s, ctx) {
|
|
|
2601
3147
|
});
|
|
2602
3148
|
|
|
2603
3149
|
tools.push({
|
|
2604
|
-
name: '
|
|
3150
|
+
name: 'dsh_team_todo',
|
|
2605
3151
|
description: '设置或更新一个任务的执行计划清单(todo)。与内置 todo_write 不同:这份清单落盘在 sidecar,面板主页 Plan 区域实时渲染,Lead 与成员都能看到(内置 todo 只属于当前会话)。语义是整体替换——每次提交完整清单(最多 50 条),用 status 标注进度:open(未开始)/ active(进行中)/ done(已完成)/ blocked(被阻塞)。Lead 在派发前/后用它给任务补计划;成员每开始或完成一步、以及通过验收后调用它更新状态。',
|
|
2606
3152
|
parameters: {
|
|
2607
3153
|
type: 'object',
|
|
@@ -2639,7 +3185,7 @@ function buildTools(s, ctx) {
|
|
|
2639
3185
|
});
|
|
2640
3186
|
|
|
2641
3187
|
tools.push({
|
|
2642
|
-
name: '
|
|
3188
|
+
name: 'dsh_team_report_task',
|
|
2643
3189
|
description: 'Report the outcome of ONE task you were dispatched (agent members: call this as the last thing you do). It marks the task done/failed/blocked on the sidecar, releases the member back to idle, advances the DAG (dependents become ready and are dispatched), and applies the team failure policy. `summary` is what the Lead and the panel will see — put the result, key file paths and any blocker in it.',
|
|
2644
3190
|
parameters: {
|
|
2645
3191
|
type: 'object',
|
|
@@ -2688,7 +3234,7 @@ function buildTools(s, ctx) {
|
|
|
2688
3234
|
};
|
|
2689
3235
|
|
|
2690
3236
|
tools.push({
|
|
2691
|
-
name: '
|
|
3237
|
+
name: 'dsh_team_memory_write',
|
|
2692
3238
|
description: 'Save ONE memory into the file-backed memory space (one JSON file per memory, never SQLite). scope=member writes the caller member\'s own space; scope=team writes the shared team space (use it when the Lead asks you to upload). Same (scope, team, owner, key) upserts and bumps version; pass expectedVersion for compare-and-set. Keep handoffs short (<=300 chars) and only save what is actually reusable — do NOT force a memory when the task produced nothing worth carrying.',
|
|
2693
3239
|
parameters: {
|
|
2694
3240
|
type: 'object',
|
|
@@ -2730,7 +3276,7 @@ function buildTools(s, ctx) {
|
|
|
2730
3276
|
});
|
|
2731
3277
|
|
|
2732
3278
|
tools.push({
|
|
2733
|
-
name: '
|
|
3279
|
+
name: 'dsh_team_memory_read',
|
|
2734
3280
|
description: 'Read ONE memory by id, or find the first matching memory by scope+key (and optional memberId). Memory ids are portable: a shared memory id can be passed to a member of another team. Returns the full value and version.',
|
|
2735
3281
|
parameters: {
|
|
2736
3282
|
type: 'object',
|
|
@@ -2761,7 +3307,7 @@ function buildTools(s, ctx) {
|
|
|
2761
3307
|
});
|
|
2762
3308
|
|
|
2763
3309
|
tools.push({
|
|
2764
|
-
name: '
|
|
3310
|
+
name: 'dsh_team_memory_list',
|
|
2765
3311
|
description: 'List memory metadata (slot/title/kind/source/updatedAt, no value body) for a team. Members see their own private memories + team-scope memories; the Lead sees all memories of the team; shared memories are visible across teams. Use q to search slot/title/tags/value text.',
|
|
2766
3312
|
parameters: {
|
|
2767
3313
|
type: 'object',
|
|
@@ -2789,7 +3335,7 @@ function buildTools(s, ctx) {
|
|
|
2789
3335
|
});
|
|
2790
3336
|
|
|
2791
3337
|
tools.push({
|
|
2792
|
-
name: '
|
|
3338
|
+
name: 'dsh_team_memory_share',
|
|
2793
3339
|
description: 'Change a memory\'s visibility: private (owner + team Lead), team (this team\'s members), shared (any team by id). The Lead uses this to hand a member\'s memory to other members; a member can share its own memory.',
|
|
2794
3340
|
parameters: {
|
|
2795
3341
|
type: 'object',
|
|
@@ -2812,7 +3358,7 @@ function buildTools(s, ctx) {
|
|
|
2812
3358
|
});
|
|
2813
3359
|
|
|
2814
3360
|
tools.push({
|
|
2815
|
-
name: '
|
|
3361
|
+
name: 'dsh_team_memory_delete',
|
|
2816
3362
|
description: 'Delete ONE memory file permanently. The owner member or the team Lead may delete; team deletion does NOT cascade to memory files. Shared memory ids keep working across teams until deleted.',
|
|
2817
3363
|
parameters: {
|
|
2818
3364
|
type: 'object',
|
|
@@ -2830,8 +3376,8 @@ function buildTools(s, ctx) {
|
|
|
2830
3376
|
});
|
|
2831
3377
|
|
|
2832
3378
|
tools.push({
|
|
2833
|
-
name: '
|
|
2834
|
-
description: 'Pump the agent-team dispatcher once: claim ready tasks for idle members and send each member its brief. Normally unnecessary —
|
|
3379
|
+
name: 'dsh_team_dispatch',
|
|
3380
|
+
description: 'Pump the agent-team dispatcher once: claim ready tasks for idle members and send each member its brief. Normally unnecessary — dsh_team_task dispatches automatically and dsh_team_report_task dispatches the next wave — but useful after dsh_team_control/resume, after approving a scope request, or when a member went idle without reporting. Safe to call repeatedly; it returns when no idle member or no ready task is left.',
|
|
2835
3381
|
parameters: {
|
|
2836
3382
|
type: 'object',
|
|
2837
3383
|
additionalProperties: false,
|
|
@@ -2846,8 +3392,8 @@ function buildTools(s, ctx) {
|
|
|
2846
3392
|
});
|
|
2847
3393
|
|
|
2848
3394
|
tools.push({
|
|
2849
|
-
name: '
|
|
2850
|
-
description: 'Decide a permission approval raised by a member. When a member runs an operation its permission preset requires approval for (sandbox escalation / write outside the sandbox), the DSH approval request is forwarded to the Lead and the member is paused. Read the requestId/member/tool/reason from the forwarded message, then call
|
|
3395
|
+
name: 'dsh_team_approve',
|
|
3396
|
+
description: 'Decide a permission approval raised by a member. When a member runs an operation its permission preset requires approval for (sandbox escalation / write outside the sandbox), the DSH approval request is forwarded to the Lead and the member is paused. Read the requestId/member/tool/reason from the forwarded message, then call dsh_team_approve with decision "allow" (authorize this one operation) or "deny". Only the Lead of that team can decide. If nobody decides before the timeout, the request is rejected automatically.',
|
|
2851
3397
|
parameters: {
|
|
2852
3398
|
type: 'object',
|
|
2853
3399
|
additionalProperties: false,
|
|
@@ -2862,7 +3408,7 @@ function buildTools(s, ctx) {
|
|
|
2862
3408
|
output: jsonOutput('{ requestId, decision, memberId, toolName, reason }'),
|
|
2863
3409
|
async execute(args, exec) {
|
|
2864
3410
|
const requestId = String(args.requestId || '').trim();
|
|
2865
|
-
if (!requestId) throw new Error('
|
|
3411
|
+
if (!requestId) throw new Error('dsh_team_approve requires requestId');
|
|
2866
3412
|
const entry = pendingApprovals.get(requestId);
|
|
2867
3413
|
if (!entry) throw new Error('审批请求不存在或已处理(可能已超时)。请以成员收到的审批消息里的 requestId 为准。');
|
|
2868
3414
|
if (String(entry.teamId) !== String(args.teamId)) throw new Error('teamId 与审批请求不匹配');
|
|
@@ -2878,7 +3424,7 @@ function buildTools(s, ctx) {
|
|
|
2878
3424
|
});
|
|
2879
3425
|
|
|
2880
3426
|
tools.push({
|
|
2881
|
-
name: '
|
|
3427
|
+
name: 'dsh_team_control',
|
|
2882
3428
|
description: 'Control one member. interrupt stops the sub-agent’s current turn and pauses its in-flight task (no retry, no attempt consumed); resume re-arms it; assign hands a ready task to an idle member; abort permanently voids a task (taskId) without retry.',
|
|
2883
3429
|
parameters: {
|
|
2884
3430
|
type: 'object',
|
|
@@ -2895,7 +3441,7 @@ function buildTools(s, ctx) {
|
|
|
2895
3441
|
output: jsonOutput('{ member, ... }'),
|
|
2896
3442
|
async execute(args, exec) {
|
|
2897
3443
|
if (args.action === 'abort') {
|
|
2898
|
-
if (!args.taskId) throw new Error('
|
|
3444
|
+
if (!args.taskId) throw new Error('dsh_team_control abort requires taskId');
|
|
2899
3445
|
const res = await request(s, `/api/tasks/${encodeURIComponent(args.taskId)}/abort`, { method: 'POST', body: { reason: args.reason || 'lead abort' } });
|
|
2900
3446
|
if (!res?.wasRunning || !res?.member?.agentSessionId) return res;
|
|
2901
3447
|
const sid = String(res.member.agentSessionId);
|
|
@@ -2911,7 +3457,7 @@ function buildTools(s, ctx) {
|
|
|
2911
3457
|
(err) => ({ ok: false, error: String(err?.message || err) }));
|
|
2912
3458
|
return { ...res, agent: interrupted };
|
|
2913
3459
|
}
|
|
2914
|
-
if (!args.memberId) throw new Error(`
|
|
3460
|
+
if (!args.memberId) throw new Error(`dsh_team_control ${args.action} requires memberId`);
|
|
2915
3461
|
const id = encodeURIComponent(args.memberId);
|
|
2916
3462
|
if (args.action === 'interrupt') {
|
|
2917
3463
|
const res = await request(s, `/api/members/${id}/interrupt`, { method: 'POST', body: { reason: args.reason || 'lead interrupt' } });
|
|
@@ -2943,15 +3489,15 @@ function buildTools(s, ctx) {
|
|
|
2943
3489
|
return res;
|
|
2944
3490
|
}
|
|
2945
3491
|
if (args.action === 'assign') {
|
|
2946
|
-
if (!args.taskId) throw new Error('
|
|
3492
|
+
if (!args.taskId) throw new Error('dsh_team_control assign requires taskId');
|
|
2947
3493
|
return await request(s, `/api/members/${id}/assign`, { method: 'POST', body: { taskId: args.taskId } });
|
|
2948
3494
|
}
|
|
2949
|
-
throw new Error(`
|
|
3495
|
+
throw new Error(`dsh_team_control unknown action: ${args.action}`);
|
|
2950
3496
|
},
|
|
2951
3497
|
});
|
|
2952
3498
|
|
|
2953
3499
|
tools.push({
|
|
2954
|
-
name: '
|
|
3500
|
+
name: 'dsh_team_member',
|
|
2955
3501
|
description: "Update or remove a team member. `update` changes role/permission/model/context. `permissionPreset` (and `role`) applies to a RUNNING member immediately, no interrupt needed; changing model, agentProvider, contextMode, agentPreset or reasoningEffort rebuilds the member's DSH sub-agent session (old context is lost) and therefore requires the member to be idle or interrupted. `retire` keeps the member row as retired and frees capacity; `remove` deletes the row and requires confirm:true. Both release the sub-agent session.",
|
|
2956
3502
|
parameters: {
|
|
2957
3503
|
type: 'object',
|
|
@@ -2959,7 +3505,7 @@ function buildTools(s, ctx) {
|
|
|
2959
3505
|
properties: {
|
|
2960
3506
|
action: { type: 'string', enum: ['update', 'retire', 'remove'] },
|
|
2961
3507
|
teamId: { type: 'string', description: 'Team id; omit to resolve from the current Lead session.' },
|
|
2962
|
-
memberId: { type: 'string', description: 'Member id returned by
|
|
3508
|
+
memberId: { type: 'string', description: 'Member id returned by dsh_team_spawn / dsh_team_status.' },
|
|
2963
3509
|
role: { type: 'string', description: 'update: new role label.' },
|
|
2964
3510
|
model: { type: 'string', description: 'update: new LLM model id (empty to inherit). Rebuilds the session.' },
|
|
2965
3511
|
agentProvider: { type: 'string', description: 'update: new LLM provider route id. Rebuilds the session.' },
|
|
@@ -2980,7 +3526,7 @@ function buildTools(s, ctx) {
|
|
|
2980
3526
|
if (current.teamId !== team.id) throw new Error('member 不属于指定团队');
|
|
2981
3527
|
|
|
2982
3528
|
if (args.action === 'retire' || args.action === 'remove') {
|
|
2983
|
-
if (args.action === 'remove' && args.confirm !== true) throw new Error('
|
|
3529
|
+
if (args.action === 'remove' && args.confirm !== true) throw new Error('dsh_team_member remove requires confirm:true');
|
|
2984
3530
|
const mode = args.action === 'remove' ? 'remove' : 'retire';
|
|
2985
3531
|
const res = await request(s, `/api/members/${id}?mode=${mode}${mode === 'remove' ? '&confirm=1' : ''}`, { method: 'DELETE' });
|
|
2986
3532
|
let agent = null;
|
|
@@ -2997,7 +3543,7 @@ function buildTools(s, ctx) {
|
|
|
2997
3543
|
return { ...res, agent, panel: panelUrl(s) };
|
|
2998
3544
|
}
|
|
2999
3545
|
|
|
3000
|
-
if (args.action !== 'update') throw new Error(`
|
|
3546
|
+
if (args.action !== 'update') throw new Error(`dsh_team_member unknown action: ${args.action}`);
|
|
3001
3547
|
if (current.status === 'retired') throw new Error('member is retired; create a new member instead');
|
|
3002
3548
|
|
|
3003
3549
|
const has = (key) => Object.prototype.hasOwnProperty.call(args, key);
|
|
@@ -3032,7 +3578,7 @@ function buildTools(s, ctx) {
|
|
|
3032
3578
|
const subs = subagentsOf(ctx);
|
|
3033
3579
|
const caller = exec?.agent;
|
|
3034
3580
|
if (!subs || typeof subs.startActivation !== 'function') throw new Error('subagents 服务不可用:无法重建成员会话');
|
|
3035
|
-
if (!caller) throw new Error('
|
|
3581
|
+
if (!caller) throw new Error('dsh_team_member update 需要 Lead 会话上下文(exec.agent 缺失)');
|
|
3036
3582
|
|
|
3037
3583
|
const leadRoute = leadRouteOf(caller);
|
|
3038
3584
|
const oldRoute = {
|
|
@@ -3074,20 +3620,19 @@ function buildTools(s, ctx) {
|
|
|
3074
3620
|
if (route.reasoningEffort) agentOptions.reasoningEffort = String(route.reasoningEffort);
|
|
3075
3621
|
|
|
3076
3622
|
const sessionId = randomUUID();
|
|
3077
|
-
const started = await subs.startActivation({
|
|
3623
|
+
const started = await subs.startActivation(activationSpec({
|
|
3624
|
+
prompt: [{ type: 'text', text: `你是团队成员 ${current.name}(${role || 'teammate'})。配置刚刚更新,这是新的会话;当前没有任务,等待 Lead 派发。收到任务后按简报执行,完成时调用 dsh_team_report_task。` }],
|
|
3625
|
+
parent: caller,
|
|
3626
|
+
...(team.workspace ? { cwd: team.workspace } : {}),
|
|
3627
|
+
...(Object.keys(agentOptions).length ? { agentOptions } : {}),
|
|
3628
|
+
...(agentPreset ? { agentPreset } : {}),
|
|
3629
|
+
}, {
|
|
3078
3630
|
delivery: 'parent',
|
|
3079
3631
|
childId: sessionId,
|
|
3080
3632
|
provider,
|
|
3081
3633
|
label: memberLabel(current.name, String(role || current.name)),
|
|
3082
|
-
request: {
|
|
3083
|
-
prompt: [{ type: 'text', text: `你是团队成员 ${current.name}(${role || 'teammate'})。配置刚刚更新,这是新的会话;当前没有任务,等待 Lead 派发。收到任务后按简报执行,完成时调用 team_report_task。` }],
|
|
3084
|
-
parent: caller,
|
|
3085
|
-
...(team.workspace ? { cwd: team.workspace } : {}),
|
|
3086
|
-
...(Object.keys(agentOptions).length ? { agentOptions } : {}),
|
|
3087
|
-
...(agentPreset ? { agentPreset } : {}),
|
|
3088
|
-
},
|
|
3089
3634
|
signal: exec.signal || AbortSignal.timeout(s.requestTimeoutMs),
|
|
3090
|
-
});
|
|
3635
|
+
}));
|
|
3091
3636
|
if (started && started.result && typeof started.result.catch === 'function') started.result.catch(() => {});
|
|
3092
3637
|
const presetResult = applyPermissionPreset(ctx, sessionId, permissionPreset);
|
|
3093
3638
|
|
|
@@ -3138,7 +3683,7 @@ function buildTools(s, ctx) {
|
|
|
3138
3683
|
});
|
|
3139
3684
|
|
|
3140
3685
|
tools.push({
|
|
3141
|
-
name: '
|
|
3686
|
+
name: 'dsh_team_report',
|
|
3142
3687
|
description: 'Export a Markdown run report: members, tasks/DAG, permission approvals (who asked for what, who decided), and the audit table with actor, action, target, and full before/after SHA-256 hashes. Use it for review, handoff, or proving who changed which file.',
|
|
3143
3688
|
parameters: {
|
|
3144
3689
|
type: 'object',
|
|
@@ -3156,7 +3701,7 @@ function buildTools(s, ctx) {
|
|
|
3156
3701
|
|
|
3157
3702
|
|
|
3158
3703
|
tools.push({
|
|
3159
|
-
name: '
|
|
3704
|
+
name: 'dsh_team_board_plan_submit',
|
|
3160
3705
|
description: 'Submit the finished plan for the current workspace-board task. Call this at the end of the planning session; the scheduler stores the plan and moves the task to planned. In same-session mode this tool also moves the task into the execution slot and keeps this session running: if the returned task status is inprogress, continue with the plan immediately; if it is planned, stop and wait for the scheduler.',
|
|
3161
3706
|
parameters: {
|
|
3162
3707
|
type: 'object',
|
|
@@ -3170,7 +3715,7 @@ function buildTools(s, ctx) {
|
|
|
3170
3715
|
output: jsonOutput('{ board task }'),
|
|
3171
3716
|
async execute(args, exec) {
|
|
3172
3717
|
const sessionId = exec?.agent?.id != null ? String(exec.agent.id) : null;
|
|
3173
|
-
if (!sessionId) throw new Error('
|
|
3718
|
+
if (!sessionId) throw new Error('dsh_team_board_plan_submit 只能在规划会话里调用');
|
|
3174
3719
|
const task = await request(s, '/api/board/agents/plan', {
|
|
3175
3720
|
method: 'POST',
|
|
3176
3721
|
body: { sessionId, plan: args.plan, summary: args.summary || null },
|
|
@@ -3179,7 +3724,27 @@ function buildTools(s, ctx) {
|
|
|
3179
3724
|
// 同会话模式:sidecar 保存计划时已经 claim 执行槽位并 attach 回本会话,
|
|
3180
3725
|
// 这里只切权限、改 phase,让同一个回合直接继续执行(不再补发第二条 prompt)。
|
|
3181
3726
|
if (task?.status === 'inprogress') {
|
|
3182
|
-
|
|
3727
|
+
const agent = rec?.handle?.agent || exec?.agent;
|
|
3728
|
+
if (task.leadPermissionPreset) boardSetPermission(ctx, agent, task.leadPermissionPreset);
|
|
3729
|
+
// prewalk:这里只武装、不切模型。规划模型先按计划落下第一笔实现动作
|
|
3730
|
+
// (首次 edit/write 或首次 dsh_team_task 派发),确认计划可执行后再交给执行模型。
|
|
3731
|
+
if (task.prewalk) {
|
|
3732
|
+
const boardSettings = await request(
|
|
3733
|
+
s,
|
|
3734
|
+
`/api/board/settings?workspaceId=${encodeURIComponent(task.workspaceId)}`,
|
|
3735
|
+
).catch(() => null);
|
|
3736
|
+
await armBoardPrewalk(ctx, agent, task, boardSettings || {});
|
|
3737
|
+
} else if (task.executionMode === 'same') {
|
|
3738
|
+
// 规划模型 ≠ 执行模型:规划一提交就交接,让新模型在同一会话里接着执行,
|
|
3739
|
+
// 而不是继续用规划模型把执行阶段干完。
|
|
3740
|
+
const boardSettings = await request(
|
|
3741
|
+
s,
|
|
3742
|
+
`/api/board/settings?workspaceId=${encodeURIComponent(task.workspaceId)}`,
|
|
3743
|
+
).catch(() => null);
|
|
3744
|
+
if (boardExecutionRouteDiffers(ctx, task, boardSettings || {})) {
|
|
3745
|
+
await boardHandoffExecution(ctx, agent, task, boardSettings || {}, 'plan-submitted');
|
|
3746
|
+
}
|
|
3747
|
+
}
|
|
3183
3748
|
if (rec) { rec.phase = 'execution'; rec.sawRunning = false; }
|
|
3184
3749
|
} else if (rec) {
|
|
3185
3750
|
rec.phase = 'planned';
|
|
@@ -3198,7 +3763,7 @@ function buildTools(s, ctx) {
|
|
|
3198
3763
|
});
|
|
3199
3764
|
|
|
3200
3765
|
tools.push({
|
|
3201
|
-
name: '
|
|
3766
|
+
name: 'dsh_team_board_task_status',
|
|
3202
3767
|
description: 'Report the current workspace-board task status from the Lead session. Call it at the end of EVERY turn: "done" after all team tasks succeed, "failed" when the task cannot be completed, and "inprogress" while work remains or when waiting for the user (also call it when the user sends a new message after a finished task).',
|
|
3203
3768
|
parameters: {
|
|
3204
3769
|
type: 'object',
|
|
@@ -3212,7 +3777,7 @@ function buildTools(s, ctx) {
|
|
|
3212
3777
|
output: jsonOutput('{ board task }'),
|
|
3213
3778
|
async execute(args, exec) {
|
|
3214
3779
|
const sessionId = exec?.agent?.id != null ? String(exec.agent.id) : null;
|
|
3215
|
-
if (!sessionId) throw new Error('
|
|
3780
|
+
if (!sessionId) throw new Error('dsh_team_board_task_status 只能在看板 Lead 会话里调用');
|
|
3216
3781
|
return await request(s, '/api/board/agents/status', {
|
|
3217
3782
|
method: 'POST',
|
|
3218
3783
|
body: { sessionId, status: args.status, summary: args.summary || null },
|
|
@@ -3220,11 +3785,125 @@ function buildTools(s, ctx) {
|
|
|
3220
3785
|
},
|
|
3221
3786
|
});
|
|
3222
3787
|
|
|
3788
|
+
tools.push({
|
|
3789
|
+
name: 'dsh_team_board_task_create',
|
|
3790
|
+
description: 'Create a new workspace-board task card (the user-facing queue the board scheduler picks up) — use it when the user asks for a new task that is a separate deliverable or deserves its own session/branch (not a step of the current task, which is dsh_team_task). This is NOT a team DAG task: team_* tools stay inside the current team. workspaceId defaults to the caller own board task, then to the only registered workspace; pass it when either is ambiguous. Pass gitBranch to run the new task on a git branch ("" = auto `task/<id>`, omitted = no branch).',
|
|
3791
|
+
parameters: {
|
|
3792
|
+
type: 'object',
|
|
3793
|
+
additionalProperties: false,
|
|
3794
|
+
properties: {
|
|
3795
|
+
title: { type: 'string', description: 'Card title; the card is created in todo.' },
|
|
3796
|
+
description: { type: 'string', description: 'Full instructions for the session that will run this card.' },
|
|
3797
|
+
workspaceId: { type: 'string', description: 'Board workspace id; inferred from the caller board task or the single registered workspace.' },
|
|
3798
|
+
workspacePath: { type: 'string', description: 'Workspace path; defaults to the registered workspace path.' },
|
|
3799
|
+
auto: { type: 'boolean', description: 'Queue immediately (default false: stays in todo until started).' },
|
|
3800
|
+
needPlan: { type: 'boolean', description: 'Run a planning session first (default true).' },
|
|
3801
|
+
useTeam: { type: 'boolean', description: 'Let the Lead orchestrate a team (default true).' },
|
|
3802
|
+
executionMode: { type: 'string', enum: ['same', 'new'], description: 'same = plan and execute in one session; new = execute in a fresh session.' },
|
|
3803
|
+
gitBranch: { type: 'string', description: 'Git branch to switch to before spawning; "" auto-generates task/<id>.' },
|
|
3804
|
+
},
|
|
3805
|
+
required: ['title'],
|
|
3806
|
+
},
|
|
3807
|
+
output: jsonOutput('{ task }'),
|
|
3808
|
+
async execute(args, exec) {
|
|
3809
|
+
const sessionId = exec?.agent?.id != null ? String(exec.agent.id) : null;
|
|
3810
|
+
let workspaceId = args.workspaceId ? String(args.workspaceId) : null;
|
|
3811
|
+
let workspacePath = args.workspacePath ? String(args.workspacePath) : null;
|
|
3812
|
+
// 优先沿用调用者自己那张看板卡的工作区:它一定和当前会话的 cwd 一致。
|
|
3813
|
+
if (!workspaceId && sessionId) {
|
|
3814
|
+
const cur = await request(s, `/api/board/by-session/${encodeURIComponent(sessionId)}`).catch(() => null);
|
|
3815
|
+
if (cur && cur.ok !== false && cur.id) {
|
|
3816
|
+
workspaceId = cur.workspaceId;
|
|
3817
|
+
workspacePath = workspacePath || cur.workspacePath;
|
|
3818
|
+
}
|
|
3819
|
+
}
|
|
3820
|
+
const list = await request(s, '/api/workspaces').catch(() => null);
|
|
3821
|
+
const items = Array.isArray(list?.items) ? list.items : [];
|
|
3822
|
+
const samePath = (a, b) => String(a || '') === String(b || '');
|
|
3823
|
+
if (!workspaceId) {
|
|
3824
|
+
const byPath = workspacePath ? items.find((w) => samePath(w.path, workspacePath)) : null;
|
|
3825
|
+
if (byPath) {
|
|
3826
|
+
workspaceId = byPath.id;
|
|
3827
|
+
workspacePath = workspacePath || byPath.path;
|
|
3828
|
+
} else if (items.length === 1) {
|
|
3829
|
+
workspaceId = items[0].id;
|
|
3830
|
+
workspacePath = workspacePath || items[0].path;
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
if (!workspaceId) throw new Error('dsh_team_board_task_create 需要 workspaceId:当前会话不属于任何看板任务,且工作区不唯一');
|
|
3834
|
+
// 手填的 workspaceId 可能根本不存在(模型常填 00000000-… 占位 UUID)。这种卡会挂到
|
|
3835
|
+
// 一个 UI 上不存在的“幽灵工作区”,看板按 workspace_id 过滤后完全看不到,所以这里必须
|
|
3836
|
+
// 先解析:按 workspacePath 改挂到已注册工作区;DSH 注册表里确实存在(sidecar 还没同步)
|
|
3837
|
+
// 才放行;否则直接报错,别落库。
|
|
3838
|
+
if (!items.some((w) => String(w.id) === workspaceId)) {
|
|
3839
|
+
const byPath = workspacePath ? items.find((w) => samePath(w.path, workspacePath)) : null;
|
|
3840
|
+
if (byPath) {
|
|
3841
|
+
workspaceId = byPath.id;
|
|
3842
|
+
workspacePath = byPath.path || workspacePath;
|
|
3843
|
+
} else {
|
|
3844
|
+
const registry = (() => { try { return ctx.get('workspaceRegistry'); } catch { return undefined; } })();
|
|
3845
|
+
const known = registry && typeof registry.get === 'function' ? registry.get(workspaceId) : null;
|
|
3846
|
+
if (!known) {
|
|
3847
|
+
throw new Error(`dsh_team_board_task_create 的 workspaceId 不存在:${workspaceId}。可用工作区:${items.map((w) => `${w.id}(${w.title || w.path})`).join('、') || '(sidecar 还没同步到工作区)'}`);
|
|
3848
|
+
}
|
|
3849
|
+
}
|
|
3850
|
+
}
|
|
3851
|
+
const task = await request(s, '/api/board/tasks', {
|
|
3852
|
+
method: 'POST',
|
|
3853
|
+
body: {
|
|
3854
|
+
workspaceId,
|
|
3855
|
+
...(workspacePath ? { workspacePath } : {}),
|
|
3856
|
+
title: args.title,
|
|
3857
|
+
description: args.description || '',
|
|
3858
|
+
...(args.auto !== undefined ? { auto: args.auto } : {}),
|
|
3859
|
+
...(args.needPlan !== undefined ? { needPlan: args.needPlan } : {}),
|
|
3860
|
+
...(args.useTeam !== undefined ? { useTeam: args.useTeam } : {}),
|
|
3861
|
+
...(args.executionMode !== undefined ? { executionMode: args.executionMode } : {}),
|
|
3862
|
+
...(args.gitBranch !== undefined ? { gitBranch: args.gitBranch } : {}),
|
|
3863
|
+
},
|
|
3864
|
+
});
|
|
3865
|
+
return { task };
|
|
3866
|
+
},
|
|
3867
|
+
});
|
|
3868
|
+
|
|
3869
|
+
tools.push({
|
|
3870
|
+
name: 'dsh_team_board_task_get',
|
|
3871
|
+
description: 'Read the current workspace-board task of this session (status/planSummary/lastError/gitBranch/sessions) when taskId is omitted, or any board card by taskId. Cheap and safe to call every turn: it returns the status snapshot, not the whole plan body. Use it to decide whether to keep working, wait, or report via dsh_team_board_task_status.',
|
|
3872
|
+
parameters: {
|
|
3873
|
+
type: 'object',
|
|
3874
|
+
additionalProperties: false,
|
|
3875
|
+
properties: {
|
|
3876
|
+
taskId: { type: 'string', description: 'Board task id (bt_…); omit to read the caller own card.' },
|
|
3877
|
+
},
|
|
3878
|
+
},
|
|
3879
|
+
output: jsonOutput('{ task }'),
|
|
3880
|
+
isConcurrencySafe: () => true,
|
|
3881
|
+
async execute(args, exec) {
|
|
3882
|
+
const pick = (t) => ({
|
|
3883
|
+
id: t.id, workspaceId: t.workspaceId, title: t.title, status: t.status,
|
|
3884
|
+
executionMode: t.executionMode, needPlan: t.needPlan, useTeam: t.useTeam,
|
|
3885
|
+
gitBranch: t.gitBranch || null,
|
|
3886
|
+
planSummary: t.planSummary || null, lastError: t.lastError || null,
|
|
3887
|
+
planningSessionId: t.planningSessionId || null, leadSessionId: t.leadSessionId || null,
|
|
3888
|
+
teams: t.teams || [], archivedAt: t.archivedAt || null, updatedAt: t.updatedAt,
|
|
3889
|
+
});
|
|
3890
|
+
if (args.taskId) {
|
|
3891
|
+
const task = await request(s, `/api/board/tasks/${encodeURIComponent(args.taskId)}`);
|
|
3892
|
+
return { task: pick(task) };
|
|
3893
|
+
}
|
|
3894
|
+
const sessionId = exec?.agent?.id != null ? String(exec.agent.id) : null;
|
|
3895
|
+
if (!sessionId) throw new Error('dsh_team_board_task_get 需要 taskId,或从看板会话里调用');
|
|
3896
|
+
const found = await request(s, `/api/board/by-session/${encodeURIComponent(sessionId)}`).catch(() => null);
|
|
3897
|
+
if (!found || found.ok === false || !found.id) throw new Error('当前会话没有关联的看板任务');
|
|
3898
|
+
return { task: pick(found) };
|
|
3899
|
+
},
|
|
3900
|
+
});
|
|
3901
|
+
|
|
3223
3902
|
return tools;
|
|
3224
3903
|
}
|
|
3225
3904
|
|
|
3226
3905
|
// ---------- trace 上报:把每次工具调用写成 span(running → done/failed) ----------
|
|
3227
|
-
/** 会话 → 团队 的粘性绑定:参数里出现 teamId 或
|
|
3906
|
+
/** 会话 → 团队 的粘性绑定:参数里出现 teamId 或 dsh_team_create 返回后记住,后续调用自动归属。 */
|
|
3228
3907
|
const teamBySession = new Map();
|
|
3229
3908
|
|
|
3230
3909
|
const clipText = (value, max) => {
|
|
@@ -3318,8 +3997,14 @@ async function reportFileChange(s, ctx, exec, next) {
|
|
|
3318
3997
|
// 再问 workingDirectory 服务;都拿不到才退回宿主进程 cwd(此时相对路径多半解析不到,diff 会被跳过)。
|
|
3319
3998
|
let agentCwd = typeof exec?.agent?.cwd === 'string' ? exec.agent.cwd : '';
|
|
3320
3999
|
if (!agentCwd && binding.cwd) agentCwd = binding.cwd;
|
|
3321
|
-
if (!agentCwd && exec?.agent?.session
|
|
3322
|
-
|
|
4000
|
+
if (!agentCwd && exec?.agent?.session) {
|
|
4001
|
+
// Cordis 的 ctx 是 Proxy:读未 inject 的服务(ctx.workingDirectory)会直接抛
|
|
4002
|
+
// 「cannot get property "workingDirectory" without inject」,可选链也拦不住。
|
|
4003
|
+
// 必须走 ctx.get()(不要求 inject);拿不到再退回宿主 cwd。
|
|
4004
|
+
try {
|
|
4005
|
+
const wd = ctx?.get?.('workingDirectory');
|
|
4006
|
+
if (wd && typeof wd.get === 'function') agentCwd = wd.get(exec.agent.session) || '';
|
|
4007
|
+
} catch { /* 忽略:目录拿不到时退回宿主 cwd */ }
|
|
3323
4008
|
}
|
|
3324
4009
|
const baseDir = agentCwd || process.cwd();
|
|
3325
4010
|
const abs = path.isAbsolute(raw) ? raw : path.resolve(baseDir, raw);
|
|
@@ -3527,10 +4212,11 @@ export function apply(ctx, config) {
|
|
|
3527
4212
|
const disposers = buildTools(s, ctx).map((tool) => ctx.tools.register(tool));
|
|
3528
4213
|
return () => {
|
|
3529
4214
|
for (const dispose of disposers.reverse()) { try { dispose(); } catch { /* ignore */ } }
|
|
3530
|
-
leadByTeam.clear(); teamCache.clear(); sessionMember.clear(); dispatching.clear(); teamBySession.clear(); contextReportAt.clear();
|
|
4215
|
+
leadByTeam.clear(); teamCache.clear(); sessionMember.clear(); dispatching.clear(); teamBySession.clear(); contextReportAt.clear(); prewalkArmed.clear();
|
|
3531
4216
|
for (const timer of idleTimers.values()) clearTimeout(timer);
|
|
3532
4217
|
for (const timer of startTimers.values()) clearTimeout(timer);
|
|
3533
4218
|
idleTimers.clear(); startTimers.clear(); agentStatusBySession.clear(); lastReplyBySession.clear();
|
|
4219
|
+
interruptNotified.clear();
|
|
3534
4220
|
const spawned = s.spawned;
|
|
3535
4221
|
if (spawned?.child && spawned.child.exitCode === null) {
|
|
3536
4222
|
try { spawned.child.kill(); } catch { /* ignore */ }
|
|
@@ -3575,14 +4261,14 @@ export function apply(ctx, config) {
|
|
|
3575
4261
|
|
|
3576
4262
|
// 审批分类需要工具参数,但 approval/request 只带 toolName/callId:
|
|
3577
4263
|
// 在 pre-execute 里按 callId 缓存成员这一轮的入参(只记成员,带 TTL),供低风险命令自动放行判定。
|
|
3578
|
-
if (s.autoApproveLowRisk) {
|
|
4264
|
+
if (s.autoApproveLowRisk || s.autoApproveTools.length) {
|
|
3579
4265
|
ctx.on('tools/pre-execute', (exec, next) => {
|
|
3580
4266
|
try { rememberPreExecuteArgs(exec); } catch { /* ignore */ }
|
|
3581
4267
|
return typeof next === 'function' ? next() : undefined;
|
|
3582
4268
|
});
|
|
3583
4269
|
}
|
|
3584
4270
|
|
|
3585
|
-
// 成员权限审批:preset 的 approval=ask 触发时,把请求转给 Lead,由
|
|
4271
|
+
// 成员权限审批:preset 的 approval=ask 触发时,把请求转给 Lead,由 dsh_team_approve 决定。
|
|
3586
4272
|
// 放在最前面(prepend),确保本插件的成员请求不会再弹出宿主审批 UI。
|
|
3587
4273
|
ctx.effect(() => {
|
|
3588
4274
|
const off = ctx.on('approval/request', (req, next) => onApprovalRequest(s, ctx, req, next), { prepend: true });
|
|
@@ -3604,7 +4290,35 @@ export function apply(ctx, config) {
|
|
|
3604
4290
|
ctx.on('tools/execute', fileChangeHook);
|
|
3605
4291
|
}
|
|
3606
4292
|
|
|
3607
|
-
//
|
|
4293
|
+
// prewalk(实验性):先在原模型上做第一笔实现动作,再交接同一条会话。
|
|
4294
|
+
// 只有武装过的看板会话参与;交接失败不影响工具结果,也不阻断任务。
|
|
4295
|
+
const prewalkHook = async (exec, next) => {
|
|
4296
|
+
const result = await next();
|
|
4297
|
+
try {
|
|
4298
|
+
const sessionId = exec?.agent?.id != null ? String(exec.agent.id) : null;
|
|
4299
|
+
const entry = sessionId ? prewalkArmed.get(sessionId) : null;
|
|
4300
|
+
if (!entry) return result;
|
|
4301
|
+
const name = String(exec?.name || '');
|
|
4302
|
+
// 任务收工(done/failed)时清掉未触发的武装,避免会话结束后残留。
|
|
4303
|
+
if (name === 'dsh_team_board_task_status' && exec?.arguments?.status !== 'inprogress') {
|
|
4304
|
+
prewalkArmed.delete(sessionId);
|
|
4305
|
+
return result;
|
|
4306
|
+
}
|
|
4307
|
+
if (!boardPrewalkWantsTool(name)) return result;
|
|
4308
|
+
// 工具报错(参数错、权限拒绝等)不算「已经落到实现」:保持武装,等下一次
|
|
4309
|
+
// 成功的 edit/write(或 dsh_team_task)再交接,避免接手模型先替规划模型收拾失败。
|
|
4310
|
+
if (result && (result.isError === true || result.error != null)) return result;
|
|
4311
|
+
prewalkArmed.delete(sessionId);
|
|
4312
|
+
await boardHandoffExecution(ctx, exec.agent, entry.task, entry.settings);
|
|
4313
|
+
} catch (err) {
|
|
4314
|
+
console.warn(`[dsh-team] prewalk: 交接失败(${String(err?.message || err)})`);
|
|
4315
|
+
}
|
|
4316
|
+
return result;
|
|
4317
|
+
};
|
|
4318
|
+
prewalkHook.dshTeamHook = 'prewalk';
|
|
4319
|
+
ctx.on('tools/execute', prewalkHook);
|
|
4320
|
+
|
|
4321
|
+
// 成员用内置 todo_write 维护计划(没建 dsh_team_todo)时,把 DSH 的 `todos` 投影镜像成
|
|
3608
4322
|
// sidecar 计划步骤:面板/团队校验能看到真实 plan,todo 勾完计划步骤也跟着完成。
|
|
3609
4323
|
ctx.on('tools/execute', async (exec, next) => {
|
|
3610
4324
|
const result = await next();
|
|
@@ -3664,7 +4378,7 @@ export function apply(ctx, config) {
|
|
|
3664
4378
|
idleTimers.delete(sessionId);
|
|
3665
4379
|
if (heldSessions.has(sessionId)) { agentStatusBySession.set(sessionId, 'interrupted'); return; }
|
|
3666
4380
|
if (agentStatusBySession.get(sessionId) !== 'idle') return; // 窗口内又跑起来了
|
|
3667
|
-
// 把这一轮最后的正文带给 sidecar:漏调
|
|
4381
|
+
// 把这一轮最后的正文带给 sidecar:漏调 dsh_team_report_task 时,兜底收尾的 task.done 也有摘要可看
|
|
3668
4382
|
const reply = lastReplyBySession.get(sessionId);
|
|
3669
4383
|
reportAgentStatus(s, sessionId, 'idle', reply ? clip(reply, 500) : undefined);
|
|
3670
4384
|
void flushMemberReply(s, sessionId).catch(() => { /* ignore */ });
|
|
@@ -3697,6 +4411,19 @@ export function apply(ctx, config) {
|
|
|
3697
4411
|
cancelIdleReport(sessionId);
|
|
3698
4412
|
agentStatusBySession.set(sessionId, 'idle');
|
|
3699
4413
|
reportAgentStatus(s, sessionId, 'failed', `模型回合失败:${msg}`);
|
|
4414
|
+
// 会话以 error 结束同样算「成员意外中断」:不通知,挂起的 Lead 只会在下一次主动查状态时才发现。
|
|
4415
|
+
const bind = sessionMember.get(sessionId);
|
|
4416
|
+
if (bind) {
|
|
4417
|
+
void notifyLeadOfMemberInterrupt(s, ctx, {
|
|
4418
|
+
teamId: bind.teamId,
|
|
4419
|
+
memberId: bind.memberId,
|
|
4420
|
+
memberName: bind.name || null,
|
|
4421
|
+
sessionId,
|
|
4422
|
+
status: 'failed',
|
|
4423
|
+
reason: `模型回合失败:${msg}`,
|
|
4424
|
+
dedupeKey: `failed:${sessionId}:${event.seq ?? event.data?.turn ?? ''}:${msg}`,
|
|
4425
|
+
}).catch(() => { /* 通知尽力而为 */ });
|
|
4426
|
+
}
|
|
3700
4427
|
}
|
|
3701
4428
|
return;
|
|
3702
4429
|
}
|
|
@@ -3757,7 +4484,7 @@ export function apply(ctx, config) {
|
|
|
3757
4484
|
}, 'dsh-team.workspace-pump()');
|
|
3758
4485
|
}
|
|
3759
4486
|
|
|
3760
|
-
// 模型目录泵:面板「模型路由」页不再依赖 lead 调
|
|
4487
|
+
// 模型目录泵:面板「模型路由」页不再依赖 lead 调 dsh_team_models。
|
|
3761
4488
|
// 启动即同步(sidecar 可能刚 spawn,失败 2s 重试),成功后按 llmCatalogMs 定时刷新。
|
|
3762
4489
|
if (s.reportLlmCatalog) {
|
|
3763
4490
|
ctx.effect(() => {
|