dsh-cohub 0.13.12 → 0.13.14
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 +120 -47
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-cohub
|
|
2
2
|
|
|
3
|
-
> 本文对应 **v0.13.
|
|
3
|
+
> 本文对应 **v0.13.14**;完整变更历史见 [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
|
@@ -433,7 +433,7 @@ function resolveProfilePatchPath(home, env = process.env) {
|
|
|
433
433
|
|
|
434
434
|
// src/preset-runtime.ts
|
|
435
435
|
import { existsSync as existsSync2, readFileSync as readFileSync2, readdirSync as readdirSync2 } from "node:fs";
|
|
436
|
-
import { join as join2 } from "node:path";
|
|
436
|
+
import { join as join2, resolve, sep } from "node:path";
|
|
437
437
|
import { fileURLToPath } from "node:url";
|
|
438
438
|
var COHUB_PRESETS_DIR = fileURLToPath(new URL("../presets/", import.meta.url));
|
|
439
439
|
function unquoteScalar(text) {
|
|
@@ -570,6 +570,11 @@ function parseMiniYaml(text) {
|
|
|
570
570
|
out.push(parseBlock(indent + 1));
|
|
571
571
|
continue;
|
|
572
572
|
}
|
|
573
|
+
if (/^!!js(\s|$)/.test(rest)) {
|
|
574
|
+
cursor++;
|
|
575
|
+
out.push(parseScalar(rest));
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
573
578
|
lines[cursor] = { raw: " ".repeat(indent + 2) + rest, indent: indent + 2, content: rest };
|
|
574
579
|
out.push(parseBlock(indent + 1));
|
|
575
580
|
}
|
|
@@ -590,6 +595,8 @@ function parseMiniYaml(text) {
|
|
|
590
595
|
return root;
|
|
591
596
|
}
|
|
592
597
|
var JS_TAG_PREFIX = /^!!js\s+([\s\S]+)$/;
|
|
598
|
+
var URL_DIR_EXPR = /^(?:process\s*\.\s*getBuiltinModule\(\s*(['"])node:url\1\s*\)\s*\.\s*)?fileURLToPath\(\s*new\s+URL\(\s*(['"])([^'"]*)\2\s*,\s*baseUrl\s*\)\s*\)$/;
|
|
599
|
+
var DROP_JS_TAG = Symbol("cohub.dropJsTag");
|
|
593
600
|
function evaluatePlatformExpr(expr, platform = process.platform) {
|
|
594
601
|
const text = expr.trim();
|
|
595
602
|
const negated = text.startsWith("!") && !text.startsWith("!==");
|
|
@@ -603,33 +610,97 @@ function evaluatePlatformExpr(expr, platform = process.platform) {
|
|
|
603
610
|
const result = equal ? platform === target : platform !== target;
|
|
604
611
|
return negated ? !result : result;
|
|
605
612
|
}
|
|
606
|
-
function
|
|
613
|
+
function evaluateUrlDirExpr(expr, baseDir) {
|
|
614
|
+
const match = URL_DIR_EXPR.exec(unquoteScalar(expr.trim()));
|
|
615
|
+
if (match === null)
|
|
616
|
+
return;
|
|
617
|
+
const relative = match[3];
|
|
618
|
+
if (relative === "" || relative.startsWith("/") || relative.startsWith("\\") || /^[a-zA-Z]:/.test(relative))
|
|
619
|
+
return;
|
|
620
|
+
const root = resolve(baseDir);
|
|
621
|
+
const target = resolve(root, relative);
|
|
622
|
+
const prefix = root.endsWith(sep) ? root : root + sep;
|
|
623
|
+
if (target !== root && !target.startsWith(prefix))
|
|
624
|
+
return;
|
|
625
|
+
return target;
|
|
626
|
+
}
|
|
627
|
+
function assertCustomSkillDirs(plugins, logger) {
|
|
628
|
+
for (const line of plugins) {
|
|
629
|
+
if (line === null || typeof line !== "object" || Array.isArray(line))
|
|
630
|
+
continue;
|
|
631
|
+
const record = line;
|
|
632
|
+
if (record.name !== "@deepseek-ai/dsh-skill-filesystem")
|
|
633
|
+
continue;
|
|
634
|
+
const config = record.config;
|
|
635
|
+
if (config === null || typeof config !== "object" || Array.isArray(config))
|
|
636
|
+
continue;
|
|
637
|
+
const cfg = config;
|
|
638
|
+
if (!("customSkillDirs" in cfg))
|
|
639
|
+
continue;
|
|
640
|
+
const dirs = cfg.customSkillDirs;
|
|
641
|
+
if (!Array.isArray(dirs)) {
|
|
642
|
+
logger?.warn?.(`cohub: skill-filesystem.customSkillDirs 不是数组(${typeof dirs}),已丢弃该键`);
|
|
643
|
+
delete cfg.customSkillDirs;
|
|
644
|
+
continue;
|
|
645
|
+
}
|
|
646
|
+
const kept = dirs.filter((entry) => typeof entry === "string");
|
|
647
|
+
if (kept.length !== dirs.length) {
|
|
648
|
+
logger?.warn?.(`cohub: skill-filesystem.customSkillDirs 含 ${dirs.length - kept.length} 个非字符串项,已剔除`);
|
|
649
|
+
cfg.customSkillDirs = kept;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
function materializeJsTags(node, logger, platform = process.platform, path = "plugins", baseDir) {
|
|
607
654
|
if (typeof node === "string") {
|
|
608
655
|
const match = JS_TAG_PREFIX.exec(node.trim());
|
|
609
656
|
if (match === null)
|
|
610
657
|
return node;
|
|
611
|
-
const
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
658
|
+
const rawExpr = match[1].trim();
|
|
659
|
+
const expr = unquoteScalar(rawExpr);
|
|
660
|
+
const boolValue = evaluatePlatformExpr(expr, platform);
|
|
661
|
+
if (boolValue !== undefined)
|
|
662
|
+
return boolValue;
|
|
663
|
+
if (baseDir !== undefined) {
|
|
664
|
+
const dirValue = evaluateUrlDirExpr(expr, baseDir);
|
|
665
|
+
if (dirValue !== undefined)
|
|
666
|
+
return dirValue;
|
|
667
|
+
}
|
|
668
|
+
logger?.warn?.(`cohub: 无法求值的 !!js 表达式,已丢弃该键以免把非字符串值交给宿主:${path} = ${rawExpr}`);
|
|
669
|
+
return DROP_JS_TAG;
|
|
617
670
|
}
|
|
618
671
|
if (Array.isArray(node)) {
|
|
619
|
-
for (let i = 0;i < node.length; i++)
|
|
620
|
-
|
|
672
|
+
for (let i = 0;i < node.length; i++) {
|
|
673
|
+
const value = materializeJsTags(node[i], logger, platform, `${path}[${i}]`, baseDir);
|
|
674
|
+
if (value === DROP_JS_TAG) {
|
|
675
|
+
node.splice(i, 1);
|
|
676
|
+
i--;
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
node[i] = value;
|
|
680
|
+
}
|
|
621
681
|
return node;
|
|
622
682
|
}
|
|
623
683
|
if (node !== null && typeof node === "object") {
|
|
624
684
|
const record = node;
|
|
625
685
|
for (const key of Object.keys(record)) {
|
|
626
|
-
|
|
686
|
+
const value = materializeJsTags(record[key], logger, platform, `${path}.${key}`, baseDir);
|
|
687
|
+
if (value === DROP_JS_TAG) {
|
|
688
|
+
delete record[key];
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
record[key] = value;
|
|
627
692
|
}
|
|
628
693
|
return record;
|
|
629
694
|
}
|
|
630
695
|
return node;
|
|
631
696
|
}
|
|
632
|
-
var TEAM_OWNED_PRESET_IDS = [
|
|
697
|
+
var TEAM_OWNED_PRESET_IDS = [
|
|
698
|
+
"co-orchestrator",
|
|
699
|
+
"cohub-subagent-readonly",
|
|
700
|
+
"cohub-subagent-readonly-net",
|
|
701
|
+
"cohub-subagent-write",
|
|
702
|
+
"cohub-subagent-write-shell"
|
|
703
|
+
];
|
|
633
704
|
function isSafePresetId2(id) {
|
|
634
705
|
return /^[a-z0-9][a-z0-9._-]*$/i.test(id) && !id.includes("..");
|
|
635
706
|
}
|
|
@@ -663,7 +734,7 @@ function loadCohubPresetDefs(presetsDir = COHUB_PRESETS_DIR, logger) {
|
|
|
663
734
|
logger?.info?.(`cohub: preset ${entry.name} 由团队注册接管(内置 dev 团队),档位注册跳过`);
|
|
664
735
|
continue;
|
|
665
736
|
}
|
|
666
|
-
const dir =
|
|
737
|
+
const dir = resolve(presetsDir, entry.name);
|
|
667
738
|
const agentFile = join2(dir, "agent.cordis.yml");
|
|
668
739
|
if (!existsSync2(agentFile))
|
|
669
740
|
continue;
|
|
@@ -674,7 +745,8 @@ function loadCohubPresetDefs(presetsDir = COHUB_PRESETS_DIR, logger) {
|
|
|
674
745
|
continue;
|
|
675
746
|
}
|
|
676
747
|
const meta = readPresetMeta2(dir);
|
|
677
|
-
const plugins = materializeJsTags(parsed, logger);
|
|
748
|
+
const plugins = materializeJsTags(parsed, logger, process.platform, "plugins", dir);
|
|
749
|
+
assertCustomSkillDirs(plugins, logger);
|
|
678
750
|
defs.push({
|
|
679
751
|
id: entry.name,
|
|
680
752
|
name: meta.name ?? entry.name,
|
|
@@ -765,6 +837,7 @@ async function registerCohubPresets(ctx, logger, presetsDir = COHUB_PRESETS_DIR)
|
|
|
765
837
|
const defs = loadCohubPresetDefs(presetsDir, logger);
|
|
766
838
|
for (const def of defs) {
|
|
767
839
|
try {
|
|
840
|
+
assertCustomSkillDirs(def.plugins, logger);
|
|
768
841
|
releaseExisting(registry, def.id);
|
|
769
842
|
let handle;
|
|
770
843
|
try {
|
|
@@ -2034,13 +2107,6 @@ Orchestrator 会在 prompt 中明确指定:
|
|
|
2034
2107
|
|
|
2035
2108
|
// src/roles.ts
|
|
2036
2109
|
var ALL_TIERS = ["ro", "ro-net", "rw", "rw-shell", "cordis"];
|
|
2037
|
-
var TIER_TO_PRESET = {
|
|
2038
|
-
ro: "cohub-subagent-readonly",
|
|
2039
|
-
"ro-net": "cohub-subagent-readonly-net",
|
|
2040
|
-
rw: "cohub-subagent-write",
|
|
2041
|
-
"rw-shell": "cohub-subagent-write-shell",
|
|
2042
|
-
cordis: "cohub-cordis"
|
|
2043
|
-
};
|
|
2044
2110
|
var BUILTIN_ROLE_TIERS = {
|
|
2045
2111
|
"co-explorer": "ro",
|
|
2046
2112
|
"co-oracle": "ro",
|
|
@@ -2106,10 +2172,6 @@ function resolveTier(roleName, customRoles) {
|
|
|
2106
2172
|
const builtin = BUILTIN_ROLE_TIERS[key];
|
|
2107
2173
|
return builtin ?? null;
|
|
2108
2174
|
}
|
|
2109
|
-
function presetForTier(tier) {
|
|
2110
|
-
const preset = TIER_TO_PRESET[tier];
|
|
2111
|
-
return typeof preset === "string" && preset.length > 0 ? preset : TIER_TO_PRESET["rw-shell"];
|
|
2112
|
-
}
|
|
2113
2175
|
var PRIMARY_AGENT_ROLE = "co-orchestrator";
|
|
2114
2176
|
function resolveActiveTeam(config) {
|
|
2115
2177
|
const id = (config?.activeTeam ?? "").trim();
|
|
@@ -5791,9 +5853,6 @@ var UNIVERSAL_DENY2 = [
|
|
|
5791
5853
|
"weather",
|
|
5792
5854
|
"video_search"
|
|
5793
5855
|
];
|
|
5794
|
-
function fallbackPresetForTier(tier) {
|
|
5795
|
-
return tier === "rw" || tier === "rw-shell" || tier === "cordis" ? SUBAGENT_WRITE_PRESET : SUBAGENT_READONLY_PRESET;
|
|
5796
|
-
}
|
|
5797
5856
|
var DEFAULT_FALLBACK_SKILL = "co-fixer";
|
|
5798
5857
|
function resolveSkillToolFilter(skillName, enabled = true, logger, customRoles) {
|
|
5799
5858
|
if (!enabled)
|
|
@@ -5811,24 +5870,14 @@ function resolveSkillToolFilter(skillName, enabled = true, logger, customRoles)
|
|
|
5811
5870
|
return;
|
|
5812
5871
|
}
|
|
5813
5872
|
}
|
|
5814
|
-
var
|
|
5815
|
-
|
|
5816
|
-
function resolveSkillAgentPreset(skillName, enabled = true, customRoles, logger) {
|
|
5873
|
+
var CORDIS_PRESET = "cohub-cordis";
|
|
5874
|
+
function resolveSkillAgentPreset(skillName, enabled = true, customRoles, _logger) {
|
|
5817
5875
|
if (!enabled)
|
|
5818
5876
|
return;
|
|
5819
5877
|
const key = (skillName ?? "").trim();
|
|
5820
5878
|
if (key === "co-orchestrator")
|
|
5821
5879
|
return;
|
|
5822
|
-
|
|
5823
|
-
if (tier === null)
|
|
5824
|
-
return SUBAGENT_WRITE_PRESET;
|
|
5825
|
-
const mapped = TIER_TO_PRESET[tier];
|
|
5826
|
-
if (typeof mapped !== "string" || mapped.length === 0) {
|
|
5827
|
-
const fallback = fallbackPresetForTier(tier);
|
|
5828
|
-
logger?.warn?.('[cohub preset] 档位 "' + tier + '"(skill=' + key + ")没有对应的子代理 preset," + "已降级为 " + fallback + "(不扩大权限)");
|
|
5829
|
-
return fallback;
|
|
5830
|
-
}
|
|
5831
|
-
return presetForTier(tier);
|
|
5880
|
+
return resolveTier(key, customRoles) === "cordis" ? CORDIS_PRESET : undefined;
|
|
5832
5881
|
}
|
|
5833
5882
|
function intersectWithRestrictable(filter, restrictableNames) {
|
|
5834
5883
|
if (!filter || !restrictableNames)
|
|
@@ -5955,6 +6004,8 @@ async function spawnWithToolFilterFallout(ctx, provider, spec) {
|
|
|
5955
6004
|
}
|
|
5956
6005
|
return handle;
|
|
5957
6006
|
} catch (error) {
|
|
6007
|
+
if (isToolFilterEnforced(error))
|
|
6008
|
+
throw error;
|
|
5958
6009
|
const message = error instanceof Error ? error.message : String(error);
|
|
5959
6010
|
const aborted = spec.signal?.aborted === true || /abort/i.test(message);
|
|
5960
6011
|
if (filter === undefined || wanted === undefined || aborted || !TOOL_FILTER_REJECTED.test(message)) {
|
|
@@ -5989,6 +6040,19 @@ function resolveAgentsService(ctx) {
|
|
|
5989
6040
|
return viaReflect;
|
|
5990
6041
|
return pick(() => ctx?.agents);
|
|
5991
6042
|
}
|
|
6043
|
+
|
|
6044
|
+
class ToolFilterEnforcedError extends Error {
|
|
6045
|
+
code = TOOL_FILTER_ENFORCED_CODE;
|
|
6046
|
+
constructor(message) {
|
|
6047
|
+
super(message);
|
|
6048
|
+
this.name = "ToolFilterEnforcedError";
|
|
6049
|
+
}
|
|
6050
|
+
}
|
|
6051
|
+
var TOOL_FILTER_ENFORCED_CODE = "cohub/toolfilter-enforced";
|
|
6052
|
+
function isToolFilterEnforced(error) {
|
|
6053
|
+
const code = error?.code;
|
|
6054
|
+
return code === TOOL_FILTER_ENFORCED_CODE;
|
|
6055
|
+
}
|
|
5992
6056
|
function applyChildToolFilterDirectly(ctx, childId, filter, degradeNotes) {
|
|
5993
6057
|
if (filter === undefined)
|
|
5994
6058
|
return;
|
|
@@ -6032,12 +6096,11 @@ function applyChildToolFilterDirectly(ctx, childId, filter, degradeNotes) {
|
|
|
6032
6096
|
tools.restrict(next);
|
|
6033
6097
|
return;
|
|
6034
6098
|
} catch (retryError) {
|
|
6035
|
-
|
|
6036
|
-
return;
|
|
6099
|
+
throw new ToolFilterEnforcedError("cohub: 子代理工具裁剪未能施加(restrict 被拒),已 fail-closed 终止本次派发:" + describeDegradeReason(retryError));
|
|
6037
6100
|
}
|
|
6038
6101
|
}
|
|
6039
6102
|
}
|
|
6040
|
-
|
|
6103
|
+
throw new ToolFilterEnforcedError("cohub: 子代理工具裁剪未能施加(restrict 被拒),已 fail-closed 终止本次派发:" + describeDegradeReason(error));
|
|
6041
6104
|
}
|
|
6042
6105
|
}
|
|
6043
6106
|
async function startSubagentRunOnce(ctx, provider, spec) {
|
|
@@ -6080,7 +6143,14 @@ ${attribution}`);
|
|
|
6080
6143
|
wrapped.stack = err.stack;
|
|
6081
6144
|
throw wrapped;
|
|
6082
6145
|
}
|
|
6083
|
-
|
|
6146
|
+
try {
|
|
6147
|
+
applyChildToolFilterDirectly(ctx, receipt.childId, spec.toolFilter, spec.degradeNotes);
|
|
6148
|
+
} catch (error) {
|
|
6149
|
+
try {
|
|
6150
|
+
receipt?.dispose?.();
|
|
6151
|
+
} catch {}
|
|
6152
|
+
throw error;
|
|
6153
|
+
}
|
|
6084
6154
|
return {
|
|
6085
6155
|
id: receipt.childId,
|
|
6086
6156
|
result: receipt.result,
|
|
@@ -6400,10 +6470,10 @@ function resolveSkillAndRoute(requestedSkill, getRoutes, ctx, logger, snapshot)
|
|
|
6400
6470
|
tier: resolveTier(DEFAULT_FALLBACK_SKILL),
|
|
6401
6471
|
builtin: true
|
|
6402
6472
|
};
|
|
6403
|
-
note = reason === "disabled" ? '传入的 skill 名 "' + echoName + '" 存在但已被禁用(config.disabledSkills),已兜底为 ' + DEFAULT_FALLBACK_SKILL + "
|
|
6473
|
+
note = reason === "disabled" ? '传入的 skill 名 "' + echoName + '" 存在但已被禁用(config.disabledSkills),已兜底为 ' + DEFAULT_FALLBACK_SKILL + ",子代理档位同步回退为 rw-shell(继承父组合 + restrict 裁剪)" + ";如需使用请从禁用清单中移除,而不是改名" : '传入的 skill 名 "' + echoName + '" 未匹配任何角色(内置角色 + config.customRoles),已兜底为 ' + DEFAULT_FALLBACK_SKILL + ",子代理档位同步回退为 rw-shell(继承父组合 + restrict 裁剪)";
|
|
6404
6474
|
} else if (fallback) {
|
|
6405
6475
|
(logger ?? ctx.logger)?.warn?.("delegate: skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + ";schema 已要求必填,出现本告警说明调用绕过了参数校验");
|
|
6406
|
-
note = "skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + "
|
|
6476
|
+
note = "skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + ",子代理档位回退为 rw-shell(继承父组合 + restrict 裁剪)";
|
|
6407
6477
|
}
|
|
6408
6478
|
const route = (getRoutes() ?? []).find((s) => s.name === requested);
|
|
6409
6479
|
return { skill: role.skill, role, route, fallback, ...note === undefined ? {} : { note } };
|
|
@@ -10604,16 +10674,19 @@ export {
|
|
|
10604
10674
|
DelegateBackgroundConfig,
|
|
10605
10675
|
ResultBudgetConfig,
|
|
10606
10676
|
ScheduleConfig,
|
|
10677
|
+
TEAM_OWNED_PRESET_IDS,
|
|
10607
10678
|
TEAM_PRESET_ORDER_BASE,
|
|
10608
10679
|
Team,
|
|
10609
10680
|
apply,
|
|
10610
10681
|
applyPresetPatchDeclarations,
|
|
10682
|
+
assertCustomSkillDirs,
|
|
10611
10683
|
buildPresetPatchDeclarations,
|
|
10612
10684
|
buildTeamPersona,
|
|
10613
10685
|
buildTeamPresetDefs,
|
|
10614
10686
|
buildTeamPresetPlugins,
|
|
10615
10687
|
copyTree,
|
|
10616
10688
|
evaluatePlatformExpr,
|
|
10689
|
+
evaluateUrlDirExpr,
|
|
10617
10690
|
hashTree,
|
|
10618
10691
|
inject,
|
|
10619
10692
|
installShippedPresets,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cohub",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.14",
|
|
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",
|