deep-read-summarize 0.6.1 → 0.6.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.
package/CHANGELOG.md CHANGED
@@ -5,6 +5,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.6.2] — 2026-11-11
9
+
10
+ 修复成稿包含前言或外层 Markdown 围栏时,笔记被误判为格式、篇幅和引用不合格的问题。
11
+
12
+ ### Fixed
13
+
14
+ - **成稿包装导致质量误报**:识别唯一、明确的完整 Markdown 笔记,先移除其外层围栏或前言,再对同一份正文执行格式、篇幅和独立原文核验并返回;普通代码块仍不计入正文。无法明确提取时保留原始回复并照常报告质量问题。
15
+ - 可选的 `draftContext` 记录提取方式以及模型在笔记前后附带的说明;主代理向用户说明这些额外文字,它们没有通过笔记的原文核验。
16
+
17
+ ### Verification
18
+
19
+ - 回归测试覆盖普通成稿、围栏包装、修订稿、嵌套代码块及提取有歧义的情况。使用 DSH 真实模型精读论文,并在成稿后人为添加围栏,确认格式和篇幅检查不再受外层包装影响;该次笔记的引用核验未通过,真实质量问题仍会照常报告。
20
+
21
+ ### Compatibility
22
+
23
+ - 升级无需更改配置;只有识别到可明确提取的笔记时才移除包装,额外文字通过可选的 `draftContext` 返回。
24
+
25
+ ### 贡献者与致谢
26
+
27
+ - 感谢 @qneko 报告和复现成稿外层 Markdown 围栏造成的质量误报([Issue #9](https://github.com/PensiveFei/deep-read-summarize/issues/9))。
28
+
8
29
  ## [0.6.1] — 2026-11-10
9
30
 
10
31
  修复普通执行路径的结果序列化错误,避免已生成的精读笔记在返回宿主时被丢弃。
package/README.en.md CHANGED
@@ -65,6 +65,8 @@ You can also provide a local file, web page, or video link. If needed, specify a
65
65
 
66
66
  Hosts with plugin-tool support register `deep_read_summarize`; older hosts use the bundled skill and workflow entry point. The tool returns the note and a suggested path; **the main agent must write the file**. Check that the file was saved and whether the result reports gaps or quality issues.
67
67
 
68
+ When an identifiable note is extracted from a wrapper, the optional `draftContext` field records the extraction and retains any surrounding text. That text is not part of the note reviewed against the source.
69
+
68
70
  <details>
69
71
  <summary>Direct tool-call example</summary>
70
72
 
package/README.md CHANGED
@@ -65,6 +65,8 @@ https://arxiv.org/abs/2307.09042
65
65
 
66
66
  支持插件工具的宿主会注册 `deep_read_summarize`;旧宿主使用插件提供的技能和 workflow 入口。精读工具返回笔记正文及建议路径,**实际写入文件需要由主代理完成**。生成后请确认文件已保存,并检查结果中是否报告内容缺口或质量问题。
67
67
 
68
+ 当工作流提取被包装的笔记时,可选字段 `draftContext` 会记录提取方式,以及模型在笔记前后附带的额外说明。这些额外文字不是经过原文核验的笔记正文。
69
+
68
70
  <details>
69
71
  <summary>直接调用工具的参数示例</summary>
70
72
 
package/docs/RELEASE.md CHANGED
@@ -156,7 +156,8 @@ npm view deep-read-summarize --prefer-online # 验证线
156
156
  | v0.4.0 | npm 已发布 | 保留完整精读与独立原文核验,减少脚本搬运、并发空等和无效修订,并修复来源质量判断与视频分P等问题。 |
157
157
  | v0.5.0 | npm 已发布 | 无字幕视频新增逐字稿内容缓存、转写阶段计时和 CPU 线程配置,保留默认精读与原文核验门槛。 |
158
158
  | v0.6.0 | npm 已发布 | 新增可配置并发、字符均衡分块与可选的并行原文核验和跨次精读缓存,保留原有默认核验路径。 |
159
- | **v0.6.1** | **npm 已发布(当前)** | 修复普通执行路径的结果序列化错误,避免已生成的精读笔记在返回宿主时被丢弃。 |
159
+ | v0.6.1 | npm 已发布 | 修复普通执行路径的结果序列化错误,避免已生成的精读笔记在返回宿主时被丢弃。 |
160
+ | **v0.6.2** | **npm 已发布(当前)** | 修复成稿包含前言或外层 Markdown 围栏时,笔记被误判为格式、篇幅和引用不合格的问题。 |
160
161
  | v1.0.0 | 计划 | API 稳定后发布 |
161
162
 
162
163
  > 早期迭代用 0.x 表达不稳定;API 稳定后再发 1.0.0。
package/lib/quality.js CHANGED
@@ -1,7 +1,58 @@
1
1
  'use strict';
2
2
 
3
- // Both functions are self-contained so workflow.js can inline them into the
3
+ // These functions are self-contained so workflow.js can inline them into the
4
4
  // coordination sandbox. They never evaluate YAML or read files themselves.
5
+ function extractNote(reply) {
6
+ const unchanged = { note: reply, context: null };
7
+ if (typeof reply !== 'string' || /^\s*---[ \t]*\r?\n/.test(reply)) return unchanged;
8
+ const lines = reply.split('\n');
9
+ function line(index) { return lines[index].replace(/\r$/, ''); }
10
+ function slice(start, end) { return lines.slice(start, end).join('\n').replace(/\r$/, ''); }
11
+ function outsideIsProse(value) {
12
+ return value.length <= 512 && !/^(?: {0,3}(?:#{1,6}[ \t]|>|[-+*][ \t]|\d+[.)][ \t]|\||[\x60~]{3,})|[ \t]*---[ \t]*$)/m.test(value);
13
+ }
14
+ function looksLikeNote(value) {
15
+ const front = value.match(/^---[ \t]*\r?\n([\s\S]*?)\r?\n---[ \t]*(?:\r?\n|$)/);
16
+ return !!front && /^title:[ \t]*\S/m.test(front[1]) && /^#[ \t]+\S/m.test(value.slice(front[0].length));
17
+ }
18
+ function extracted(note, kind, before, after) {
19
+ const prefix = before.trim(), suffix = after.trim();
20
+ return { note, context: { kind, before: prefix, after: suffix } };
21
+ }
22
+
23
+ // A short plain-text preamble can precede an otherwise ordinary note,
24
+ // including one with its own code examples. Preserve that preamble.
25
+ for (let i = 1; i < lines.length; i++) {
26
+ if (!/^---[ \t]*$/.test(line(i))) continue;
27
+ const prefix = slice(0, i);
28
+ if (!outsideIsProse(prefix)) break;
29
+ const candidate = lines.slice(i).join('\n');
30
+ if (looksLikeNote(candidate)) return extracted(candidate, 'preamble', prefix, '');
31
+ }
32
+
33
+ // Treat only a single, closed top-level Markdown fence as an outer wrapper.
34
+ // Longer or differently marked inner fences remain part of the note.
35
+ const blocks = [];
36
+ for (let i = 0; i < lines.length; i++) {
37
+ const open = line(i).match(/^ {0,3}([\x60]{3,}|~{3,})(.*)$/);
38
+ if (!open) continue;
39
+ let end = i + 1;
40
+ for (; end < lines.length; end++) {
41
+ const close = line(end).match(/^ {0,3}([\x60]+|~+)[ \t]*$/);
42
+ if (close && close[1][0] === open[1][0] && close[1].length >= open[1].length) break;
43
+ }
44
+ if (end === lines.length) return unchanged;
45
+ blocks.push({ start: i, end, info: open[2].trim() });
46
+ i = end;
47
+ }
48
+ if (blocks.length !== 1 || !/^(?:markdown|md)?$/i.test(blocks[0].info)) return unchanged;
49
+ const block = blocks[0], before = slice(0, block.start), after = slice(block.end + 1);
50
+ const candidate = slice(block.start + 1, block.end)
51
+ .replace(/^(?:[ \t]*\r?\n)+/, '').replace(/(?:\r?\n[ \t]*)+$/, '');
52
+ if (!outsideIsProse(before) || !outsideIsProse(after) || !looksLikeNote(candidate)) return unchanged;
53
+ return extracted(candidate, 'fenced', before, after);
54
+ }
55
+
5
56
  function checkNoteStructure(note, options) {
6
57
  const opts = options || {};
7
58
  const issues = [];
@@ -215,4 +266,4 @@ function validateSourceCheck(check, context) {
215
266
  return { passed: issues.length === 0 && gates.every(gate => results[gate]), checks: results, issues, chunkChecks, citationChecks };
216
267
  }
217
268
 
218
- module.exports = { checkNoteStructure, validateSourceCheck };
269
+ module.exports = { extractNote, checkNoteStructure, validateSourceCheck };
@@ -376,7 +376,7 @@ if (fmProfile === "obsidian") {
376
376
  fm.push("---");
377
377
 
378
378
  const draftPrompt = [
379
- "将以下多块精读结果整合为完整的结构化精读笔记,只输出标准 Markdown(含 YAML frontmatter)。",
379
+ "将以下多块精读结果整合为完整的结构化精读笔记,只输出标准 Markdown(含 YAML frontmatter),不要前言、结尾说明或包裹整篇笔记的代码围栏;笔记内部需要的代码块可保留。",
380
380
  sourceComplete ? "来源完整性仍需由独立原文核验确认。" : "本次来源不完整。必须在正文开头保留以下可见来源限制,不得称为完整视频精读或补写未取得的视频内容:\n" + sourceNotice,
381
381
  "模板:"
382
382
  ].concat(fm, [
@@ -410,7 +410,10 @@ if (typeof draft !== "string" || !draft.trim()) return timedResult({ ok: false,
410
410
  // ---------- 5. 程序检查 + 独立原文核验 ----------
411
411
  phase("质量校验");
412
412
  const qualityStartedAt = Date.now();
413
- let verified = draft;
413
+ const extractedDraft = __quality.extractNote(draft);
414
+ let verified = extractedDraft.note;
415
+ const draftContext = [];
416
+ if (extractedDraft.context) draftContext.push(Object.assign({ stage: "draft" }, extractedDraft.context));
414
417
  let passed = false;
415
418
  let issues = [];
416
419
  let qualityChecks = {};
@@ -560,7 +563,7 @@ for (let round = 0; round <= maxRetries; round++) {
560
563
  if (!repairableSource) break;
561
564
  if (round < maxRetries) {
562
565
  const fixPrompt = [
563
- "修正以下笔记以解决校验问题,输出完整修正版:",
566
+ "修正以下笔记以解决校验问题,只输出完整修正版 Markdown,不要前言、结尾说明或包裹整篇笔记的代码围栏:",
564
567
  issues.map(function (s) { return "- " + s; }).join("\n"),
565
568
  "原文路径和覆盖证据(必要时用 read 核对,不能臆造缺口):", JSON.stringify(sourceContext),
566
569
  "必须保留的 frontmatter 模板:", fm.join("\n"),
@@ -575,11 +578,13 @@ for (let round = 0; round <= maxRetries; round++) {
575
578
  if (typeof repaired !== "string" || !repaired.trim()) {
576
579
  issues.push("修正结果为空或不是字符串,已保留上一份有效笔记"); break;
577
580
  }
578
- const repairedStructure = __quality.checkNoteStructure(repaired, structureOptions);
581
+ const extractedRepair = __quality.extractNote(repaired);
582
+ const repairedStructure = __quality.checkNoteStructure(extractedRepair.note, structureOptions);
579
583
  if (!repairedStructure.formatComplete || (localCheck.lengthMet && !repairedStructure.lengthMet)) {
580
584
  issues.push("修正结果格式不完整或篇幅退化,已保留上一份有效笔记"); break;
581
585
  }
582
- verified = repaired;
586
+ verified = extractedRepair.note;
587
+ if (extractedRepair.context) draftContext.push(Object.assign({ stage: "repair" }, extractedRepair.context));
583
588
  }
584
589
  }
585
590
 
@@ -603,6 +608,7 @@ return timedResult({
603
608
  coverageComplete: coverageComplete,
604
609
  textSource: textSource,
605
610
  sourceComplete: sourceComplete,
611
+ ...(draftContext.length ? { draftContext: draftContext } : {}),
606
612
  note: verified,
607
613
  ...(cacheResume ? { __cacheReads: reads } : {})
608
614
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deep-read-summarize",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "Deep reading & summarization for DSH: books/papers/videos/web → structured Markdown notes with YAML frontmatter. Plugin parsers, MapReduce deep-read, JSON Schema-constrained sub-tasks.",
5
5
  "type": "commonjs",
6
6
  "main": "index.js",
@@ -44,13 +44,13 @@ whenToUse: 用户提供一本书、论文(arXiv/PDF)、视频链接(YouTub
44
44
  6. **波次3 合并成稿**:整合为完整笔记(Reduce),内嵌质量自检
45
45
  7. **质量校验**:程序检查 frontmatter 模板、必要章节和篇幅;核验代理必须读取本次原文,逐块提供摘录、对第 4 节逐字引用提供原句与行号。`parallelQuality: true` 时多分块由独立代理并行核验各块及全部显式引文,另由代理检查全局术语与语言一致性;默认沿用原核验路径,`readConcurrency` 同时限制并行核验并发。不得只看笔记或仅返回 pass。`qualityEvidence` 可供回查;核验失败必须如实报告。`maxRetries` 为 0–3,修订失败、空结果或结构退化时保留上一份有效成稿。缺总行数、精读失败、仅简介或未知视频来源等问题不能靠改写笔记消除,不进行徒劳全文修订
46
46
  8. **落盘(必须,别跳过)**:精读工具只返回 `note`(笔记正文)与 `filePath`(建议路径)——**脚本本身没有文件系统权限**。拿到结果后要用 `write` 工具把 `note` 原样写入 `filePath`(目录不存在就先创建);不写就等于笔记丢了,用户只会看到一段返回文本
47
- 9. **如实交代结果**:`ok: false` 要说明卡在哪一步(`stage`)和原因,别拿半成品冒充成品;`qualityPassed: false`、`qualityIssues` 非空、或 `failedChunks > 0`(有块精读失败、笔记存在缺口)时,必须在回复里点出来
47
+ 9. **如实交代结果**:`ok: false` 要说明卡在哪一步(`stage`)和原因,别拿半成品冒充成品;`qualityPassed: false`、`qualityIssues` 非空、或 `failedChunks > 0`(有块精读失败、笔记存在缺口)时,必须在回复里点出来。若 `draftContext` 中 `before` 或 `after` 非空,向用户说明其中保留的成稿额外文字;这些文字未通过原文核验,不要把它当成已核验的笔记内容
48
48
 
49
49
  跨次精读缓存默认关闭,仅插件工具入口支持;启用 `readCache` 时必须填写 `readCacheIdentity`(供应商、固定模型版本及输出相关设置)。身份由调用者保证,变更时必须更换;缓存明文保存在 `tempDir/.read-cache-v1`,可能包含原文摘录,命中后仍独立核验原文。
50
50
 
51
51
  ## 输出
52
52
 
53
- 精读工具返回 `{ ok, filePath, note, qualityPassed, qualityIssues, qualityChecks, qualityEvidence, failedChunks, coverageComplete, sourceComplete, textSource, timings, readTimings }`。`coverageComplete: false` 表示缺少有效总行数,无法确认尾部覆盖;`sourceComplete: false` 表示视频仅有简介或来源未确认,笔记会保留来源限制且质量降级。来源完整性仍依据获取代理声明,不能当作视频真实内容已全部证明。`timings` 提供 detect/fetch/read/draft/quality/total 毫秒耗时;`readTimings` 提供精读块的行号、毫秒耗时、成功状态及缓存命中状态,不能由此推测未提供的 token 用量。
53
+ 精读工具返回 `{ ok, filePath, note, qualityPassed, qualityIssues, qualityChecks, qualityEvidence, failedChunks, coverageComplete, sourceComplete, textSource, timings, readTimings }`;可选 `draftContext` 记录成稿或修订稿的提取方式(`stage`、`kind`)及笔记前后额外文字(`before`、`after`),`kind` 为 `fenced` 或 `preamble`。`coverageComplete: false` 表示缺少有效总行数,无法确认尾部覆盖;`sourceComplete: false` 表示视频仅有简介或来源未确认,笔记会保留来源限制且质量降级。来源完整性仍依据获取代理声明,不能当作视频真实内容已全部证明。`timings` 提供 detect/fetch/read/draft/quality/total 毫秒耗时;`readTimings` 提供精读块的行号、毫秒耗时、成功状态及缓存命中状态,不能由此推测未提供的 token 用量。
54
54
 
55
55
  > ⚠️ **`note` 就是完整笔记正文,`filePath` 只是建议路径**:脚本运行在无文件系统的沙箱里(DSH 的 workflow 契约:脚本只负责协调子代理),**它不会替你写文件**。必须由你(主代理)在拿到结果后用 `write` 工具把它写到 `filePath`——默认 `./output/`,可用 `options.outputDir` 指向 Obsidian 仓库或静态站点的内容目录。
56
56
 
package/workflow.js CHANGED
@@ -80,7 +80,8 @@ function buildSelfContainedScript(parserRegistry = parsers.registry) {
80
80
  const runtimePaths = { transcribeScript: fs.realpathSync(path.join(__dirname, 'scripts', 'transcribe.js')), chunkBalanceScript: fs.realpathSync(path.join(__dirname, 'scripts', 'chunk-balance.js')) };
81
81
  return 'const __runtimePaths = ' + JSON.stringify(runtimePaths) + ';\n' +
82
82
  'const normalizeWorkflowOptions = ' + normalizeWorkflowOptions.toString() + ';\n' +
83
- 'const __quality = { checkNoteStructure: ' + quality.checkNoteStructure.toString() +
83
+ 'const __quality = { extractNote: ' + quality.extractNote.toString() +
84
+ ', checkNoteStructure: ' + quality.checkNoteStructure.toString() +
84
85
  ', validateSourceCheck: ' + quality.validateSourceCheck.toString() + ' };\n' +
85
86
  RAW_SCRIPT.replace(marker, impl + "\nconst parsers = args._parsers || __parsers;");
86
87
  }