dsh-cohub 0.10.3 → 0.10.4
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 +84 -23
- 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.4**;完整变更历史见 [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)
|
|
@@ -3570,15 +3581,19 @@ function resolveSkillAndRoute(requestedSkill, getRoutes, ctx, logger) {
|
|
|
3570
3581
|
const requested = (typeof requestedSkill === "string" ? requestedSkill : "").trim();
|
|
3571
3582
|
const skillName = requested || DEFAULT_FALLBACK_SKILL;
|
|
3572
3583
|
const fallback = requested.length === 0;
|
|
3584
|
+
const echoName = firstLineClamped(skillName, SKILL_NAME_ECHO_MAX) || "unknown";
|
|
3573
3585
|
let skill = COHUB_SKILLS.find((s) => s.name === skillName);
|
|
3586
|
+
let note;
|
|
3574
3587
|
if (!skill) {
|
|
3575
3588
|
(logger ?? ctx.logger)?.warn?.('delegate: unknown skill "' + skillName + '", falling back to co-fixer');
|
|
3576
3589
|
skill = COHUB_SKILLS.find((s) => s.name === DEFAULT_FALLBACK_SKILL);
|
|
3590
|
+
note = '传入的 skill 名 "' + echoName + '" 未匹配任何 co-* 代理,已兜底为 ' + DEFAULT_FALLBACK_SKILL + ",子代理 preset 同步回退为实施类 " + SUBAGENT_WRITE_PRESET;
|
|
3577
3591
|
} else if (fallback) {
|
|
3578
3592
|
(logger ?? ctx.logger)?.warn?.("delegate: skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + ";schema 已要求必填,出现本告警说明调用绕过了参数校验");
|
|
3593
|
+
note = "skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + ",子代理 preset 回退为实施类 " + SUBAGENT_WRITE_PRESET;
|
|
3579
3594
|
}
|
|
3580
3595
|
const route = (getRoutes() ?? []).find((s) => s.name === requested);
|
|
3581
|
-
return { skill, route, fallback };
|
|
3596
|
+
return { skill, route, fallback, ...note === undefined ? {} : { note } };
|
|
3582
3597
|
}
|
|
3583
3598
|
function formatSkillLabel(skill, fallback) {
|
|
3584
3599
|
return fallback ? skill.name + " (default:" + DEFAULT_FALLBACK_SKILL + ")" : skill.name;
|
|
@@ -3674,10 +3689,17 @@ function resolveDelegationDepth(agent) {
|
|
|
3674
3689
|
return MAX_DELEGATION_DEPTH;
|
|
3675
3690
|
return depth;
|
|
3676
3691
|
}
|
|
3692
|
+
function describeDepthCandidate(value) {
|
|
3693
|
+
const kind = value === null ? "null" : typeof value;
|
|
3694
|
+
const shown = typeof value === "string" ? JSON.stringify(value) : String(value);
|
|
3695
|
+
return shown + "(" + kind + ")";
|
|
3696
|
+
}
|
|
3677
3697
|
function guardDelegationDepth(agent, logger) {
|
|
3678
3698
|
const depth = resolveDelegationDepth(agent);
|
|
3679
3699
|
if (depth === undefined) {
|
|
3680
|
-
|
|
3700
|
+
const header = agent?.session?.header;
|
|
3701
|
+
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));
|
|
3702
|
+
logger?.warn?.("[cohub depth-guard] 无法判定委派深度,按兼容策略放行(fail-open)" + ":session.header.delegationDepth / options.subagentDepth / session.delegationDepth 均缺失或非法," + '且 header.origin 不是 "subagent";本次委派继续执行,嵌套上限不再生效。' + '若上面某候选是字符串 "0" 之类的类型错误,请修宿主(合法值为 number 且为安全整数)');
|
|
3681
3703
|
return;
|
|
3682
3704
|
}
|
|
3683
3705
|
if (depth < MAX_DELEGATION_DEPTH)
|
|
@@ -3896,7 +3918,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3896
3918
|
const { retry, stall, schedule, budget, background, subagentPresetEnabled } = resolveRuntimeConfig();
|
|
3897
3919
|
const RETRYABLE = new Set(retry.retryableReasons);
|
|
3898
3920
|
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);
|
|
3921
|
+
const { skill, route, fallback: skillFallback, note: skillNote } = resolveSkillAndRoute(args.skill, getRoutes, ctx);
|
|
3900
3922
|
const skillTag = formatSkillLabel(skill, skillFallback);
|
|
3901
3923
|
const brief = skill.brief?.trim();
|
|
3902
3924
|
if (!brief) {
|
|
@@ -3905,6 +3927,14 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3905
3927
|
const agentOptions = await buildAgentOptions(route, ctx, skill.name);
|
|
3906
3928
|
const toolFilter = resolveSkillToolFilter(skill.name, config.toolFilter?.enabled ?? true, ctx.logger);
|
|
3907
3929
|
const degradeNotes = [];
|
|
3930
|
+
if (skillNote !== undefined) {
|
|
3931
|
+
upsertDegradeNote(degradeNotes, {
|
|
3932
|
+
id: "skill",
|
|
3933
|
+
what: "skill 名未命中",
|
|
3934
|
+
effect: "子代理已按兜底角色 " + skill.name + " 执行",
|
|
3935
|
+
reason: skillNote
|
|
3936
|
+
});
|
|
3937
|
+
}
|
|
3908
3938
|
const agentPreset = resolveSkillAgentPreset(skill.name, subagentPresetEnabled);
|
|
3909
3939
|
const fp = envFingerprint();
|
|
3910
3940
|
const contractResult = resolveContractText({ enabled: envContract.enabled, text: envContract.text }, envSig, ctx, fp);
|
|
@@ -4080,7 +4110,8 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4080
4110
|
retries++;
|
|
4081
4111
|
await new Promise((r) => setTimeout(r, retry.retryDelayMs));
|
|
4082
4112
|
}
|
|
4083
|
-
const
|
|
4113
|
+
const degradeText = formatDegradeNotes(degradeNotes).replace(/\s+/g, " ");
|
|
4114
|
+
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
4115
|
err.cause = {
|
|
4085
4116
|
stopReason: lastReason,
|
|
4086
4117
|
...lastDiagnostic === undefined ? {} : { diagnostic: lastDiagnostic },
|
|
@@ -4088,7 +4119,8 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4088
4119
|
...lastPartialBudget === lastPartial ? {} : { partialBudget: lastPartialBudget },
|
|
4089
4120
|
skill: skill.name,
|
|
4090
4121
|
retries,
|
|
4091
|
-
...stallState.last ? { stall: stallState.last } : {}
|
|
4122
|
+
...stallState.last ? { stall: stallState.last } : {},
|
|
4123
|
+
...degradeText.length > 0 ? { degrade: degradeText } : {}
|
|
4092
4124
|
};
|
|
4093
4125
|
throw err;
|
|
4094
4126
|
};
|
|
@@ -4406,6 +4438,7 @@ function createCouncilTool(config, ctx) {
|
|
|
4406
4438
|
|
|
4407
4439
|
// src/delegate_batch.ts
|
|
4408
4440
|
import { defineTool as defineTool3 } from "@deepseek-ai/dsh-tools";
|
|
4441
|
+
var BATCH_TASK_ID_ECHO_MAX = 40;
|
|
4409
4442
|
var MAX_BATCH_SIZE = 20;
|
|
4410
4443
|
function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
4411
4444
|
const envContract = createEnvContract(config);
|
|
@@ -4480,7 +4513,16 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4480
4513
|
});
|
|
4481
4514
|
const starts = await Promise.allSettled(normalized.map(async ({ task, taskId, requestedSkill, skillFallback }) => {
|
|
4482
4515
|
const startedAt = Date.now();
|
|
4483
|
-
const { skill, route } = resolveSkillAndRoute(requestedSkill, getRoutes, ctx, ctx.logger);
|
|
4516
|
+
const { skill, route, note: skillNote } = resolveSkillAndRoute(requestedSkill, getRoutes, ctx, ctx.logger);
|
|
4517
|
+
const taskNotes = [];
|
|
4518
|
+
if (skillNote !== undefined) {
|
|
4519
|
+
taskNotes.push({
|
|
4520
|
+
id: "skill",
|
|
4521
|
+
what: "skill 名未命中",
|
|
4522
|
+
effect: "子代理已按兜底角色 " + skill.name + " 执行",
|
|
4523
|
+
reason: skillNote
|
|
4524
|
+
});
|
|
4525
|
+
}
|
|
4484
4526
|
const skillTag = formatSkillLabel(skill, skillFallback);
|
|
4485
4527
|
const promptText = buildDelegatePrompt({
|
|
4486
4528
|
skill,
|
|
@@ -4512,20 +4554,26 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4512
4554
|
...toolFilter !== undefined ? { toolFilter } : {},
|
|
4513
4555
|
...agentPreset !== undefined ? { agentPreset } : {},
|
|
4514
4556
|
...agentOptions ? { agentOptions } : {},
|
|
4515
|
-
signal: ac.signal
|
|
4557
|
+
signal: ac.signal,
|
|
4558
|
+
degradeNotes: taskNotes
|
|
4516
4559
|
});
|
|
4517
|
-
return { taskId, skillName: skill.name, skillTag, task, run, ac, onExecAbort, startedAt, startError: undefined };
|
|
4560
|
+
return { taskId, skillName: skill.name, skillTag, task, taskNotes, run, ac, onExecAbort, startedAt, startError: undefined };
|
|
4518
4561
|
} catch (startError) {
|
|
4519
4562
|
if (onExecAbort && exec.signal) {
|
|
4520
4563
|
try {
|
|
4521
4564
|
exec.signal.removeEventListener("abort", onExecAbort);
|
|
4522
4565
|
} catch {}
|
|
4523
4566
|
}
|
|
4524
|
-
return { taskId, skillName: skill.name, skillTag, task, run: undefined, ac, onExecAbort: null, startedAt, startError };
|
|
4567
|
+
return { taskId, skillName: skill.name, skillTag, task, taskNotes, run: undefined, ac, onExecAbort: null, startedAt, startError };
|
|
4525
4568
|
}
|
|
4526
4569
|
}));
|
|
4527
4570
|
const results = [];
|
|
4528
4571
|
const runs = [];
|
|
4572
|
+
const perTaskNotes = [];
|
|
4573
|
+
const degradeField = (notes) => {
|
|
4574
|
+
const text = formatDegradeNotes(notes).trim();
|
|
4575
|
+
return text.length > 0 ? { degrade: text } : {};
|
|
4576
|
+
};
|
|
4529
4577
|
try {
|
|
4530
4578
|
for (const s of starts) {
|
|
4531
4579
|
if (s.status === "rejected") {
|
|
@@ -4533,19 +4581,22 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4533
4581
|
}
|
|
4534
4582
|
const val = s.value;
|
|
4535
4583
|
if (val.startError) {
|
|
4584
|
+
perTaskNotes.push({ taskId: val.taskId, notes: val.taskNotes ?? [] });
|
|
4536
4585
|
results.push({
|
|
4537
4586
|
id: val.taskId,
|
|
4538
4587
|
skill: val.skillTag,
|
|
4539
4588
|
status: "error",
|
|
4540
|
-
error: val.startError instanceof Error ? val.startError.message : String(val.startError)
|
|
4589
|
+
error: val.startError instanceof Error ? val.startError.message : String(val.startError),
|
|
4590
|
+
...degradeField(val.taskNotes ?? [])
|
|
4541
4591
|
});
|
|
4542
4592
|
continue;
|
|
4543
4593
|
}
|
|
4544
|
-
const { run, taskId, skillName, skillTag, ac, onExecAbort, startedAt } = val;
|
|
4545
|
-
runs.push({ run, taskId, skillName, skillTag, ac, onExecAbort, startedAt });
|
|
4594
|
+
const { run, taskId, skillName, skillTag, taskNotes, ac, onExecAbort, startedAt } = val;
|
|
4595
|
+
runs.push({ run, taskId, skillName, skillTag, taskNotes, ac, onExecAbort, startedAt });
|
|
4596
|
+
perTaskNotes.push({ taskId, notes: taskNotes });
|
|
4546
4597
|
run.result.catch(() => {});
|
|
4547
4598
|
}
|
|
4548
|
-
for (const { run, taskId, skillName, skillTag, ac, startedAt } of runs) {
|
|
4599
|
+
for (const { run, taskId, skillName, skillTag, taskNotes, ac, startedAt } of runs) {
|
|
4549
4600
|
let outcome;
|
|
4550
4601
|
let timer = null;
|
|
4551
4602
|
const remainingMs = Math.max(0, wallClockBudgetMs - (Date.now() - startedAt));
|
|
@@ -4578,7 +4629,8 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4578
4629
|
id: taskId,
|
|
4579
4630
|
skill: skillTag,
|
|
4580
4631
|
status: "completed",
|
|
4581
|
-
result: resultText
|
|
4632
|
+
result: resultText,
|
|
4633
|
+
...degradeField(taskNotes)
|
|
4582
4634
|
});
|
|
4583
4635
|
} else {
|
|
4584
4636
|
const diag = typeof outcome?.diagnostic === "string" ? outcome.diagnostic : undefined;
|
|
@@ -4588,7 +4640,8 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4588
4640
|
status: "failed",
|
|
4589
4641
|
error: `stopReason: ${outcome?.stopReason ?? "unknown"}` + (diag === undefined ? "" : `; diagnostic: ${diag}`),
|
|
4590
4642
|
stopReason: outcome?.stopReason,
|
|
4591
|
-
...diag === undefined ? {} : { diagnostic: diag }
|
|
4643
|
+
...diag === undefined ? {} : { diagnostic: diag },
|
|
4644
|
+
...degradeField(taskNotes)
|
|
4592
4645
|
});
|
|
4593
4646
|
}
|
|
4594
4647
|
} catch (e) {
|
|
@@ -4596,7 +4649,8 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4596
4649
|
id: taskId,
|
|
4597
4650
|
skill: skillTag,
|
|
4598
4651
|
status: "error",
|
|
4599
|
-
error: e instanceof Error ? e.message : String(e)
|
|
4652
|
+
error: e instanceof Error ? e.message : String(e),
|
|
4653
|
+
...degradeField(taskNotes)
|
|
4600
4654
|
});
|
|
4601
4655
|
} finally {
|
|
4602
4656
|
if (timer)
|
|
@@ -4672,7 +4726,14 @@ ${r.result}
|
|
|
4672
4726
|
ctx?.logger?.warn?.("[cohub budget] batch:total:拼装结果 " + fullChars + " 字符 ≈ " + approxTokens(fullChars) + " tokens 超过总预算 " + budget.batchTotalMaxChars + " 字符,已裁剪;各任务全文见各自的 locator。仅告警,不阻断。");
|
|
4673
4727
|
}
|
|
4674
4728
|
maybeDeferTodoNudge(exec);
|
|
4675
|
-
|
|
4729
|
+
const allNotes = [];
|
|
4730
|
+
for (const { taskId, notes } of perTaskNotes) {
|
|
4731
|
+
const echoTaskId = firstLineClamped(taskId, BATCH_TASK_ID_ECHO_MAX);
|
|
4732
|
+
for (const note of notes) {
|
|
4733
|
+
allNotes.push({ id: note.id, what: echoTaskId + " " + note.what, effect: note.effect, reason: note.reason });
|
|
4734
|
+
}
|
|
4735
|
+
}
|
|
4736
|
+
return statsLine + output + formatDegradeNotes(allNotes);
|
|
4676
4737
|
}
|
|
4677
4738
|
});
|
|
4678
4739
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cohub",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
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",
|