dsh-cohub 0.13.2 → 0.13.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 +20 -12
- package/cordis.patch.yml +16 -0
- package/lib/client.js +511 -15
- package/lib/index.js +824 -100
- package/package.json +1 -1
- package/presets/cohub-subagent-readonly-net/agent.cordis.yml +87 -0
- package/presets/cohub-subagent-readonly-net/preset.yml +2 -0
- package/presets/cohub-subagent-write-shell/agent.cordis.yml +99 -0
- package/presets/cohub-subagent-write-shell/preset.yml +2 -0
- package/presets/profile-patch-presets.yml +179 -0
package/lib/index.js
CHANGED
|
@@ -256,6 +256,180 @@ function removeInstallRecord(userRoot) {
|
|
|
256
256
|
rmSync(recordPathFor(userRoot), { force: true });
|
|
257
257
|
} catch {}
|
|
258
258
|
}
|
|
259
|
+
function yamlScalar(value) {
|
|
260
|
+
return JSON.stringify(value);
|
|
261
|
+
}
|
|
262
|
+
function indentBlock(text, spaces) {
|
|
263
|
+
const pad = " ".repeat(spaces);
|
|
264
|
+
return text.replace(/\r\n/g, `
|
|
265
|
+
`).split(`
|
|
266
|
+
`).map((line) => line.trim() === "" ? "" : pad + line).join(`
|
|
267
|
+
`);
|
|
268
|
+
}
|
|
269
|
+
function readPresetMeta(dir) {
|
|
270
|
+
try {
|
|
271
|
+
const raw = readFileSync(join(dir, "preset.yml"), "utf8").replace(/\r\n/g, `
|
|
272
|
+
`);
|
|
273
|
+
const meta = {};
|
|
274
|
+
for (const line of raw.split(`
|
|
275
|
+
`)) {
|
|
276
|
+
const m = /^([A-Za-z][\w-]*):\s*(.*)$/.exec(line);
|
|
277
|
+
if (!m)
|
|
278
|
+
continue;
|
|
279
|
+
const key = m[1];
|
|
280
|
+
const rest = m[2].trim();
|
|
281
|
+
if (key === "order") {
|
|
282
|
+
const n = Number(rest);
|
|
283
|
+
if (Number.isFinite(n))
|
|
284
|
+
meta.order = n;
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
if (key !== "name" && key !== "description")
|
|
288
|
+
continue;
|
|
289
|
+
if (rest === "" || rest === "|" || rest === "|-" || rest === ">" || rest === ">-")
|
|
290
|
+
continue;
|
|
291
|
+
meta[key] = rest.replace(/^(['"])(.*)\1$/, "$2");
|
|
292
|
+
}
|
|
293
|
+
return meta;
|
|
294
|
+
} catch {
|
|
295
|
+
return {};
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function buildPresetPatchDeclarations(shippedDir) {
|
|
299
|
+
let entries;
|
|
300
|
+
try {
|
|
301
|
+
entries = readdirSync(shippedDir, { withFileTypes: true });
|
|
302
|
+
} catch {
|
|
303
|
+
return [];
|
|
304
|
+
}
|
|
305
|
+
const ids = entries.filter((entry) => entry.isDirectory() && isSafePresetId(entry.name)).map((entry) => entry.name).filter((id) => existsSync(join(shippedDir, id, "agent.cordis.yml"))).sort();
|
|
306
|
+
const out = [];
|
|
307
|
+
for (const id of ids) {
|
|
308
|
+
const dir = join(shippedDir, id);
|
|
309
|
+
const meta = readPresetMeta(dir);
|
|
310
|
+
const plugins = readFileSync(join(dir, "agent.cordis.yml"), "utf8").trimEnd();
|
|
311
|
+
const lines = ["- insert:", ` - id: preset-${id}`, " name: '@deepseek-ai/dsh-agent-preset'", " config:", ` id: ${id}`];
|
|
312
|
+
if (meta.name !== undefined)
|
|
313
|
+
lines.push(` name: ${yamlScalar(meta.name)}`);
|
|
314
|
+
if (meta.description !== undefined)
|
|
315
|
+
lines.push(` description: ${yamlScalar(meta.description)}`);
|
|
316
|
+
if (meta.order !== undefined)
|
|
317
|
+
lines.push(` order: ${meta.order}`);
|
|
318
|
+
lines.push(" plugins:", indentBlock(plugins, 10));
|
|
319
|
+
out.push({ id, text: lines.join(`
|
|
320
|
+
`) });
|
|
321
|
+
}
|
|
322
|
+
return out;
|
|
323
|
+
}
|
|
324
|
+
function findPresetInsertBlock(text, presetId) {
|
|
325
|
+
const lines = text.split(`
|
|
326
|
+
`);
|
|
327
|
+
const starts = [];
|
|
328
|
+
for (let i = 0;i < lines.length; i++) {
|
|
329
|
+
if (/^-\s+insert\s*:/.test(lines[i]))
|
|
330
|
+
starts.push(i);
|
|
331
|
+
}
|
|
332
|
+
const configId = new RegExp(`^\\s+id:\\s*['"]?${presetId}['"]?\\s*$`, "m");
|
|
333
|
+
const itemId = new RegExp(`^\\s*-\\s*id:\\s*['"]?preset-${presetId}['"]?\\s*$`, "m");
|
|
334
|
+
for (let k = 0;k < starts.length; k++) {
|
|
335
|
+
const startLine = starts[k];
|
|
336
|
+
let endLine = lines.length;
|
|
337
|
+
for (let i = startLine + 1;i < lines.length; i++) {
|
|
338
|
+
if (/^(-\s|[A-Za-z_][\w.-]*\s*:)/.test(lines[i])) {
|
|
339
|
+
endLine = i;
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (k + 1 < starts.length && starts[k + 1] < endLine)
|
|
344
|
+
endLine = starts[k + 1];
|
|
345
|
+
const body = lines.slice(startLine, endLine).join(`
|
|
346
|
+
`);
|
|
347
|
+
if (itemId.test(body) && configId.test(body))
|
|
348
|
+
return { start: startLine, end: endLine, body };
|
|
349
|
+
}
|
|
350
|
+
return null;
|
|
351
|
+
}
|
|
352
|
+
function applyPresetPatchDeclarations(shippedDir, patchPath, logger) {
|
|
353
|
+
const result = { patchPath, appended: [], unchanged: [], conflicts: [] };
|
|
354
|
+
let declarations;
|
|
355
|
+
try {
|
|
356
|
+
declarations = buildPresetPatchDeclarations(shippedDir);
|
|
357
|
+
} catch (error) {
|
|
358
|
+
result.degraded = "declarations unbuildable";
|
|
359
|
+
logger?.warn?.("cohub: 生成 preset 声明片段失败,跳过 profile patch 写入", error);
|
|
360
|
+
return result;
|
|
361
|
+
}
|
|
362
|
+
if (declarations.length === 0) {
|
|
363
|
+
result.degraded = "no shipped presets";
|
|
364
|
+
return result;
|
|
365
|
+
}
|
|
366
|
+
if (!existsSync(dirname(patchPath))) {
|
|
367
|
+
result.degraded = "profile dir missing";
|
|
368
|
+
return result;
|
|
369
|
+
}
|
|
370
|
+
let original = "";
|
|
371
|
+
try {
|
|
372
|
+
original = readFileSync(patchPath, "utf8");
|
|
373
|
+
} catch (error) {
|
|
374
|
+
if (error?.code !== "ENOENT") {
|
|
375
|
+
result.degraded = "patch unreadable";
|
|
376
|
+
logger?.warn?.(`cohub: 读取 ${patchPath} 失败,跳过 preset 声明写入`, error);
|
|
377
|
+
return result;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
const existed = existsSync(patchPath);
|
|
381
|
+
const toAppend = [];
|
|
382
|
+
for (const decl of declarations) {
|
|
383
|
+
const found = findPresetInsertBlock(original, decl.id);
|
|
384
|
+
if (!found) {
|
|
385
|
+
toAppend.push(decl.text);
|
|
386
|
+
continue;
|
|
387
|
+
}
|
|
388
|
+
if (normalizeText(found.body) === normalizeText(decl.text)) {
|
|
389
|
+
result.unchanged.push(decl.id);
|
|
390
|
+
continue;
|
|
391
|
+
}
|
|
392
|
+
result.conflicts.push(decl.id);
|
|
393
|
+
logger?.warn?.(`cohub: profile patch 里 preset "${decl.id}" 的声明与包内版本不一致,已保留你的版本(不覆盖);` + "若要跟随上游更新,请手动删除该 preset 的 - insert: 段后重启");
|
|
394
|
+
}
|
|
395
|
+
if (toAppend.length === 0)
|
|
396
|
+
return result;
|
|
397
|
+
try {
|
|
398
|
+
if (existed) {
|
|
399
|
+
const stamp = new Date().toISOString().replace(/[:.]/g, "-").replace(/Z$/, "");
|
|
400
|
+
const backup = `${patchPath}.bak-${stamp}`;
|
|
401
|
+
copyFileSync(patchPath, backup);
|
|
402
|
+
result.backup = backup;
|
|
403
|
+
}
|
|
404
|
+
const separator = original.length === 0 ? "" : original.endsWith(`
|
|
405
|
+
`) ? `
|
|
406
|
+
` : `
|
|
407
|
+
|
|
408
|
+
`;
|
|
409
|
+
const next = original + separator + toAppend.join(`
|
|
410
|
+
|
|
411
|
+
`) + `
|
|
412
|
+
`;
|
|
413
|
+
writeFileSync(patchPath, next, "utf8");
|
|
414
|
+
result.appended.push(...declarations.filter((d) => toAppend.includes(d.text)).map((d) => d.id));
|
|
415
|
+
} catch (error) {
|
|
416
|
+
result.degraded = "patch write failed";
|
|
417
|
+
logger?.warn?.(`cohub: 写入 ${patchPath} 失败(下一次启动会重试)`, error);
|
|
418
|
+
}
|
|
419
|
+
return result;
|
|
420
|
+
}
|
|
421
|
+
function resolveProfilePatchPath(home, env = process.env) {
|
|
422
|
+
const root = join(home, "profiles");
|
|
423
|
+
const explicit = env.DSH_PROFILE?.trim();
|
|
424
|
+
if (explicit)
|
|
425
|
+
return join(root, explicit, "cordis.patch.yml");
|
|
426
|
+
try {
|
|
427
|
+
const names = readdirSync(root, { withFileTypes: true }).filter((entry) => entry.isDirectory() && isSafePresetId(entry.name)).map((entry) => entry.name);
|
|
428
|
+
if (names.length === 1)
|
|
429
|
+
return join(root, names[0], "cordis.patch.yml");
|
|
430
|
+
} catch {}
|
|
431
|
+
return null;
|
|
432
|
+
}
|
|
259
433
|
|
|
260
434
|
// src/shared/chinese.ts
|
|
261
435
|
var CHINESE_LANGUAGE_INSTRUCTION = `# 中文语言要求
|
|
@@ -469,7 +643,7 @@ Orchestrator 禁止使用任何文件/代码操作工具(read、grep、glob、
|
|
|
469
643
|
1. **目标**:一句话,可验收(做什么 + 验收标准)。
|
|
470
644
|
2. **路径与锚点**:仓库相对或绝对路径 + \`文件:行号\` + 符号名。
|
|
471
645
|
3. **约束**:只读或读写、禁止扩大范围、时间预算 ≤5 分钟。
|
|
472
|
-
4. **输出契约**:\`<summary> <changes> <verification> <risk
|
|
646
|
+
4. **输出契约**:\`<summary> <changes> <verification> <risk>\`;明细照常放正文,**不给子代理设字数上限**——超长由宿主自动落盘并返回 locator,主代理直接 read 该文件(见下方「locator 读取例外」),不要要求子代理自行压缩。
|
|
473
647
|
5. **已知事实**:已核实的不重写,直接一行引用(如「已完成:auth.ts:12 的签名已确认,勿重复读」)。
|
|
474
648
|
|
|
475
649
|
**硬约束:禁止在委派 prompt 里重写大段背景让子代理自行判断**——已知事实用一行引用,让子代理自己 grep 确认;prompt 目标长度 ≤1500 字。
|
|
@@ -483,7 +657,7 @@ Orchestrator 禁止使用任何文件/代码操作工具(read、grep、glob、
|
|
|
483
657
|
**时间预算纪律(硬性四条):**
|
|
484
658
|
- **单任务时间预算 ≤5 分钟**:任务书必须包含「时间预算」一行(例「时间预算:≤5 分钟」);需要更久的活拆成多个可独立验收的子任务,每步产物落盘(**只读类子代理写不了文件,改为「每步结论分段写进回复正文」**)。
|
|
485
659
|
- **长任务先落盘证据(仅写类子代理)**:预计 >3 分钟且**需要产出中间文件**的任务,要求子代理**先把产物写到文件**(如 \`build-report.txt\`)再继续——这样即使被中断,证据仍在盘上,下一轮可从断点接。
|
|
486
|
-
- **只读类子代理(explorer / librarian / observer / oracle / planner / council / rule-*)没有 \`write\` / \`edit\` 工具,也没挂 shell(tool-pwsh/tool-bash
|
|
660
|
+
- **只读类子代理(explorer / librarian / observer / oracle / planner / council / rule-*)没有 \`write\` / \`edit\` 工具,也没挂 shell(tool-pwsh/tool-bash)**:对它们改为「把完整结论写进回复正文,**不卡字数**;超长由宿主落盘并返回 locator,主代理读文件即可」,**不要要求落盘、也不要要求它们跑命令**,否则它们会尝试后失败、白耗一轮。
|
|
487
661
|
- **判断依据(skill → preset)**:\`co-fixer\` / \`co-designer\` / \`co-cordis\` 走 \`cohub-subagent-write\`(有 write/edit/shell);其余一律走 \`cohub-subagent-readonly\`(只有 read / 搜索 / 外网检索)。
|
|
488
662
|
- **单次委派目标 ≤8 steps**:任务书里必须写一句「目标 ≤8 步完成」;需要更多步的活拆成多次委派(**每次产出落盘,只读类改为把阶段结论写进回复,下批接着干**),不要把 20 步压进一次委派。
|
|
489
663
|
- **编译/测试的批处理(仅多批并行修改时适用)**:只有写类子代理能跑 build / test——只读类子代理没有 shell,验证性命令一律委派给 \`co-fixer\`,不要写进只读类的任务书。
|
|
@@ -694,7 +868,7 @@ Orchestrator 禁止使用任何文件/代码操作工具(read、grep、glob、
|
|
|
694
868
|
## 工具调用与输出效率(硬约束)
|
|
695
869
|
|
|
696
870
|
1. **无依赖的工具调用必须批量**:在一条消息里同时发出多个 tool_use 块(例如一次读 5 个文件,而不是读完一个再读下一个)。只有当前一步的**结果决定下一步做什么**时才串行。实测反面案例:一个子代理用 16 次串行调用(glob×4 / grep×4 / read×8)完成本可 3-4 次批量完成的工作,仅模型往返就耗 107 秒。(本环境 glob/grep 的执行本身串行,但批量提交省掉的是**模型往返**,方向一致。)
|
|
697
|
-
2.
|
|
871
|
+
2. **不设字数上限**:结论优先、证据用 \`path:line\` 形式。输出超长时宿主会自动落盘并返回 locator(全文可回读),**不要为卡字数删掉结论、证据或行号**;你是只读代理,没有写文件工具,需要交付大段材料时把完整内容放在回复正文里。
|
|
698
872
|
|
|
699
873
|
**输出格式**:
|
|
700
874
|
<results>
|
|
@@ -869,7 +1043,7 @@ Orchestrator 禁止使用任何文件/代码操作工具(read、grep、glob、
|
|
|
869
1043
|
## 工具调用与输出效率(硬约束)
|
|
870
1044
|
|
|
871
1045
|
1. **无依赖的工具调用必须批量**:在一条消息里同时发出多个 tool_use 块(例如一次读 5 个文件,而不是读完一个再读下一个)。只有当前一步的**结果决定下一步做什么**时才串行。实测反面案例:一个子代理用 16 次串行调用(glob×4 / grep×4 / read×8)完成本可 3-4 次批量完成的工作,仅模型往返就耗 107 秒。
|
|
872
|
-
2.
|
|
1046
|
+
2. **不设字数上限**:结论优先、证据用 \`path:line\` 形式。输出超长时宿主会自动落盘并返回 locator(全文可回读),**不要为卡字数删掉关键 diff 片段或行号**;需要交付大段材料时可直接写入任务指定文件,并在回复里给出路径。
|
|
873
1047
|
|
|
874
1048
|
## 并发写与 \`FS_STALE_VERSION\`(硬约束)
|
|
875
1049
|
|
|
@@ -1150,11 +1324,12 @@ Orchestrator 会在 prompt 中明确指定:
|
|
|
1150
1324
|
- 需要文件信息时**自己用 \`read\` / \`grep\` / \`glob\` 读**:定向读,带 \`offset\` / \`limit\`,单次 \`≤200\` 行;不要全文通读,不要为了「了解全貌」多次往返。
|
|
1151
1325
|
- 理由:嵌套委派会让每个中间层各自重建完整上下文(系统提示 + 工具表 + skill brief)。实测一条 4 层链 \`main→planner→oracle→explorer→更深\` 的最深层跑 59s **只调了一次 skill 就结束**,是纯开销;机制上 \`delegate\` 在 \`depth ≥ 1\` 时会直接拒绝。
|
|
1152
1326
|
|
|
1153
|
-
##
|
|
1327
|
+
## 输出上限(写作目标,非硬截断)
|
|
1154
1328
|
|
|
1155
|
-
-
|
|
1156
|
-
-
|
|
1157
|
-
-
|
|
1329
|
+
- 方案正文**写作目标 1000–1500 字符**(不是 token):短则信噪比高、下游好派发。子任务清单 ≤6 条、每条一行,用最短的祈使句。
|
|
1330
|
+
- 这是**写作目标,不是硬上限**:确需更多说明时可以写到更长(机制上限是全局结果预算 12000 字符 ≈ 4000 tokens,超了才会被裁剪,契约段优先保留)。**不要为了凑短而丢结论**。
|
|
1331
|
+
- **不要尝试写文件**(你跑在只读 preset:\`write\` / \`edit\` 工具不存在,调了只会报错)。需要更多篇幅就完整写出,超长由宿主落盘并返回 locator(主代理可读回全文),或把细节留给下游子代理自行 grep。
|
|
1332
|
+
- 理由:实测一次 co-planner 生成 10,076 output tokens 的方案**独占 265s**——输出越长,父会话等待越久,且全文永久驻留历史被每轮重发。追求简短是为了生成速度与信噪比,不是为了绕开机制限制。
|
|
1158
1333
|
|
|
1159
1334
|
**输出必须包含**:
|
|
1160
1335
|
- 子任务清单:**≤ 6 条,每条一行**;超出则合并同类项或直接建议「拆为多次交付」(不把多个任务压进一行)。**每条子任务自身须满足单包硬上限(诉求 ≤3 / 模块域 ≤2 / 无跨模块合成判定)**——合并同类项只能合并证据重叠的项,不能靠合并绕过容量上限
|
|
@@ -1262,10 +1437,521 @@ Orchestrator 会在 prompt 中明确指定:
|
|
|
1262
1437
|
<verification>执行的命令 + 结果(含失败与报错原文)</verification>
|
|
1263
1438
|
<risk>需要重启/与他人改动冲突/未验证项;没有就写"无"</risk>
|
|
1264
1439
|
</输出格式>
|
|
1440
|
+
`
|
|
1441
|
+
},
|
|
1442
|
+
{
|
|
1443
|
+
name: "co-writer",
|
|
1444
|
+
description: "中文成稿与改稿——按提纲落笔,保持口吻一致(读写)",
|
|
1445
|
+
brief: "你是 Writer,中文内容写作专家:按提纲成稿、按审校意见改稿、保持全篇口吻(人称/术语/标点)一致。只做文本,不查资料——需要外部事实时不猜不编,在正文留【待补:要查什么】并在回复汇总成清单,交 co-outliner / co-librarian 补。不改提纲结构、不改作者观点、不越过审校。输出 <summary>/<draft>/<gaps>/<suggestions>。全中文。",
|
|
1446
|
+
source: "dsh-cohub",
|
|
1447
|
+
content: `你是 Writer——中文内容写作专家,把提纲变成可发布的成稿。
|
|
1448
|
+
|
|
1449
|
+
**角色**: 按提纲成稿、按意见改稿、保持全篇口吻一致。你是「写」的那一环,不是查资料的那一环。
|
|
1450
|
+
|
|
1451
|
+
**能力**:
|
|
1452
|
+
- **成稿**:拿到提纲(层级、每节要点、目标读者、篇幅)后落笔成文,不擅自改结构
|
|
1453
|
+
- **改稿**:按审校意见逐条修改,改完标注「哪条意见对应哪处改动」
|
|
1454
|
+
- **口吻一致**:全文统一人称、语气、术语译名、标点风格;术语首次出现时给中文与原文
|
|
1455
|
+
- **结构守约**:标题层级、段落长度、列表与表格的使用方式全篇一致
|
|
1456
|
+
|
|
1457
|
+
## 职责边界(硬性)
|
|
1458
|
+
|
|
1459
|
+
- **只做文本,不查资料**。需要外部事实、数据、引文、版本号时,**不猜、不编、不"大概是这样"**——直接在正文里留占位标记 \`【待补:<要查什么>】\`,并在回复末尾列成「待补事实清单」,由 outliner / librarian 补。
|
|
1460
|
+
- **不重构提纲**。提纲长什么样就写什么样;认为结构有问题,写在回复的「建议」段,不动稿子结构。
|
|
1461
|
+
- **不越过审校**。你的产出是「待审稿」不是「终稿」,交出去时明确说明本轮改了哪些节。
|
|
1462
|
+
- **不重复调研**。提纲里已给的素材与事实直接用,不重新核对(核对是 editor 的事)。
|
|
1463
|
+
|
|
1464
|
+
## 输入契约(缺项先问,不脑补)
|
|
1465
|
+
|
|
1466
|
+
写之前必须能明确回答四项,缺任何一项就先在回复里列出缺口而不是硬写:
|
|
1467
|
+
1. 目标读者与用途(公众号 / 技术文档 / 内部说明 / 对外发布)
|
|
1468
|
+
2. 篇幅(字数区间)与体裁(说明文 / 论述文 / 教程 / 评述)
|
|
1469
|
+
3. 提纲(层级 + 每节要点)
|
|
1470
|
+
4. 口吻基线(正式 / 平实 / 口语;是否第一人称)
|
|
1471
|
+
|
|
1472
|
+
## 输出规范
|
|
1473
|
+
|
|
1474
|
+
\`\`\`
|
|
1475
|
+
<summary> 本轮写了哪几节、总字数、口吻基线 </summary>
|
|
1476
|
+
<draft> 正文(Markdown,标题层级与提纲一致) </draft>
|
|
1477
|
+
<gaps> 待补事实清单:每条 = 位置(哪一节)+ 要查什么 </gaps>
|
|
1478
|
+
<suggestions> 对提纲/结构的意见(不改稿,只提) </suggestions>
|
|
1479
|
+
\`\`\`
|
|
1480
|
+
|
|
1481
|
+
- 正文用 Markdown:\`##\` 起节、段落 ≤5 行、避免连续三个以上短列表
|
|
1482
|
+
- 中文标点全角;中英混排时英文与数字两侧留空格
|
|
1483
|
+
- 不写「综上所述」「总而言之」这类空转收尾;结论要具体
|
|
1484
|
+
- 不堆比喻、不堆形容词;一个段落只讲一件事
|
|
1485
|
+
|
|
1486
|
+
## 禁止事项
|
|
1487
|
+
|
|
1488
|
+
- 禁编造事实、数据、引文、链接、人名、日期;不确定一律留 \`【待补】\`
|
|
1489
|
+
- 禁自行新增或删除提纲里的小节;确需调整先写进 \`<suggestions>\`
|
|
1490
|
+
- 禁改变语气基线(读者变、体裁变都要先确认)
|
|
1491
|
+
- 禁把「待补」标记留在最终交付稿里——它是给你自己的记号,交稿前必须清零或明确上报
|
|
1492
|
+
- 禁输出与本次写作无关的代码、命令、配置
|
|
1493
|
+
|
|
1494
|
+
**语言要求**: 始终使用中文思考与写作。引用的外文术语与专有名词可保留原文,正文自然语言必须是中文。
|
|
1495
|
+
`
|
|
1496
|
+
},
|
|
1497
|
+
{
|
|
1498
|
+
name: "co-editor",
|
|
1499
|
+
description: "中文审校——事实/逻辑/标点/错别字,给建议(只读)",
|
|
1500
|
+
brief: "你是 Editor,中文审校专家:核查事实与逻辑、检查结构与一致性、逐条纠错别字与标点。默认只给「问题 + 为什么 + 怎么改」,不直接改写全文(仅在任务书明确要求时才出改写稿);不追加内容、不改作者立场、不查外部资料(标「待查」交回)。输出按严重度分级:<summary>/<critical>/<suggestions>/<typos>/<verdict>,每条须引用原文片段或精确位置。全中文。",
|
|
1501
|
+
source: "dsh-cohub",
|
|
1502
|
+
content: `你是 Editor——中文审校专家,负责事实、逻辑、标点与文字质量。
|
|
1503
|
+
|
|
1504
|
+
**角色**: 审校已有稿件,逐条给出「哪里有问题 + 为什么 + 怎么改」。**默认不改写全文**。
|
|
1505
|
+
|
|
1506
|
+
**能力**:
|
|
1507
|
+
- **事实核查**:数字、日期、人名、机构名、术语、引用出处、版本号;与稿件自带依据或常识冲突的必须标出
|
|
1508
|
+
- **逻辑检查**:论点与论据是否对应、因果是否成立、有无循环论证 / 稻草人 / 以偏概全、前后是否自相矛盾
|
|
1509
|
+
- **结构检查**:章节顺序是否服务主题、有无重复段落、有无只起过渡作用却不承载信息的小节
|
|
1510
|
+
- **文字检查**:错别字、生造词、中英混排空格、全角/半角标点、书名号与引号误用、单位与符号规范
|
|
1511
|
+
- **一致性检查**:同一概念是否多种叫法、人称是否漂移、标题层级是否跳级
|
|
1512
|
+
|
|
1513
|
+
## 职责边界(硬性)
|
|
1514
|
+
|
|
1515
|
+
- **默认只给建议,不改写**。输出是「问题清单 + 建议改法」,作者自己动手。
|
|
1516
|
+
- **例外(仅在明确要求时才做)**:任务书出现「直接改稿 / 出终稿 / 帮我改好」时,才输出完整改写稿;并且在改写稿前先用清单说明改了哪些类问题。
|
|
1517
|
+
- **不追加内容**。不改观点、不加论证、不补案例、不替作者表态;缺素材只写「此处缺论据,建议补 X 类证据」。
|
|
1518
|
+
- **不重复写作**。认为某节需要重写,指出「需重写」及理由,不自行动笔。
|
|
1519
|
+
- **不查外部资料**。需要外部依据时标注「待查:<具体问题>」,交回需要联网的角色。
|
|
1520
|
+
|
|
1521
|
+
## 输入契约
|
|
1522
|
+
|
|
1523
|
+
审稿前确认:稿件原文(或路径)、目标读者与用途、字数是否受限、是否有既定风格规范。缺稿件不臆测——直接说明需要原文。
|
|
1524
|
+
|
|
1525
|
+
## 输出规范
|
|
1526
|
+
|
|
1527
|
+
按严重度分三级,逐条编号,每条必须能定位:
|
|
1528
|
+
|
|
1529
|
+
\`\`\`
|
|
1530
|
+
<summary> 稿件概况:字数、体裁、总问题数(严重/建议/文字) </summary>
|
|
1531
|
+
|
|
1532
|
+
<critical> 严重(必须改,否则不可发布)
|
|
1533
|
+
1. [第 N 节 / "原文片段"] 问题类型(事实/逻辑/合规)
|
|
1534
|
+
- 问题:具体错在哪
|
|
1535
|
+
- 建议:改成什么,或补什么依据
|
|
1536
|
+
|
|
1537
|
+
<suggestions> 建议(可优化)
|
|
1538
|
+
1. [第 N 节] 问题类型(结构/表达/一致性)
|
|
1539
|
+
- 问题/建议
|
|
1540
|
+
|
|
1541
|
+
<typos> 文字与标点(逐条列,可直接替换)
|
|
1542
|
+
- "错→对"(出现位置)
|
|
1543
|
+
|
|
1544
|
+
<verdict> 结论:可发布 / 修改后可发布 / 需重写(给一句理由) </verdict>
|
|
1545
|
+
\`\`\`
|
|
1546
|
+
|
|
1547
|
+
- 每条问题必须引用原文片段或精确位置(节号 / 段号),否则视为无效意见
|
|
1548
|
+
- 不写「语言可以更优美」这类空泛评价;要说清「哪一句、什么问题、改成什么」
|
|
1549
|
+
- 「建议改法」给最小改动版,不做风格化重写
|
|
1550
|
+
|
|
1551
|
+
## 禁止事项
|
|
1552
|
+
|
|
1553
|
+
- 禁在未明确要求时输出整篇改写稿
|
|
1554
|
+
- 禁把「我更喜欢这种写法」当作问题提出;只报客观缺陷(错、矛盾、歧义、不合规范)
|
|
1555
|
+
- 禁编造事实来源或凭空断言原作「数据错误」——无依据时写「无法核实,建议补出处」
|
|
1556
|
+
- 禁只报「有问题」不给改法;也禁只给改法不说问题
|
|
1557
|
+
- 禁改作者立场与观点
|
|
1558
|
+
|
|
1559
|
+
**语言要求**: 始终使用中文思考与回复。引用原文片段保持原样(含其错误),便于作者定位。
|
|
1560
|
+
`
|
|
1561
|
+
},
|
|
1562
|
+
{
|
|
1563
|
+
name: "co-outliner",
|
|
1564
|
+
description: "中文选题与写作提纲——结构设计 + 素材清单(只读+联网)",
|
|
1565
|
+
brief: "你是 Outliner,中文内容创作的前置角色:把模糊需求收敛成可写的选题(读者/核心主张/差异点),输出写作提纲(2-4 个一级节 + 每节论证任务)、素材清单与待查清单、需作者确认项(≤3)。不写成稿、不代查外部资料(列入 <to-research> 交 librarian)、不拍板不可逆决策。输出 <summary>/<outline>/<materials>/<to-research>/<open-questions>。全中文。",
|
|
1566
|
+
source: "dsh-cohub",
|
|
1567
|
+
content: `你是 Outliner——中文内容创作的前置角色:选题、调研提纲、结构设计、素材清单。
|
|
1568
|
+
|
|
1569
|
+
**角色**: 在动笔之前把「写什么、给谁写、按什么顺序写、需要哪些素材」定清楚,产出可直接交给 writer 的写作提纲。
|
|
1570
|
+
|
|
1571
|
+
**能力**:
|
|
1572
|
+
- **选题收敛**:把模糊需求收敛成一个可写的题目——目标读者、核心主张(一句话)、与读者既有认知的差异点
|
|
1573
|
+
- **调研提纲**:列出「必须查清的事实」清单(谁、何时、多少、依据出处),标出哪些是硬事实、哪些是观点
|
|
1574
|
+
- **结构设计**:给出层级目录(2-4 个一级节,每节 2-4 个要点),说明每节的论证任务(立论 / 举证 / 反驳 / 收束)
|
|
1575
|
+
- **素材清单**:每节需要什么类型的素材(数据、案例、引文、对比、图示),标注来源候选与缺失项
|
|
1576
|
+
|
|
1577
|
+
## 职责边界(硬性)
|
|
1578
|
+
|
|
1579
|
+
- **不写成稿**。你产出提纲与清单,不产出正文段落;示例句最多一句,用来锁定口吻。
|
|
1580
|
+
- **不代查外部资料**。需要联网核实的事实列成「待查清单」交 librarian / 主代理;你只做结构设计与需求拆解。
|
|
1581
|
+
- **不拍板不可逆决策**。涉及立场、敏感表述、对外署名口径的,写成「需作者确认项」,不代替作者决定。
|
|
1582
|
+
- **不重复已定事实**。任务书已给定的读者/篇幅/口吻直接沿用,不重新质疑。
|
|
1583
|
+
|
|
1584
|
+
## 输入契约
|
|
1585
|
+
|
|
1586
|
+
先确认四项,缺项可给「默认值 + 一句说明」继续推进,但必须在输出里标出用的是默认值:
|
|
1587
|
+
1. 主题与大致方向(一句话即可)
|
|
1588
|
+
2. 目标读者与发布渠道
|
|
1589
|
+
3. 期望篇幅与体裁
|
|
1590
|
+
4. 硬约束(发布时间、必须覆盖的点、必须回避的点)
|
|
1591
|
+
|
|
1592
|
+
## 输出规范
|
|
1593
|
+
|
|
1594
|
+
\`\`\`
|
|
1595
|
+
<summary> 选题一句话 + 目标读者 + 核心主张 + 建议篇幅 </summary>
|
|
1596
|
+
|
|
1597
|
+
<outline>
|
|
1598
|
+
## 1. <节标题>(本节任务:立论 / 举证 / 对比 / 收束)
|
|
1599
|
+
- 要点 1
|
|
1600
|
+
- 要点 2
|
|
1601
|
+
## 2. ...
|
|
1602
|
+
</outline>
|
|
1603
|
+
|
|
1604
|
+
<materials> 素材清单(按节分组)
|
|
1605
|
+
- 第 1 节:需 <数据类型>,来源候选 <X>,是否已具备:是/待查
|
|
1606
|
+
|
|
1607
|
+
<to-research> 待查清单(交给 librarian / 主代理)
|
|
1608
|
+
- <具体要查什么> —— 为什么需要(支撑哪一节哪个论点)
|
|
1609
|
+
|
|
1610
|
+
<open-questions> 需作者确认(≤3 条,超出说明需求过大建议拆分)
|
|
1611
|
+
</open-questions>
|
|
1612
|
+
\`\`\`
|
|
1613
|
+
|
|
1614
|
+
- 提纲层级不超过三层;一级节 2-4 个,单节要点 2-4 条
|
|
1615
|
+
- 每个要点是一句「可写的断言」或「必须回答的问题」,不写空标签(如「背景介绍」「总结」要说明介绍什么、总结什么)
|
|
1616
|
+
- 核心主张必须是一句可被反驳的话;写不出可被反驳的主张说明选题还没收敛
|
|
1617
|
+
- 待查清单每条都要能直接作为检索词,不写「查一些资料」这种无法执行的任务
|
|
1618
|
+
|
|
1619
|
+
## 禁止事项
|
|
1620
|
+
|
|
1621
|
+
- 禁输出成稿正文(>2 句的连续段落即违规)
|
|
1622
|
+
- 禁把待查事实直接写成结论(不确定就进 \`<to-research>\`)
|
|
1623
|
+
- 禁给出超过 4 个一级节的结构——需求过大时明确建议拆分为多篇,而不是堆一张巨型提纲
|
|
1624
|
+
- 禁使用「深入探讨」「全面分析」这类无信息量的节标题
|
|
1625
|
+
- 禁在素材清单里填编造的数据、案例或链接
|
|
1626
|
+
|
|
1627
|
+
**语言要求**: 始终使用中文思考与回复。提纲与要点一律中文;专有名词与术语可保留原文。
|
|
1265
1628
|
`
|
|
1266
1629
|
}
|
|
1267
1630
|
];
|
|
1268
1631
|
|
|
1632
|
+
// src/roles.ts
|
|
1633
|
+
var ALL_TIERS = ["ro", "ro-net", "rw", "rw-shell", "cordis"];
|
|
1634
|
+
var TIER_TO_PRESET = {
|
|
1635
|
+
ro: "cohub-subagent-readonly",
|
|
1636
|
+
"ro-net": "cohub-subagent-readonly-net",
|
|
1637
|
+
rw: "cohub-subagent-write",
|
|
1638
|
+
"rw-shell": "cohub-subagent-write-shell",
|
|
1639
|
+
cordis: "cohub-cordis"
|
|
1640
|
+
};
|
|
1641
|
+
var BUILTIN_ROLE_TIERS = {
|
|
1642
|
+
"co-explorer": "ro",
|
|
1643
|
+
"co-oracle": "ro",
|
|
1644
|
+
"co-planner": "ro",
|
|
1645
|
+
"co-council": "ro",
|
|
1646
|
+
"co-observer": "ro",
|
|
1647
|
+
"co-rule-user": "ro",
|
|
1648
|
+
"co-rule-project": "ro",
|
|
1649
|
+
"co-rule-app": "ro",
|
|
1650
|
+
"co-editor": "ro",
|
|
1651
|
+
"co-librarian": "ro-net",
|
|
1652
|
+
"co-outliner": "ro-net",
|
|
1653
|
+
"co-designer": "rw",
|
|
1654
|
+
"co-writer": "rw",
|
|
1655
|
+
"co-fixer": "rw-shell",
|
|
1656
|
+
"co-cordis": "cordis"
|
|
1657
|
+
};
|
|
1658
|
+
var SHELL_TOOL = process.platform === "win32" ? "pwsh" : "bash";
|
|
1659
|
+
var UNIVERSAL_DENY = [
|
|
1660
|
+
"ask_user_question",
|
|
1661
|
+
"create_goal",
|
|
1662
|
+
"update_goal",
|
|
1663
|
+
"get_goal",
|
|
1664
|
+
"weather",
|
|
1665
|
+
"video_search"
|
|
1666
|
+
];
|
|
1667
|
+
var READ_ONLY_DENY = [
|
|
1668
|
+
"write",
|
|
1669
|
+
"edit",
|
|
1670
|
+
SHELL_TOOL,
|
|
1671
|
+
"create_worktree",
|
|
1672
|
+
"workflow",
|
|
1673
|
+
"delegate",
|
|
1674
|
+
"delegate_batch",
|
|
1675
|
+
"subagent",
|
|
1676
|
+
"subagent_fork"
|
|
1677
|
+
];
|
|
1678
|
+
var WRITE_DENY = [
|
|
1679
|
+
"create_worktree",
|
|
1680
|
+
"workflow",
|
|
1681
|
+
"delegate",
|
|
1682
|
+
"delegate_batch",
|
|
1683
|
+
"subagent",
|
|
1684
|
+
"subagent_fork"
|
|
1685
|
+
];
|
|
1686
|
+
var TIER_TOOLS = {
|
|
1687
|
+
ro: { deny: [...READ_ONLY_DENY, ...UNIVERSAL_DENY] },
|
|
1688
|
+
"ro-net": { deny: [...READ_ONLY_DENY, ...UNIVERSAL_DENY] },
|
|
1689
|
+
rw: { deny: [...WRITE_DENY, ...UNIVERSAL_DENY] },
|
|
1690
|
+
"rw-shell": { deny: [...WRITE_DENY, ...UNIVERSAL_DENY] },
|
|
1691
|
+
cordis: { deny: [...WRITE_DENY, ...UNIVERSAL_DENY] }
|
|
1692
|
+
};
|
|
1693
|
+
function isTier(value) {
|
|
1694
|
+
return typeof value === "string" && ALL_TIERS.includes(value);
|
|
1695
|
+
}
|
|
1696
|
+
function resolveTier(roleName, customRoles) {
|
|
1697
|
+
const key = (roleName ?? "").trim();
|
|
1698
|
+
if (key.length === 0)
|
|
1699
|
+
return null;
|
|
1700
|
+
const custom = customRoles?.find((role) => (role?.name ?? "").trim() === key);
|
|
1701
|
+
if (custom && isTier(custom.tier))
|
|
1702
|
+
return custom.tier;
|
|
1703
|
+
const builtin = BUILTIN_ROLE_TIERS[key];
|
|
1704
|
+
return builtin ?? null;
|
|
1705
|
+
}
|
|
1706
|
+
function presetForTier(tier) {
|
|
1707
|
+
const preset = TIER_TO_PRESET[tier];
|
|
1708
|
+
return typeof preset === "string" && preset.length > 0 ? preset : TIER_TO_PRESET["rw-shell"];
|
|
1709
|
+
}
|
|
1710
|
+
var CUSTOM_ROLE_SOURCE = "dsh-cohub:customRole";
|
|
1711
|
+
function resolveSkillSnapshot(config) {
|
|
1712
|
+
const roles = COHUB_SKILLS.map((skill) => ({
|
|
1713
|
+
skill,
|
|
1714
|
+
tier: BUILTIN_ROLE_TIERS[skill.name] ?? null,
|
|
1715
|
+
builtin: true
|
|
1716
|
+
}));
|
|
1717
|
+
const position = new Map(roles.map((role, index) => [role.skill.name, index]));
|
|
1718
|
+
for (const raw of config?.customRoles ?? []) {
|
|
1719
|
+
const name = (raw?.name ?? "").trim();
|
|
1720
|
+
if (name.length === 0)
|
|
1721
|
+
continue;
|
|
1722
|
+
const prompt = typeof raw.prompt === "string" ? raw.prompt.trim() : "";
|
|
1723
|
+
const description = typeof raw.description === "string" && raw.description.trim().length > 0 ? raw.description : "用户自定义角色 " + name;
|
|
1724
|
+
const tier = isTier(raw.tier) ? raw.tier : BUILTIN_ROLE_TIERS[name] ?? null;
|
|
1725
|
+
const at = position.get(name);
|
|
1726
|
+
if (at === undefined) {
|
|
1727
|
+
position.set(name, roles.length);
|
|
1728
|
+
roles.push({
|
|
1729
|
+
skill: { name, description, brief: prompt, source: CUSTOM_ROLE_SOURCE, content: prompt },
|
|
1730
|
+
tier,
|
|
1731
|
+
builtin: false
|
|
1732
|
+
});
|
|
1733
|
+
} else {
|
|
1734
|
+
const prev = roles[at];
|
|
1735
|
+
roles[at] = {
|
|
1736
|
+
skill: {
|
|
1737
|
+
...prev.skill,
|
|
1738
|
+
description,
|
|
1739
|
+
brief: prompt.length > 0 ? prompt : prev.skill.brief,
|
|
1740
|
+
content: prompt.length > 0 ? prompt : prev.skill.content
|
|
1741
|
+
},
|
|
1742
|
+
tier,
|
|
1743
|
+
builtin: false
|
|
1744
|
+
};
|
|
1745
|
+
}
|
|
1746
|
+
}
|
|
1747
|
+
const disabled = new Set((config?.disabledSkills ?? []).map((name) => (name ?? "").trim()).filter((name) => name.length > 0));
|
|
1748
|
+
const byName = new Map(roles.map((role) => [role.skill.name, role]));
|
|
1749
|
+
return {
|
|
1750
|
+
roles,
|
|
1751
|
+
names: roles.map((role) => role.skill.name),
|
|
1752
|
+
resolve(roleName) {
|
|
1753
|
+
const key = (roleName ?? "").trim();
|
|
1754
|
+
if (key.length === 0)
|
|
1755
|
+
return { ok: false, reason: "unknown" };
|
|
1756
|
+
if (disabled.has(key))
|
|
1757
|
+
return { ok: false, reason: "disabled" };
|
|
1758
|
+
const role = byName.get(key);
|
|
1759
|
+
return role === undefined ? { ok: false, reason: "unknown" } : { ok: true, role };
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
// src/custom-skills.ts
|
|
1765
|
+
var CUSTOM_SKILL_SOURCE = "runtime";
|
|
1766
|
+
var CUSTOM_SKILL_TIER_KEY = "tier";
|
|
1767
|
+
var NAME_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
1768
|
+
var CUSTOM_ROLE_POLL_MS = 1000;
|
|
1769
|
+
var BUILTIN_SKILL_NAMES = COHUB_SKILLS.map((skill) => skill.name);
|
|
1770
|
+
function text(value) {
|
|
1771
|
+
return typeof value === "string" ? value : "";
|
|
1772
|
+
}
|
|
1773
|
+
function planCustomSkills(roles, builtinNames = BUILTIN_SKILL_NAMES) {
|
|
1774
|
+
const registrations = [];
|
|
1775
|
+
const warnings = [];
|
|
1776
|
+
const skips = [];
|
|
1777
|
+
const builtin = new Set(builtinNames);
|
|
1778
|
+
const seen = new Set;
|
|
1779
|
+
for (const [index, role] of (Array.isArray(roles) ? roles : []).entries()) {
|
|
1780
|
+
const name = text(role?.name).trim();
|
|
1781
|
+
const where = `customRoles[${index}]` + (name.length > 0 ? `(${name})` : "");
|
|
1782
|
+
if (name.length === 0) {
|
|
1783
|
+
warnings.push(`cohub: ${where} 缺少角色名,已跳过`);
|
|
1784
|
+
skips.push({ name, reason: "invalid-name" });
|
|
1785
|
+
continue;
|
|
1786
|
+
}
|
|
1787
|
+
if (!NAME_PATTERN.test(name)) {
|
|
1788
|
+
warnings.push(`cohub: ${where} 角色名不是 kebab-case(只允许 a-z0-9 与单个连字符),已跳过`);
|
|
1789
|
+
skips.push({ name, reason: "invalid-name" });
|
|
1790
|
+
continue;
|
|
1791
|
+
}
|
|
1792
|
+
if (builtin.has(name)) {
|
|
1793
|
+
warnings.push(`cohub: ${where} 与内置角色重名,已跳过(内置角色优先)`);
|
|
1794
|
+
skips.push({ name, reason: "builtin-conflict" });
|
|
1795
|
+
continue;
|
|
1796
|
+
}
|
|
1797
|
+
if (seen.has(name)) {
|
|
1798
|
+
warnings.push(`cohub: ${where} 与此前自定义角色重名,已跳过(保留第一条)`);
|
|
1799
|
+
skips.push({ name, reason: "duplicate" });
|
|
1800
|
+
continue;
|
|
1801
|
+
}
|
|
1802
|
+
if (!isTier(role?.tier)) {
|
|
1803
|
+
warnings.push(`cohub: ${where} tier 非法(${String(role?.tier)}),已跳过;合法值:ro / ro-net / rw / rw-shell / cordis`);
|
|
1804
|
+
skips.push({ name, reason: "invalid-tier" });
|
|
1805
|
+
continue;
|
|
1806
|
+
}
|
|
1807
|
+
seen.add(name);
|
|
1808
|
+
const description = text(role?.description).trim();
|
|
1809
|
+
registrations.push({
|
|
1810
|
+
name,
|
|
1811
|
+
description: description.length > 0 ? description : `${name}(用户自定义角色)`,
|
|
1812
|
+
content: text(role?.prompt),
|
|
1813
|
+
source: CUSTOM_SKILL_SOURCE,
|
|
1814
|
+
metadata: { [CUSTOM_SKILL_TIER_KEY]: role.tier, custom: true }
|
|
1815
|
+
});
|
|
1816
|
+
}
|
|
1817
|
+
return { registrations, warnings, skips };
|
|
1818
|
+
}
|
|
1819
|
+
function fingerprint(skill) {
|
|
1820
|
+
return [skill.name, skill.description, skill.content, String(skill.metadata[CUSTOM_SKILL_TIER_KEY])].join("\x00");
|
|
1821
|
+
}
|
|
1822
|
+
function createCustomSkillRegistry(options) {
|
|
1823
|
+
const { skills, getRoles, logger } = options;
|
|
1824
|
+
const builtinNames = options.builtinNames ?? BUILTIN_SKILL_NAMES;
|
|
1825
|
+
const setTimer = options.setInterval ?? ((fn, ms) => setInterval(fn, ms));
|
|
1826
|
+
const clearTimer = options.clearInterval ?? ((handle) => clearInterval(handle));
|
|
1827
|
+
const active = new Map;
|
|
1828
|
+
const warned = new Set;
|
|
1829
|
+
let lastSignature = null;
|
|
1830
|
+
let timer = null;
|
|
1831
|
+
let disposed = false;
|
|
1832
|
+
function warnOnce(message) {
|
|
1833
|
+
if (warned.has(message))
|
|
1834
|
+
return;
|
|
1835
|
+
warned.add(message);
|
|
1836
|
+
logger?.warn?.(message);
|
|
1837
|
+
}
|
|
1838
|
+
const skipLogged = new Set;
|
|
1839
|
+
function logSkips(skips) {
|
|
1840
|
+
for (const skip of skips) {
|
|
1841
|
+
const key = `${skip.reason}\x00${skip.name}`;
|
|
1842
|
+
if (skipLogged.has(key))
|
|
1843
|
+
continue;
|
|
1844
|
+
skipLogged.add(key);
|
|
1845
|
+
const shown = skip.name.length > 0 ? skip.name : "<empty>";
|
|
1846
|
+
console.log("[cohub/custom-role] skipped name=" + shown + " reason=" + skip.reason);
|
|
1847
|
+
logger?.info?.(`[cohub/custom-role] skipped name=${shown} reason=${skip.reason}`);
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
function sync() {
|
|
1851
|
+
if (disposed)
|
|
1852
|
+
return;
|
|
1853
|
+
const plan = planCustomSkills(getRoles(), builtinNames);
|
|
1854
|
+
for (const message of plan.warnings)
|
|
1855
|
+
warnOnce(message);
|
|
1856
|
+
logSkips(plan.skips);
|
|
1857
|
+
const signature = plan.registrations.map(fingerprint).join("\x01");
|
|
1858
|
+
if (signature === lastSignature)
|
|
1859
|
+
return;
|
|
1860
|
+
lastSignature = signature;
|
|
1861
|
+
const next = new Map(plan.registrations.map((skill) => [skill.name, skill]));
|
|
1862
|
+
let added = 0;
|
|
1863
|
+
let removed = 0;
|
|
1864
|
+
let updated = 0;
|
|
1865
|
+
const rebuilt = new Set;
|
|
1866
|
+
for (const [name, entry] of [...active]) {
|
|
1867
|
+
const upcoming = next.get(name);
|
|
1868
|
+
if (upcoming !== undefined && fingerprint(upcoming) === entry.print)
|
|
1869
|
+
continue;
|
|
1870
|
+
try {
|
|
1871
|
+
entry.dispose();
|
|
1872
|
+
console.log("[cohub/custom-role] disposed name=" + name);
|
|
1873
|
+
logger?.info?.(`[cohub/custom-role] disposed name=${name}`);
|
|
1874
|
+
if (upcoming !== undefined) {
|
|
1875
|
+
updated += 1;
|
|
1876
|
+
rebuilt.add(name);
|
|
1877
|
+
} else {
|
|
1878
|
+
removed += 1;
|
|
1879
|
+
}
|
|
1880
|
+
} catch (error) {
|
|
1881
|
+
logger?.warn?.(`cohub: 注销自定义角色技能 ${name} 失败(忽略)`, error);
|
|
1882
|
+
}
|
|
1883
|
+
active.delete(name);
|
|
1884
|
+
}
|
|
1885
|
+
for (const skill of plan.registrations) {
|
|
1886
|
+
if (active.has(skill.name))
|
|
1887
|
+
continue;
|
|
1888
|
+
try {
|
|
1889
|
+
const off = skills.register(skill);
|
|
1890
|
+
active.set(skill.name, {
|
|
1891
|
+
dispose: typeof off === "function" ? off : () => {},
|
|
1892
|
+
print: fingerprint(skill)
|
|
1893
|
+
});
|
|
1894
|
+
console.log("[cohub/custom-role] registered name=" + skill.name + " tier=" + String(skill.metadata[CUSTOM_SKILL_TIER_KEY]));
|
|
1895
|
+
logger?.info?.(`[cohub/custom-role] registered name=${skill.name} tier=${String(skill.metadata[CUSTOM_SKILL_TIER_KEY])}`);
|
|
1896
|
+
if (!rebuilt.has(skill.name))
|
|
1897
|
+
added += 1;
|
|
1898
|
+
} catch (error) {
|
|
1899
|
+
logger?.warn?.(`cohub: 注册自定义角色技能 ${skill.name} 失败(跳过)`, error);
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
console.log("[cohub/custom-role] sync changed added=" + added + " removed=" + removed + " updated=" + updated);
|
|
1903
|
+
logger?.info?.(`[cohub/custom-role] sync changed added=${added} removed=${removed} updated=${updated}`);
|
|
1904
|
+
if (plan.registrations.length > 0) {
|
|
1905
|
+
logger?.info?.(`cohub: 自定义角色技能 ${active.size} 个(${[...active.keys()].join(", ")})`);
|
|
1906
|
+
}
|
|
1907
|
+
}
|
|
1908
|
+
return {
|
|
1909
|
+
sync,
|
|
1910
|
+
active: () => [...active.keys()],
|
|
1911
|
+
start(intervalMs = CUSTOM_ROLE_POLL_MS) {
|
|
1912
|
+
sync();
|
|
1913
|
+
console.log("[cohub/custom-role] watcher started interval=" + intervalMs);
|
|
1914
|
+
logger?.info?.(`[cohub/custom-role] watcher started interval=${intervalMs}`);
|
|
1915
|
+
if (timer !== null || intervalMs <= 0)
|
|
1916
|
+
return () => {};
|
|
1917
|
+
timer = setTimer(() => {
|
|
1918
|
+
try {
|
|
1919
|
+
sync();
|
|
1920
|
+
} catch (error) {
|
|
1921
|
+
logger?.warn?.("cohub: 自定义角色对账失败(忽略)", error);
|
|
1922
|
+
}
|
|
1923
|
+
}, intervalMs);
|
|
1924
|
+
const handle = timer;
|
|
1925
|
+
if (typeof handle?.unref === "function")
|
|
1926
|
+
handle.unref();
|
|
1927
|
+
return () => {
|
|
1928
|
+
if (timer !== null) {
|
|
1929
|
+
clearTimer(timer);
|
|
1930
|
+
timer = null;
|
|
1931
|
+
}
|
|
1932
|
+
};
|
|
1933
|
+
},
|
|
1934
|
+
dispose() {
|
|
1935
|
+
disposed = true;
|
|
1936
|
+
if (timer !== null) {
|
|
1937
|
+
clearTimer(timer);
|
|
1938
|
+
timer = null;
|
|
1939
|
+
}
|
|
1940
|
+
for (const [name, entry] of active) {
|
|
1941
|
+
try {
|
|
1942
|
+
entry.dispose();
|
|
1943
|
+
console.log("[cohub/custom-role] disposed name=" + name);
|
|
1944
|
+
logger?.info?.(`[cohub/custom-role] disposed name=${name}`);
|
|
1945
|
+
} catch {
|
|
1946
|
+
logger?.warn?.(`cohub: 卸载时注销自定义角色技能 ${name} 失败(忽略)`);
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
active.clear();
|
|
1950
|
+
lastSignature = null;
|
|
1951
|
+
}
|
|
1952
|
+
};
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1269
1955
|
// src/council.ts
|
|
1270
1956
|
import { defineTool as defineTool2 } from "@deepseek-ai/dsh-tools";
|
|
1271
1957
|
|
|
@@ -1620,15 +2306,8 @@ var DEFAULT_BATCH_TASK_CHARS = 2500;
|
|
|
1620
2306
|
var DEFAULT_BATCH_TOTAL_CHARS = 6000;
|
|
1621
2307
|
var DEFAULT_CONTEXT_WARN_TOKENS = 60000;
|
|
1622
2308
|
var MIN_BUDGET_CHARS = 200;
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
};
|
|
1626
|
-
function resolveSkillResultMaxChars(budget, skillName) {
|
|
1627
|
-
const key = typeof skillName === "string" ? skillName.trim() : "";
|
|
1628
|
-
const tier = key.length > 0 ? SKILL_RESULT_BUDGET_CHARS[key] : undefined;
|
|
1629
|
-
if (tier === undefined)
|
|
1630
|
-
return budget.maxChars;
|
|
1631
|
-
return Math.max(MIN_BUDGET_CHARS, Math.min(budget.maxChars, tier));
|
|
2309
|
+
function resolveSkillResultMaxChars(budget, _skillName) {
|
|
2310
|
+
return budget.maxChars;
|
|
1632
2311
|
}
|
|
1633
2312
|
var XML_TAGS = ["summary", "results", "answer", "changes", "verification", "risk"];
|
|
1634
2313
|
var PRIMARY_XML_TAGS = ["results", "answer"];
|
|
@@ -1640,7 +2319,7 @@ var SEP = `
|
|
|
1640
2319
|
`;
|
|
1641
2320
|
var LOCATOR_FALLBACK = "落盘失败";
|
|
1642
2321
|
var OVERHEAD_RESERVE = 24;
|
|
1643
|
-
var USAGE_HINT = "
|
|
2322
|
+
var USAGE_HINT = "(全文已完整保存在该文件,主代理需要明细时直接 read(同一 locator 最多读 2 次);子代理无需为控字数删减内容)";
|
|
1644
2323
|
var CONTRACT_CLIP_MARK = `
|
|
1645
2324
|
…[契约段自身超预算,已中段省略]…
|
|
1646
2325
|
`;
|
|
@@ -4182,27 +4861,7 @@ function formatContractViolation(errors) {
|
|
|
4182
4861
|
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 调度;该工具可用时)。";
|
|
4183
4862
|
var DELEGATE_PERSONA = "你是被委派的专职代理:严格遵循任务消息中的角色定义、关键约束、输出格式与工具指令,并完成末尾的具体任务。" + "你的首条用户消息(下方任务书)已含 `--- 你的具体任务 ---` 分隔符,即身份判据成立:不要调用 skill 工具加载 co-orchestrator 技能——技能指令已由 brief 注入。" + PARALLEL_TOOL_DISCIPLINE;
|
|
4184
4863
|
var DEFAULT_SPAWN_TRANSPORT = "spawn";
|
|
4185
|
-
var
|
|
4186
|
-
var READ_ONLY_DENY = [
|
|
4187
|
-
"write",
|
|
4188
|
-
"edit",
|
|
4189
|
-
SHELL_TOOL,
|
|
4190
|
-
"create_worktree",
|
|
4191
|
-
"workflow",
|
|
4192
|
-
"delegate",
|
|
4193
|
-
"delegate_batch",
|
|
4194
|
-
"subagent",
|
|
4195
|
-
"subagent_fork"
|
|
4196
|
-
];
|
|
4197
|
-
var WRITE_DENY = [
|
|
4198
|
-
"create_worktree",
|
|
4199
|
-
"workflow",
|
|
4200
|
-
"delegate",
|
|
4201
|
-
"delegate_batch",
|
|
4202
|
-
"subagent",
|
|
4203
|
-
"subagent_fork"
|
|
4204
|
-
];
|
|
4205
|
-
var UNIVERSAL_DENY = [
|
|
4864
|
+
var UNIVERSAL_DENY2 = [
|
|
4206
4865
|
"ask_user_question",
|
|
4207
4866
|
"create_goal",
|
|
4208
4867
|
"update_goal",
|
|
@@ -4210,28 +4869,20 @@ var UNIVERSAL_DENY = [
|
|
|
4210
4869
|
"weather",
|
|
4211
4870
|
"video_search"
|
|
4212
4871
|
];
|
|
4213
|
-
|
|
4214
|
-
"
|
|
4215
|
-
|
|
4216
|
-
"co-planner",
|
|
4217
|
-
"co-council",
|
|
4218
|
-
"co-observer",
|
|
4219
|
-
"co-librarian",
|
|
4220
|
-
"co-rule-user",
|
|
4221
|
-
"co-rule-project",
|
|
4222
|
-
"co-rule-app"
|
|
4223
|
-
]);
|
|
4224
|
-
var WRITE_SKILLS = new Set(["co-fixer", "co-designer", "co-cordis"]);
|
|
4872
|
+
function fallbackPresetForTier(tier) {
|
|
4873
|
+
return tier === "rw" || tier === "rw-shell" || tier === "cordis" ? SUBAGENT_WRITE_PRESET : SUBAGENT_READONLY_PRESET;
|
|
4874
|
+
}
|
|
4225
4875
|
var DEFAULT_FALLBACK_SKILL = "co-fixer";
|
|
4226
|
-
function resolveSkillToolFilter(skillName, enabled = true, logger) {
|
|
4876
|
+
function resolveSkillToolFilter(skillName, enabled = true, logger, customRoles) {
|
|
4227
4877
|
if (!enabled)
|
|
4228
4878
|
return;
|
|
4229
4879
|
try {
|
|
4230
4880
|
const key = (skillName ?? "").trim();
|
|
4231
4881
|
if (key === "co-orchestrator")
|
|
4232
4882
|
return;
|
|
4233
|
-
const
|
|
4234
|
-
const
|
|
4883
|
+
const tier = resolveTier(key, customRoles);
|
|
4884
|
+
const base = tier === null ? UNIVERSAL_DENY2 : TIER_TOOLS[tier].deny;
|
|
4885
|
+
const deny = [...new Set([...base, ...UNIVERSAL_DENY2])];
|
|
4235
4886
|
return deny.length > 0 ? { deny } : undefined;
|
|
4236
4887
|
} catch (error) {
|
|
4237
4888
|
logger?.warn?.("[cohub toolfilter] 构造子代理工具裁剪失败,已回退全量工具:" + (error instanceof Error ? error.message : String(error)));
|
|
@@ -4240,19 +4891,22 @@ function resolveSkillToolFilter(skillName, enabled = true, logger) {
|
|
|
4240
4891
|
}
|
|
4241
4892
|
var SUBAGENT_READONLY_PRESET = "cohub-subagent-readonly";
|
|
4242
4893
|
var SUBAGENT_WRITE_PRESET = "cohub-subagent-write";
|
|
4243
|
-
function resolveSkillAgentPreset(skillName, enabled = true) {
|
|
4894
|
+
function resolveSkillAgentPreset(skillName, enabled = true, customRoles, logger) {
|
|
4244
4895
|
if (!enabled)
|
|
4245
4896
|
return;
|
|
4246
4897
|
const key = (skillName ?? "").trim();
|
|
4247
4898
|
if (key === "co-orchestrator")
|
|
4248
4899
|
return;
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
if (READ_ONLY_SKILLS.has(key))
|
|
4252
|
-
return SUBAGENT_READONLY_PRESET;
|
|
4253
|
-
if (WRITE_SKILLS.has(key))
|
|
4900
|
+
const tier = resolveTier(key, customRoles);
|
|
4901
|
+
if (tier === null)
|
|
4254
4902
|
return SUBAGENT_WRITE_PRESET;
|
|
4255
|
-
|
|
4903
|
+
const mapped = TIER_TO_PRESET[tier];
|
|
4904
|
+
if (typeof mapped !== "string" || mapped.length === 0) {
|
|
4905
|
+
const fallback = fallbackPresetForTier(tier);
|
|
4906
|
+
logger?.warn?.('[cohub preset] 档位 "' + tier + '"(skill=' + key + ")没有对应的子代理 preset," + "已降级为 " + fallback + "(不扩大权限)");
|
|
4907
|
+
return fallback;
|
|
4908
|
+
}
|
|
4909
|
+
return presetForTier(tier);
|
|
4256
4910
|
}
|
|
4257
4911
|
function intersectWithRestrictable(filter, restrictableNames) {
|
|
4258
4912
|
if (!filter || !restrictableNames)
|
|
@@ -4725,23 +5379,32 @@ class StallWatchdog {
|
|
|
4725
5379
|
});
|
|
4726
5380
|
}
|
|
4727
5381
|
}
|
|
4728
|
-
function resolveSkillAndRoute(requestedSkill, getRoutes, ctx, logger) {
|
|
5382
|
+
function resolveSkillAndRoute(requestedSkill, getRoutes, ctx, logger, snapshot) {
|
|
4729
5383
|
const requested = (typeof requestedSkill === "string" ? requestedSkill : "").trim();
|
|
4730
5384
|
const skillName = requested || DEFAULT_FALLBACK_SKILL;
|
|
4731
5385
|
const fallback = requested.length === 0;
|
|
4732
5386
|
const echoName = firstLineClamped(skillName, SKILL_NAME_ECHO_MAX) || "unknown";
|
|
4733
|
-
|
|
5387
|
+
const snap = snapshot ?? resolveSkillSnapshot();
|
|
5388
|
+
const lookup = snap.resolve(skillName);
|
|
5389
|
+
let role = lookup.ok ? lookup.role : undefined;
|
|
5390
|
+
const missReason = lookup.ok ? "unknown" : lookup.reason;
|
|
4734
5391
|
let note;
|
|
4735
|
-
if (
|
|
4736
|
-
|
|
4737
|
-
|
|
4738
|
-
|
|
5392
|
+
if (role === undefined) {
|
|
5393
|
+
const reason = missReason;
|
|
5394
|
+
(logger ?? ctx.logger)?.warn?.("delegate: " + (reason === "disabled" ? "disabled" : "unknown") + ' skill "' + skillName + '", falling back to co-fixer');
|
|
5395
|
+
const fallbackLookup = snap.resolve(DEFAULT_FALLBACK_SKILL);
|
|
5396
|
+
role = fallbackLookup.ok ? fallbackLookup.role : {
|
|
5397
|
+
skill: COHUB_SKILLS.find((s) => s.name === DEFAULT_FALLBACK_SKILL),
|
|
5398
|
+
tier: resolveTier(DEFAULT_FALLBACK_SKILL),
|
|
5399
|
+
builtin: true
|
|
5400
|
+
};
|
|
5401
|
+
note = reason === "disabled" ? '传入的 skill 名 "' + echoName + '" 存在但已被禁用(config.disabledSkills),已兜底为 ' + DEFAULT_FALLBACK_SKILL + ",子代理 preset 同步回退为实施类 " + SUBAGENT_WRITE_PRESET + ";如需使用请从禁用清单中移除,而不是改名" : '传入的 skill 名 "' + echoName + '" 未匹配任何角色(内置角色 + config.customRoles),已兜底为 ' + DEFAULT_FALLBACK_SKILL + ",子代理 preset 同步回退为实施类 " + SUBAGENT_WRITE_PRESET;
|
|
4739
5402
|
} else if (fallback) {
|
|
4740
5403
|
(logger ?? ctx.logger)?.warn?.("delegate: skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + ";schema 已要求必填,出现本告警说明调用绕过了参数校验");
|
|
4741
5404
|
note = "skill 未提供(缺字段/空串/纯空白),已兜底为 " + DEFAULT_FALLBACK_SKILL + ",子代理 preset 回退为实施类 " + SUBAGENT_WRITE_PRESET;
|
|
4742
5405
|
}
|
|
4743
5406
|
const route = (getRoutes() ?? []).find((s) => s.name === requested);
|
|
4744
|
-
return { skill, route, fallback, ...note === undefined ? {} : { note } };
|
|
5407
|
+
return { skill: role.skill, role, route, fallback, ...note === undefined ? {} : { note } };
|
|
4745
5408
|
}
|
|
4746
5409
|
function resolveRouteOutputContract(skillName, route) {
|
|
4747
5410
|
return resolveOutputContract(skillName, route?.outputContract);
|
|
@@ -5026,7 +5689,9 @@ function buildOutputContractBlock(schema) {
|
|
|
5026
5689
|
`;
|
|
5027
5690
|
}
|
|
5028
5691
|
function buildDelegatePrompt(params) {
|
|
5029
|
-
|
|
5692
|
+
const custom = (params.customPrompt ?? "").trim();
|
|
5693
|
+
const roleText = custom.length > 0 ? params.customPrompt : params.skill.brief || params.skill.content;
|
|
5694
|
+
return roleText + params.contractText + `
|
|
5030
5695
|
|
|
5031
5696
|
--- 你的具体任务 ---
|
|
5032
5697
|
|
|
@@ -5097,7 +5762,11 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
5097
5762
|
const { retry, stall, schedule, budget, background, subagentPresetEnabled } = resolveRuntimeConfig();
|
|
5098
5763
|
const RETRYABLE = new Set(retry.retryableReasons);
|
|
5099
5764
|
ctx.logger?.info?.("[cohub schedule] 生效调度参数:batch=" + (schedule?.maxParallelBatch ?? 5) + " wallMs=" + (schedule?.wallClockBudgetMs ?? WALL_CLOCK_BUDGET_MS));
|
|
5100
|
-
const
|
|
5765
|
+
const skillSnapshot = resolveSkillSnapshot({
|
|
5766
|
+
customRoles: config.customRoles,
|
|
5767
|
+
disabledSkills: config.disabledSkills
|
|
5768
|
+
});
|
|
5769
|
+
const { skill, role: skillRole, route, fallback: skillFallback, note: skillNote } = resolveSkillAndRoute(args.skill, getRoutes, ctx, ctx.logger, skillSnapshot);
|
|
5101
5770
|
const skillTag = formatSkillLabel(skill, skillFallback);
|
|
5102
5771
|
const outputContract = resolveRouteOutputContract(skill.name, route);
|
|
5103
5772
|
const contractActive = outputContract.level !== "off" && outputContract.schema !== undefined;
|
|
@@ -5109,7 +5778,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
5109
5778
|
}
|
|
5110
5779
|
const degradeNotes = [];
|
|
5111
5780
|
const agentOptions = await buildAgentOptions(route, ctx, skill.name, (note) => upsertDegradeNote(degradeNotes, note));
|
|
5112
|
-
const toolFilter = resolveSkillToolFilter(skill.name, config.toolFilter?.enabled ?? true, ctx.logger);
|
|
5781
|
+
const toolFilter = resolveSkillToolFilter(skill.name, config.toolFilter?.enabled ?? true, ctx.logger, config.customRoles);
|
|
5113
5782
|
if (skillNote !== undefined) {
|
|
5114
5783
|
upsertDegradeNote(degradeNotes, {
|
|
5115
5784
|
id: "skill",
|
|
@@ -5118,7 +5787,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
5118
5787
|
reason: skillNote
|
|
5119
5788
|
});
|
|
5120
5789
|
}
|
|
5121
|
-
const agentPreset = resolveSkillAgentPreset(skill.name, subagentPresetEnabled);
|
|
5790
|
+
const agentPreset = resolveSkillAgentPreset(skill.name, subagentPresetEnabled, config.customRoles, ctx.logger);
|
|
5122
5791
|
const fp = envFingerprint();
|
|
5123
5792
|
const contractResult = resolveContractText({ enabled: envContract.enabled, text: envContract.text }, envSig, ctx, fp);
|
|
5124
5793
|
const contractText = contractResult.text;
|
|
@@ -5158,6 +5827,7 @@ function createDelegateTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
5158
5827
|
[重试 #` + attempt + "] 上一次执行中止,原因:" + lastReason + (lastDiagnostic === undefined ? "" : ";诊断:" + lastDiagnostic) + ";已完成部分:" + (lastPartial || "(无)") + stallNote + "。请从中断处继续,不要重复已完成步骤。" : "";
|
|
5159
5828
|
const promptText = buildDelegatePrompt({
|
|
5160
5829
|
skill,
|
|
5830
|
+
...skillRole !== undefined && !skillRole.builtin && skillRole.skill.brief.length > 0 ? { customPrompt: skillRole.skill.brief } : {},
|
|
5161
5831
|
contractText,
|
|
5162
5832
|
userPrompt: args.prompt,
|
|
5163
5833
|
retryNote,
|
|
@@ -5738,15 +6408,22 @@ function validateTaskScope(scope) {
|
|
|
5738
6408
|
var BATCH_TASK_ID_ECHO_MAX = 40;
|
|
5739
6409
|
var KNOWN_SKILL_NAMES = COHUB_SKILLS.map((s) => s.name);
|
|
5740
6410
|
var SKILL_NAMES_TEXT = KNOWN_SKILL_NAMES.join(", ");
|
|
5741
|
-
|
|
5742
|
-
function assertKnownSkill(raw) {
|
|
6411
|
+
function assertKnownSkill(raw, snapshot) {
|
|
5743
6412
|
if (raw.length === 0)
|
|
5744
6413
|
return { ok: true };
|
|
5745
|
-
|
|
6414
|
+
const lookup = snapshot.resolve(raw);
|
|
6415
|
+
if (lookup.ok)
|
|
5746
6416
|
return { ok: true };
|
|
6417
|
+
const names = snapshot.names.join(" / ");
|
|
6418
|
+
if (lookup.reason === "disabled") {
|
|
6419
|
+
return {
|
|
6420
|
+
ok: false,
|
|
6421
|
+
error: `skill 名 "${raw}" 存在但已被禁用(config.disabledSkills),当前不可派发;` + `如需使用请将其从禁用清单中移除,而不是改名。可用角色:${names}`
|
|
6422
|
+
};
|
|
6423
|
+
}
|
|
5747
6424
|
return {
|
|
5748
6425
|
ok: false,
|
|
5749
|
-
error: `skill 名 "${raw}"
|
|
6426
|
+
error: `skill 名 "${raw}" 不存在。可用角色:${names}` + `(co-orchestrator 为主代理,通常委派用其余 ${snapshot.names.length - 1} 个)`
|
|
5750
6427
|
};
|
|
5751
6428
|
}
|
|
5752
6429
|
var MAX_BATCH_SIZE = 20;
|
|
@@ -5876,6 +6553,10 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
5876
6553
|
throw new Error(depthRejection);
|
|
5877
6554
|
}
|
|
5878
6555
|
const { wallClockBudgetMs, maxParallelBatch, budget, toolFilterEnabled, presetEnabled } = resolveRuntimeConfig();
|
|
6556
|
+
const skillSnapshot = resolveSkillSnapshot({
|
|
6557
|
+
customRoles: config.customRoles,
|
|
6558
|
+
disabledSkills: config.disabledSkills
|
|
6559
|
+
});
|
|
5879
6560
|
const tasks = args.tasks ?? [];
|
|
5880
6561
|
if (tasks.length === 0) {
|
|
5881
6562
|
return "delegate_batch: 无任务";
|
|
@@ -5910,7 +6591,7 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
5910
6591
|
const startedAt = Date.now();
|
|
5911
6592
|
const taskEvents = batchEvents[index];
|
|
5912
6593
|
pushBatchEvent(taskEvents, { taskId, phase: "started", at: startedAt });
|
|
5913
|
-
const skillCheck = assertKnownSkill(requestedSkill);
|
|
6594
|
+
const skillCheck = assertKnownSkill(requestedSkill, skillSnapshot);
|
|
5914
6595
|
if (!skillCheck.ok) {
|
|
5915
6596
|
ctx.logger?.warn?.('[cohub delegate_batch] task "' + taskId + '" 的 skill 名 "' + requestedSkill + '" 不在合法名单内,已按错误返回(不再静默降级为 ' + DEFAULT_FALLBACK_SKILL + ")");
|
|
5916
6597
|
return {
|
|
@@ -5945,7 +6626,7 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
5945
6626
|
scopeError: scopeCheck.error
|
|
5946
6627
|
};
|
|
5947
6628
|
}
|
|
5948
|
-
const { skill, route, note: skillNote } = resolveSkillAndRoute(requestedSkill, getRoutes, ctx, ctx.logger);
|
|
6629
|
+
const { skill, role: skillRole, route, note: skillNote } = resolveSkillAndRoute(requestedSkill, getRoutes, ctx, ctx.logger, skillSnapshot);
|
|
5949
6630
|
const taskNotes = [];
|
|
5950
6631
|
if (skillNote !== undefined) {
|
|
5951
6632
|
taskNotes.push({
|
|
@@ -5961,14 +6642,15 @@ function createDelegateBatchTool(ctx, getRoutes, config = {}, getSettings) {
|
|
|
5961
6642
|
const outputContractText = contractActive && outputContract.schema !== undefined ? buildOutputContractBlock(outputContract.schema) : "";
|
|
5962
6643
|
const buildPrompt = (rewriteNote) => buildDelegatePrompt({
|
|
5963
6644
|
skill,
|
|
6645
|
+
...skillRole !== undefined && !skillRole.builtin && skillRole.skill.brief.length > 0 ? { customPrompt: skillRole.skill.brief } : {},
|
|
5964
6646
|
contractText,
|
|
5965
6647
|
userPrompt: task.prompt,
|
|
5966
6648
|
...rewriteNote === undefined ? {} : { retryNote: rewriteNote },
|
|
5967
6649
|
outputContractText
|
|
5968
6650
|
});
|
|
5969
6651
|
const promptText = buildPrompt();
|
|
5970
|
-
const toolFilter = resolveSkillToolFilter(skill.name, toolFilterEnabled, ctx.logger);
|
|
5971
|
-
const agentPreset = resolveSkillAgentPreset(skill.name, presetEnabled);
|
|
6652
|
+
const toolFilter = resolveSkillToolFilter(skill.name, toolFilterEnabled, ctx.logger, config.customRoles);
|
|
6653
|
+
const agentPreset = resolveSkillAgentPreset(skill.name, presetEnabled, config.customRoles, ctx.logger);
|
|
5972
6654
|
const ac = new AbortController;
|
|
5973
6655
|
let onExecAbort = null;
|
|
5974
6656
|
if (exec.signal) {
|
|
@@ -7062,7 +7744,7 @@ var KIND_TITLE = {
|
|
|
7062
7744
|
function num2(v) {
|
|
7063
7745
|
return typeof v === "number" && Number.isFinite(v) ? String(v) : DASH;
|
|
7064
7746
|
}
|
|
7065
|
-
function
|
|
7747
|
+
function text2(v) {
|
|
7066
7748
|
return typeof v === "string" && v.length > 0 ? v : DASH;
|
|
7067
7749
|
}
|
|
7068
7750
|
function usageCell(usage) {
|
|
@@ -7080,7 +7762,7 @@ function toolCounts(turn) {
|
|
|
7080
7762
|
return { total: String(tools.length), errors: String(errors) };
|
|
7081
7763
|
}
|
|
7082
7764
|
function anchorOf(ev) {
|
|
7083
|
-
const base = `[${
|
|
7765
|
+
const base = `[${text2(ev?.sessionId)} · turn ${num2(ev?.turn)} · seq ${num2(ev?.seq)}]`;
|
|
7084
7766
|
return typeof ev?.callId === "string" && ev.callId.length > 0 ? `${base.slice(0, -1)} · call ${ev.callId}]` : base;
|
|
7085
7767
|
}
|
|
7086
7768
|
function excerptOf(raw, limit) {
|
|
@@ -7098,7 +7780,7 @@ function severityOf(finding) {
|
|
|
7098
7780
|
function renderFinding(finding, opts, excerptLimit) {
|
|
7099
7781
|
const out = [];
|
|
7100
7782
|
const sev = severityOf(finding);
|
|
7101
|
-
out.push(sev !== null ? `- **issue · ${sev}** — ${
|
|
7783
|
+
out.push(sev !== null ? `- **issue · ${sev}** — ${text2(finding?.text)}` : `- **${text2(finding?.text)}**`);
|
|
7102
7784
|
const evidence = Array.isArray(finding?.evidence) ? finding.evidence : [];
|
|
7103
7785
|
for (const ev of evidence)
|
|
7104
7786
|
out.push(` - 锚点:${anchorOf(ev)}`);
|
|
@@ -7118,7 +7800,7 @@ function renderFinding(finding, opts, excerptLimit) {
|
|
|
7118
7800
|
}
|
|
7119
7801
|
const limits = Array.isArray(finding?.limitations) ? finding.limitations : [];
|
|
7120
7802
|
for (const l of limits)
|
|
7121
|
-
out.push(` - 局限:${
|
|
7803
|
+
out.push(` - 局限:${text2(l)}`);
|
|
7122
7804
|
return out;
|
|
7123
7805
|
}
|
|
7124
7806
|
var STATUS_TITLE = {
|
|
@@ -7194,19 +7876,19 @@ function renderMarkdown(report, opts = {}) {
|
|
|
7194
7876
|
const lineageTotal = typeof coverage.lineageTotal === "number" && Number.isFinite(coverage.lineageTotal) ? coverage.lineageTotal : null;
|
|
7195
7877
|
const sessionsAnalyzedRaw = typeof coverage.sessionsAnalyzed === "number" && Number.isFinite(coverage.sessionsAnalyzed) ? coverage.sessionsAnalyzed : null;
|
|
7196
7878
|
const sessionsTruncatedEffective = inferSessionsTruncated(sessionsTruncated, lineageTotal, sessionsAnalyzedRaw);
|
|
7197
|
-
const samplingNote =
|
|
7879
|
+
const samplingNote = text2(coverage.samplingNote);
|
|
7198
7880
|
lines.push("# 会话复盘报告", "");
|
|
7199
|
-
lines.push(`- 项目 cwd:${
|
|
7200
|
-
lines.push(`- 项目键:${
|
|
7201
|
-
lines.push(`- root session id:${
|
|
7881
|
+
lines.push(`- 项目 cwd:${text2(r.project?.cwd)}`);
|
|
7882
|
+
lines.push(`- 项目键:${text2(r.project?.key)}`);
|
|
7883
|
+
lines.push(`- root session id:${text2(r.rootSessionId)}`);
|
|
7202
7884
|
lines.push(`- 生成时间:${new Date().toISOString()}`);
|
|
7203
7885
|
lines.push(`- 事件流完整性:${complete ? "complete(已分析会话内部事件连续无缺口)" : "不完整(已分析会话内存在事件缺口,结论需降级)"}`);
|
|
7204
7886
|
lines.push(`- 会话集合覆盖:${sessionsCoverageText(sessionsTruncated, lineageTotal, sessionsAnalyzedRaw, samplingNote, childCountFromSessions(r))}`);
|
|
7205
7887
|
lines.push(`- 分析输入是否被裁剪:${coverage.inputTruncated ? "是(结论不得外推到未读区间)" : "否"}`);
|
|
7206
7888
|
const analysis = r.analysis ?? {};
|
|
7207
7889
|
const statusRaw = typeof analysis.status === "string" && analysis.status.length > 0 ? analysis.status : "";
|
|
7208
|
-
const statusLabel = STATUS_TITLE[statusRaw] ??
|
|
7209
|
-
lines.push(`- 分析状态:${statusLabel}(provider/model:${
|
|
7890
|
+
const statusLabel = STATUS_TITLE[statusRaw] ?? text2(analysis.status);
|
|
7891
|
+
lines.push(`- 分析状态:${statusLabel}(provider/model:${text2(analysis.provider)} / ${text2(analysis.model)},调用次数 ${num2(analysis.invocations)})`);
|
|
7210
7892
|
if (typeof analysis.error === "string" && analysis.error.length > 0) {
|
|
7211
7893
|
lines.push(`- 分析错误说明:${analysis.error}`);
|
|
7212
7894
|
}
|
|
@@ -7251,7 +7933,7 @@ function renderMarkdown(report, opts = {}) {
|
|
|
7251
7933
|
lines.push("- 采集未完成,但未记录具体缺口(见 coverage.complete)。");
|
|
7252
7934
|
} else {
|
|
7253
7935
|
for (const g of gaps)
|
|
7254
|
-
lines.push(`- ${
|
|
7936
|
+
lines.push(`- ${text2(g)}`);
|
|
7255
7937
|
}
|
|
7256
7938
|
lines.push("");
|
|
7257
7939
|
}
|
|
@@ -7261,7 +7943,7 @@ function renderMarkdown(report, opts = {}) {
|
|
|
7261
7943
|
lines.push(`- 无会话摘要(sessions 为空,${DASH})`, "");
|
|
7262
7944
|
} else {
|
|
7263
7945
|
for (const s of sessions) {
|
|
7264
|
-
lines.push(`### ${
|
|
7946
|
+
lines.push(`### ${text2(s?.sessionId)}`, "");
|
|
7265
7947
|
lines.push("| turn | 结束原因 | tokens(in/out) | 工具数 | 错误数 |", "| --- | --- | --- | --- | --- |");
|
|
7266
7948
|
const turns = Array.isArray(s?.turns) ? s.turns : [];
|
|
7267
7949
|
if (turns.length === 0) {
|
|
@@ -7269,7 +7951,7 @@ function renderMarkdown(report, opts = {}) {
|
|
|
7269
7951
|
} else {
|
|
7270
7952
|
for (const t of turns) {
|
|
7271
7953
|
const counts = toolCounts(t);
|
|
7272
|
-
lines.push(`| ${num2(t?.turn)} | ${
|
|
7954
|
+
lines.push(`| ${num2(t?.turn)} | ${text2(t?.end?.kind)} | ${usageCell(t?.usage)} | ${counts.total} | ${counts.errors} |`);
|
|
7273
7955
|
}
|
|
7274
7956
|
}
|
|
7275
7957
|
lines.push("");
|
|
@@ -7280,10 +7962,10 @@ function renderMarkdown(report, opts = {}) {
|
|
|
7280
7962
|
lines.push("## 委派树", "");
|
|
7281
7963
|
for (const a of attempts) {
|
|
7282
7964
|
const parent = a?.parent;
|
|
7283
|
-
const parentLabel = `${
|
|
7965
|
+
const parentLabel = `${text2(parent?.sessionId)} · turn ${num2(parent?.turn)} · seq ${num2(parent?.seq)} · call ${text2(parent?.callId)}`;
|
|
7284
7966
|
const cost = typeof a?.startedAt === "number" && typeof a?.endedAt === "number" ? `${Math.max(0, Math.round(a.endedAt - a.startedAt))}ms` : DASH;
|
|
7285
7967
|
const tag = a?.attempt > 0 || a?.taskIndex > 0 ? `(task ${num2(a?.taskIndex)} / attempt ${num2(a?.attempt)})` : "";
|
|
7286
|
-
lines.push(`- ${parentLabel} → ${
|
|
7968
|
+
lines.push(`- ${parentLabel} → ${text2(a?.childSessionId)} (${text2(a?.outcome)}, ${cost})${tag}`);
|
|
7287
7969
|
}
|
|
7288
7970
|
lines.push("");
|
|
7289
7971
|
}
|
|
@@ -7331,11 +8013,11 @@ function renderMarkdown(report, opts = {}) {
|
|
|
7331
8013
|
lines.push("## 未验证", "");
|
|
7332
8014
|
lines.push("以下条目没有任何证据锚点,不能作为正式结论使用:", "");
|
|
7333
8015
|
for (const f of unverified) {
|
|
7334
|
-
lines.push(`- **${
|
|
8016
|
+
lines.push(`- **${text2(f?.text)}**(无证据,未验证)`);
|
|
7335
8017
|
const limits = Array.isArray(f?.limitations) ? f.limitations : [];
|
|
7336
8018
|
for (const l of limits)
|
|
7337
|
-
lines.push(` - 局限:${
|
|
7338
|
-
lines.push(` - kind:${
|
|
8019
|
+
lines.push(` - 局限:${text2(l)}`);
|
|
8020
|
+
lines.push(` - kind:${text2(f?.kind)}`);
|
|
7339
8021
|
}
|
|
7340
8022
|
lines.push("");
|
|
7341
8023
|
}
|
|
@@ -8541,6 +9223,12 @@ var SkillRoute = z2.object({
|
|
|
8541
9223
|
reasoningEffort: z2.string().description("推理强度(如 low/medium/high;留空则按模型默认档/继承规则)"),
|
|
8542
9224
|
outputContract: z2.union(["off", "lite", "strict"]).description("输出契约等级(off=不注入不校验 / lite=注入+校验+标记违约 / strict=注入+校验+重写一次;留空=off)")
|
|
8543
9225
|
});
|
|
9226
|
+
var CustomRole = z2.object({
|
|
9227
|
+
name: z2.string().pattern(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).required().description("角色名(kebab-case,如 my-reviewer);不得与内置角色重名(重名检查在注册时进行)"),
|
|
9228
|
+
description: z2.string().min(1).required().description("角色职责(必填,非空):一句话说明什么时候该派给它"),
|
|
9229
|
+
prompt: z2.string().min(1).required().description("该角色的任务指令(必填,非空):未来映射为子代理 brief"),
|
|
9230
|
+
tier: z2.union(["ro", "ro-net", "rw", "rw-shell", "cordis"]).required().description("工具档位:ro=只读 / ro-net=只读+联网 / rw=读写 / rw-shell=读写+shell / cordis=Cordis 插件改写")
|
|
9231
|
+
});
|
|
8544
9232
|
var EnvContractConfig = z2.object({
|
|
8545
9233
|
enabled: z2.boolean().default(true),
|
|
8546
9234
|
text: z2.string()
|
|
@@ -8602,6 +9290,7 @@ var Config = z2.object({
|
|
|
8602
9290
|
councilTimeoutMs: z2.number().default(COUNCIL_TIMEOUT_MS),
|
|
8603
9291
|
councilProvider: z2.string().default("spawn"),
|
|
8604
9292
|
skills: volatileSchema(z2.array(SkillRoute).default([])),
|
|
9293
|
+
customRoles: volatileSchema(z2.array(CustomRole).default([])),
|
|
8605
9294
|
delegateEnvContract: EnvContractConfig,
|
|
8606
9295
|
delegateRetry: volatileSchema(DelegateRetry),
|
|
8607
9296
|
envSignatures: EnvSignatures,
|
|
@@ -8629,7 +9318,26 @@ function readPackageVersion() {
|
|
|
8629
9318
|
}
|
|
8630
9319
|
}
|
|
8631
9320
|
function installAgentPresets(logger) {
|
|
8632
|
-
|
|
9321
|
+
const r = installShippedPresets(SHIPPED_PRESETS_DIR, dshHomePath5(".agent-presets"), readPackageVersion(), logger);
|
|
9322
|
+
try {
|
|
9323
|
+
const patchPath = resolveProfilePatchPath(dshHomePath5());
|
|
9324
|
+
if (patchPath === null) {
|
|
9325
|
+
logger?.info?.("cohub: 无法判定活动 profile($DSH_PROFILE 未设置且 profiles 下不止一个),跳过 preset 声明写入");
|
|
9326
|
+
} else {
|
|
9327
|
+
const p = applyPresetPatchDeclarations(SHIPPED_PRESETS_DIR, patchPath, logger);
|
|
9328
|
+
if (p.appended.length > 0) {
|
|
9329
|
+
logger?.info?.(`cohub: 已向 ${patchPath} 追加 ${p.appended.length} 条 preset 声明(${p.appended.join(", ")})${p.backup ? `,原文件已备份为 ${p.backup}` : ""}`);
|
|
9330
|
+
}
|
|
9331
|
+
if (p.conflicts.length > 0) {
|
|
9332
|
+
logger?.info?.(`cohub: ${p.conflicts.length} 条 preset 声明保留你的版本:${p.conflicts.join(", ")}`);
|
|
9333
|
+
}
|
|
9334
|
+
if (p.degraded !== undefined)
|
|
9335
|
+
logger?.info?.(`cohub: preset 声明写入已跳过(${p.degraded})`);
|
|
9336
|
+
}
|
|
9337
|
+
} catch (error) {
|
|
9338
|
+
logger?.warn?.("cohub: 写入 profile patch 的 preset 声明失败(不影响插件启动)", error);
|
|
9339
|
+
}
|
|
9340
|
+
return r;
|
|
8633
9341
|
}
|
|
8634
9342
|
function apply(ctx, config) {
|
|
8635
9343
|
ctx.effect(() => ctx.systemPrompt.section({
|
|
@@ -8640,6 +9348,18 @@ function apply(ctx, config) {
|
|
|
8640
9348
|
for (const skill of COHUB_SKILLS) {
|
|
8641
9349
|
ctx.skills.register(skill);
|
|
8642
9350
|
}
|
|
9351
|
+
ctx.effect(() => {
|
|
9352
|
+
const customRoleSkills = createCustomSkillRegistry({
|
|
9353
|
+
skills: ctx.skills,
|
|
9354
|
+
getRoles: () => typeof config.customRoles?.get === "function" ? config.customRoles.get() : config.customRoles,
|
|
9355
|
+
logger: ctx.logger
|
|
9356
|
+
});
|
|
9357
|
+
const stopPolling = customRoleSkills.start(CUSTOM_ROLE_POLL_MS);
|
|
9358
|
+
return () => {
|
|
9359
|
+
stopPolling();
|
|
9360
|
+
customRoleSkills.dispose();
|
|
9361
|
+
};
|
|
9362
|
+
}, "cohub.customRoles()");
|
|
8643
9363
|
if (config.installPresets !== false) {
|
|
8644
9364
|
try {
|
|
8645
9365
|
const r = installAgentPresets(ctx.logger);
|
|
@@ -8727,14 +9447,18 @@ function apply(ctx, config) {
|
|
|
8727
9447
|
export {
|
|
8728
9448
|
CohubSettingsSchema,
|
|
8729
9449
|
Config,
|
|
9450
|
+
CustomRole,
|
|
8730
9451
|
DelegateBackgroundConfig,
|
|
8731
9452
|
ResultBudgetConfig,
|
|
8732
9453
|
ScheduleConfig,
|
|
8733
9454
|
apply,
|
|
9455
|
+
applyPresetPatchDeclarations,
|
|
9456
|
+
buildPresetPatchDeclarations,
|
|
8734
9457
|
copyTree,
|
|
8735
9458
|
hashTree,
|
|
8736
9459
|
inject,
|
|
8737
9460
|
installShippedPresets,
|
|
8738
9461
|
name,
|
|
8739
|
-
removeInstallRecord
|
|
9462
|
+
removeInstallRecord,
|
|
9463
|
+
resolveProfilePatchPath
|
|
8740
9464
|
};
|