dsh-cohub 0.8.0 → 0.8.1
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/lib/index.js +55 -32
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1851,6 +1851,7 @@ var READ_ONLY_SKILLS = new Set([
|
|
|
1851
1851
|
"co-rule-app"
|
|
1852
1852
|
]);
|
|
1853
1853
|
var WRITE_SKILLS = new Set(["co-fixer", "co-designer", "co-cordis"]);
|
|
1854
|
+
var DEFAULT_FALLBACK_SKILL = "co-fixer";
|
|
1854
1855
|
function resolveSkillToolFilter(skillName, enabled = true, logger) {
|
|
1855
1856
|
if (!enabled)
|
|
1856
1857
|
return;
|
|
@@ -1872,8 +1873,10 @@ function resolveSkillAgentPreset(skillName, enabled = true) {
|
|
|
1872
1873
|
if (!enabled)
|
|
1873
1874
|
return;
|
|
1874
1875
|
const key = (skillName ?? "").trim();
|
|
1875
|
-
if (key
|
|
1876
|
+
if (key === "co-orchestrator")
|
|
1876
1877
|
return;
|
|
1878
|
+
if (key.length === 0)
|
|
1879
|
+
return SUBAGENT_WRITE_PRESET;
|
|
1877
1880
|
if (READ_ONLY_SKILLS.has(key))
|
|
1878
1881
|
return SUBAGENT_READONLY_PRESET;
|
|
1879
1882
|
if (WRITE_SKILLS.has(key))
|
|
@@ -2198,16 +2201,21 @@ class StallWatchdog {
|
|
|
2198
2201
|
}
|
|
2199
2202
|
}
|
|
2200
2203
|
function resolveSkillAndRoute(requestedSkill, getRoutes, ctx, logger) {
|
|
2201
|
-
const
|
|
2204
|
+
const requested = (typeof requestedSkill === "string" ? requestedSkill : "").trim();
|
|
2205
|
+
const skillName = requested || DEFAULT_FALLBACK_SKILL;
|
|
2206
|
+
const fallback = requested.length === 0;
|
|
2202
2207
|
let skill = COHUB_SKILLS.find((s) => s.name === skillName);
|
|
2203
2208
|
if (!skill) {
|
|
2204
2209
|
(logger ?? ctx.logger)?.warn?.('delegate: unknown skill "' + skillName + '", falling back to co-fixer');
|
|
2205
|
-
skill = COHUB_SKILLS.find((s) => s.name ===
|
|
2206
|
-
} else if (
|
|
2207
|
-
(logger ?? ctx.logger)?.
|
|
2210
|
+
skill = COHUB_SKILLS.find((s) => s.name === DEFAULT_FALLBACK_SKILL);
|
|
2211
|
+
} else if (fallback) {
|
|
2212
|
+
(logger ?? ctx.logger)?.warn?.("delegate: skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + ";schema 已要求必填,出现本告警说明调用绕过了参数校验");
|
|
2208
2213
|
}
|
|
2209
|
-
const route = (getRoutes() ?? []).find((s) => s.name ===
|
|
2210
|
-
return { skill, route };
|
|
2214
|
+
const route = (getRoutes() ?? []).find((s) => s.name === requested);
|
|
2215
|
+
return { skill, route, fallback };
|
|
2216
|
+
}
|
|
2217
|
+
function formatSkillLabel(skill, fallback) {
|
|
2218
|
+
return fallback ? skill.name + " (default:" + DEFAULT_FALLBACK_SKILL + ")" : skill.name;
|
|
2211
2219
|
}
|
|
2212
2220
|
function normalizeReasoningEffort(value) {
|
|
2213
2221
|
if (typeof value !== "string")
|
|
@@ -2495,7 +2503,8 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
2495
2503
|
parameters: {
|
|
2496
2504
|
skill: {
|
|
2497
2505
|
type: "string",
|
|
2498
|
-
|
|
2506
|
+
required: true,
|
|
2507
|
+
description: "必填,专职代理技能名,必须是 co-* 代理名(co-fixer/co-explorer/co-oracle/co-planner 等)。" + '缺省会报错 invalid arguments: missing required property "skill"——不填就无法路由 provider/model,' + "也挂不上该角色的子代理 preset 与工具裁剪"
|
|
2499
2508
|
},
|
|
2500
2509
|
prompt: {
|
|
2501
2510
|
type: "string",
|
|
@@ -2521,10 +2530,11 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
2521
2530
|
const { retry, stall, schedule, budget, background, subagentPresetEnabled } = resolveRuntimeConfig();
|
|
2522
2531
|
const RETRYABLE = new Set(retry.retryableReasons);
|
|
2523
2532
|
ctx.logger?.info?.("[cohub schedule] 生效调度参数:batch=" + (schedule?.maxParallelBatch ?? 3) + " wallMs=" + (schedule?.wallClockBudgetMs ?? WALL_CLOCK_BUDGET_MS));
|
|
2524
|
-
const { skill, route } = resolveSkillAndRoute(args.skill, getRoutes, ctx);
|
|
2533
|
+
const { skill, route, fallback: skillFallback } = resolveSkillAndRoute(args.skill, getRoutes, ctx);
|
|
2534
|
+
const skillTag = formatSkillLabel(skill, skillFallback);
|
|
2525
2535
|
const brief = skill.brief?.trim();
|
|
2526
2536
|
if (!brief) {
|
|
2527
|
-
ctx.logger?.warn?.('delegate: skill "' +
|
|
2537
|
+
ctx.logger?.warn?.('delegate: skill "' + skillTag + '" 缺少 brief,回退完整 content');
|
|
2528
2538
|
}
|
|
2529
2539
|
const agentOptions = await buildAgentOptions(route, ctx, skill.name);
|
|
2530
2540
|
const toolFilter = resolveSkillToolFilter(skill.name, config.toolFilter?.enabled ?? true, ctx.logger);
|
|
@@ -2592,7 +2602,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
2592
2602
|
let run;
|
|
2593
2603
|
try {
|
|
2594
2604
|
run = await startSubagentRun(ctx, DEFAULT_SPAWN_TRANSPORT, {
|
|
2595
|
-
label: "delegate:" +
|
|
2605
|
+
label: "delegate:" + skillTag,
|
|
2596
2606
|
prompt: [{ type: "text", text: promptText }],
|
|
2597
2607
|
parent,
|
|
2598
2608
|
persona: DELEGATE_PERSONA,
|
|
@@ -2648,7 +2658,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
2648
2658
|
return await budgetSubagentResult(ctx, exec, contentText(outcome.output), {
|
|
2649
2659
|
maxChars: resolveSkillResultMaxChars(budget, skill.name),
|
|
2650
2660
|
scope: "delegate",
|
|
2651
|
-
label:
|
|
2661
|
+
label: skillTag,
|
|
2652
2662
|
enabled: budget.enabled
|
|
2653
2663
|
});
|
|
2654
2664
|
}
|
|
@@ -2659,7 +2669,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
2659
2669
|
lastPartialBudget = budget.enabled && partialRaw.length > budget.partialMaxChars ? applyResultBudget(partialRaw, {
|
|
2660
2670
|
maxChars: budget.partialMaxChars,
|
|
2661
2671
|
scope: "delegate:partial",
|
|
2662
|
-
label:
|
|
2672
|
+
label: skillTag,
|
|
2663
2673
|
locatorFallback: "未落盘(失败路径不写盘)"
|
|
2664
2674
|
}).text : partialRaw;
|
|
2665
2675
|
stallState.last = stallInfo;
|
|
@@ -2676,7 +2686,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
2676
2686
|
...lastDiagnostic === undefined ? {} : { diagnostic: lastDiagnostic },
|
|
2677
2687
|
partial: lastPartial,
|
|
2678
2688
|
...lastPartialBudget === lastPartial ? {} : { partialBudget: lastPartialBudget },
|
|
2679
|
-
skill:
|
|
2689
|
+
skill: skill.name,
|
|
2680
2690
|
retries,
|
|
2681
2691
|
...stallState.last ? { stall: stallState.last } : {}
|
|
2682
2692
|
};
|
|
@@ -3021,14 +3031,18 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3021
3031
|
tasks: {
|
|
3022
3032
|
type: "array",
|
|
3023
3033
|
required: true,
|
|
3024
|
-
description:
|
|
3034
|
+
description: '任务列表,每个任务的 skill 与 prompt 均为必填(漏传 skill 会报 invalid arguments: missing required property "tasks[i].skill")。' + "上限由 schedule.maxParallelBatch 限制(默认 3,最大 20)。",
|
|
3025
3035
|
items: {
|
|
3026
3036
|
type: "object",
|
|
3027
3037
|
additionalProperties: false,
|
|
3028
3038
|
properties: {
|
|
3029
3039
|
id: { type: "string", description: "可选任务标识,用于结果映射" },
|
|
3030
|
-
skill: {
|
|
3031
|
-
|
|
3040
|
+
skill: {
|
|
3041
|
+
type: "string",
|
|
3042
|
+
required: true,
|
|
3043
|
+
description: "必填,必须指定 co-* 代理名(co-fixer / co-explorer / co-oracle / co-planner 等)。" + '漏传会导致 label 变成 ":undefined" 并失去 preset 路由与工具裁剪,故直接判为非法参数'
|
|
3044
|
+
},
|
|
3045
|
+
prompt: { type: "string", required: true, description: "必填,给该代理的具体任务描述(自包含)" }
|
|
3032
3046
|
}
|
|
3033
3047
|
}
|
|
3034
3048
|
}
|
|
@@ -3054,10 +3068,19 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3054
3068
|
}
|
|
3055
3069
|
const batchStartedAt = Date.now();
|
|
3056
3070
|
const contractText = envContract.enabled ? resolveContractText(envContract, envSig, ctx).text : "";
|
|
3057
|
-
const
|
|
3058
|
-
const startedAt = Date.now();
|
|
3071
|
+
const normalized = tasks.map((task, index) => {
|
|
3059
3072
|
const taskId = task.id ?? `task-${index}`;
|
|
3060
|
-
const
|
|
3073
|
+
const raw = typeof task.skill === "string" ? task.skill.trim() : "";
|
|
3074
|
+
const skillFallback = raw.length === 0;
|
|
3075
|
+
if (skillFallback) {
|
|
3076
|
+
ctx.logger?.warn?.('[cohub delegate_batch] task "' + taskId + '" 缺少 skill(收到 ' + JSON.stringify(task.skill ?? null) + "),已兜底为 " + DEFAULT_FALLBACK_SKILL + ";schema 已要求 skill 必填,出现本告警说明调用绕过了参数校验");
|
|
3077
|
+
}
|
|
3078
|
+
return { task, taskId, requestedSkill: skillFallback ? DEFAULT_FALLBACK_SKILL : raw, skillFallback };
|
|
3079
|
+
});
|
|
3080
|
+
const starts = await Promise.allSettled(normalized.map(async ({ task, taskId, requestedSkill, skillFallback }) => {
|
|
3081
|
+
const startedAt = Date.now();
|
|
3082
|
+
const { skill, route } = resolveSkillAndRoute(requestedSkill, getRoutes, ctx, ctx.logger);
|
|
3083
|
+
const skillTag = formatSkillLabel(skill, skillFallback);
|
|
3061
3084
|
const promptText = buildDelegatePrompt({
|
|
3062
3085
|
skill,
|
|
3063
3086
|
contractText,
|
|
@@ -3081,7 +3104,7 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3081
3104
|
}
|
|
3082
3105
|
try {
|
|
3083
3106
|
const run = await startSubagentRun(ctx, DEFAULT_SPAWN_TRANSPORT, {
|
|
3084
|
-
label: `delegate_batch:${taskId}:${
|
|
3107
|
+
label: `delegate_batch:${taskId}:${skillTag}`,
|
|
3085
3108
|
prompt: [{ type: "text", text: promptText }],
|
|
3086
3109
|
parent,
|
|
3087
3110
|
persona: DELEGATE_PERSONA,
|
|
@@ -3090,14 +3113,14 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3090
3113
|
...agentOptions ? { agentOptions } : {},
|
|
3091
3114
|
signal: ac.signal
|
|
3092
3115
|
});
|
|
3093
|
-
return { taskId, task, run, ac, onExecAbort, startedAt, startError: undefined };
|
|
3116
|
+
return { taskId, skillName: skill.name, skillTag, task, run, ac, onExecAbort, startedAt, startError: undefined };
|
|
3094
3117
|
} catch (startError) {
|
|
3095
3118
|
if (onExecAbort && exec.signal) {
|
|
3096
3119
|
try {
|
|
3097
3120
|
exec.signal.removeEventListener("abort", onExecAbort);
|
|
3098
3121
|
} catch {}
|
|
3099
3122
|
}
|
|
3100
|
-
return { taskId, task, run: undefined, ac, onExecAbort: null, startedAt, startError };
|
|
3123
|
+
return { taskId, skillName: skill.name, skillTag, task, run: undefined, ac, onExecAbort: null, startedAt, startError };
|
|
3101
3124
|
}
|
|
3102
3125
|
}));
|
|
3103
3126
|
const results = [];
|
|
@@ -3111,17 +3134,17 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3111
3134
|
if (val.startError) {
|
|
3112
3135
|
results.push({
|
|
3113
3136
|
id: val.taskId,
|
|
3114
|
-
skill: val.
|
|
3137
|
+
skill: val.skillTag,
|
|
3115
3138
|
status: "error",
|
|
3116
3139
|
error: val.startError instanceof Error ? val.startError.message : String(val.startError)
|
|
3117
3140
|
});
|
|
3118
3141
|
continue;
|
|
3119
3142
|
}
|
|
3120
|
-
const { run, taskId,
|
|
3121
|
-
runs.push({ run, taskId,
|
|
3143
|
+
const { run, taskId, skillName, skillTag, ac, onExecAbort, startedAt } = val;
|
|
3144
|
+
runs.push({ run, taskId, skillName, skillTag, ac, onExecAbort, startedAt });
|
|
3122
3145
|
run.result.catch(() => {});
|
|
3123
3146
|
}
|
|
3124
|
-
for (const { run, taskId,
|
|
3147
|
+
for (const { run, taskId, skillName, skillTag, ac, startedAt } of runs) {
|
|
3125
3148
|
let outcome;
|
|
3126
3149
|
let timer = null;
|
|
3127
3150
|
const remainingMs = Math.max(0, wallClockBudgetMs - (Date.now() - startedAt));
|
|
@@ -3144,15 +3167,15 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3144
3167
|
]);
|
|
3145
3168
|
if (outcome?.stopReason === "completed") {
|
|
3146
3169
|
const resultText = await budgetSubagentResult(ctx, exec, contentText(outcome.output), {
|
|
3147
|
-
maxChars: Math.min(budget.batchTaskMaxChars, resolveSkillResultMaxChars(budget,
|
|
3170
|
+
maxChars: Math.min(budget.batchTaskMaxChars, resolveSkillResultMaxChars(budget, skillName)),
|
|
3148
3171
|
scope: "batch:task",
|
|
3149
|
-
label: taskId + ":" +
|
|
3172
|
+
label: taskId + ":" + skillTag,
|
|
3150
3173
|
enabled: budget.enabled,
|
|
3151
3174
|
toolName: "delegate_batch"
|
|
3152
3175
|
});
|
|
3153
3176
|
results.push({
|
|
3154
3177
|
id: taskId,
|
|
3155
|
-
skill:
|
|
3178
|
+
skill: skillTag,
|
|
3156
3179
|
status: "completed",
|
|
3157
3180
|
result: resultText
|
|
3158
3181
|
});
|
|
@@ -3160,7 +3183,7 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3160
3183
|
const diag = typeof outcome?.diagnostic === "string" ? outcome.diagnostic : undefined;
|
|
3161
3184
|
results.push({
|
|
3162
3185
|
id: taskId,
|
|
3163
|
-
skill:
|
|
3186
|
+
skill: skillTag,
|
|
3164
3187
|
status: "failed",
|
|
3165
3188
|
error: `stopReason: ${outcome?.stopReason ?? "unknown"}` + (diag === undefined ? "" : `; diagnostic: ${diag}`),
|
|
3166
3189
|
stopReason: outcome?.stopReason,
|
|
@@ -3170,7 +3193,7 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
3170
3193
|
} catch (e) {
|
|
3171
3194
|
results.push({
|
|
3172
3195
|
id: taskId,
|
|
3173
|
-
skill:
|
|
3196
|
+
skill: skillTag,
|
|
3174
3197
|
status: "error",
|
|
3175
3198
|
error: e instanceof Error ? e.message : String(e)
|
|
3176
3199
|
});
|
package/package.json
CHANGED