dsh-cohub 0.13.9 → 0.13.11

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-cohub
2
2
 
3
- > 本文对应 **v0.13.9**;完整变更历史见 [CHANGELOG.md](./CHANGELOG.md)。
3
+ > 本文对应 **v0.13.11**;完整变更历史见 [CHANGELOG.md](./CHANGELOG.md)。
4
4
 
5
5
  DeepSeek Harness 版(对照 [OpenCode 版](../oh-my-opencode-cohub/)):中文智能体编排插件。
6
6
  把「纯调度模式 + 内置技能(代理编排体系 + co-cordis 组合创作 + 写作组)+ 多模型共识 + 运行期调度韧性」移植到 DSH 原生能力之上。
package/lib/index.js CHANGED
@@ -629,6 +629,7 @@ function materializeJsTags(node, logger, platform = process.platform, path = "pl
629
629
  }
630
630
  return node;
631
631
  }
632
+ var TEAM_OWNED_PRESET_IDS = ["co-orchestrator"];
632
633
  function isSafePresetId2(id) {
633
634
  return /^[a-z0-9][a-z0-9._-]*$/i.test(id) && !id.includes("..");
634
635
  }
@@ -658,6 +659,10 @@ function loadCohubPresetDefs(presetsDir = COHUB_PRESETS_DIR, logger) {
658
659
  for (const entry of entries) {
659
660
  if (!entry.isDirectory() || !isSafePresetId2(entry.name))
660
661
  continue;
662
+ if (TEAM_OWNED_PRESET_IDS.includes(entry.name)) {
663
+ logger?.info?.(`cohub: preset ${entry.name} 由团队注册接管(内置 dev 团队),档位注册跳过`);
664
+ continue;
665
+ }
661
666
  const dir = join2(presetsDir, entry.name);
662
667
  const agentFile = join2(dir, "agent.cordis.yml");
663
668
  if (!existsSync2(agentFile))
@@ -810,6 +815,7 @@ var BUILTIN_TEAMS = [
810
815
  id: "dev",
811
816
  name: "开发团队",
812
817
  description: "通用软件开发团队:调度 + 12 个专职子代理",
818
+ presetId: "co-orchestrator",
813
819
  members: [
814
820
  "co-fixer",
815
821
  "co-designer",
@@ -5760,6 +5766,20 @@ function formatContractViolation(errors) {
5760
5766
  }
5761
5767
 
5762
5768
  // src/delegate.ts
5769
+ function normalizeAdvisorySignals(value) {
5770
+ if (value === undefined || value === null)
5771
+ return ["S2", "S3"];
5772
+ const raw = Array.isArray(value) ? value : [];
5773
+ const out = [];
5774
+ for (const item of raw) {
5775
+ if (typeof item !== "string")
5776
+ continue;
5777
+ const sig = item.trim().toUpperCase();
5778
+ if ((sig === "S2" || sig === "S3") && !out.includes(sig))
5779
+ out.push(sig);
5780
+ }
5781
+ return out;
5782
+ }
5763
5783
  var PARALLEL_TOOL_DISCIPLINE = "【并行工具纪律】① 同一条消息内一次性发起全部独立只读查询,不要发一个等一个。" + "② 真并发的只读工具:read、read_image、web_search、web_fetch、subagent。" + "注意 glob、grep 虽然只读但不可并发(会被串行执行),别指望它们并行。" + "③ 可并发调用必须连续相邻,中间不要插 bash、edit、write、grep 等串行调用," + "否则其后调用另起一组、并发度归零([read, bash, read] 并发度=1,[read, read, read, bash] 并发度=3)。" + "④ 不要依赖平台真并发:需要 N 个互不依赖的子任务时,优先用 delegate_batch" + "(内部 Promise.allSettled,不依赖 agent loop 调度;该工具可用时)。";
5764
5784
  var DELEGATE_PERSONA = "你是被委派的专职代理:严格遵循任务消息中的角色定义、关键约束、输出格式与工具指令,并完成末尾的具体任务。" + "你的首条用户消息(下方任务书)已含 `--- 你的具体任务 ---` 分隔符,即身份判据成立:不要调用 skill 工具加载 co-orchestrator 技能——技能指令已由 brief 注入。" + PARALLEL_TOOL_DISCIPLINE;
5765
5785
  var DEFAULT_SPAWN_TRANSPORT = "spawn";
@@ -6100,6 +6120,9 @@ function normalizeArguments(args) {
6100
6120
  }
6101
6121
  return raw.replace(/\s+/g, " ").trim().slice(0, 200);
6102
6122
  }
6123
+ function maskSecrets(text) {
6124
+ return text.replace(/\bsk-[A-Za-z0-9_-]{8,}/g, "sk-***").replace(/\bBearer\s+[A-Za-z0-9._-]{8,}/g, "Bearer ***").replace(/\b(api[_-]?key|token|secret|password)(\s*[:=]\s*)[^\s&,"']{6,}/gi, (_m, key, sep) => key + sep + "***").replace(/([?&](?:api[_-]?key|key|token|secret|password)=)[^&\s"']{6,}/gi, (_m, prefix) => prefix + "***");
6125
+ }
6103
6126
  function describeFailureDetail(value) {
6104
6127
  const seen = new Set;
6105
6128
  let cur = value;
@@ -6117,7 +6140,7 @@ function describeFailureDetail(value) {
6117
6140
  text = String(cur);
6118
6141
  if (text === undefined)
6119
6142
  return;
6120
- const oneLine = text.replace(/\s+/g, " ").trim();
6143
+ const oneLine = maskSecrets(text.replace(/\s+/g, " ").trim());
6121
6144
  if (oneLine.length === 0)
6122
6145
  return;
6123
6146
  return oneLine.length > 200 ? oneLine.slice(0, 200) + "…" : oneLine;
@@ -6126,12 +6149,14 @@ function describeFailureDetail(value) {
6126
6149
  class StallWatchdog {
6127
6150
  cfg;
6128
6151
  onStall;
6152
+ onAdvisory;
6129
6153
  off = null;
6130
6154
  timer = null;
6131
6155
  boundId = null;
6132
6156
  buffer = new Map;
6133
6157
  triggered = false;
6134
6158
  maxBuffer = 5000;
6159
+ advisory = { sent: false, since: 0, signals: [] };
6135
6160
  s = {
6136
6161
  lastToolAt: 0,
6137
6162
  lastToolResultAt: 0,
@@ -6147,18 +6172,22 @@ class StallWatchdog {
6147
6172
  lastCallKey: null,
6148
6173
  pendingCall: null
6149
6174
  };
6150
- constructor(cfg, onStall) {
6175
+ constructor(cfg, onStall, onAdvisory) {
6176
+ const idleMs = Math.max(0, cfg.idleMs ?? 600000);
6151
6177
  this.cfg = {
6152
6178
  enabled: cfg.enabled ?? false,
6153
6179
  consecutiveErrors: Math.max(1, Math.trunc(cfg.consecutiveErrors ?? 3)),
6154
- idleMs: Math.max(0, cfg.idleMs ?? 600000),
6180
+ idleMs,
6155
6181
  reasoningWithoutAction: Math.max(1, Math.trunc(cfg.reasoningWithoutAction ?? 50)),
6156
6182
  loopCount: Math.max(1, Math.trunc(cfg.loopCount ?? 3)),
6157
6183
  graceMs: Math.max(0, cfg.graceMs ?? 30000),
6158
6184
  recoverable: cfg.recoverable ?? true,
6185
+ advisorySignals: normalizeAdvisorySignals(cfg.advisorySignals),
6186
+ advisoryMaxMs: Math.max(0, cfg.advisoryMaxMs ?? idleMs * 2),
6159
6187
  checkIntervalMs: Math.max(50, cfg.checkIntervalMs ?? 1000)
6160
6188
  };
6161
6189
  this.onStall = onStall;
6190
+ this.onAdvisory = onAdvisory;
6162
6191
  }
6163
6192
  attach(ctx) {
6164
6193
  if (this.off)
@@ -6270,6 +6299,11 @@ class StallWatchdog {
6270
6299
  }
6271
6300
  this.check();
6272
6301
  }
6302
+ resetAdvisory() {
6303
+ if (!this.advisory.sent && this.advisory.since === 0)
6304
+ return;
6305
+ this.advisory = { sent: false, since: 0, signals: [] };
6306
+ }
6273
6307
  check() {
6274
6308
  if (this.triggered)
6275
6309
  return;
@@ -6280,27 +6314,71 @@ class StallWatchdog {
6280
6314
  const s2 = s.lastActivityAt > 0 && now - s.lastActivityAt > cfg.idleMs;
6281
6315
  const s3 = s.reasoningStreak >= cfg.reasoningWithoutAction;
6282
6316
  const s4 = s.loopStreak >= cfg.loopCount;
6283
- const fired = [];
6317
+ if (!s1 && !s2 && !s3 && !s4) {
6318
+ this.resetAdvisory();
6319
+ return;
6320
+ }
6321
+ const graceOk = s.lastSuccessAt === 0 || now - s.lastSuccessAt > cfg.graceMs;
6322
+ if (!graceOk) {
6323
+ this.resetAdvisory();
6324
+ return;
6325
+ }
6326
+ const advisoryOn = new Set(cfg.advisorySignals);
6327
+ const fatal = [];
6328
+ const advisoryNow = [];
6284
6329
  if (s1)
6285
- fired.push("S1:连续同类错误x" + s.consecutiveErrors);
6330
+ fatal.push("S1:连续同类错误x" + s.consecutiveErrors);
6331
+ if (s4)
6332
+ fatal.push("S4:重复调用循环x" + s.loopStreak);
6286
6333
  if (s2)
6287
- fired.push("S2:无结果空转");
6334
+ (advisoryOn.has("S2") ? advisoryNow : fatal).push("S2:无结果空转");
6288
6335
  if (s3)
6289
- fired.push("S3:纯推理无动作x" + s.reasoningStreak);
6290
- if (s4)
6291
- fired.push("S4:重复调用循环x" + s.loopStreak);
6292
- if (fired.length === 0)
6336
+ (advisoryOn.has("S3") ? advisoryNow : fatal).push("S3:纯推理无动作x" + s.reasoningStreak);
6337
+ const silentMs = s.lastActivityAt > 0 ? now - s.lastActivityAt : -1;
6338
+ const sinceSuccess = s.lastSuccessAt === 0 ? "无" : now - s.lastSuccessAt + "ms";
6339
+ if (fatal.length > 0) {
6340
+ const escalated = this.advisory.sent;
6341
+ const fired = [...new Set(fatal.concat(advisoryNow).concat(this.advisory.signals))];
6342
+ const diag = "停滞检测触发 [" + fired.join(", ") + "];距最近成功工具结果 " + sinceSuccess + ";最近工具结果 " + (s.lastToolResultAt === 0 ? "无" : now - s.lastToolResultAt + "ms 前") + (escalated ? ";已由停滞告警升级(告警持续 " + (now - this.advisory.since) + "ms)" : "");
6343
+ this.triggered = true;
6344
+ const info = {
6345
+ signals: fired,
6346
+ diagnostics: diag,
6347
+ ...escalated ? { escalated: true } : {}
6348
+ };
6349
+ queueMicrotask(() => {
6350
+ if (this.triggered && this.off)
6351
+ this.onStall(info);
6352
+ });
6293
6353
  return;
6294
- const graceOk = s.lastSuccessAt === 0 || now - s.lastSuccessAt > cfg.graceMs;
6295
- if (!graceOk)
6354
+ }
6355
+ if (!this.advisory.sent) {
6356
+ this.advisory = { sent: true, since: now, signals: advisoryNow.slice() };
6357
+ const info = {
6358
+ signals: advisoryNow.slice(),
6359
+ diagnostics: "停滞告警(未中止)[" + advisoryNow.join(", ") + "];距最近活动 " + (silentMs < 0 ? "无" : silentMs + "ms") + ";持续满足超过 " + cfg.advisoryMaxMs + "ms 未恢复将升级为中止;距最近成功工具结果 " + sinceSuccess,
6360
+ advisory: true
6361
+ };
6362
+ queueMicrotask(() => {
6363
+ if (this.off && !this.triggered)
6364
+ this.onAdvisory?.(info);
6365
+ });
6296
6366
  return;
6297
- this.triggered = true;
6298
- const diag = "停滞检测触发 [" + fired.join(", ") + "];距最近成功工具结果 " + (s.lastSuccessAt === 0 ? "无" : now - s.lastSuccessAt + "ms") + ";最近工具结果 " + (s.lastToolResultAt === 0 ? "无" : now - s.lastToolResultAt + "ms 前");
6299
- const info = { signals: fired, diagnostics: diag };
6300
- queueMicrotask(() => {
6301
- if (this.triggered && this.off)
6302
- this.onStall(info);
6303
- });
6367
+ }
6368
+ const heldMs = now - this.advisory.since;
6369
+ if (heldMs > cfg.advisoryMaxMs) {
6370
+ const fired = [...new Set(this.advisory.signals.concat(advisoryNow))];
6371
+ this.triggered = true;
6372
+ const info = {
6373
+ signals: fired,
6374
+ diagnostics: "停滞检测触发(告警超上限,已升级为中止)[" + fired.join(", ") + "];告警已持续 " + heldMs + "ms(上限 " + cfg.advisoryMaxMs + "ms);距最近活动 " + (silentMs < 0 ? "无" : silentMs + "ms") + ";距最近成功工具结果 " + sinceSuccess,
6375
+ escalated: true
6376
+ };
6377
+ queueMicrotask(() => {
6378
+ if (this.triggered && this.off)
6379
+ this.onStall(info);
6380
+ });
6381
+ }
6304
6382
  }
6305
6383
  }
6306
6384
  function resolveSkillAndRoute(requestedSkill, getRoutes, ctx, logger, snapshot) {
@@ -6668,14 +6746,17 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
6668
6746
  retryDelayMs: Math.max(0, retryCfg?.retryDelayMs ?? 1000),
6669
6747
  retryableReasons: retryCfg?.retryableReasons ?? ["aborted"]
6670
6748
  };
6749
+ const stallIdleMs = Math.max(0, retryCfg?.stall?.idleMs ?? 600000);
6671
6750
  const stall = {
6672
6751
  enabled: retryCfg?.stall?.enabled ?? false,
6673
6752
  consecutiveErrors: Math.max(1, Math.trunc(retryCfg?.stall?.consecutiveErrors ?? 3)),
6674
- idleMs: Math.max(0, retryCfg?.stall?.idleMs ?? 600000),
6753
+ idleMs: stallIdleMs,
6675
6754
  reasoningWithoutAction: Math.max(1, Math.trunc(retryCfg?.stall?.reasoningWithoutAction ?? 50)),
6676
6755
  loopCount: Math.max(1, Math.trunc(retryCfg?.stall?.loopCount ?? 3)),
6677
6756
  graceMs: Math.max(0, retryCfg?.stall?.graceMs ?? 30000),
6678
6757
  recoverable: retryCfg?.stall?.recoverable ?? true,
6758
+ advisorySignals: normalizeAdvisorySignals(retryCfg?.stall?.advisorySignals),
6759
+ advisoryMaxMs: Math.max(0, retryCfg?.stall?.advisoryMaxMs ?? stallIdleMs * 2),
6679
6760
  checkIntervalMs: Math.max(50, retryCfg?.stall?.checkIntervalMs ?? 1000)
6680
6761
  };
6681
6762
  const scheduleCfg = settingsNow.schedule ?? config.schedule;
@@ -6771,7 +6852,6 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
6771
6852
  const runAttempts = async (outerSignal) => {
6772
6853
  let lastReason = "unknown";
6773
6854
  let lastDiagnostic;
6774
- let lastRunError;
6775
6855
  let lastPartial = "";
6776
6856
  let lastPartialBudget = "";
6777
6857
  const stallState = { last: null };
@@ -6833,6 +6913,8 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
6833
6913
  stallInfo = info;
6834
6914
  ctx.logger?.info?.("[cohub stall] " + JSON.stringify(info));
6835
6915
  forwardAbort();
6916
+ }, (info) => {
6917
+ ctx.logger?.warn?.("[cohub stall advisory] " + JSON.stringify(info));
6836
6918
  });
6837
6919
  const attached = watchdog.attach(ctx);
6838
6920
  if (!attached) {
@@ -6885,7 +6967,6 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
6885
6967
  await new Promise((r) => setTimeout(r, retry.retryDelayMs));
6886
6968
  continue;
6887
6969
  }
6888
- lastRunError = describeFailureDetail(error) ?? lastRunError;
6889
6970
  reportAttempt("", "failed", String(error?.message ?? error));
6890
6971
  throw error;
6891
6972
  }
@@ -6922,7 +7003,6 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
6922
7003
  await safeDispose();
6923
7004
  outcome = { stopReason: "aborted", output: [], diagnostic: "raced abort(result 未结算)" };
6924
7005
  } else {
6925
- lastRunError = describeFailureDetail(error) ?? lastRunError;
6926
7006
  reportAttempt(String(run?.id ?? ""), "failed", "error");
6927
7007
  throw error;
6928
7008
  }
@@ -6974,7 +7054,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
6974
7054
  lastReason = String(outcome?.stopReason ?? "unknown");
6975
7055
  const outcomeDiag = typeof outcome?.diagnostic === "string" && outcome.diagnostic.length > 0 ? outcome.diagnostic : undefined;
6976
7056
  const residualDetail = describeFailureDetail(outcome);
6977
- lastDiagnostic = outcomeDiag ?? (residualDetail !== undefined ? "subagent error: " + residualDetail : lastRunError === undefined ? undefined : "run error: " + lastRunError);
7057
+ lastDiagnostic = outcomeDiag ?? (residualDetail === undefined ? undefined : "subagent error: " + residualDetail);
6978
7058
  const partialRaw = contentText(outcome?.output ?? []);
6979
7059
  lastPartial = partialRaw.slice(0, 500);
6980
7060
  lastPartialBudget = budget.enabled && partialRaw.length > budget.partialMaxChars ? applyResultBudget(partialRaw, {
@@ -10270,7 +10350,9 @@ var StallDetector = z2.object({
10270
10350
  reasoningWithoutAction: z2.number().default(50),
10271
10351
  loopCount: z2.number().default(3),
10272
10352
  graceMs: z2.number().default(30000),
10273
- recoverable: z2.boolean().default(true)
10353
+ recoverable: z2.boolean().default(true),
10354
+ advisorySignals: z2.array(z2.string()).default(["S2", "S3"]),
10355
+ advisoryMaxMs: z2.number().description("告警升级上限毫秒;省略 = idleMs × 2;0 = 告警后立即升级")
10274
10356
  }).default({});
10275
10357
  var DelegateRetry = z2.object({
10276
10358
  maxRetries: z2.number().default(0),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cohub",
3
- "version": "0.13.9",
3
+ "version": "0.13.11",
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",
@@ -1,3 +1,3 @@
1
- name: CoHub 调度者(带 Cordis)(cohub-cordis)
2
- description: co-orchestrator 主代理 + co_* 运行时工具(co_inspect_list / co_define / co_run 等),可直接委派 co-cordis 子代理修插件、试挂载、审核 harness 组合。纯调度纪律 + cordis 能力。需要无 cordis 的纯调度版本请用 co-orchestrator。co-cordis 子代理
3
- order: 5
1
+ name: 内部 · CoHub 调度者(带 Cordis)(cohub-cordis)
2
+ description: 内部工具集,供 cohub 编排自动选择,请勿手动选择。co-orchestrator 主代理 + co_* 运行时工具(co_inspect_list / co_define / co_run 等),可直接委派 co-cordis 子代理修插件、试挂载、审核 harness 组合。纯调度纪律 + cordis 能力。需要无 cordis 的纯调度版本请用 co-orchestrator。co-cordis 子代理
3
+ order: 900
@@ -1,2 +1,3 @@
1
- name: CoHub 子代理·只读(cohub-subagent-readonly)
2
- description: cohub 编排体系的只读子代理专用 preset:co-explorer / co-librarian / co-observer / co-oracle / co-planner / co-council / co-rule-* 使用;无写盘、无 Shell、无委派类工具。
1
+ name: 内部 · CoHub 子代理·只读(cohub-subagent-readonly)
2
+ description: 内部工具集,供 cohub 编排自动选择,请勿手动选择。cohub 编排体系的只读子代理专用 preset:co-explorer / co-librarian / co-observer / co-oracle / co-planner / co-council / co-rule-* 使用;无写盘、无 Shell、无委派类工具。
3
+ order: 900
@@ -1,2 +1,3 @@
1
- name: CoHub 子代理·只读+联网(cohub-subagent-readonly-net)
2
- description: cohub 编排体系的联网只读子代理专用 preset:co-librarian / co-observer / co-planner / co-council 使用;在 readonly 基础上接通外网抓取(web 检索类工具可用),仍无写盘、无 Shell、无委派类工具。
1
+ name: 内部 · CoHub 子代理·只读+联网(cohub-subagent-readonly-net)
2
+ description: 内部工具集,供 cohub 编排自动选择,请勿手动选择。cohub 编排体系的联网只读子代理专用 preset:co-librarian / co-observer / co-planner / co-council 使用;在 readonly 基础上接通外网抓取(web 检索类工具可用),仍无写盘、无 Shell、无委派类工具。
3
+ order: 900
@@ -1,2 +1,3 @@
1
- name: CoHub 子代理·可写(cohub-subagent-write)
2
- description: cohub 编排体系的实施类子代理专用 preset:co-fixer / co-designer / co-cordis 使用;含文件读写与 Shell,但不含任何委派类工具。
1
+ name: 内部 · CoHub 子代理·可写(cohub-subagent-write)
2
+ description: 内部工具集,供 cohub 编排自动选择,请勿手动选择。cohub 编排体系的实施类子代理专用 preset:co-fixer / co-designer / co-cordis 使用;含文件读写与 Shell,但不含任何委派类工具。
3
+ order: 900
@@ -1,2 +1,3 @@
1
- name: CoHub 子代理·读写+Shell(cohub-subagent-write-shell)
2
- description: cohub 编排体系的全能实施类子代理专用 preset:co-fixer / co-designer / co-cordis 使用;文件读写 + Shell + 外网抓取,但不含任何委派类工具。
1
+ name: 内部 · CoHub 子代理·读写+Shell(cohub-subagent-write-shell)
2
+ description: 内部工具集,供 cohub 编排自动选择,请勿手动选择。cohub 编排体系的万能实施类子代理专用 preset:co-fixer / co-designer / co-cordis 使用;文件读写 + Shell + 外网抓取,但不含任何委派类工具。
3
+ order: 900