dsh-cohub 0.10.2 → 0.10.3
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 +140 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# dsh-cohub
|
|
2
2
|
|
|
3
|
-
> 本文对应 **v0.10.
|
|
3
|
+
> 本文对应 **v0.10.3**;完整变更历史见 [CHANGELOG.md](./CHANGELOG.md)。
|
|
4
4
|
|
|
5
5
|
DeepSeek Harness 版(对照 [OpenCode 版](../oh-my-opencode-cohub/)):中文智能体编排插件。
|
|
6
6
|
把「纯调度模式 + 13 个技能(12 个代理编排体系 + co-cordis 组合创作)+ 多模型共识 + 运行期调度韧性」移植到 DSH 原生能力之上。
|
package/lib/index.js
CHANGED
|
@@ -5950,6 +5950,12 @@ function applyDiscoveryCoverage(coverage, discovery, childReadFailed = 0) {
|
|
|
5950
5950
|
coverage.samplingNote = undefined;
|
|
5951
5951
|
}
|
|
5952
5952
|
}
|
|
5953
|
+
function throwIfAborted(signal) {
|
|
5954
|
+
if (signal?.aborted) {
|
|
5955
|
+
const reason = signal.reason;
|
|
5956
|
+
throw reason instanceof Error ? reason : new Error("分析已取消(" + String(reason ?? "aborted") + ")");
|
|
5957
|
+
}
|
|
5958
|
+
}
|
|
5953
5959
|
async function findChildIds(ctx, rootId, signal) {
|
|
5954
5960
|
try {
|
|
5955
5961
|
const trace = ctx?.sessionQuery?.traceSession;
|
|
@@ -5967,6 +5973,7 @@ async function findChildIds(ctx, rootId, signal) {
|
|
|
5967
5973
|
}
|
|
5968
5974
|
}
|
|
5969
5975
|
} catch (error) {
|
|
5976
|
+
throwIfAborted(signal);
|
|
5970
5977
|
ctx.logger?.warn?.("[cohub review] traceSession 失败:" + String(error?.message ?? error));
|
|
5971
5978
|
}
|
|
5972
5979
|
try {
|
|
@@ -6004,6 +6011,7 @@ async function findChildIds(ctx, rootId, signal) {
|
|
|
6004
6011
|
}
|
|
6005
6012
|
return toDiscovery(found, "list");
|
|
6006
6013
|
} catch (error) {
|
|
6014
|
+
throwIfAborted(signal);
|
|
6007
6015
|
ctx.logger?.warn?.("[cohub review] listSessions 失败:" + String(error?.message ?? error));
|
|
6008
6016
|
}
|
|
6009
6017
|
return { ids: [], total: 0, truncated: false, source: "list" };
|
|
@@ -6029,7 +6037,10 @@ function appendErrorLog(cwd, sessionId, message) {
|
|
|
6029
6037
|
mkdirSync5(dirname5(logPath), { recursive: true });
|
|
6030
6038
|
appendFileSync(logPath, new Date().toISOString() + "\t" + sessionId + "\t" + message.replace(/\s+/g, " ").slice(0, 500) + `
|
|
6031
6039
|
`, "utf8");
|
|
6032
|
-
|
|
6040
|
+
return logPath;
|
|
6041
|
+
} catch {
|
|
6042
|
+
return null;
|
|
6043
|
+
}
|
|
6033
6044
|
}
|
|
6034
6045
|
function writeErrorRecord(cwd, sessionId, error) {
|
|
6035
6046
|
const stamp = new Date().toISOString().replace(/[:.]/g, "-");
|
|
@@ -6364,6 +6375,7 @@ async function readRootSession(ctx, sessionId, signal) {
|
|
|
6364
6375
|
try {
|
|
6365
6376
|
read = await ctx.sessionQuery.readSession(current, signal);
|
|
6366
6377
|
} catch (error) {
|
|
6378
|
+
throwIfAborted(signal);
|
|
6367
6379
|
failed = "根会话读取失败(" + String(error?.message ?? error) + ")";
|
|
6368
6380
|
ctx.logger?.warn?.("[cohub review] " + failed + ",降级为空事件继续出报告");
|
|
6369
6381
|
read = { session: { id: current }, events: [] };
|
|
@@ -6379,6 +6391,7 @@ async function readRootSession(ctx, sessionId, signal) {
|
|
|
6379
6391
|
try {
|
|
6380
6392
|
parentRead = await ctx.sessionQuery.readSession(parent, signal);
|
|
6381
6393
|
} catch (error) {
|
|
6394
|
+
throwIfAborted(signal);
|
|
6382
6395
|
ctx.logger?.warn?.("[cohub review] 上溯父会话失败,以 " + current + " 为根:" + String(error?.message ?? error));
|
|
6383
6396
|
break;
|
|
6384
6397
|
}
|
|
@@ -6388,15 +6401,25 @@ async function readRootSession(ctx, sessionId, signal) {
|
|
|
6388
6401
|
}
|
|
6389
6402
|
return { sessionId: current, read, failed };
|
|
6390
6403
|
}
|
|
6391
|
-
async function runAnalysis(
|
|
6404
|
+
async function runAnalysis(req) {
|
|
6405
|
+
const { ctx, agent, sessionId, cwdHint, withLlm } = req;
|
|
6406
|
+
const external = req.signal;
|
|
6392
6407
|
const controller = new AbortController;
|
|
6393
|
-
const
|
|
6394
|
-
const
|
|
6408
|
+
const onExternalAbort = () => controller.abort(external?.reason);
|
|
6409
|
+
const timer = setTimeout(() => controller.abort(new Error("分析超时(" + Math.round(ANALYSIS_TIMEOUT_MS / 1000) + " 秒)")), ANALYSIS_TIMEOUT_MS);
|
|
6410
|
+
if (external) {
|
|
6411
|
+
if (external.aborted)
|
|
6412
|
+
onExternalAbort();
|
|
6413
|
+
else
|
|
6414
|
+
external.addEventListener("abort", onExternalAbort, { once: true });
|
|
6415
|
+
}
|
|
6395
6416
|
try {
|
|
6396
|
-
await runAnalysisInner(ctx, agent, sessionId, cwdHint, withLlm, signal);
|
|
6417
|
+
return { ok: true, ...await runAnalysisInner(ctx, agent, sessionId, cwdHint, withLlm, controller.signal) };
|
|
6397
6418
|
} catch (error) {
|
|
6419
|
+
const reason = String(error?.message ?? error);
|
|
6398
6420
|
const errorPath = writeErrorRecord(cwdHint, sessionId, error);
|
|
6399
|
-
|
|
6421
|
+
const logPath = appendErrorLog(cwdHint, sessionId, reason);
|
|
6422
|
+
ctx.logger?.warn?.("[cohub review] 分析失败(error-*.json " + (errorPath !== null ? "已" : "未") + "落盘):" + reason);
|
|
6400
6423
|
if (errorPath !== null) {
|
|
6401
6424
|
try {
|
|
6402
6425
|
updateIndex({
|
|
@@ -6408,15 +6431,16 @@ async function runAnalysis(ctx, agent, sessionId, cwdHint, withLlm) {
|
|
|
6408
6431
|
jsonPath: errorPath,
|
|
6409
6432
|
mdPath: null,
|
|
6410
6433
|
projectCopyPath: null,
|
|
6411
|
-
note: "本次复盘整体失败,仅落盘 error 记录:" +
|
|
6434
|
+
note: "本次复盘整体失败,仅落盘 error 记录:" + reason.slice(0, 200),
|
|
6412
6435
|
lineageTotal: undefined,
|
|
6413
6436
|
sessionsTruncated: undefined
|
|
6414
6437
|
});
|
|
6415
6438
|
} catch {}
|
|
6416
6439
|
}
|
|
6417
|
-
|
|
6440
|
+
return { ok: false, reason, errorPath, logPath };
|
|
6418
6441
|
} finally {
|
|
6419
6442
|
clearTimeout(timer);
|
|
6443
|
+
external?.removeEventListener("abort", onExternalAbort);
|
|
6420
6444
|
}
|
|
6421
6445
|
}
|
|
6422
6446
|
async function runAnalysisInner(ctx, agent, sessionId, cwdHint, withLlm, signal) {
|
|
@@ -6433,6 +6457,7 @@ async function runAnalysisInner(ctx, agent, sessionId, cwdHint, withLlm, signal)
|
|
|
6433
6457
|
const read = await ctx.sessionQuery.readSession(childId, signal);
|
|
6434
6458
|
children.push(toSessionEvents(read, childId));
|
|
6435
6459
|
} catch (error) {
|
|
6460
|
+
throwIfAborted(signal);
|
|
6436
6461
|
childReadFailed++;
|
|
6437
6462
|
gaps.push(childId + ": 子会话读取失败(" + String(error?.message ?? error) + ")");
|
|
6438
6463
|
}
|
|
@@ -6485,6 +6510,7 @@ async function runAnalysisInner(ctx, agent, sessionId, cwdHint, withLlm, signal)
|
|
|
6485
6510
|
analysis.status = "failed";
|
|
6486
6511
|
analysis.error = result.reason;
|
|
6487
6512
|
ctx.logger?.warn?.("[cohub review] LLM 分析失败:" + result.reason);
|
|
6513
|
+
throwIfAborted(signal);
|
|
6488
6514
|
}
|
|
6489
6515
|
} else {
|
|
6490
6516
|
analysis.status = "completed";
|
|
@@ -6527,44 +6553,126 @@ async function runAnalysisInner(ctx, agent, sessionId, cwdHint, withLlm, signal)
|
|
|
6527
6553
|
} catch (error) {
|
|
6528
6554
|
ctx.logger?.warn?.("[cohub review] 复盘索引更新异常:" + String(error?.message ?? error));
|
|
6529
6555
|
}
|
|
6556
|
+
return {
|
|
6557
|
+
report,
|
|
6558
|
+
jsonPath,
|
|
6559
|
+
mdPath: mdOk ? mdPath : null,
|
|
6560
|
+
projectCopyPath: copy.path,
|
|
6561
|
+
persisted: jsonOk && mdOk
|
|
6562
|
+
};
|
|
6530
6563
|
}
|
|
6531
6564
|
function cwdHintOf(inv) {
|
|
6532
6565
|
const cwd = inv?.agent?.session?.header?.cwd ?? inv?.agent?.session?.meta?.cwd ?? inv?.agent?.options?.cwd ?? null;
|
|
6533
6566
|
return typeof cwd === "string" && cwd.length > 0 ? cwd : null;
|
|
6534
6567
|
}
|
|
6535
6568
|
var inFlight = new Set;
|
|
6569
|
+
function formatElapsed(ms) {
|
|
6570
|
+
const safe = Number.isFinite(ms) && ms >= 0 ? ms : 0;
|
|
6571
|
+
return safe < 1000 ? (safe / 1000).toFixed(1) + "s" : Math.round(safe / 1000) + "s";
|
|
6572
|
+
}
|
|
6573
|
+
function kindBreakdown(report) {
|
|
6574
|
+
const order = ["issue", "praise", "observation", "suggestion"];
|
|
6575
|
+
const counts = new Map;
|
|
6576
|
+
for (const f of report.findings ?? []) {
|
|
6577
|
+
const kind = typeof f?.kind === "string" ? f.kind : "observation";
|
|
6578
|
+
counts.set(kind, (counts.get(kind) ?? 0) + 1);
|
|
6579
|
+
}
|
|
6580
|
+
const parts = [];
|
|
6581
|
+
for (const kind of order) {
|
|
6582
|
+
const n = counts.get(kind);
|
|
6583
|
+
if (n !== undefined && n > 0)
|
|
6584
|
+
parts.push(kind + " " + n);
|
|
6585
|
+
}
|
|
6586
|
+
for (const [kind, n] of counts) {
|
|
6587
|
+
if (!order.includes(kind))
|
|
6588
|
+
parts.push(kind + " " + n);
|
|
6589
|
+
}
|
|
6590
|
+
return parts.length > 0 ? "(" + parts.join(" / ") + ")" : "";
|
|
6591
|
+
}
|
|
6592
|
+
function formatSuccessText(art, elapsedMs, withLlm) {
|
|
6593
|
+
const report = art.report;
|
|
6594
|
+
const lines = [];
|
|
6595
|
+
const status = report.analysis?.status ?? "completed";
|
|
6596
|
+
const head = status === "completed" ? "报告已生成" : "报告已生成(分析未完整完成)";
|
|
6597
|
+
lines.push(head + "(用时 " + formatElapsed(elapsedMs) + (withLlm ? "" : ",仅统计,跳过 LLM") + ")");
|
|
6598
|
+
const findings = Array.isArray(report.findings) ? report.findings : [];
|
|
6599
|
+
lines.push("- 结论:" + findings.length + " 条" + kindBreakdown(report));
|
|
6600
|
+
const cov = report.coverage;
|
|
6601
|
+
const analyzed = typeof cov?.sessionsAnalyzed === "number" ? cov.sessionsAnalyzed : undefined;
|
|
6602
|
+
const total = typeof cov?.lineageTotal === "number" ? cov.lineageTotal : undefined;
|
|
6603
|
+
if (analyzed !== undefined && total !== undefined) {
|
|
6604
|
+
const note = cov.samplingNote ? "(" + cov.samplingNote + ")" : "";
|
|
6605
|
+
lines.push("- 覆盖:已分析 " + analyzed + " / 共 " + total + " 个子会话" + note);
|
|
6606
|
+
} else {
|
|
6607
|
+
lines.push("- 覆盖:已读取 " + (Array.isArray(report.sessions) ? report.sessions.length : 0) + " 个会话(子会话总数未知;根会话 + 子会话)");
|
|
6608
|
+
}
|
|
6609
|
+
const reportPath = art.projectCopyPath ?? art.mdPath ?? art.jsonPath;
|
|
6610
|
+
lines.push("- 报告:" + reportPath);
|
|
6611
|
+
if (art.projectCopyPath === null && art.mdPath !== null) {
|
|
6612
|
+
lines.push("- 说明:项目内副本未写入(" + (report.coverage?.gaps?.length ? "见报告缺口" : "cwd 不可用或 .gitignore 冲突") + "),以上为全局目录路径");
|
|
6613
|
+
}
|
|
6614
|
+
if (!art.persisted) {
|
|
6615
|
+
lines.push("- 注意:报告落盘不完整(JSON/MD 至少一个写失败),路径可能不可读");
|
|
6616
|
+
}
|
|
6617
|
+
if (cov?.sessionsTruncated === true) {
|
|
6618
|
+
lines.push("- 提示:**未分析的子会话不在结论内**(结论不得外推到这些子会话)");
|
|
6619
|
+
}
|
|
6620
|
+
if (cov?.inputTruncated === true) {
|
|
6621
|
+
lines.push("- 提示:喂给模型的输入被裁剪过,结论不得外推到未读区间");
|
|
6622
|
+
}
|
|
6623
|
+
if (status !== "completed") {
|
|
6624
|
+
const reason = typeof report.analysis?.error === "string" && report.analysis.error.length > 0 ? report.analysis.error : "原因未记录(详见报告 analysis 段)";
|
|
6625
|
+
lines.push("- 状态:" + status + " —— " + reason);
|
|
6626
|
+
}
|
|
6627
|
+
return lines.join(`
|
|
6628
|
+
`);
|
|
6629
|
+
}
|
|
6630
|
+
function formatErrorText(outcome, elapsedMs) {
|
|
6631
|
+
const lines = ["分析失败:" + outcome.reason + "(用时 " + formatElapsed(elapsedMs) + ")"];
|
|
6632
|
+
if (outcome.errorPath !== null)
|
|
6633
|
+
lines.push("- 错误详情:" + outcome.errorPath);
|
|
6634
|
+
else
|
|
6635
|
+
lines.push("- 错误详情:未落盘(写 error-*.json 失败)");
|
|
6636
|
+
if (outcome.logPath !== null)
|
|
6637
|
+
lines.push("- 错误日志:" + outcome.logPath);
|
|
6638
|
+
else
|
|
6639
|
+
lines.push("- 错误日志:未落盘(写 _errors.log 失败)");
|
|
6640
|
+
return lines.join(`
|
|
6641
|
+
`);
|
|
6642
|
+
}
|
|
6536
6643
|
function registerReviewCommand(ctx) {
|
|
6537
|
-
const handler = (inv) => {
|
|
6644
|
+
const handler = async (inv) => {
|
|
6645
|
+
const startedAt = Date.now();
|
|
6646
|
+
let sessionId = null;
|
|
6647
|
+
let cwdHint = null;
|
|
6648
|
+
let claimed = false;
|
|
6538
6649
|
try {
|
|
6539
|
-
const
|
|
6540
|
-
if (typeof
|
|
6650
|
+
const sid = inv?.agent?.session?.id;
|
|
6651
|
+
if (typeof sid !== "string" || sid.length === 0) {
|
|
6541
6652
|
return { kind: "error", text: "无法确定当前会话 id,已跳过复盘。" };
|
|
6542
6653
|
}
|
|
6543
|
-
|
|
6544
|
-
|
|
6654
|
+
sessionId = sid;
|
|
6655
|
+
if (inFlight.has(sid)) {
|
|
6656
|
+
return { kind: "error", text: "上一次分析仍在进行中,请稍候(会话 " + sid + ")。" };
|
|
6545
6657
|
}
|
|
6546
6658
|
const rawInput = typeof inv?.rawInput === "string" ? inv.rawInput : "";
|
|
6547
6659
|
const withLlm = !/(^|\s)--no-llm(\s|$)/.test(rawInput);
|
|
6548
|
-
|
|
6549
|
-
inFlight.add(
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
ctx.logger?.warn?.("[cohub review] 报告生成失败:" + message);
|
|
6557
|
-
} finally {
|
|
6558
|
-
inFlight.delete(sessionId);
|
|
6559
|
-
}
|
|
6560
|
-
})();
|
|
6561
|
-
const dir = reviewStorePath(cwdHint, sessionId, "").replace(/[\\/]$/, "");
|
|
6562
|
-
return {
|
|
6563
|
-
kind: "success",
|
|
6564
|
-
text: "正在生成报告…(" + (withLlm ? "含一次 LLM 分析" : "仅统计,跳过 LLM") + ")输出目录:" + dir
|
|
6565
|
-
};
|
|
6660
|
+
cwdHint = cwdHintOf(inv);
|
|
6661
|
+
inFlight.add(sid);
|
|
6662
|
+
claimed = true;
|
|
6663
|
+
const outcome = await runAnalysis({ ctx, agent: inv?.agent, sessionId: sid, cwdHint, withLlm, signal: inv?.signal });
|
|
6664
|
+
if (outcome.ok) {
|
|
6665
|
+
return { kind: "success", text: formatSuccessText(outcome, Date.now() - startedAt, withLlm) };
|
|
6666
|
+
}
|
|
6667
|
+
return { kind: "error", text: formatErrorText(outcome, Date.now() - startedAt) };
|
|
6566
6668
|
} catch (error) {
|
|
6567
|
-
|
|
6669
|
+
const message = String(error?.message ?? error);
|
|
6670
|
+
if (sessionId !== null)
|
|
6671
|
+
appendErrorLog(cwdHint, sessionId, message);
|
|
6672
|
+
return { kind: "error", text: "复盘命令执行异常:" + message };
|
|
6673
|
+
} finally {
|
|
6674
|
+
if (claimed && sessionId !== null)
|
|
6675
|
+
inFlight.delete(sessionId);
|
|
6568
6676
|
}
|
|
6569
6677
|
};
|
|
6570
6678
|
try {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-cohub",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.3",
|
|
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",
|