dsh-cohub 0.10.3 → 0.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/index.js +182 -44
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-cohub
|
|
2
2
|
|
|
3
|
-
> 本文对应 **v0.10.
|
|
3
|
+
> 本文对应 **v0.10.5**;完整变更历史见 [CHANGELOG.md](./CHANGELOG.md)。
|
|
4
4
|
|
|
5
5
|
DeepSeek Harness 版(对照 [OpenCode 版](../oh-my-opencode-cohub/)):中文智能体编排插件。
|
|
6
6
|
把「纯调度模式 + 13 个技能(12 个代理编排体系 + co-cordis 组合创作)+ 多模型共识 + 运行期调度韧性」移植到 DSH 原生能力之上。
|
package/lib/index.js
CHANGED
|
@@ -3133,7 +3133,7 @@ function resolveSkillAgentPreset(skillName, enabled = true) {
|
|
|
3133
3133
|
return SUBAGENT_READONLY_PRESET;
|
|
3134
3134
|
if (WRITE_SKILLS.has(key))
|
|
3135
3135
|
return SUBAGENT_WRITE_PRESET;
|
|
3136
|
-
return;
|
|
3136
|
+
return SUBAGENT_WRITE_PRESET;
|
|
3137
3137
|
}
|
|
3138
3138
|
function intersectWithRestrictable(filter, restrictableNames) {
|
|
3139
3139
|
if (!filter || !restrictableNames)
|
|
@@ -3146,25 +3146,36 @@ function intersectWithRestrictable(filter, restrictableNames) {
|
|
|
3146
3146
|
};
|
|
3147
3147
|
return next.allow !== undefined || next.deny !== undefined ? next : undefined;
|
|
3148
3148
|
}
|
|
3149
|
+
var SKILL_NAME_ECHO_MAX = 80;
|
|
3150
|
+
function flattenToOneLine(text) {
|
|
3151
|
+
return text.replace(/\s+/g, " ").trim();
|
|
3152
|
+
}
|
|
3153
|
+
function firstLineClamped(raw, maxChars) {
|
|
3154
|
+
const firstLine = flattenToOneLine(raw.split(/[\r\n]/, 1)[0] ?? "").replace(/\[/g, "[").replace(/\]/g, "]");
|
|
3155
|
+
return firstLine.length > maxChars ? firstLine.slice(0, maxChars) + "…" : firstLine;
|
|
3156
|
+
}
|
|
3149
3157
|
function describeDegradeReason(error) {
|
|
3150
3158
|
const message = error?.message;
|
|
3151
3159
|
const raw = typeof message === "string" && message.length > 0 ? message : String(error);
|
|
3152
|
-
const
|
|
3153
|
-
|
|
3154
|
-
return text.length > 200 ? text.slice(0, 200) : text;
|
|
3160
|
+
const text = firstLineClamped(raw, 200);
|
|
3161
|
+
return text.length > 0 ? text : "unknown";
|
|
3155
3162
|
}
|
|
3156
3163
|
function formatDegradeNotes(notes) {
|
|
3157
3164
|
if (notes === undefined || notes.length === 0)
|
|
3158
3165
|
return "";
|
|
3166
|
+
const reasonOf = (note) => {
|
|
3167
|
+
const flat = firstLineClamped(String(note.reason ?? ""), 200);
|
|
3168
|
+
return flat.length > 0 ? flat : "unknown";
|
|
3169
|
+
};
|
|
3159
3170
|
if (notes.length === 1) {
|
|
3160
3171
|
const only = notes[0];
|
|
3161
3172
|
return `
|
|
3162
3173
|
|
|
3163
|
-
[` + only.what + "," + only.effect + ":" + only
|
|
3174
|
+
[` + only.what + "," + only.effect + ":" + reasonOf(only) + "]";
|
|
3164
3175
|
}
|
|
3165
3176
|
return `
|
|
3166
3177
|
|
|
3167
|
-
[降级提示:` + notes.map((n) => n.what + "," + n.effect + "(" + n
|
|
3178
|
+
[降级提示:` + notes.map((n) => n.what + "," + n.effect + "(" + reasonOf(n) + ")").join(";") + "]";
|
|
3168
3179
|
}
|
|
3169
3180
|
function upsertDegradeNote(notes, note) {
|
|
3170
3181
|
if (notes === undefined)
|
|
@@ -3320,7 +3331,10 @@ async function startSubagentRunOnce(ctx, provider, spec) {
|
|
|
3320
3331
|
const subagents = ctx?.subagents;
|
|
3321
3332
|
if (!subagents)
|
|
3322
3333
|
throw new Error("cohub: startSubagentRun requires the subagents service");
|
|
3323
|
-
const signal = spec.signal
|
|
3334
|
+
const signal = spec.signal;
|
|
3335
|
+
if (signal === undefined) {
|
|
3336
|
+
ctx?.logger?.warn?.("[cohub] startSubagentRun 无可用 signal:子运行不可中止(父轮停止无法回收)");
|
|
3337
|
+
}
|
|
3324
3338
|
if (typeof subagents.startActivation === "function") {
|
|
3325
3339
|
const prompt = spec.persona !== undefined ? [{ type: "text", text: spec.persona }, ...spec.prompt] : spec.prompt;
|
|
3326
3340
|
const receipt = await subagents.startActivation({
|
|
@@ -3333,7 +3347,7 @@ async function startSubagentRunOnce(ctx, provider, spec) {
|
|
|
3333
3347
|
...spec.agentOptions !== undefined ? { agentOptions: spec.agentOptions } : {},
|
|
3334
3348
|
...spec.toolFilter !== undefined ? { toolFilter: spec.toolFilter } : {}
|
|
3335
3349
|
},
|
|
3336
|
-
signal,
|
|
3350
|
+
...signal !== undefined ? { signal } : {},
|
|
3337
3351
|
delivery: "caller"
|
|
3338
3352
|
});
|
|
3339
3353
|
applyChildToolFilterDirectly(ctx, receipt.childId, spec.toolFilter, spec.degradeNotes);
|
|
@@ -3351,7 +3365,7 @@ async function startSubagentRunOnce(ctx, provider, spec) {
|
|
|
3351
3365
|
...spec.toolFilter !== undefined ? { toolFilter: spec.toolFilter } : {},
|
|
3352
3366
|
...spec.agentPreset !== undefined ? { agentPreset: spec.agentPreset } : {},
|
|
3353
3367
|
...spec.agentOptions !== undefined ? { agentOptions: spec.agentOptions } : {},
|
|
3354
|
-
signal
|
|
3368
|
+
...signal !== undefined ? { signal } : {}
|
|
3355
3369
|
});
|
|
3356
3370
|
return {
|
|
3357
3371
|
id: run.id,
|
|
@@ -3570,15 +3584,19 @@ function resolveSkillAndRoute(requestedSkill, getRoutes, ctx, logger) {
|
|
|
3570
3584
|
const requested = (typeof requestedSkill === "string" ? requestedSkill : "").trim();
|
|
3571
3585
|
const skillName = requested || DEFAULT_FALLBACK_SKILL;
|
|
3572
3586
|
const fallback = requested.length === 0;
|
|
3587
|
+
const echoName = firstLineClamped(skillName, SKILL_NAME_ECHO_MAX) || "unknown";
|
|
3573
3588
|
let skill = COHUB_SKILLS.find((s) => s.name === skillName);
|
|
3589
|
+
let note;
|
|
3574
3590
|
if (!skill) {
|
|
3575
3591
|
(logger ?? ctx.logger)?.warn?.('delegate: unknown skill "' + skillName + '", falling back to co-fixer');
|
|
3576
3592
|
skill = COHUB_SKILLS.find((s) => s.name === DEFAULT_FALLBACK_SKILL);
|
|
3593
|
+
note = '传入的 skill 名 "' + echoName + '" 未匹配任何 co-* 代理,已兜底为 ' + DEFAULT_FALLBACK_SKILL + ",子代理 preset 同步回退为实施类 " + SUBAGENT_WRITE_PRESET;
|
|
3577
3594
|
} else if (fallback) {
|
|
3578
3595
|
(logger ?? ctx.logger)?.warn?.("delegate: skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + ";schema 已要求必填,出现本告警说明调用绕过了参数校验");
|
|
3596
|
+
note = "skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + ",子代理 preset 回退为实施类 " + SUBAGENT_WRITE_PRESET;
|
|
3579
3597
|
}
|
|
3580
3598
|
const route = (getRoutes() ?? []).find((s) => s.name === requested);
|
|
3581
|
-
return { skill, route, fallback };
|
|
3599
|
+
return { skill, route, fallback, ...note === undefined ? {} : { note } };
|
|
3582
3600
|
}
|
|
3583
3601
|
function formatSkillLabel(skill, fallback) {
|
|
3584
3602
|
return fallback ? skill.name + " (default:" + DEFAULT_FALLBACK_SKILL + ")" : skill.name;
|
|
@@ -3674,10 +3692,17 @@ function resolveDelegationDepth(agent) {
|
|
|
3674
3692
|
return MAX_DELEGATION_DEPTH;
|
|
3675
3693
|
return depth;
|
|
3676
3694
|
}
|
|
3695
|
+
function describeDepthCandidate(value) {
|
|
3696
|
+
const kind = value === null ? "null" : typeof value;
|
|
3697
|
+
const shown = typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
3698
|
+
return shown + "(" + kind + ")";
|
|
3699
|
+
}
|
|
3677
3700
|
function guardDelegationDepth(agent, logger) {
|
|
3678
3701
|
const depth = resolveDelegationDepth(agent);
|
|
3679
3702
|
if (depth === undefined) {
|
|
3680
|
-
|
|
3703
|
+
const header = agent?.session?.header;
|
|
3704
|
+
logger?.warn?.("[cohub depth-guard] 深度候选原始值:" + "header.delegationDepth=" + describeDepthCandidate(header?.delegationDepth) + " / options.subagentDepth=" + describeDepthCandidate(agent?.options?.subagentDepth) + " / session.delegationDepth=" + describeDepthCandidate(agent?.session?.delegationDepth) + " / header.origin=" + describeDepthCandidate(header?.origin));
|
|
3705
|
+
logger?.warn?.("[cohub depth-guard] 无法判定委派深度,按兼容策略放行(fail-open)" + ":session.header.delegationDepth / options.subagentDepth / session.delegationDepth 均缺失或非法," + '且 header.origin 不是 "subagent";本次委派继续执行,嵌套上限不再生效。' + '若上面某候选是字符串 "0" 之类的类型错误,请修宿主(合法值为 number 且为安全整数)');
|
|
3681
3706
|
return;
|
|
3682
3707
|
}
|
|
3683
3708
|
if (depth < MAX_DELEGATION_DEPTH)
|
|
@@ -3896,7 +3921,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3896
3921
|
const { retry, stall, schedule, budget, background, subagentPresetEnabled } = resolveRuntimeConfig();
|
|
3897
3922
|
const RETRYABLE = new Set(retry.retryableReasons);
|
|
3898
3923
|
ctx.logger?.info?.("[cohub schedule] 生效调度参数:batch=" + (schedule?.maxParallelBatch ?? 3) + " wallMs=" + (schedule?.wallClockBudgetMs ?? WALL_CLOCK_BUDGET_MS));
|
|
3899
|
-
const { skill, route, fallback: skillFallback } = resolveSkillAndRoute(args.skill, getRoutes, ctx);
|
|
3924
|
+
const { skill, route, fallback: skillFallback, note: skillNote } = resolveSkillAndRoute(args.skill, getRoutes, ctx);
|
|
3900
3925
|
const skillTag = formatSkillLabel(skill, skillFallback);
|
|
3901
3926
|
const brief = skill.brief?.trim();
|
|
3902
3927
|
if (!brief) {
|
|
@@ -3905,6 +3930,14 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3905
3930
|
const agentOptions = await buildAgentOptions(route, ctx, skill.name);
|
|
3906
3931
|
const toolFilter = resolveSkillToolFilter(skill.name, config.toolFilter?.enabled ?? true, ctx.logger);
|
|
3907
3932
|
const degradeNotes = [];
|
|
3933
|
+
if (skillNote !== undefined) {
|
|
3934
|
+
upsertDegradeNote(degradeNotes, {
|
|
3935
|
+
id: "skill",
|
|
3936
|
+
what: "skill 名未命中",
|
|
3937
|
+
effect: "子代理已按兜底角色 " + skill.name + " 执行",
|
|
3938
|
+
reason: skillNote
|
|
3939
|
+
});
|
|
3940
|
+
}
|
|
3908
3941
|
const agentPreset = resolveSkillAgentPreset(skill.name, subagentPresetEnabled);
|
|
3909
3942
|
const fp = envFingerprint();
|
|
3910
3943
|
const contractResult = resolveContractText({ enabled: envContract.enabled, text: envContract.text }, envSig, ctx, fp);
|
|
@@ -4006,7 +4039,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4006
4039
|
learner.detach();
|
|
4007
4040
|
if (onExecAbort && outerSignal)
|
|
4008
4041
|
outerSignal.removeEventListener("abort", onExecAbort);
|
|
4009
|
-
if (ac?.signal.aborted) {
|
|
4042
|
+
if (ac?.signal.aborted || outerSignal?.aborted === true) {
|
|
4010
4043
|
lastReason = "aborted";
|
|
4011
4044
|
lastDiagnostic = undefined;
|
|
4012
4045
|
lastPartial = "";
|
|
@@ -4029,12 +4062,37 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4029
4062
|
if (learner)
|
|
4030
4063
|
learner.bind(run.id);
|
|
4031
4064
|
run.result.catch(() => {});
|
|
4065
|
+
let disposed = false;
|
|
4066
|
+
const safeDispose = async () => {
|
|
4067
|
+
if (disposed)
|
|
4068
|
+
return;
|
|
4069
|
+
disposed = true;
|
|
4070
|
+
try {
|
|
4071
|
+
await run.dispose();
|
|
4072
|
+
} catch {}
|
|
4073
|
+
};
|
|
4074
|
+
const RACED_ABORT = { delegateRaceAborted: true };
|
|
4075
|
+
let abortHandler = null;
|
|
4032
4076
|
let outcome;
|
|
4033
4077
|
try {
|
|
4034
|
-
|
|
4078
|
+
if (signal && !signal.aborted) {
|
|
4079
|
+
const abortPromise = new Promise((_, reject) => {
|
|
4080
|
+
const onAbort = () => reject(RACED_ABORT);
|
|
4081
|
+
abortHandler = onAbort;
|
|
4082
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
4083
|
+
});
|
|
4084
|
+
outcome = await Promise.race([run.result, abortPromise]);
|
|
4085
|
+
} else {
|
|
4086
|
+
outcome = await run.result;
|
|
4087
|
+
}
|
|
4035
4088
|
} catch (error) {
|
|
4036
|
-
|
|
4037
|
-
|
|
4089
|
+
if (error === RACED_ABORT) {
|
|
4090
|
+
await safeDispose();
|
|
4091
|
+
outcome = { stopReason: "aborted", output: [], diagnostic: "raced abort(result 未结算)" };
|
|
4092
|
+
} else {
|
|
4093
|
+
reportAttempt(String(run?.id ?? ""), "failed", "error");
|
|
4094
|
+
throw error;
|
|
4095
|
+
}
|
|
4038
4096
|
} finally {
|
|
4039
4097
|
if (learner) {
|
|
4040
4098
|
if (learner.flush()) {
|
|
@@ -4046,9 +4104,9 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4046
4104
|
watchdog.detach();
|
|
4047
4105
|
if (onExecAbort && outerSignal)
|
|
4048
4106
|
outerSignal.removeEventListener("abort", onExecAbort);
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4107
|
+
if (abortHandler && signal)
|
|
4108
|
+
signal.removeEventListener("abort", abortHandler);
|
|
4109
|
+
await safeDispose();
|
|
4052
4110
|
}
|
|
4053
4111
|
if (outcome?.stopReason === "completed") {
|
|
4054
4112
|
reportAttempt(String(run?.id ?? ""), "completed", "completed");
|
|
@@ -4080,7 +4138,8 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4080
4138
|
retries++;
|
|
4081
4139
|
await new Promise((r) => setTimeout(r, retry.retryDelayMs));
|
|
4082
4140
|
}
|
|
4083
|
-
const
|
|
4141
|
+
const degradeText = formatDegradeNotes(degradeNotes).replace(/\s+/g, " ");
|
|
4142
|
+
const err = new Error('delegate: subagent stopped with reason "' + lastReason + '" after ' + retries + " retry(ies)" + (lastDiagnostic === undefined ? "" : "; diagnostic: " + lastDiagnostic) + (stallState.last ? "; stalled: " + stallState.last.diagnostics : "") + "; partial: " + lastPartial + degradeText);
|
|
4084
4143
|
err.cause = {
|
|
4085
4144
|
stopReason: lastReason,
|
|
4086
4145
|
...lastDiagnostic === undefined ? {} : { diagnostic: lastDiagnostic },
|
|
@@ -4088,7 +4147,8 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4088
4147
|
...lastPartialBudget === lastPartial ? {} : { partialBudget: lastPartialBudget },
|
|
4089
4148
|
skill: skill.name,
|
|
4090
4149
|
retries,
|
|
4091
|
-
...stallState.last ? { stall: stallState.last } : {}
|
|
4150
|
+
...stallState.last ? { stall: stallState.last } : {},
|
|
4151
|
+
...degradeText.length > 0 ? { degrade: degradeText } : {}
|
|
4092
4152
|
};
|
|
4093
4153
|
throw err;
|
|
4094
4154
|
};
|
|
@@ -4113,6 +4173,25 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4113
4173
|
ctx.logger?.warn?.("[cohub background-fallback] " + bgFallbackReason + ",回退前台");
|
|
4114
4174
|
} else if (jobs !== undefined && typeof jobs.start === "function") {
|
|
4115
4175
|
const cancelAc = new AbortController;
|
|
4176
|
+
const parentSig = exec?.signal;
|
|
4177
|
+
const onParentAbort = () => {
|
|
4178
|
+
try {
|
|
4179
|
+
cancelAc.abort();
|
|
4180
|
+
} catch {}
|
|
4181
|
+
};
|
|
4182
|
+
const detachParentAbort = () => {
|
|
4183
|
+
try {
|
|
4184
|
+
parentSig?.removeEventListener("abort", onParentAbort);
|
|
4185
|
+
} catch {}
|
|
4186
|
+
};
|
|
4187
|
+
if (parentSig) {
|
|
4188
|
+
if (parentSig.aborted) {
|
|
4189
|
+
ctx.logger?.info?.("[cohub background] 父轮已中止,后台 delegate 直接按取消处理(reason=" + String(parentSig.reason?.kind ?? "unknown") + ")");
|
|
4190
|
+
onParentAbort();
|
|
4191
|
+
} else {
|
|
4192
|
+
parentSig.addEventListener("abort", onParentAbort, { once: true });
|
|
4193
|
+
}
|
|
4194
|
+
}
|
|
4116
4195
|
let jobId;
|
|
4117
4196
|
try {
|
|
4118
4197
|
const startJob = (ownerValue) => jobs.start({
|
|
@@ -4130,6 +4209,8 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4130
4209
|
return { status: "killed", detail: "delegate 已取消(job_kill / owner 释放)" };
|
|
4131
4210
|
}
|
|
4132
4211
|
return { status: "failed", detail: String(error) };
|
|
4212
|
+
} finally {
|
|
4213
|
+
detachParentAbort();
|
|
4133
4214
|
}
|
|
4134
4215
|
})();
|
|
4135
4216
|
return {
|
|
@@ -4160,6 +4241,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4160
4241
|
ctx.logger?.info?.("[cohub background] delegate 已注册为后台 job:" + jobId + "(skill=" + skill.name + ")");
|
|
4161
4242
|
return "已在后台启动:" + skill.name + "(job: " + jobId + ")。" + '取结果:job_output({ job_id: "' + jobId + '", wait: true });' + "或等自动唤醒(job 完成且你空闲时会自动开新一轮,最多连续 3 次)。" + "等待期间可以继续派发别的任务或推进其他工作(后台任务不计入当前批次耗时)。";
|
|
4162
4243
|
}
|
|
4244
|
+
detachParentAbort();
|
|
4163
4245
|
if (bgFallbackReason === undefined) {
|
|
4164
4246
|
bgFallbackReason = "jobs.start 未返回 jobId";
|
|
4165
4247
|
ctx.logger?.warn?.("[cohub background-fallback] " + bgFallbackReason + ",回退前台");
|
|
@@ -4406,6 +4488,7 @@ function createCouncilTool(config, ctx) {
|
|
|
4406
4488
|
|
|
4407
4489
|
// src/delegate_batch.ts
|
|
4408
4490
|
import { defineTool as defineTool3 } from "@deepseek-ai/dsh-tools";
|
|
4491
|
+
var BATCH_TASK_ID_ECHO_MAX = 40;
|
|
4409
4492
|
var MAX_BATCH_SIZE = 20;
|
|
4410
4493
|
function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
4411
4494
|
const envContract = createEnvContract(config);
|
|
@@ -4480,7 +4563,16 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4480
4563
|
});
|
|
4481
4564
|
const starts = await Promise.allSettled(normalized.map(async ({ task, taskId, requestedSkill, skillFallback }) => {
|
|
4482
4565
|
const startedAt = Date.now();
|
|
4483
|
-
const { skill, route } = resolveSkillAndRoute(requestedSkill, getRoutes, ctx, ctx.logger);
|
|
4566
|
+
const { skill, route, note: skillNote } = resolveSkillAndRoute(requestedSkill, getRoutes, ctx, ctx.logger);
|
|
4567
|
+
const taskNotes = [];
|
|
4568
|
+
if (skillNote !== undefined) {
|
|
4569
|
+
taskNotes.push({
|
|
4570
|
+
id: "skill",
|
|
4571
|
+
what: "skill 名未命中",
|
|
4572
|
+
effect: "子代理已按兜底角色 " + skill.name + " 执行",
|
|
4573
|
+
reason: skillNote
|
|
4574
|
+
});
|
|
4575
|
+
}
|
|
4484
4576
|
const skillTag = formatSkillLabel(skill, skillFallback);
|
|
4485
4577
|
const promptText = buildDelegatePrompt({
|
|
4486
4578
|
skill,
|
|
@@ -4512,20 +4604,26 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4512
4604
|
...toolFilter !== undefined ? { toolFilter } : {},
|
|
4513
4605
|
...agentPreset !== undefined ? { agentPreset } : {},
|
|
4514
4606
|
...agentOptions ? { agentOptions } : {},
|
|
4515
|
-
signal: ac.signal
|
|
4607
|
+
signal: ac.signal,
|
|
4608
|
+
degradeNotes: taskNotes
|
|
4516
4609
|
});
|
|
4517
|
-
return { taskId, skillName: skill.name, skillTag, task, run, ac, onExecAbort, startedAt, startError: undefined };
|
|
4610
|
+
return { taskId, skillName: skill.name, skillTag, task, taskNotes, run, ac, onExecAbort, startedAt, startError: undefined };
|
|
4518
4611
|
} catch (startError) {
|
|
4519
4612
|
if (onExecAbort && exec.signal) {
|
|
4520
4613
|
try {
|
|
4521
4614
|
exec.signal.removeEventListener("abort", onExecAbort);
|
|
4522
4615
|
} catch {}
|
|
4523
4616
|
}
|
|
4524
|
-
return { taskId, skillName: skill.name, skillTag, task, run: undefined, ac, onExecAbort: null, startedAt, startError };
|
|
4617
|
+
return { taskId, skillName: skill.name, skillTag, task, taskNotes, run: undefined, ac, onExecAbort: null, startedAt, startError };
|
|
4525
4618
|
}
|
|
4526
4619
|
}));
|
|
4527
4620
|
const results = [];
|
|
4528
4621
|
const runs = [];
|
|
4622
|
+
const perTaskNotes = [];
|
|
4623
|
+
const degradeField = (notes) => {
|
|
4624
|
+
const text = formatDegradeNotes(notes).trim();
|
|
4625
|
+
return text.length > 0 ? { degrade: text } : {};
|
|
4626
|
+
};
|
|
4529
4627
|
try {
|
|
4530
4628
|
for (const s of starts) {
|
|
4531
4629
|
if (s.status === "rejected") {
|
|
@@ -4533,37 +4631,64 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4533
4631
|
}
|
|
4534
4632
|
const val = s.value;
|
|
4535
4633
|
if (val.startError) {
|
|
4634
|
+
perTaskNotes.push({ taskId: val.taskId, notes: val.taskNotes ?? [] });
|
|
4536
4635
|
results.push({
|
|
4537
4636
|
id: val.taskId,
|
|
4538
4637
|
skill: val.skillTag,
|
|
4539
4638
|
status: "error",
|
|
4540
|
-
error: val.startError instanceof Error ? val.startError.message : String(val.startError)
|
|
4639
|
+
error: val.startError instanceof Error ? val.startError.message : String(val.startError),
|
|
4640
|
+
...degradeField(val.taskNotes ?? [])
|
|
4541
4641
|
});
|
|
4542
4642
|
continue;
|
|
4543
4643
|
}
|
|
4544
|
-
const { run, taskId, skillName, skillTag, ac, onExecAbort, startedAt } = val;
|
|
4545
|
-
|
|
4644
|
+
const { run, taskId, skillName, skillTag, taskNotes, ac, onExecAbort, startedAt } = val;
|
|
4645
|
+
let disposed = false;
|
|
4646
|
+
const safeDispose = () => {
|
|
4647
|
+
if (disposed)
|
|
4648
|
+
return;
|
|
4649
|
+
disposed = true;
|
|
4650
|
+
Promise.resolve().then(() => run.dispose()).catch(() => {});
|
|
4651
|
+
};
|
|
4652
|
+
runs.push({ run, safeDispose, taskId, skillName, skillTag, taskNotes, ac, onExecAbort, startedAt });
|
|
4653
|
+
perTaskNotes.push({ taskId, notes: taskNotes });
|
|
4546
4654
|
run.result.catch(() => {});
|
|
4547
4655
|
}
|
|
4548
|
-
for (const { run, taskId, skillName, skillTag, ac, startedAt } of runs) {
|
|
4656
|
+
for (const { run, safeDispose, taskId, skillName, skillTag, taskNotes, ac, startedAt } of runs) {
|
|
4549
4657
|
let outcome;
|
|
4550
4658
|
let timer = null;
|
|
4659
|
+
const abortOffs = [];
|
|
4551
4660
|
const remainingMs = Math.max(0, wallClockBudgetMs - (Date.now() - startedAt));
|
|
4661
|
+
const parentSignal = exec.signal;
|
|
4552
4662
|
try {
|
|
4553
4663
|
outcome = await Promise.race([
|
|
4554
4664
|
run.result,
|
|
4555
4665
|
new Promise((_, reject) => {
|
|
4666
|
+
const failFast = (message) => {
|
|
4667
|
+
if (timer) {
|
|
4668
|
+
clearTimeout(timer);
|
|
4669
|
+
timer = null;
|
|
4670
|
+
}
|
|
4671
|
+
safeDispose();
|
|
4672
|
+
reject(new Error(message));
|
|
4673
|
+
};
|
|
4674
|
+
const onAbort = () => {
|
|
4675
|
+
if (!ac.signal.aborted)
|
|
4676
|
+
ac.abort();
|
|
4677
|
+
failFast(`已取消:实际耗时 ${Date.now() - startedAt}ms(父级 abort)`);
|
|
4678
|
+
};
|
|
4679
|
+
if (parentSignal) {
|
|
4680
|
+
if (parentSignal.aborted) {
|
|
4681
|
+
onAbort();
|
|
4682
|
+
return;
|
|
4683
|
+
}
|
|
4684
|
+
parentSignal.addEventListener("abort", onAbort, { once: true });
|
|
4685
|
+
abortOffs.push(() => parentSignal.removeEventListener("abort", onAbort));
|
|
4686
|
+
}
|
|
4556
4687
|
timer = setTimeout(() => {
|
|
4557
4688
|
if (!ac.signal.aborted)
|
|
4558
4689
|
ac.abort();
|
|
4559
|
-
|
|
4690
|
+
failFast(`超时:实际耗时 ${Date.now() - startedAt}ms(预算 ${wallClockBudgetMs}ms)`);
|
|
4560
4691
|
}, remainingMs);
|
|
4561
|
-
if (exec.signal && !exec.signal.aborted) {
|
|
4562
|
-
exec.signal.addEventListener("abort", () => {
|
|
4563
|
-
if (timer)
|
|
4564
|
-
clearTimeout(timer);
|
|
4565
|
-
}, { once: true });
|
|
4566
|
-
}
|
|
4567
4692
|
})
|
|
4568
4693
|
]);
|
|
4569
4694
|
if (outcome?.stopReason === "completed") {
|
|
@@ -4578,7 +4703,8 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4578
4703
|
id: taskId,
|
|
4579
4704
|
skill: skillTag,
|
|
4580
4705
|
status: "completed",
|
|
4581
|
-
result: resultText
|
|
4706
|
+
result: resultText,
|
|
4707
|
+
...degradeField(taskNotes)
|
|
4582
4708
|
});
|
|
4583
4709
|
} else {
|
|
4584
4710
|
const diag = typeof outcome?.diagnostic === "string" ? outcome.diagnostic : undefined;
|
|
@@ -4588,7 +4714,8 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4588
4714
|
status: "failed",
|
|
4589
4715
|
error: `stopReason: ${outcome?.stopReason ?? "unknown"}` + (diag === undefined ? "" : `; diagnostic: ${diag}`),
|
|
4590
4716
|
stopReason: outcome?.stopReason,
|
|
4591
|
-
...diag === undefined ? {} : { diagnostic: diag }
|
|
4717
|
+
...diag === undefined ? {} : { diagnostic: diag },
|
|
4718
|
+
...degradeField(taskNotes)
|
|
4592
4719
|
});
|
|
4593
4720
|
}
|
|
4594
4721
|
} catch (e) {
|
|
@@ -4596,15 +4723,21 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4596
4723
|
id: taskId,
|
|
4597
4724
|
skill: skillTag,
|
|
4598
4725
|
status: "error",
|
|
4599
|
-
error: e instanceof Error ? e.message : String(e)
|
|
4726
|
+
error: e instanceof Error ? e.message : String(e),
|
|
4727
|
+
...degradeField(taskNotes)
|
|
4600
4728
|
});
|
|
4601
4729
|
} finally {
|
|
4602
4730
|
if (timer)
|
|
4603
4731
|
clearTimeout(timer);
|
|
4732
|
+
for (const off of abortOffs) {
|
|
4733
|
+
try {
|
|
4734
|
+
off();
|
|
4735
|
+
} catch {}
|
|
4736
|
+
}
|
|
4604
4737
|
}
|
|
4605
4738
|
}
|
|
4606
4739
|
} finally {
|
|
4607
|
-
for (const {
|
|
4740
|
+
for (const { safeDispose, ac, onExecAbort } of runs) {
|
|
4608
4741
|
if (onExecAbort && exec.signal) {
|
|
4609
4742
|
try {
|
|
4610
4743
|
exec.signal.removeEventListener("abort", onExecAbort);
|
|
@@ -4612,9 +4745,7 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4612
4745
|
}
|
|
4613
4746
|
if (!ac.signal.aborted)
|
|
4614
4747
|
ac.abort();
|
|
4615
|
-
|
|
4616
|
-
run.dispose();
|
|
4617
|
-
} catch {}
|
|
4748
|
+
safeDispose();
|
|
4618
4749
|
}
|
|
4619
4750
|
}
|
|
4620
4751
|
const batchElapsedMs = Date.now() - batchStartedAt;
|
|
@@ -4672,7 +4803,14 @@ ${r.result}
|
|
|
4672
4803
|
ctx?.logger?.warn?.("[cohub budget] batch:total:拼装结果 " + fullChars + " 字符 ≈ " + approxTokens(fullChars) + " tokens 超过总预算 " + budget.batchTotalMaxChars + " 字符,已裁剪;各任务全文见各自的 locator。仅告警,不阻断。");
|
|
4673
4804
|
}
|
|
4674
4805
|
maybeDeferTodoNudge(exec);
|
|
4675
|
-
|
|
4806
|
+
const allNotes = [];
|
|
4807
|
+
for (const { taskId, notes } of perTaskNotes) {
|
|
4808
|
+
const echoTaskId = firstLineClamped(taskId, BATCH_TASK_ID_ECHO_MAX);
|
|
4809
|
+
for (const note of notes) {
|
|
4810
|
+
allNotes.push({ id: note.id, what: echoTaskId + " " + note.what, effect: note.effect, reason: note.reason });
|
|
4811
|
+
}
|
|
4812
|
+
}
|
|
4813
|
+
return statsLine + output + formatDegradeNotes(allNotes);
|
|
4676
4814
|
}
|
|
4677
4815
|
});
|
|
4678
4816
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cohub",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.5",
|
|
4
4
|
"description": "DeepSeek Harness 版 CoHub:中文智能体编排——用户可选 2 种工作模式(co-orchestrator 纯调度 / cohub-cordis 创造模式)+ 13 个专职代理技能 + 多模型共识;另由 cohub-subagent-readonly / cohub-subagent-write 两个支撑 preset 实现子代理读写硬隔离(共 4 个 preset)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|