dsh-cohub 0.10.0 → 0.10.2

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/lib/index.js +558 -65
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # dsh-cohub
2
2
 
3
- > 本文对应 **v0.10.0**;完整变更历史见 [CHANGELOG.md](./CHANGELOG.md)。
3
+ > 本文对应 **v0.10.2**;完整变更历史见 [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
@@ -1,8 +1,8 @@
1
1
  // src/index.ts
2
2
  import z2 from "@deepseek-ai/schemastery";
3
- import { readFileSync as readFileSync4 } from "node:fs";
3
+ import { readFileSync as readFileSync5 } from "node:fs";
4
4
  import { fileURLToPath } from "node:url";
5
- import { dshHomePath as dshHomePath4 } from "@deepseek-ai/dsh-home-paths";
5
+ import { dshHomePath as dshHomePath5 } from "@deepseek-ai/dsh-home-paths";
6
6
 
7
7
  // src/preset-install.ts
8
8
  import { createHash } from "node:crypto";
@@ -5092,9 +5092,9 @@ function createReviewCollector(ctx, opts = {}) {
5092
5092
 
5093
5093
  // src/review-command.ts
5094
5094
  import { createHash as createHash4 } from "node:crypto";
5095
- import { existsSync as existsSync4, mkdirSync as mkdirSync4, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "node:fs";
5096
- import { dirname as dirname4 } from "node:path";
5097
- import { dshHomePath as dshHomePath3 } from "@deepseek-ai/dsh-home-paths";
5095
+ import { appendFileSync, existsSync as existsSync5, mkdirSync as mkdirSync5, renameSync as renameSync3, writeFileSync as writeFileSync5 } from "node:fs";
5096
+ import { dirname as dirname5 } from "node:path";
5097
+ import { dshHomePath as dshHomePath4 } from "@deepseek-ai/dsh-home-paths";
5098
5098
 
5099
5099
  // src/review-report.ts
5100
5100
  import { createHash as createHash3 } from "node:crypto";
@@ -5345,9 +5345,18 @@ function excerptOf(raw, limit) {
5345
5345
  const flat = raw.replace(/\s+/g, " ").trim();
5346
5346
  return flat.length > limit ? `${flat.slice(0, limit)}…` : flat;
5347
5347
  }
5348
+ var SEVERITY_RANK = { high: 0, medium: 1, low: 2 };
5349
+ var SEVERITY_ORDER = ["high", "medium", "low"];
5350
+ function severityOf(finding) {
5351
+ if (finding?.kind !== "issue")
5352
+ return null;
5353
+ const s = finding?.severity;
5354
+ return s === "high" || s === "medium" || s === "low" ? s : null;
5355
+ }
5348
5356
  function renderFinding(finding, opts, excerptLimit) {
5349
5357
  const out = [];
5350
- out.push(`- **${text(finding?.text)}**`);
5358
+ const sev = severityOf(finding);
5359
+ out.push(sev !== null ? `- **issue · ${sev}** — ${text(finding?.text)}` : `- **${text(finding?.text)}**`);
5351
5360
  const evidence = Array.isArray(finding?.evidence) ? finding.evidence : [];
5352
5361
  for (const ev of evidence)
5353
5362
  out.push(` - 锚点:${anchorOf(ev)}`);
@@ -5375,6 +5384,60 @@ var STATUS_TITLE = {
5375
5384
  interrupted: "interrupted(被取消,结论不完整)",
5376
5385
  failed: "failed(分析失败,本轮没有模型结论,原因见下方「分析错误说明」)"
5377
5386
  };
5387
+ function inferSessionsTruncated(sessionsTruncated, lineageTotal, sessionsAnalyzed) {
5388
+ if (typeof sessionsTruncated === "boolean")
5389
+ return sessionsTruncated;
5390
+ if (lineageTotal !== null && sessionsAnalyzed !== null)
5391
+ return sessionsAnalyzed < lineageTotal;
5392
+ return;
5393
+ }
5394
+ function ruleText(note) {
5395
+ return note.length > 0 && note !== DASH ? note : "";
5396
+ }
5397
+ function ruleSuffix(note) {
5398
+ const rule = ruleText(note);
5399
+ return rule.length > 0 ? `(${rule})` : "";
5400
+ }
5401
+ function samplingKind(note) {
5402
+ const rule = ruleText(note);
5403
+ const sampled = rule.includes("取最新");
5404
+ const readFailed = rule.includes("读取失败");
5405
+ if (sampled && readFailed)
5406
+ return "both";
5407
+ if (sampled)
5408
+ return "sampled";
5409
+ if (readFailed)
5410
+ return "readFailed";
5411
+ return "unknown";
5412
+ }
5413
+ function sessionsCoverageText(sessionsTruncatedRaw, lineageTotal, sessionsAnalyzed, samplingNote, childCount) {
5414
+ const sessionsTruncated = inferSessionsTruncated(sessionsTruncatedRaw, lineageTotal, sessionsAnalyzed);
5415
+ const analyzed = sessionsAnalyzed ?? (sessionsTruncated === false ? childCount : null);
5416
+ if (sessionsTruncated === true) {
5417
+ if (lineageTotal !== null && analyzed !== null) {
5418
+ return `已分析 ${analyzed} / 共 ${lineageTotal} 个子会话${ruleSuffix(samplingNote)}`;
5419
+ }
5420
+ if (lineageTotal !== null)
5421
+ return `共 ${lineageTotal} 个子会话(已分析数未记录)`;
5422
+ if (analyzed !== null)
5423
+ return `已分析 ${analyzed} 个子会话(总数未知)`;
5424
+ return "已取样截断(总数未记录)";
5425
+ }
5426
+ if (sessionsTruncated === false) {
5427
+ if (analyzed !== null)
5428
+ return `全部 ${analyzed} 个子会话`;
5429
+ if (lineageTotal !== null)
5430
+ return `全部 ${lineageTotal} 个子会话`;
5431
+ return "全部子会话(数量未记录)";
5432
+ }
5433
+ return "未知(本报告由旧版本生成,未记录子会话总数)";
5434
+ }
5435
+ function childCountFromSessions(report) {
5436
+ const list = Array.isArray(report?.sessions) ? report.sessions : [];
5437
+ if (list.length === 0)
5438
+ return null;
5439
+ return Math.max(0, list.length - 1);
5440
+ }
5378
5441
  function renderMarkdown(report, opts = {}) {
5379
5442
  const r = report ?? {};
5380
5443
  const excerptLimit = typeof opts.excerptLimit === "number" && opts.excerptLimit > 0 ? Math.floor(opts.excerptLimit) : 120;
@@ -5385,12 +5448,18 @@ function renderMarkdown(report, opts = {}) {
5385
5448
  const coverage = r.coverage ?? { throughSeq: {}, complete: false, gaps: [], inputTruncated: false };
5386
5449
  const gaps = Array.isArray(coverage.gaps) ? coverage.gaps : [];
5387
5450
  const complete = coverage.complete === true;
5451
+ const sessionsTruncated = coverage.sessionsTruncated;
5452
+ const lineageTotal = typeof coverage.lineageTotal === "number" && Number.isFinite(coverage.lineageTotal) ? coverage.lineageTotal : null;
5453
+ const sessionsAnalyzedRaw = typeof coverage.sessionsAnalyzed === "number" && Number.isFinite(coverage.sessionsAnalyzed) ? coverage.sessionsAnalyzed : null;
5454
+ const sessionsTruncatedEffective = inferSessionsTruncated(sessionsTruncated, lineageTotal, sessionsAnalyzedRaw);
5455
+ const samplingNote = text(coverage.samplingNote);
5388
5456
  lines.push("# 会话复盘报告", "");
5389
5457
  lines.push(`- 项目 cwd:${text(r.project?.cwd)}`);
5390
5458
  lines.push(`- 项目键:${text(r.project?.key)}`);
5391
5459
  lines.push(`- root session id:${text(r.rootSessionId)}`);
5392
5460
  lines.push(`- 生成时间:${new Date().toISOString()}`);
5393
- lines.push(`- 采集完整性:${complete ? "complete(所有目标会话已读至末尾)" : "不完整(存在缺口,结论需降级)"}`);
5461
+ lines.push(`- 事件流完整性:${complete ? "complete(已分析会话内部事件连续无缺口)" : "不完整(已分析会话内存在事件缺口,结论需降级)"}`);
5462
+ lines.push(`- 会话集合覆盖:${sessionsCoverageText(sessionsTruncated, lineageTotal, sessionsAnalyzedRaw, samplingNote, childCountFromSessions(r))}`);
5394
5463
  lines.push(`- 分析输入是否被裁剪:${coverage.inputTruncated ? "是(结论不得外推到未读区间)" : "否"}`);
5395
5464
  const analysis = r.analysis ?? {};
5396
5465
  const statusRaw = typeof analysis.status === "string" && analysis.status.length > 0 ? analysis.status : "";
@@ -5410,6 +5479,22 @@ function renderMarkdown(report, opts = {}) {
5410
5479
  lines.push("## 覆盖范围", "");
5411
5480
  const throughSeq = coverage.throughSeq ?? {};
5412
5481
  const throughEntries = Object.entries(throughSeq);
5482
+ const rootSid = typeof r.rootSessionId === "string" ? r.rootSessionId : "";
5483
+ const rootSeq = rootSid.length > 0 ? throughSeq[rootSid] : undefined;
5484
+ if (typeof rootSeq === "number" && Number.isFinite(rootSeq)) {
5485
+ lines.push(`> 本报告是快照:根会话截至 seq ${rootSeq}。此后的新 turn 与委派不在本报告范围内,需要重新生成。`, "");
5486
+ } else {
5487
+ lines.push(`> 本报告是快照:根会话的已读 seq ${DASH}(未记录)。此后的新 turn 与委派不在本报告范围内,需要重新生成。`, "");
5488
+ }
5489
+ if (sessionsTruncatedEffective === true) {
5490
+ const totalLabel = lineageTotal !== null ? `${lineageTotal} 个` : `${DASH}(未记录)个`;
5491
+ const analyzedLabel = sessionsAnalyzedRaw !== null ? `${sessionsAnalyzedRaw} 个` : `${DASH}(未记录)个`;
5492
+ if (samplingKind(samplingNote) === "readFailed") {
5493
+ lines.push(`⚠️ 部分子会话读取失败:共 ${totalLabel},成功分析 ${analyzedLabel}。失败子会话的消耗与问题不在本报告内。`, "");
5494
+ } else {
5495
+ lines.push(`⚠️ 子会话取样截断:共 ${totalLabel},只分析了 ${analyzedLabel}${ruleSuffix(samplingNote)}。未分析的子会话的消耗与问题不在本报告内。`, "");
5496
+ }
5497
+ }
5413
5498
  if (throughEntries.length === 0) {
5414
5499
  lines.push(`- 无覆盖记录(throughSeq 为空,${DASH})`);
5415
5500
  } else {
@@ -5464,10 +5549,28 @@ function renderMarkdown(report, opts = {}) {
5464
5549
  if (verified.length === 0) {
5465
5550
  lines.push(`- 本报告没有带证据的结论(findings 为空,${DASH});原因见「分析状态」与「限制说明」。`, "");
5466
5551
  } else {
5552
+ const issueCounts = new Map;
5553
+ for (const f of verified) {
5554
+ const sev = severityOf(f);
5555
+ if (sev !== null)
5556
+ issueCounts.set(sev, (issueCounts.get(sev) ?? 0) + 1);
5557
+ }
5558
+ const totalIssues = [...issueCounts.values()].reduce((a, b) => a + b, 0);
5559
+ if (totalIssues > 0) {
5560
+ const dist = SEVERITY_ORDER.filter((s) => (issueCounts.get(s) ?? 0) > 0).map((s) => `${s} ${issueCounts.get(s)}`).join(" / ");
5561
+ lines.push(`- 问题分布:${dist}`, "");
5562
+ }
5467
5563
  for (const kind of KIND_ORDER) {
5468
- const group = verified.filter((f) => f?.kind === kind);
5564
+ let group = verified.filter((f) => f?.kind === kind);
5469
5565
  if (group.length === 0)
5470
5566
  continue;
5567
+ if (kind === "issue") {
5568
+ group = [...group].sort((a, b) => {
5569
+ const ra = SEVERITY_RANK[severityOf(a) ?? ""] ?? SEVERITY_ORDER.length;
5570
+ const rb = SEVERITY_RANK[severityOf(b) ?? ""] ?? SEVERITY_ORDER.length;
5571
+ return ra - rb;
5572
+ });
5573
+ }
5471
5574
  lines.push(`### ${KIND_TITLE[kind] ?? kind}`, "");
5472
5575
  for (const f of group)
5473
5576
  lines.push(...renderFinding(f, opts, excerptLimit));
@@ -5497,21 +5600,31 @@ function renderMarkdown(report, opts = {}) {
5497
5600
  lines.push("## 限制说明", "");
5498
5601
  const noConclusion = verified.length === 0;
5499
5602
  const analysisError = typeof r.analysis?.error === "string" && r.analysis.error.length > 0 ? String(r.analysis.error) : null;
5500
- const needsReview = gaps.length > 0 || unverified.length > 0 || !complete;
5603
+ const needsReview = gaps.length > 0 || unverified.length > 0 || !complete || coverage.inputTruncated === true || sessionsTruncatedEffective === true;
5501
5604
  if (needsReview) {
5502
5605
  lines.push("本报告存在未覆盖部分,结论需人工复核。", "");
5606
+ if (coverage.inputTruncated === true) {
5607
+ lines.push("- 分析输入被裁剪:模型摘要超过 12000 字被裁剪(coverage.inputTruncated),结论不得外推到未读区间。");
5608
+ }
5609
+ if (sessionsTruncatedEffective === true) {
5610
+ const totalLabel = lineageTotal !== null ? `${lineageTotal}` : `${DASH}`;
5611
+ const analyzedLabel = sessionsAnalyzedRaw !== null ? `${sessionsAnalyzedRaw}` : `${DASH}`;
5612
+ if (samplingKind(samplingNote) === "readFailed") {
5613
+ lines.push(`- 部分子会话读取失败:共 ${totalLabel} 个,成功分析 ${analyzedLabel} 个,失败子会话不在结论范围内。`);
5614
+ } else {
5615
+ lines.push(`- 子会话取样截断:共 ${totalLabel} 个,只分析了 ${analyzedLabel} 个${ruleSuffix(samplingNote)},未分析的子会话不在结论范围内。`);
5616
+ }
5617
+ }
5503
5618
  if (gaps.length > 0)
5504
5619
  lines.push(`- 采集缺口 ${gaps.length} 处,相关区间的事件未被读到,不应据此下结论。`);
5620
+ if (!complete)
5621
+ lines.push("- coverage.complete 为 false,已分析会话内存在事件缺口,统计数字不完整。");
5505
5622
  if (unverified.length > 0) {
5506
5623
  lines.push(`- ${unverified.length} 条结论缺少证据,已移入「未验证」节,未计入正式分组。`);
5507
5624
  }
5508
5625
  if (noConclusion) {
5509
5626
  lines.push("- 本次复盘**没有产出任何带锚点的结论**(findings 为空),不存在可复核的结论条目。");
5510
5627
  }
5511
- if (!complete)
5512
- lines.push("- coverage.complete 为 false,统计数字不完整。");
5513
- if (coverage.inputTruncated)
5514
- lines.push("- 分析输入被裁剪,结论不得外推到未读区间。");
5515
5628
  if (analysisError)
5516
5629
  lines.push(`- 分析失败/降级原因:${analysisError}`);
5517
5630
  lines.push("");
@@ -5528,18 +5641,242 @@ function renderMarkdown(report, opts = {}) {
5528
5641
  `);
5529
5642
  }
5530
5643
 
5644
+ // src/review-index.ts
5645
+ import { existsSync as existsSync4, mkdirSync as mkdirSync4, readFileSync as readFileSync4, renameSync as renameSync2, writeFileSync as writeFileSync4 } from "node:fs";
5646
+ import { basename, dirname as dirname4, join as join2 } from "node:path";
5647
+ import { dshHomePath as dshHomePath3 } from "@deepseek-ai/dsh-home-paths";
5648
+ var REVIEW_INDEX_VERSION = 1;
5649
+ function reviewIndexDir() {
5650
+ return dshHomePath3("cohub", "reviews");
5651
+ }
5652
+ function indexPath() {
5653
+ return join2(reviewIndexDir(), "index.json");
5654
+ }
5655
+ function indexMarkdownPath() {
5656
+ return join2(reviewIndexDir(), "INDEX.md");
5657
+ }
5658
+ function projectReviewDir(cwd) {
5659
+ return join2(cwd, ".cohub", "reviews");
5660
+ }
5661
+ function projectCopyPath(cwd, stamp) {
5662
+ if (typeof cwd !== "string" || cwd.length === 0)
5663
+ return null;
5664
+ return join2(projectReviewDir(cwd), "report-" + stamp + ".md");
5665
+ }
5666
+ function writeTextAtomic(file, text) {
5667
+ const tmp = file + ".tmp";
5668
+ try {
5669
+ mkdirSync4(dirname4(file), { recursive: true });
5670
+ writeFileSync4(tmp, text, "utf8");
5671
+ renameSync2(tmp, file);
5672
+ return true;
5673
+ } catch {
5674
+ try {
5675
+ if (existsSync4(tmp))
5676
+ renameSync2(tmp, tmp + ".failed");
5677
+ } catch {}
5678
+ return false;
5679
+ }
5680
+ }
5681
+ function ensureProjectGitignore(cwd) {
5682
+ const file = join2(cwd, ".cohub", ".gitignore");
5683
+ try {
5684
+ if (existsSync4(file)) {
5685
+ const text = readFileSync4(file, "utf8");
5686
+ if (!text.includes("*")) {
5687
+ return "已存在 " + file + ' 且内容不含 "*",未覆盖;如需忽略整个 .cohub/ 请手动加入一行 *';
5688
+ }
5689
+ return null;
5690
+ }
5691
+ mkdirSync4(dirname4(file), { recursive: true });
5692
+ writeFileSync4(file, `*
5693
+ `, "utf8");
5694
+ return null;
5695
+ } catch (error) {
5696
+ return "写入 " + file + " 失败(" + String(error?.message ?? error) + "),项目内副本可能被 git 跟踪";
5697
+ }
5698
+ }
5699
+ function writeProjectCopy(cwd, markdown, stamp) {
5700
+ const file = projectCopyPath(cwd, stamp);
5701
+ if (file === null)
5702
+ return { path: null, note: "cwd 为空,跳过项目内副本" };
5703
+ const notes = [];
5704
+ try {
5705
+ if (!writeTextAtomic(file, markdown)) {
5706
+ return { path: null, note: "项目内副本写入失败(目录只读或无权限):" + file };
5707
+ }
5708
+ } catch (error) {
5709
+ return {
5710
+ path: null,
5711
+ note: "项目内副本写入失败(目录只读或无权限):" + String(error?.message ?? error)
5712
+ };
5713
+ }
5714
+ const gitignoreNote = ensureProjectGitignore(cwd);
5715
+ if (gitignoreNote !== null)
5716
+ notes.push(gitignoreNote);
5717
+ return { path: file, note: notes.length > 0 ? notes.join(";") : null };
5718
+ }
5719
+ function emptyIndex() {
5720
+ return { version: REVIEW_INDEX_VERSION, updatedAt: new Date().toISOString(), projects: {} };
5721
+ }
5722
+ function loadIndex() {
5723
+ const file = indexPath();
5724
+ try {
5725
+ if (!existsSync4(file))
5726
+ return emptyIndex();
5727
+ const parsed = JSON.parse(readFileSync4(file, "utf8"));
5728
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
5729
+ throw new Error("index.json 结构不合法");
5730
+ if (parsed.version !== REVIEW_INDEX_VERSION)
5731
+ throw new Error("index.json 版本不符");
5732
+ if (parsed.projects === null || typeof parsed.projects !== "object" || Array.isArray(parsed.projects)) {
5733
+ throw new Error("index.json projects 不合法");
5734
+ }
5735
+ return {
5736
+ version: REVIEW_INDEX_VERSION,
5737
+ updatedAt: typeof parsed.updatedAt === "string" ? parsed.updatedAt : new Date().toISOString(),
5738
+ projects: parsed.projects
5739
+ };
5740
+ } catch {
5741
+ isolateCorrupt2(file);
5742
+ return emptyIndex();
5743
+ }
5744
+ }
5745
+ function isolateCorrupt2(file) {
5746
+ try {
5747
+ if (!existsSync4(file))
5748
+ return;
5749
+ renameSync2(file, file + ".corrupt");
5750
+ } catch {}
5751
+ }
5752
+ function slashed(p) {
5753
+ return typeof p === "string" && p.length > 0 ? p.replace(/\\/g, "/") : null;
5754
+ }
5755
+ function updateIndex(entry) {
5756
+ try {
5757
+ const index = loadIndex();
5758
+ const key = cwdDirName(entry.cwd);
5759
+ const cwd = typeof entry.cwd === "string" && entry.cwd.length > 0 ? entry.cwd : null;
5760
+ const at = typeof entry.at === "string" && entry.at.length > 0 ? entry.at : new Date().toISOString();
5761
+ const prev = index.projects[key];
5762
+ const lastReport = {
5763
+ at,
5764
+ sessionId: entry.sessionId,
5765
+ status: entry.status,
5766
+ findings: Number.isFinite(entry.findings) ? entry.findings : 0,
5767
+ sessions: Number.isFinite(entry.sessions) ? entry.sessions : 0,
5768
+ jsonPath: slashed(entry.jsonPath) ?? "",
5769
+ mdPath: slashed(entry.mdPath ?? null),
5770
+ projectCopyPath: slashed(entry.projectCopyPath ?? null)
5771
+ };
5772
+ if (typeof entry.note === "string" && entry.note.length > 0)
5773
+ lastReport.note = entry.note;
5774
+ if (Number.isFinite(entry.lineageTotal))
5775
+ lastReport.lineageTotal = entry.lineageTotal;
5776
+ if (typeof entry.sessionsTruncated === "boolean")
5777
+ lastReport.sessionsTruncated = entry.sessionsTruncated;
5778
+ index.projects[key] = {
5779
+ cwd: slashed(cwd) ?? prev?.cwd ?? "",
5780
+ name: cwd !== null ? basename(cwd) : prev?.name ?? "(未知项目)",
5781
+ lastReport
5782
+ };
5783
+ index.version = REVIEW_INDEX_VERSION;
5784
+ index.updatedAt = new Date().toISOString();
5785
+ const jsonOk = writeTextAtomic(indexPath(), JSON.stringify(index, null, 2));
5786
+ writeTextAtomic(indexMarkdownPath(), renderIndexMarkdown(index));
5787
+ return jsonOk;
5788
+ } catch {
5789
+ return false;
5790
+ }
5791
+ }
5792
+ function formatLocalTime(iso) {
5793
+ const d = new Date(iso);
5794
+ if (Number.isNaN(d.getTime()))
5795
+ return iso;
5796
+ const pad = (n) => String(n).padStart(2, "0");
5797
+ return d.getFullYear() + "-" + pad(d.getMonth() + 1) + "-" + pad(d.getDate()) + " " + pad(d.getHours()) + ":" + pad(d.getMinutes()) + ":" + pad(d.getSeconds());
5798
+ }
5799
+ function sortedProjects(index) {
5800
+ const rows = Object.entries(index.projects);
5801
+ rows.sort((a, b) => {
5802
+ const ta = Date.parse(a[1]?.lastReport?.at ?? "") || 0;
5803
+ const tb = Date.parse(b[1]?.lastReport?.at ?? "") || 0;
5804
+ if (tb !== ta)
5805
+ return tb - ta;
5806
+ return String(a[1]?.name ?? "").localeCompare(String(b[1]?.name ?? ""));
5807
+ });
5808
+ return rows;
5809
+ }
5810
+ function sessionsCoverage(r) {
5811
+ const total = typeof r.lineageTotal === "number" && Number.isFinite(r.lineageTotal) ? r.lineageTotal : null;
5812
+ const analyzed = Number.isFinite(r.sessions) && r.sessions > 0 ? Math.max(0, r.sessions - 1) : null;
5813
+ const truncated = typeof r.sessionsTruncated === "boolean" ? r.sessionsTruncated : total !== null && analyzed !== null ? total > analyzed : null;
5814
+ if (truncated === true) {
5815
+ if (total !== null && analyzed !== null)
5816
+ return `(子会话 ${analyzed}/${total})`;
5817
+ if (total !== null)
5818
+ return `(子会话共 ${total},已分析数未知)`;
5819
+ return "(子会话取样截断,总数未知)";
5820
+ }
5821
+ if (truncated === false)
5822
+ return "(子会话全量)";
5823
+ return "(子会话总数未知)";
5824
+ }
5825
+ function renderIndexMarkdown(index) {
5826
+ const rows = sortedProjects(index);
5827
+ const lines = [];
5828
+ lines.push("# CoHub 复盘索引");
5829
+ lines.push("");
5830
+ lines.push("自动生成,勿手工编辑(每次 `/cohub-review` 落盘后全量重写)。");
5831
+ lines.push("");
5832
+ lines.push("索引更新时间:" + formatLocalTime(index.updatedAt) + "(本地时间) 项目数:" + rows.length);
5833
+ lines.push("");
5834
+ if (rows.length === 0) {
5835
+ lines.push("_暂无复盘记录。_");
5836
+ lines.push("");
5837
+ return lines.join(`
5838
+ `);
5839
+ }
5840
+ lines.push("| 项目 | 状态 | findings | 会话数 | 最近报告(本地时间) |");
5841
+ lines.push("| --- | --- | --- | --- | --- |");
5842
+ for (const [, p] of rows) {
5843
+ const r = p.lastReport;
5844
+ lines.push("| " + p.name + " | " + r.status + " | " + r.findings + " | " + r.sessions + sessionsCoverage(r) + " | " + formatLocalTime(r.at) + " |");
5845
+ }
5846
+ lines.push("");
5847
+ for (const [key, p] of rows) {
5848
+ const r = p.lastReport;
5849
+ lines.push("## " + p.name + "(" + key + ")");
5850
+ lines.push("");
5851
+ lines.push("- 项目路径:`" + (p.cwd.length > 0 ? p.cwd : "(未知)") + "`");
5852
+ lines.push("- 最近报告:" + formatLocalTime(r.at) + "(本地时间)");
5853
+ lines.push("- 状态:" + r.status + " findings:" + r.findings + " 会话数:" + r.sessions + sessionsCoverage(r));
5854
+ lines.push("- 会话:" + r.sessionId);
5855
+ lines.push("- 报告(DSH):`" + (r.jsonPath.length > 0 ? r.jsonPath : "(无)") + "`");
5856
+ lines.push("- 报告 MD:`" + (r.mdPath ?? "(无)") + "`");
5857
+ lines.push("- 项目内副本:" + (r.projectCopyPath !== null ? "`" + r.projectCopyPath + "`" : "(无)"));
5858
+ if (typeof r.note === "string" && r.note.length > 0)
5859
+ lines.push("- 提示:" + r.note);
5860
+ lines.push("");
5861
+ }
5862
+ return lines.join(`
5863
+ `);
5864
+ }
5865
+
5531
5866
  // src/review-command.ts
5532
5867
  var DIGEST_LIMIT_CHARS = 12000;
5533
5868
  var ANALYSIS_MAX_TOKENS = 5000;
5534
5869
  var RAW_OUTPUT_KEEP_CHARS = 2000;
5535
5870
  var MAX_CHILD_SESSIONS = 50;
5871
+ var MAX_LINEAGE_WALK_DEPTH = 64;
5872
+ var ANALYSIS_TIMEOUT_MS = 60000;
5536
5873
  var MAX_ROOT_ASCEND = 32;
5537
5874
  function idOf(rec) {
5538
- const v = rec?.session?.id ?? rec?.id ?? rec?.sessionId;
5875
+ const v = rec?.session?.id ?? rec?.id ?? rec?.sessionId ?? rec?.header?.id ?? rec?.session?.header?.id;
5539
5876
  return typeof v === "string" && v.length > 0 ? v : undefined;
5540
5877
  }
5541
5878
  function parentOf(rec) {
5542
- const v = rec?.session?.parentSession ?? rec?.parentSession ?? rec?.parentSessionId;
5879
+ const v = rec?.session?.parentSession ?? rec?.parentSession ?? rec?.parentSessionId ?? rec?.header?.parentSession ?? rec?.session?.header?.parentSession;
5543
5880
  return typeof v === "string" && v.length > 0 ? v : undefined;
5544
5881
  }
5545
5882
  function toSessionEvents(read, fallbackId) {
@@ -5561,82 +5898,151 @@ function toSessionEvents(read, fallbackId) {
5561
5898
  events
5562
5899
  };
5563
5900
  }
5564
- function collectLineageIds(node, out, depth = 0) {
5565
- if (node === null || typeof node !== "object" || depth > 8)
5901
+ function createdAtOf(rec) {
5902
+ const v = rec?.header?.createdAt ?? rec?.session?.header?.createdAt ?? rec?.createdAt;
5903
+ return typeof v === "number" && Number.isFinite(v) ? v : 0;
5904
+ }
5905
+ function normalizeSessionId(id) {
5906
+ const s = typeof id === "string" ? id : "";
5907
+ return s.startsWith("session-") ? s.slice("session-".length) : s;
5908
+ }
5909
+ function collectLineageNodes(node, out, depth = 0) {
5910
+ if (node === null || typeof node !== "object" || depth > MAX_LINEAGE_WALK_DEPTH)
5566
5911
  return;
5567
5912
  if (Array.isArray(node)) {
5568
5913
  for (const item of node)
5569
- collectLineageIds(item, out, depth + 1);
5914
+ collectLineageNodes(item, out, depth + 1);
5570
5915
  return;
5571
5916
  }
5572
5917
  const direct = idOf(node);
5573
- if (direct)
5574
- out.add(direct);
5918
+ if (direct && !out.has(direct))
5919
+ out.set(direct, { id: direct, createdAt: createdAtOf(node) });
5575
5920
  for (const value of Object.values(node)) {
5576
5921
  if (value !== null && typeof value === "object")
5577
- collectLineageIds(value, out, depth + 1);
5922
+ collectLineageNodes(value, out, depth + 1);
5923
+ }
5924
+ }
5925
+ function sampleNewest(nodes, limit) {
5926
+ const sorted = [...nodes].sort((a, b) => b.createdAt - a.createdAt || a.id.localeCompare(b.id));
5927
+ return sorted.slice(0, Math.max(0, limit)).map((n) => n.id);
5928
+ }
5929
+ function toDiscovery(nodes, source) {
5930
+ const total = nodes.size;
5931
+ const ids = sampleNewest(nodes.values(), MAX_CHILD_SESSIONS);
5932
+ return { ids, total, truncated: total > ids.length, source };
5933
+ }
5934
+ function applyDiscoveryCoverage(coverage, discovery, childReadFailed = 0) {
5935
+ const failed = Math.max(0, childReadFailed);
5936
+ const sampled = discovery.ids.length;
5937
+ const sessionsAnalyzed = Math.max(0, sampled - failed);
5938
+ coverage.lineageTotal = discovery.total;
5939
+ coverage.sessionsAnalyzed = sessionsAnalyzed;
5940
+ coverage.sessionsTruncated = discovery.total > sessionsAnalyzed;
5941
+ const sampledOut = sampled < discovery.total;
5942
+ const readFailed = failed > 0;
5943
+ if (sampledOut && readFailed) {
5944
+ coverage.samplingNote = "按创建时间倒序取最新,且存在读取失败的子会话";
5945
+ } else if (sampledOut) {
5946
+ coverage.samplingNote = "按创建时间倒序取最新";
5947
+ } else if (readFailed) {
5948
+ coverage.samplingNote = "存在读取失败的子会话";
5949
+ } else {
5950
+ coverage.samplingNote = undefined;
5578
5951
  }
5579
5952
  }
5580
5953
  async function findChildIds(ctx, rootId, signal) {
5581
- const ids = new Set;
5582
5954
  try {
5583
5955
  const trace = ctx?.sessionQuery?.traceSession;
5584
5956
  if (typeof trace === "function") {
5585
5957
  const tree = await trace.call(ctx.sessionQuery, rootId, signal);
5586
- const found = new Set;
5587
- collectLineageIds(tree?.descendants, found);
5588
- for (const id of found)
5589
- if (id !== rootId)
5590
- ids.add(id);
5958
+ if (tree !== null && typeof tree === "object") {
5959
+ const found = new Map;
5960
+ collectLineageNodes(tree?.descendants, found);
5961
+ const rootKey = normalizeSessionId(rootId);
5962
+ for (const id of [...found.keys()]) {
5963
+ if (id === rootId || normalizeSessionId(id) === rootKey)
5964
+ found.delete(id);
5965
+ }
5966
+ return toDiscovery(found, "trace");
5967
+ }
5591
5968
  }
5592
5969
  } catch (error) {
5593
5970
  ctx.logger?.warn?.("[cohub review] traceSession 失败:" + String(error?.message ?? error));
5594
5971
  }
5595
- if (ids.size > 0)
5596
- return [...ids].slice(0, MAX_CHILD_SESSIONS);
5597
5972
  try {
5598
5973
  const list = await ctx.sessionQuery.listSessions(signal);
5599
5974
  const records = Array.isArray(list) ? list : [];
5600
5975
  const byParent = new Map;
5601
5976
  for (const rec of records) {
5602
- const id = idOf(rec);
5603
5977
  const parent = parentOf(rec);
5604
- if (!id || !parent)
5978
+ const key = normalizeSessionId(parent);
5979
+ if (!key)
5605
5980
  continue;
5606
- const bucket = byParent.get(parent) ?? [];
5607
- bucket.push(id);
5608
- byParent.set(parent, bucket);
5981
+ const bucket = byParent.get(key) ?? [];
5982
+ bucket.push(rec);
5983
+ byParent.set(key, bucket);
5609
5984
  }
5610
- const queue = [rootId];
5611
- while (queue.length > 0 && ids.size < MAX_CHILD_SESSIONS) {
5985
+ const found = new Map;
5986
+ const rootKey = normalizeSessionId(rootId);
5987
+ const queue = [rootKey];
5988
+ const seenParents = new Set([rootKey]);
5989
+ while (queue.length > 0) {
5612
5990
  const cur = queue.shift();
5613
- for (const child of byParent.get(cur) ?? []) {
5614
- if (child === rootId || ids.has(child))
5991
+ for (const rec of byParent.get(cur) ?? []) {
5992
+ const id = idOf(rec);
5993
+ if (!id)
5994
+ continue;
5995
+ const idKey = normalizeSessionId(id);
5996
+ if (idKey === rootKey || found.has(id))
5615
5997
  continue;
5616
- ids.add(child);
5617
- queue.push(child);
5998
+ found.set(id, { id, createdAt: createdAtOf(rec) });
5999
+ if (!seenParents.has(idKey)) {
6000
+ seenParents.add(idKey);
6001
+ queue.push(idKey);
6002
+ }
5618
6003
  }
5619
6004
  }
6005
+ return toDiscovery(found, "list");
5620
6006
  } catch (error) {
5621
6007
  ctx.logger?.warn?.("[cohub review] listSessions 失败:" + String(error?.message ?? error));
5622
6008
  }
5623
- return [...ids];
6009
+ return { ids: [], total: 0, truncated: false, source: "list" };
5624
6010
  }
5625
- function writeTextAtomic(file, text) {
6011
+ function writeTextAtomic2(file, text) {
5626
6012
  const tmp = file + ".tmp";
5627
6013
  try {
5628
- mkdirSync4(dirname4(file), { recursive: true });
5629
- writeFileSync4(tmp, text, "utf8");
5630
- renameSync2(tmp, file);
6014
+ mkdirSync5(dirname5(file), { recursive: true });
6015
+ writeFileSync5(tmp, text, "utf8");
6016
+ renameSync3(tmp, file);
5631
6017
  return true;
5632
6018
  } catch {
5633
6019
  try {
5634
- if (existsSync4(tmp))
5635
- renameSync2(tmp, tmp + ".failed");
6020
+ if (existsSync5(tmp))
6021
+ renameSync3(tmp, tmp + ".failed");
5636
6022
  } catch {}
5637
6023
  return false;
5638
6024
  }
5639
6025
  }
6026
+ function appendErrorLog(cwd, sessionId, message) {
6027
+ try {
6028
+ const logPath = reviewStorePath(cwd, sessionId, "_errors.log");
6029
+ mkdirSync5(dirname5(logPath), { recursive: true });
6030
+ appendFileSync(logPath, new Date().toISOString() + "\t" + sessionId + "\t" + message.replace(/\s+/g, " ").slice(0, 500) + `
6031
+ `, "utf8");
6032
+ } catch {}
6033
+ }
6034
+ function writeErrorRecord(cwd, sessionId, error) {
6035
+ const stamp = new Date().toISOString().replace(/[:.]/g, "-");
6036
+ const payload = {
6037
+ error: String(error?.message ?? error),
6038
+ stack: typeof error?.stack === "string" ? error.stack : undefined,
6039
+ sessionId,
6040
+ cwd: cwd ?? null,
6041
+ timestamp: new Date().toISOString()
6042
+ };
6043
+ const file = reviewStorePath(cwd, sessionId, "error-" + stamp + ".json");
6044
+ return writeTextAtomic2(file, JSON.stringify(payload, null, 2)) ? file : null;
6045
+ }
5640
6046
  function buildDigest(report) {
5641
6047
  const lines = [];
5642
6048
  lines.push("rootSessionId: " + report.rootSessionId);
@@ -5776,8 +6182,9 @@ function buildEvidenceIndex(sessions) {
5776
6182
  }
5777
6183
  return index;
5778
6184
  }
5779
- function normalizeFindings(raw, index, defaultSessionId) {
6185
+ function normalizeFindings(raw, index, defaultSessionId, warn) {
5780
6186
  const KINDS = new Set(["observation", "praise", "issue", "suggestion"]);
6187
+ const SEVERITIES = new Set(["low", "medium", "high"]);
5781
6188
  const out = [];
5782
6189
  for (const item of raw) {
5783
6190
  const rec = item;
@@ -5807,7 +6214,21 @@ function normalizeFindings(raw, index, defaultSessionId) {
5807
6214
  evidence.push({ sessionId, turn, seq, callId });
5808
6215
  }
5809
6216
  const limitations = Array.isArray(rec?.limitations) ? rec.limitations.filter((x) => typeof x === "string").slice(0, 5) : [];
5810
- out.push({ id: "f-" + String(out.length + 1).padStart(3, "0"), kind, text, evidence, limitations });
6217
+ let severity;
6218
+ if (kind === "issue") {
6219
+ if (SEVERITIES.has(rec?.severity)) {
6220
+ severity = rec.severity;
6221
+ } else {
6222
+ severity = "medium";
6223
+ warn?.("issue 缺合法 severity(" + String(rec?.severity) + "),已降级为 medium:" + text.slice(0, 40));
6224
+ }
6225
+ } else if (SEVERITIES.has(rec?.severity)) {
6226
+ warn?.("非 issue(" + kind + ")带了 severity=" + String(rec?.severity) + ",已丢弃:" + text.slice(0, 40));
6227
+ }
6228
+ const finding = { id: "f-" + String(out.length + 1).padStart(3, "0"), kind, text, evidence, limitations };
6229
+ if (severity !== undefined)
6230
+ finding.severity = severity;
6231
+ out.push(finding);
5811
6232
  if (out.length >= 30)
5812
6233
  break;
5813
6234
  }
@@ -5902,7 +6323,9 @@ async function callAnalysis(ctx, agent, digest, signal) {
5902
6323
  const prompt = [
5903
6324
  "下面是某会话的统计摘要(每行 turn 含 end 事件 seq、usage、工具状态)。",
5904
6325
  "请输出 JSON 数组,每项形如:",
5905
- '{"kind":"observation|praise|issue|suggestion","text":"中文结论","evidence":[{"sessionId":"...","turn":1,"seq":42,"callId":null}],"limitations":["..."]}',
6326
+ '{"kind":"observation|praise|issue|suggestion","severity":"high|medium|low(仅 kind=issue 时给)","text":"中文结论","evidence":[{"sessionId":"...","turn":1,"seq":42,"callId":null}],"limitations":["..."]}',
6327
+ "severity 规则:kind=issue **必须**给 severity,取值只能是 high / medium / low;kind 为 observation / praise / suggestion 时**不要输出 severity**(会被丢弃)。",
6328
+ "severity 判据:high = 导致任务失败、数据丢失、需人工介入、或明显浪费大量 token/时间(如单轮输入 200+ 倍于输出、整轮中断);" + "medium = 效率明显下降、有返工、需要额外轮次才完成;low = 轻微冗余、可读性/组织性问题、不影响结果。",
5906
6329
  "硬规则:每条必须带至少 1 条 evidence;evidence 的 sessionId/turn/seq 必须来自下方摘要中真实出现的数据;",
5907
6330
  "不要编造 seq,不要给无证据的结论(无证据结论将被丢弃)。最多 12 条。",
5908
6331
  "",
@@ -5936,7 +6359,15 @@ async function callAnalysis(ctx, agent, digest, signal) {
5936
6359
  }
5937
6360
  async function readRootSession(ctx, sessionId, signal) {
5938
6361
  let current = sessionId;
5939
- let read = await ctx.sessionQuery.readSession(current, signal);
6362
+ let read;
6363
+ let failed;
6364
+ try {
6365
+ read = await ctx.sessionQuery.readSession(current, signal);
6366
+ } catch (error) {
6367
+ failed = "根会话读取失败(" + String(error?.message ?? error) + ")";
6368
+ ctx.logger?.warn?.("[cohub review] " + failed + ",降级为空事件继续出报告");
6369
+ read = { session: { id: current }, events: [] };
6370
+ }
5940
6371
  const seen = new Set([current]);
5941
6372
  for (let depth = 0;depth < MAX_ROOT_ASCEND; depth++) {
5942
6373
  const parent = parentOf(read);
@@ -5955,26 +6386,61 @@ async function readRootSession(ctx, sessionId, signal) {
5955
6386
  current = parent;
5956
6387
  read = parentRead;
5957
6388
  }
5958
- return { sessionId: current, read };
6389
+ return { sessionId: current, read, failed };
5959
6390
  }
5960
6391
  async function runAnalysis(ctx, agent, sessionId, cwdHint, withLlm) {
5961
- const signal = undefined;
5962
- const { sessionId: rootId, read: rootRead } = await readRootSession(ctx, sessionId, signal);
6392
+ const controller = new AbortController;
6393
+ const timer = setTimeout(() => controller.abort(), ANALYSIS_TIMEOUT_MS);
6394
+ const signal = controller.signal;
6395
+ try {
6396
+ await runAnalysisInner(ctx, agent, sessionId, cwdHint, withLlm, signal);
6397
+ } catch (error) {
6398
+ const errorPath = writeErrorRecord(cwdHint, sessionId, error);
6399
+ ctx.logger?.warn?.("[cohub review] 分析失败(error-*.json " + (errorPath !== null ? "已" : "未") + "落盘):" + String(error?.message ?? error));
6400
+ if (errorPath !== null) {
6401
+ try {
6402
+ updateIndex({
6403
+ cwd: cwdHint,
6404
+ sessionId,
6405
+ status: "failed",
6406
+ findings: 0,
6407
+ sessions: 0,
6408
+ jsonPath: errorPath,
6409
+ mdPath: null,
6410
+ projectCopyPath: null,
6411
+ note: "本次复盘整体失败,仅落盘 error 记录:" + String(error?.message ?? error).slice(0, 200),
6412
+ lineageTotal: undefined,
6413
+ sessionsTruncated: undefined
6414
+ });
6415
+ } catch {}
6416
+ }
6417
+ throw error;
6418
+ } finally {
6419
+ clearTimeout(timer);
6420
+ }
6421
+ }
6422
+ async function runAnalysisInner(ctx, agent, sessionId, cwdHint, withLlm, signal) {
6423
+ const { sessionId: rootId, read: rootRead, failed: rootFailed } = await readRootSession(ctx, sessionId, signal);
5963
6424
  const root = toSessionEvents(rootRead, rootId);
5964
- const childIds = await findChildIds(ctx, root.sessionId, signal);
6425
+ const discovery = await findChildIds(ctx, root.sessionId, signal);
5965
6426
  const children = [];
5966
6427
  const gaps = [];
5967
- for (const childId of childIds) {
6428
+ let childReadFailed = 0;
6429
+ if (rootFailed)
6430
+ gaps.push(rootId + ": " + rootFailed);
6431
+ for (const childId of discovery.ids) {
5968
6432
  try {
5969
6433
  const read = await ctx.sessionQuery.readSession(childId, signal);
5970
6434
  children.push(toSessionEvents(read, childId));
5971
6435
  } catch (error) {
6436
+ childReadFailed++;
5972
6437
  gaps.push(childId + ": 子会话读取失败(" + String(error?.message ?? error) + ")");
5973
6438
  }
5974
6439
  }
5975
6440
  const report = buildReport({ root, children });
6441
+ applyDiscoveryCoverage(report.coverage, discovery, childReadFailed);
5976
6442
  report.coverage.gaps.push(...gaps);
5977
- if (gaps.length > 0)
6443
+ if (childReadFailed > 0 || rootFailed)
5978
6444
  report.coverage.complete = false;
5979
6445
  const cwd = root.cwd ?? cwdHint;
5980
6446
  const { text: digest, digest: inputDigest, truncated } = buildDigest(report);
@@ -5994,7 +6460,7 @@ async function runAnalysis(ctx, agent, sessionId, cwdHint, withLlm) {
5994
6460
  const rawItems = extracted.items;
5995
6461
  if (rawItems !== null) {
5996
6462
  const index = buildEvidenceIndex([root, ...children]);
5997
- report.findings = normalizeFindings(rawItems, index, root.sessionId);
6463
+ report.findings = normalizeFindings(rawItems, index, root.sessionId, (msg) => ctx.logger?.warn?.("[cohub review] " + msg));
5998
6464
  const dropped = rawItems.length - report.findings.length;
5999
6465
  if (extracted.truncated) {
6000
6466
  analysis.status = "interrupted";
@@ -6027,15 +6493,40 @@ async function runAnalysis(ctx, agent, sessionId, cwdHint, withLlm) {
6027
6493
  }
6028
6494
  const md = renderMarkdown(report, { excerptLimit: 120 });
6029
6495
  const stamp = new Date().toISOString().replace(/[:.]/g, "-");
6030
- const jsonPath = reviewStorePath(cwd, root.sessionId, "report-" + stamp + ".json");
6031
- const mdPath = reviewStorePath(cwd, root.sessionId, "report-" + stamp + ".md");
6032
- const jsonOk = writeTextAtomic(jsonPath, JSON.stringify(report, null, 2));
6033
- const mdOk = writeTextAtomic(mdPath, md);
6496
+ const jsonPath = reviewStorePath(cwd, sessionId, "report-" + stamp + ".json");
6497
+ const mdPath = reviewStorePath(cwd, sessionId, "report-" + stamp + ".md");
6498
+ const jsonOk = writeTextAtomic2(jsonPath, JSON.stringify(report, null, 2));
6499
+ const mdOk = writeTextAtomic2(mdPath, md);
6034
6500
  if (!jsonOk || !mdOk) {
6035
6501
  ctx.logger?.warn?.("[cohub review] 报告落盘失败:json=" + jsonPath + " md=" + mdPath);
6036
6502
  } else {
6037
6503
  ctx.logger.info?.("[cohub review] 报告已生成:" + mdPath);
6038
6504
  }
6505
+ const copy = writeProjectCopy(cwd, md, stamp);
6506
+ if (copy.path !== null) {
6507
+ ctx.logger.info?.("[cohub review] 项目内副本:" + copy.path);
6508
+ } else if (copy.note !== null) {
6509
+ ctx.logger?.warn?.("[cohub review] 未写项目内副本:" + copy.note);
6510
+ }
6511
+ try {
6512
+ const indexed = updateIndex({
6513
+ cwd,
6514
+ sessionId,
6515
+ status: analysis.status,
6516
+ findings: Array.isArray(report.findings) ? report.findings.length : 0,
6517
+ sessions: Array.isArray(report.sessions) ? report.sessions.length : 0,
6518
+ jsonPath,
6519
+ mdPath: mdOk ? mdPath : null,
6520
+ projectCopyPath: copy.path,
6521
+ note: copy.note ?? undefined,
6522
+ lineageTotal: report.coverage.lineageTotal,
6523
+ sessionsTruncated: report.coverage.sessionsTruncated
6524
+ });
6525
+ if (!indexed)
6526
+ ctx.logger?.warn?.("[cohub review] 复盘索引更新失败(不影响报告)");
6527
+ } catch (error) {
6528
+ ctx.logger?.warn?.("[cohub review] 复盘索引更新异常:" + String(error?.message ?? error));
6529
+ }
6039
6530
  }
6040
6531
  function cwdHintOf(inv) {
6041
6532
  const cwd = inv?.agent?.session?.header?.cwd ?? inv?.agent?.session?.meta?.cwd ?? inv?.agent?.options?.cwd ?? null;
@@ -6060,7 +6551,9 @@ function registerReviewCommand(ctx) {
6060
6551
  try {
6061
6552
  await runAnalysis(ctx, inv?.agent, sessionId, cwdHint, withLlm);
6062
6553
  } catch (error) {
6063
- ctx.logger?.warn?.("[cohub review] 报告生成失败:" + String(error?.message ?? error));
6554
+ const message = String(error?.message ?? error);
6555
+ appendErrorLog(cwdHint, sessionId, message);
6556
+ ctx.logger?.warn?.("[cohub review] 报告生成失败:" + message);
6064
6557
  } finally {
6065
6558
  inFlight.delete(sessionId);
6066
6559
  }
@@ -6278,14 +6771,14 @@ var CohubSettingsSchema = z2.object({
6278
6771
  var SHIPPED_PRESETS_DIR = fileURLToPath(new URL("../presets/", import.meta.url));
6279
6772
  function readPackageVersion() {
6280
6773
  try {
6281
- const pkg = JSON.parse(readFileSync4(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8"));
6774
+ const pkg = JSON.parse(readFileSync5(fileURLToPath(new URL("../package.json", import.meta.url)), "utf8"));
6282
6775
  return typeof pkg?.version === "string" ? pkg.version : "0.0.0";
6283
6776
  } catch {
6284
6777
  return "0.0.0";
6285
6778
  }
6286
6779
  }
6287
6780
  function installAgentPresets(logger) {
6288
- return installShippedPresets(SHIPPED_PRESETS_DIR, dshHomePath4(".agent-presets"), readPackageVersion(), logger);
6781
+ return installShippedPresets(SHIPPED_PRESETS_DIR, dshHomePath5(".agent-presets"), readPackageVersion(), logger);
6289
6782
  }
6290
6783
  function apply(ctx, config) {
6291
6784
  ctx.effect(() => ctx.systemPrompt.section({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-cohub",
3
- "version": "0.10.0",
3
+ "version": "0.10.2",
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",