dsh-cohub 0.10.4 → 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 +100 -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.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
|
@@ -3331,7 +3331,10 @@ async function startSubagentRunOnce(ctx, provider, spec) {
|
|
|
3331
3331
|
const subagents = ctx?.subagents;
|
|
3332
3332
|
if (!subagents)
|
|
3333
3333
|
throw new Error("cohub: startSubagentRun requires the subagents service");
|
|
3334
|
-
const signal = spec.signal
|
|
3334
|
+
const signal = spec.signal;
|
|
3335
|
+
if (signal === undefined) {
|
|
3336
|
+
ctx?.logger?.warn?.("[cohub] startSubagentRun 无可用 signal:子运行不可中止(父轮停止无法回收)");
|
|
3337
|
+
}
|
|
3335
3338
|
if (typeof subagents.startActivation === "function") {
|
|
3336
3339
|
const prompt = spec.persona !== undefined ? [{ type: "text", text: spec.persona }, ...spec.prompt] : spec.prompt;
|
|
3337
3340
|
const receipt = await subagents.startActivation({
|
|
@@ -3344,7 +3347,7 @@ async function startSubagentRunOnce(ctx, provider, spec) {
|
|
|
3344
3347
|
...spec.agentOptions !== undefined ? { agentOptions: spec.agentOptions } : {},
|
|
3345
3348
|
...spec.toolFilter !== undefined ? { toolFilter: spec.toolFilter } : {}
|
|
3346
3349
|
},
|
|
3347
|
-
signal,
|
|
3350
|
+
...signal !== undefined ? { signal } : {},
|
|
3348
3351
|
delivery: "caller"
|
|
3349
3352
|
});
|
|
3350
3353
|
applyChildToolFilterDirectly(ctx, receipt.childId, spec.toolFilter, spec.degradeNotes);
|
|
@@ -3362,7 +3365,7 @@ async function startSubagentRunOnce(ctx, provider, spec) {
|
|
|
3362
3365
|
...spec.toolFilter !== undefined ? { toolFilter: spec.toolFilter } : {},
|
|
3363
3366
|
...spec.agentPreset !== undefined ? { agentPreset: spec.agentPreset } : {},
|
|
3364
3367
|
...spec.agentOptions !== undefined ? { agentOptions: spec.agentOptions } : {},
|
|
3365
|
-
signal
|
|
3368
|
+
...signal !== undefined ? { signal } : {}
|
|
3366
3369
|
});
|
|
3367
3370
|
return {
|
|
3368
3371
|
id: run.id,
|
|
@@ -4036,7 +4039,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4036
4039
|
learner.detach();
|
|
4037
4040
|
if (onExecAbort && outerSignal)
|
|
4038
4041
|
outerSignal.removeEventListener("abort", onExecAbort);
|
|
4039
|
-
if (ac?.signal.aborted) {
|
|
4042
|
+
if (ac?.signal.aborted || outerSignal?.aborted === true) {
|
|
4040
4043
|
lastReason = "aborted";
|
|
4041
4044
|
lastDiagnostic = undefined;
|
|
4042
4045
|
lastPartial = "";
|
|
@@ -4059,12 +4062,37 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4059
4062
|
if (learner)
|
|
4060
4063
|
learner.bind(run.id);
|
|
4061
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;
|
|
4062
4076
|
let outcome;
|
|
4063
4077
|
try {
|
|
4064
|
-
|
|
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
|
+
}
|
|
4065
4088
|
} catch (error) {
|
|
4066
|
-
|
|
4067
|
-
|
|
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
|
+
}
|
|
4068
4096
|
} finally {
|
|
4069
4097
|
if (learner) {
|
|
4070
4098
|
if (learner.flush()) {
|
|
@@ -4076,9 +4104,9 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4076
4104
|
watchdog.detach();
|
|
4077
4105
|
if (onExecAbort && outerSignal)
|
|
4078
4106
|
outerSignal.removeEventListener("abort", onExecAbort);
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4107
|
+
if (abortHandler && signal)
|
|
4108
|
+
signal.removeEventListener("abort", abortHandler);
|
|
4109
|
+
await safeDispose();
|
|
4082
4110
|
}
|
|
4083
4111
|
if (outcome?.stopReason === "completed") {
|
|
4084
4112
|
reportAttempt(String(run?.id ?? ""), "completed", "completed");
|
|
@@ -4145,6 +4173,25 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4145
4173
|
ctx.logger?.warn?.("[cohub background-fallback] " + bgFallbackReason + ",回退前台");
|
|
4146
4174
|
} else if (jobs !== undefined && typeof jobs.start === "function") {
|
|
4147
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
|
+
}
|
|
4148
4195
|
let jobId;
|
|
4149
4196
|
try {
|
|
4150
4197
|
const startJob = (ownerValue) => jobs.start({
|
|
@@ -4162,6 +4209,8 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4162
4209
|
return { status: "killed", detail: "delegate 已取消(job_kill / owner 释放)" };
|
|
4163
4210
|
}
|
|
4164
4211
|
return { status: "failed", detail: String(error) };
|
|
4212
|
+
} finally {
|
|
4213
|
+
detachParentAbort();
|
|
4165
4214
|
}
|
|
4166
4215
|
})();
|
|
4167
4216
|
return {
|
|
@@ -4192,6 +4241,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4192
4241
|
ctx.logger?.info?.("[cohub background] delegate 已注册为后台 job:" + jobId + "(skill=" + skill.name + ")");
|
|
4193
4242
|
return "已在后台启动:" + skill.name + "(job: " + jobId + ")。" + '取结果:job_output({ job_id: "' + jobId + '", wait: true });' + "或等自动唤醒(job 完成且你空闲时会自动开新一轮,最多连续 3 次)。" + "等待期间可以继续派发别的任务或推进其他工作(后台任务不计入当前批次耗时)。";
|
|
4194
4243
|
}
|
|
4244
|
+
detachParentAbort();
|
|
4195
4245
|
if (bgFallbackReason === undefined) {
|
|
4196
4246
|
bgFallbackReason = "jobs.start 未返回 jobId";
|
|
4197
4247
|
ctx.logger?.warn?.("[cohub background-fallback] " + bgFallbackReason + ",回退前台");
|
|
@@ -4592,29 +4642,53 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4592
4642
|
continue;
|
|
4593
4643
|
}
|
|
4594
4644
|
const { run, taskId, skillName, skillTag, taskNotes, ac, onExecAbort, startedAt } = val;
|
|
4595
|
-
|
|
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 });
|
|
4596
4653
|
perTaskNotes.push({ taskId, notes: taskNotes });
|
|
4597
4654
|
run.result.catch(() => {});
|
|
4598
4655
|
}
|
|
4599
|
-
for (const { run, taskId, skillName, skillTag, taskNotes, ac, startedAt } of runs) {
|
|
4656
|
+
for (const { run, safeDispose, taskId, skillName, skillTag, taskNotes, ac, startedAt } of runs) {
|
|
4600
4657
|
let outcome;
|
|
4601
4658
|
let timer = null;
|
|
4659
|
+
const abortOffs = [];
|
|
4602
4660
|
const remainingMs = Math.max(0, wallClockBudgetMs - (Date.now() - startedAt));
|
|
4661
|
+
const parentSignal = exec.signal;
|
|
4603
4662
|
try {
|
|
4604
4663
|
outcome = await Promise.race([
|
|
4605
4664
|
run.result,
|
|
4606
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
|
+
}
|
|
4607
4687
|
timer = setTimeout(() => {
|
|
4608
4688
|
if (!ac.signal.aborted)
|
|
4609
4689
|
ac.abort();
|
|
4610
|
-
|
|
4690
|
+
failFast(`超时:实际耗时 ${Date.now() - startedAt}ms(预算 ${wallClockBudgetMs}ms)`);
|
|
4611
4691
|
}, remainingMs);
|
|
4612
|
-
if (exec.signal && !exec.signal.aborted) {
|
|
4613
|
-
exec.signal.addEventListener("abort", () => {
|
|
4614
|
-
if (timer)
|
|
4615
|
-
clearTimeout(timer);
|
|
4616
|
-
}, { once: true });
|
|
4617
|
-
}
|
|
4618
4692
|
})
|
|
4619
4693
|
]);
|
|
4620
4694
|
if (outcome?.stopReason === "completed") {
|
|
@@ -4655,10 +4729,15 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4655
4729
|
} finally {
|
|
4656
4730
|
if (timer)
|
|
4657
4731
|
clearTimeout(timer);
|
|
4732
|
+
for (const off of abortOffs) {
|
|
4733
|
+
try {
|
|
4734
|
+
off();
|
|
4735
|
+
} catch {}
|
|
4736
|
+
}
|
|
4658
4737
|
}
|
|
4659
4738
|
}
|
|
4660
4739
|
} finally {
|
|
4661
|
-
for (const {
|
|
4740
|
+
for (const { safeDispose, ac, onExecAbort } of runs) {
|
|
4662
4741
|
if (onExecAbort && exec.signal) {
|
|
4663
4742
|
try {
|
|
4664
4743
|
exec.signal.removeEventListener("abort", onExecAbort);
|
|
@@ -4666,9 +4745,7 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
4666
4745
|
}
|
|
4667
4746
|
if (!ac.signal.aborted)
|
|
4668
4747
|
ac.abort();
|
|
4669
|
-
|
|
4670
|
-
run.dispose();
|
|
4671
|
-
} catch {}
|
|
4748
|
+
safeDispose();
|
|
4672
4749
|
}
|
|
4673
4750
|
}
|
|
4674
4751
|
const batchElapsedMs = Date.now() - batchStartedAt;
|
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",
|