deep-read-summarize 0.3.17 → 0.3.19

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/parsers/index.js CHANGED
@@ -30,22 +30,46 @@ const builtins = {
30
30
  */
31
31
  class ParserRegistry {
32
32
  constructor() {
33
- this.parsers = { ...builtins };
33
+ this.parsers = Object.create(null);
34
+ this._sources = new WeakMap();
35
+ for (const type of Object.keys(builtins)) this.register(builtins[type], require.resolve('./' + type));
34
36
  this._loadCustom();
35
37
  }
36
38
 
39
+ /** Remember the module, not just its function: module factories preserve helpers and closures. */
40
+ register(mod, filename) {
41
+ if (!mod || typeof mod.name !== 'string' || !mod.name.trim() || typeof mod.buildPrompt !== 'function') {
42
+ throw new Error('parser must expose a name and buildPrompt(input, options) function');
43
+ }
44
+ const types = mod.types === undefined ? [mod.name] : mod.types;
45
+ if (!Array.isArray(types) || !types.length || types.some(function (type) { return typeof type !== 'string' || !type.trim(); })) {
46
+ throw new Error('parser.types must be a non-empty array of type names');
47
+ }
48
+ if (filename) this._sources.set(mod, { filename: filename, buildPrompt: mod.buildPrompt });
49
+ for (const type of types) this.parsers[type] = mod;
50
+ return mod;
51
+ }
52
+
53
+ sourceFor(mod) {
54
+ const known = this._sources.get(mod);
55
+ if (known) return known.buildPrompt === mod.buildPrompt ? known.filename : undefined;
56
+ // Also preserve modules supplied programmatically through registry.parsers.
57
+ for (const filename of Object.keys(require.cache)) {
58
+ if (require.cache[filename].exports === mod) return filename;
59
+ }
60
+ return undefined;
61
+ }
62
+
37
63
  _loadCustom() {
38
64
  const customDir = path.join(__dirname, "..", "custom-parsers");
39
65
  if (!fs.existsSync(customDir)) return;
40
66
  for (const file of fs.readdirSync(customDir)) {
41
67
  if (!file.endsWith(".js")) continue;
42
68
  try {
43
- const mod = require(path.join(customDir, file));
69
+ const filename = path.join(customDir, file);
70
+ const mod = require(filename);
44
71
  if (mod && mod.name && mod.buildPrompt) {
45
- // 支持自定义类型名,或覆盖内置类型
46
- for (const t of mod.types || [mod.name]) {
47
- this.parsers[t] = mod;
48
- }
72
+ this.register(mod, filename);
49
73
  console.log("[parsers] loaded custom parser:", mod.name);
50
74
  }
51
75
  } catch (e) {
@@ -82,5 +106,6 @@ const registry = new ParserRegistry();
82
106
  module.exports = {
83
107
  resolve: (type) => registry.resolve(type),
84
108
  list: () => registry.list(),
85
- registry
109
+ registry,
110
+ ParserRegistry
86
111
  };
package/parsers/video.js CHANGED
@@ -31,6 +31,7 @@ module.exports = {
31
31
  const whisperModel = o.whisperModel || "small";
32
32
  const language = o.language || "zh";
33
33
  const device = o.device || "cpu";
34
+ const includeTimestamps = o.includeTimestamps === true;
34
35
  const degradeMsg = "需要人工提供转写文本或视频文案";
35
36
 
36
37
  const noSubtitleBranch = wantTranscribe
@@ -48,6 +49,9 @@ module.exports = {
48
49
 
49
50
  const steps = [
50
51
  "记录文本来源(metadata.textSource):subtitle(平台字幕)/ transcription(本地转写)/ desc(仅简介,作为降级/背景)/ manual(用户提供)。",
52
+ includeTimestamps
53
+ ? "保留真实时间定位:B站字幕保留每条 from/to,YouTube CC 保留每条 cue 的 start/end;转成文本时每段独占一行,格式为 [HH:MM:SS.mmm --> HH:MM:SS.mmm] 原文。写入目标文件时保留这些时间,不可把全文压成一行。简介/人工文案若没有真实时间信息,明确注明无法提供时间戳,禁止猜测或编造。"
54
+ : "字幕或转写按原有分段逐段换行写入目标文件,保留内容结构,不要把全文压成一行;本次不要求在正文标时间戳。",
51
55
  "统一流程:① 先取视频字幕(B站 AI 字幕 / YouTube yt-dlp CC);" + noSubtitleBranch,
52
56
  "若输入是 B 站链接(bilibili.com / b23.tv,短链先用 curl -L 跟随重定向提取 BV 号):用 curl(Windows 10+ 与 macOS/Linux 均自带,零安装)调官方公开 API:\n" +
53
57
  " 1) 元数据+简介:curl 'https://api.bilibili.com/x/web-interface/view?bvid=<BV>' → 取 title / desc(简介仅作背景/补充,不满一篇精读)/ owner.name / duration / aid / cid\n" +
@@ -64,8 +68,8 @@ module.exports = {
64
68
  "转写执行(faster-whisper " + whisperModel + " / int8 / " + language + ",镜像+缓存,保证本机与用户一致):\n" +
65
69
  " ① 先取音频:B站用 playurl(curl 'https://api.bilibili.com/x/player/playurl?avid=<aid>&cid=<cid>&fnval=16&fourk=1' 的 dash.audio[0].baseUrl)或 yt-dlp,下载存到 '" + tempDir + "/audio.m4a';\n" +
66
70
  " ② 定位插件转写脚本(文件名固定 `transcribe.js`):Windows 用 `Get-ChildItem -Path $env:USERPROFILE/.dsh -Recurse -Filter transcribe.js`;macOS/Linux 用 `find \"$HOME/.dsh\" -name transcribe.js`(也可直接用 glob 搜 *transcribe.js);\n" +
67
- " ③ 运行(**三平台命令行完全一致**,脚本是 Node 写的,与 pwsh / bash 无关):`node <脚本路径> --audio '" + tempDir + "/audio.m4a' --out '" + tempDir + "/transcript.txt' --device " + device + " --model " + whisperModel + " --language " + language + "`;\n" +
68
- " ④ 转写可能较慢:用 run_in_background: true 启动后,轮询输出文件 '" + tempDir + "/transcript.txt' 是否写出内容(非空且稳定),或日志出现 DONE;设合理超时,超时/失败则降级;**脚本以非 0 退出也算失败**——包括「转写结果为空」(纯静音 / 纯音乐常见,脚本此时会删掉空文件),务必按降级处理,不要把空文件当成功;\n" +
71
+ " ③ 运行(**三平台命令行完全一致**,脚本是 Node 写的,与 pwsh / bash 无关):`node <脚本路径> --audio '" + tempDir + "/audio.m4a' --out '" + tempDir + "/transcript.txt' --device " + device + " --model " + whisperModel + " --language " + language + (includeTimestamps ? " --timestamps" : "") + "`;\n" +
72
+ " ④ 转写可能较慢:可用 run_in_background: true 启动,但必须跟踪**本次启动的进程**直到结束;只有确认**本次进程退出码为 0**,且本次目标文件 '" + tempDir + "/transcript.txt' 存在并非空,才算成功。脚本先写本次独有的暂存文件,校验后才原子发布目标文件;**不要仅凭文件非空/稳定或日志出现 DONE 判断完成,不要复用其他任务或上次运行的逐字稿**。设合理超时,超时则终止本次进程;超时/非 0 退出/空产物均按降级处理;\n" +
69
73
  " ⑤ 成功后读取 transcript.txt 作为全文(textSource=transcription)。脚本自举:uv 建 Python 3.12 环境 + 镜像装 faster-whisper + hf-mirror 下模型并缓存;Windows/macOS/Linux 是**同一份实现**。**⚠️ 首次转写会先下载模型(small 约 484MB,hf-mirror,非 GitHub)并较慢——先向用户说明这是正常的一次性下载,勿当成卡死;之后缓存复用、秒开。**\n" +
70
74
  " ⑥ 若 `node` 不在 PATH(macOS 从图形界面启动时常见),先用 `command -v node` 确认;确认不可用就直接降级,不要为了跑转写脚本去安装 Node。"
71
75
  );
package/schemas/index.js CHANGED
@@ -6,8 +6,9 @@
6
6
  // (kind 的 enum 按解析器注册表补齐),脚本里不再有第二份副本。
7
7
  // - chunkReadSchema:**workflow 没用**。波次2 的子代理直接返回自由文本,
8
8
  // 成稿时按 Markdown 拼接;这份留给程序化调用方(自建管线要结构化块输出时)。
9
- // - qualityChecklistSchema:**workflow 没用**。波次3 的内嵌自检走脚本内的
10
- // { pass, issues } 轻量 schema。
9
+ // - qualityChecklistSchema:留给程序化调用方的通用六项清单。
10
+ // workflow 使用脚本内的原文核验 schema(逐块摘录与引用行号证据);
11
+ // 格式和篇幅由 lib/quality.js 的程序检查决定,不能被模型的 pass 覆盖。
11
12
  // 改这个文件会直接影响波次1 —— 改完跑 npm test(内含 schema 子集回归)。
12
13
  //
13
14
  // 注意:本 schema 子集遵循 DSH workflow agent() 的约束
@@ -3,7 +3,7 @@
3
3
  // transcribe.js — faster-whisper 转写自举脚本(插件内部,跨平台:Windows/macOS/Linux)
4
4
  // ============================================================================
5
5
  // 用法(三平台完全一致,不需要 pwsh / bash 之别):
6
- // node transcribe.js --audio <音频文件> --out <输出txt> [--model small] [--language zh] [--device cpu|auto|cuda]
6
+ // node transcribe.js --audio <音频文件> --out <输出txt> [--model small] [--language zh] [--device cpu|auto|cuda] [--timestamps]
7
7
  // node transcribe.js --self-check # 只打印解析出的路径,不安装、不下载、不联网
8
8
  //
9
9
  // 为什么是 Node 而不是 PowerShell / shell:
@@ -152,15 +152,15 @@ function venvEnvAttempts(baseEnv, mirror) {
152
152
  /**
153
153
  * 判定转写产物是否可用。
154
154
  * 0 字节 = VAD 把整段音频滤掉了(纯静音 / 纯 BGM)或解码失败。此时**不能算成功**:
155
- * 调用方按「输出文件非空且稳定」判断完成,而提示词里还有一条「日志出现 DONE」——
156
- * 两者叠加会让空逐字稿被当成转写成功,再拿去做精读。所以删掉空文件并以非 0 退出(code 3)。
155
+ * 只有本次进程退出码为 0 且发布了非空输出才算完成;空产物保留在本次暂存目录,
156
+ * 清理后以非 0 退出(code 3),不会发布到调用方读取的最终路径。
157
157
  */
158
158
  function judgeTranscript(bytes) {
159
159
  if (bytes > 0) return { ok: true, code: 0, message: '' };
160
160
  return {
161
161
  ok: false,
162
162
  code: 3,
163
- message: '转写结果为空(0 字节):音频可能是纯静音 / 纯音乐,或解码失败。已删除空输出文件,请按降级处理(让用户提供文案,或用 options.transcribe=false)。'
163
+ message: '转写结果为空(0 字节):音频可能是纯静音 / 纯音乐,或解码失败。未发布空输出文件,请按降级处理(让用户提供文案,或用 options.transcribe=false)。'
164
164
  };
165
165
  }
166
166
 
@@ -171,7 +171,7 @@ function isFileAt(p) {
171
171
 
172
172
  /** 解析命令行(支持 --k v、--k=v、-k v 三种写法)。 */
173
173
  function parseArgs(argv) {
174
- const out = { audio: '', out: '', model: 'small', language: 'zh', device: 'cpu', selfCheck: false, help: false, unknown: [] };
174
+ const out = { audio: '', out: '', model: 'small', language: 'zh', device: 'cpu', timestamps: false, selfCheck: false, help: false, unknown: [] };
175
175
  const takes = {
176
176
  '--audio': 'audio', '-a': 'audio',
177
177
  '--out': 'out', '-o': 'out',
@@ -184,6 +184,8 @@ function parseArgs(argv) {
184
184
  const a = String(list[i]);
185
185
  if (a === '--help' || a === '-h') { out.help = true; continue; }
186
186
  if (a === '--self-check') { out.selfCheck = true; continue; }
187
+ if (a === '--timestamps' || a === '--timestamps=true') { out.timestamps = true; continue; }
188
+ if (a === '--no-timestamps' || a === '--timestamps=false') { out.timestamps = false; continue; }
187
189
  if (takes[a]) {
188
190
  const v = list[i + 1];
189
191
  if (v === undefined || String(v).indexOf('-') === 0) { out.unknown.push(a); continue; }
@@ -198,7 +200,7 @@ function parseArgs(argv) {
198
200
  return out;
199
201
  }
200
202
 
201
- /** 运行时 Python 片段:分段文本以空格连接成一行落盘;device 默认 cpu,非 cpu 失败自动回退。 */
203
+ /** 运行时 Python 片段:逐段换行,可保留真实起止时间;device 默认 cpu,非 cpu 失败自动回退。 */
202
204
  const PY_RUNNER = [
203
205
  "import os",
204
206
  "import sys",
@@ -210,7 +212,14 @@ const PY_RUNNER = [
210
212
  "def run(device):",
211
213
  " model = load(device)",
212
214
  " segs, info = model.transcribe(os.environ['DRS_AUDIO'], vad_filter=True, language=(os.environ.get('DRS_LANG') or None))",
213
- " return [s.text.strip() for s in segs], info",
215
+ " return [{'start': s.start, 'end': s.end, 'text': s.text.strip()} for s in segs], info",
216
+ "",
217
+ "def timestamp(seconds):",
218
+ " millis = max(0, int(round(float(seconds) * 1000)))",
219
+ " hours, millis = divmod(millis, 3600000)",
220
+ " minutes, millis = divmod(millis, 60000)",
221
+ " seconds, millis = divmod(millis, 1000)",
222
+ " return '%02d:%02d:%02d.%03d' % (hours, minutes, seconds, millis)",
214
223
  "",
215
224
  "# device 默认 cpu:ctranslate2 只要探测到 NVIDIA 显卡就会在 auto 下选 CUDA,",
216
225
  "# 而多数机器没装 cuBLAS/cuDNN(cublas64_12.dll),会在推理时硬失败(实测 RTX 3050 复现)。",
@@ -223,11 +232,19 @@ const PY_RUNNER = [
223
232
  " print('[transcribe] device=%s failed (%s); retrying on cpu' % (device, exc), file=sys.stderr)",
224
233
  " segments, info = run('cpu')",
225
234
  "",
226
- "# 先把全部分段收集完再落盘:中途失败时不会留下半截 transcript.txt",
227
- "# (调用方按「文件非空且稳定」判断完成,半截文件会被误判成成功)。",
228
- "with open(os.environ['DRS_OUT'], 'w', encoding='utf-8') as f:",
229
- " f.write(' '.join([x for x in segments if x]))",
230
- "print('DONE', info.language, round(info.duration, 1))",
235
+ "# DRS_OUT 是本次调用独有的暂存路径;Node 校验后才原子发布到最终路径。",
236
+ "# 先收集全部分段再落盘,中途推理失败不会留下半截文本。",
237
+ "include_timestamps = os.environ.get('DRS_TIMESTAMPS') == '1'",
238
+ "lines = []",
239
+ "for segment in segments:",
240
+ " text = segment['text'].replace('\\r', ' ').replace('\\n', ' ')",
241
+ " if not text:",
242
+ " continue",
243
+ " if include_timestamps:",
244
+ " text = '[%s --> %s] %s' % (timestamp(segment['start']), timestamp(segment['end']), text)",
245
+ " lines.append(text)",
246
+ "with open(os.environ['DRS_OUT'], 'w', encoding='utf-8', newline='\\n') as f:",
247
+ " f.write('\\n'.join(lines))",
231
248
  ""
232
249
  ].join("\n");
233
250
 
@@ -236,11 +253,12 @@ const PY_RUNNER = [
236
253
  // ---------------------------------------------------------------------------
237
254
 
238
255
  const USAGE = [
239
- '用法:node transcribe.js --audio <音频文件> --out <输出txt> [--model small] [--language zh] [--device cpu|auto|cuda]',
256
+ '用法:node transcribe.js --audio <音频文件> --out <输出txt> [--model small] [--language zh] [--device cpu|auto|cuda] [--timestamps]',
240
257
  ' node transcribe.js --self-check # 只打印解析出的路径,不安装不下载',
241
258
  '',
242
259
  '选项:--audio/-a --out/-o --model/-m(默认 small) --language/-l(默认 zh)',
243
- ' --device(默认 cpu;auto/cuda 需自备 CUDA 运行库,失败会自动回退 cpu)'
260
+ ' --device(默认 cpu;auto/cuda 需自备 CUDA 运行库,失败会自动回退 cpu)',
261
+ ' --timestamps(逐段保留真实起止时间;默认关闭,关闭时仍按段换行)'
244
262
  ].join('\n');
245
263
 
246
264
  function fail(msg, code) {
@@ -284,16 +302,29 @@ function main(argv) {
284
302
  process.stderr.write(USAGE + '\n');
285
303
  return fail('--audio 与 --out 都是必填的。');
286
304
  }
287
- if (!fs.existsSync(args.audio)) return fail('音频文件不存在:' + args.audio);
288
- if (!isFileAt(args.audio)) return fail('--audio 不是文件(是不是给了目录?):' + args.audio);
289
- if (uv === null) {
290
- return fail('没有找到 uv。请先安装:' + uvInstallHint(c) + '(装好后重跑本脚本;或改用 options.transcribe=false / 手动提供转写文本降级)');
291
- }
292
-
305
+ const outputPath = path.resolve(args.out);
306
+ let stagingDir = null;
293
307
  try {
308
+ // 清理旧结果前先保护输入,避免 --audio 与 --out 指向同一文件。
309
+ if (path.resolve(args.audio) === outputPath ||
310
+ (fs.existsSync(args.audio) && fs.existsSync(outputPath) &&
311
+ fs.realpathSync(args.audio) === fs.realpathSync(outputPath))) {
312
+ return fail('--audio 与 --out 不能指向同一文件。');
313
+ }
314
+ // 从本次调用开始就不允许旧逐字稿继续充当“已完成”的产物。
315
+ fs.rmSync(outputPath, { force: true });
316
+ if (!fs.existsSync(args.audio)) return fail('音频文件不存在:' + args.audio);
317
+ if (!isFileAt(args.audio)) return fail('--audio 不是文件(是不是给了目录?):' + args.audio);
318
+ if (uv === null) {
319
+ return fail('没有找到 uv。请先安装:' + uvInstallHint(c) + '(装好后重跑本脚本;或改用 options.transcribe=false / 手动提供转写文本降级)');
320
+ }
321
+
294
322
  fs.mkdirSync(root, { recursive: true });
295
323
  // 输出目录可能在别处(如 ./.tmp),提前建好,免得 python 侧报一句难懂的错
296
- fs.mkdirSync(path.dirname(path.resolve(args.out)), { recursive: true });
324
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
325
+ // 与最终文件处于同一文件系统,rename 才能原子发布;每次调用独占暂存目录。
326
+ stagingDir = fs.mkdtempSync(path.join(path.dirname(outputPath), '.drs-transcribe-'));
327
+ const stagingOutput = path.join(stagingDir, 'transcript.txt');
297
328
 
298
329
  const childEnv = Object.assign({}, process.env);
299
330
 
@@ -330,28 +361,34 @@ function main(argv) {
330
361
  childEnv.HF_HUB_DISABLE_XET = '1';
331
362
  childEnv.HF_HUB_DISABLE_SYMLINKS_WARNING = '1';
332
363
  childEnv.DRS_AUDIO = args.audio;
333
- childEnv.DRS_OUT = args.out;
364
+ childEnv.DRS_OUT = stagingOutput;
334
365
  childEnv.DRS_MODEL = args.model;
335
366
  childEnv.DRS_LANG = args.language;
336
367
  childEnv.DRS_DEVICE = args.device;
368
+ childEnv.DRS_TIMESTAMPS = args.timestamps ? '1' : '0';
337
369
 
338
- const pyScript = path.join(root, 'transcribe_run.py');
370
+ const pyScript = path.join(stagingDir, 'transcribe_run.py');
339
371
  fs.writeFileSync(pyScript, PY_RUNNER, 'utf8');
340
372
 
341
373
  // 4) 转写(首次会下载模型到 HF_HOME,之后缓存复用)
342
374
  runStep(py, [pyScript], childEnv, '转写');
343
375
 
344
- const bytes = fs.statSync(args.out).size;
345
- process.stdout.write('TRANSCRIBED ' + bytes + ' bytes to ' + args.out + '\n');
376
+ const bytes = fs.statSync(stagingOutput).size;
346
377
  const verdict = judgeTranscript(bytes);
347
378
  if (!verdict.ok) {
348
- // 删掉空文件:留着它会让「文件存在」被当成完成
349
- try { fs.rmSync(args.out, { force: true }); } catch (e) { /* 删不掉也要如实报错 */ }
350
379
  return fail(verdict.message, verdict.code);
351
380
  }
381
+ fs.renameSync(stagingOutput, outputPath);
382
+ process.stdout.write('TRANSCRIBED ' + bytes + ' bytes to ' + args.out + '\n');
383
+ process.stdout.write('DONE\n');
352
384
  return 0;
353
385
  } catch (e) {
354
386
  return fail(e.message + '(可降级:让用户手动提供转写文本,或用 options.transcribe=false 跳过转写)');
387
+ } finally {
388
+ if (stagingDir) {
389
+ try { fs.rmSync(stagingDir, { recursive: true, force: true }); }
390
+ catch (e) { process.stderr.write('[transcribe] 暂存目录清理失败:' + stagingDir + '(' + e.message + ')\n'); }
391
+ }
355
392
  }
356
393
  }
357
394
 
@@ -36,17 +36,17 @@ whenToUse: 用户提供一本书、论文(arXiv/PDF)、视频链接(YouTub
36
36
 
37
37
  1. **配置校验**:缺 input 或 type 非法 → 报 FATAL 终止
38
38
  2. **幂等检查(由你执行,脚本不做)**:脚本在沙箱内没有文件系统,写不了指纹记录。落盘前先看目标 `filePath` 是否已有同名笔记——已存在就问用户是覆盖还是跳过,别默默重跑一遍烧 token。(要在程序里做去重,可用插件导出的 `lib/cache.js`:fingerprint / hasProcessed / markProcessed。)
39
- 3. **解析器选择**:按类型从 parsers 注册表选解析器(book/paper/video/web)
40
- 4. **波次1 获取+分块**:解析器获取全文 → 写入临时文件 → 生成分块计划(JSON Schema 校验)
39
+ 3. **解析器选择**:按类型从 parsers 注册表选解析器(book/paper/video/web)。`auto` 对明确视频链接、arXiv 论文链接、电子书扩展名直接分流;同站的图文/频道/帮助页、PDF/未知网页/文本等模糊输入先轻量识别,不能固定当作网页。识别失败返回 `stage: "detect"`,再请用户显式指定类型
40
+ 4. **波次1 获取+分块**:解析器获取全文 → 写入本次独立的临时子目录 → 生成分块计划(JSON Schema 校验)。`tempDir` 是根目录,不要复用其他 `run-*` 任务的 input/audio/transcript;分块超过上限时合并相邻区间,保持从第 1 行到 totalLines 的完整覆盖
41
41
  5. **波次2 并行精读**:每个分块一个子代理深度精读(Map)
42
42
  6. **波次3 合并成稿**:整合为完整笔记(Reduce),内嵌质量自检
43
- 7. **质量校验**:可选重试(maxRetries),检查覆盖度/引用真实性/术语一致/格式完整/篇幅/语言
43
+ 7. **质量校验**:程序检查 frontmatter 模板、必要章节和篇幅;核验代理必须读取本次原文,逐块提供摘录、对第 4 节逐字引用提供原句与行号。不得只看笔记或仅返回 pass。`qualityEvidence` 可供回查;核验失败必须如实报告。`maxRetries` 为 0–3,修订失败、空结果或结构退化时保留上一份有效成稿
44
44
  8. **落盘(必须,别跳过)**:workflow 工具只返回 `note`(笔记正文)与 `filePath`(建议路径)——**脚本本身没有文件系统权限**。拿到结果后要用 `write` 工具把 `note` 原样写入 `filePath`(目录不存在就先创建);不写就等于笔记丢了,用户只会看到一段返回文本
45
45
  9. **如实交代结果**:`ok: false` 要说明卡在哪一步(`stage`)和原因,别拿半成品冒充成品;`qualityPassed: false`、`qualityIssues` 非空、或 `failedChunks > 0`(有块精读失败、笔记存在缺口)时,必须在回复里点出来
46
46
 
47
47
  ## 输出
48
48
 
49
- workflow 返回 `{ ok, filePath, note, qualityPassed, qualityIssues, failedChunks, textSource }`。
49
+ workflow 返回 `{ ok, filePath, note, qualityPassed, qualityIssues, qualityChecks, qualityEvidence, failedChunks, coverageComplete, textSource }`。`coverageComplete: false` 表示获取结果缺少有效总行数,无法确认尾部覆盖;此时质量状态也会降级,必须向用户说明。
50
50
 
51
51
  > ⚠️ **`note` 就是完整笔记正文,`filePath` 只是建议路径**:脚本运行在无文件系统的沙箱里(DSH 的 workflow 契约:脚本只负责协调子代理),**它不会替你写文件**。必须由你(主代理)在拿到结果后用 `write` 工具把它写到 `filePath`——默认 `./output/`,可用 `options.outputDir` 指向 Obsidian 仓库或静态站点的内容目录。
52
52
 
@@ -85,6 +85,7 @@ status: 已完成
85
85
  - 运行 yt-dlp 加 `--socket-timeout 15 --retries 3` 防超时。
86
86
  - **跨平台**:Windows / macOS / Linux **同等支持**(0.3.9 起)。无字幕自动转写走 `scripts/transcribe.js`(Node + `uv` + Python 3.12),三平台命令一致:`node <脚本路径> --audio <音频> --out <txt> [--device cpu]`;脚本定位命令按系统选(Windows `Get-ChildItem -Path $env:USERPROFILE/.dsh -Recurse -Filter transcribe.js`,macOS/Linux `find "$HOME/.dsh" -name transcribe.js`)。缓存目录按平台取:Windows `%LOCALAPPDATA%\deep-read-summarize`、macOS `~/Library/Caches/deep-read-summarize`、Linux `$XDG_CACHE_HOME/deep-read-summarize`。若 `node` 不在 PATH(macOS 从图形界面启动时常见)则直接降级,不要为此安装 Node。
87
87
  - 默认不标时间戳(`options.includeTimestamps` 可开)
88
+ - 开启时间戳时保留字幕 cue 或转写分段的真实起止时间,输出 `[HH:MM:SS.mmm --> HH:MM:SS.mmm]`;关闭时仍逐段换行。原文没有时间信息时注明无法定位,不得推算或编造。
88
89
 
89
90
  ## 参考
90
91
 
package/workflow.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // Version: 3.0.0
4
4
  // ============================================================================
5
5
  // 【用法】meta → workflow meta;script → workflow script;
6
- // args: { "input": "<url|path>", "type": "auto", "options": { "minWords": 2500, "fastMode": false, "maxChunks": 4, "transcribe": true, "requireCitations": true, "includeTimestamps": false, "cache": true, "outputDir": "./output", "tempDir": "./.tmp" } }
6
+ // args: { "input": "<url|path>", "type": "auto", "options": { "minWords": 2500, "fastMode": false, "maxChunks": 4, "transcribe": true, "requireCitations": true, "includeTimestamps": false, "outputDir": "./output", "tempDir": "./.tmp" } }
7
7
  // ============================================================================
8
8
 
9
9
  const meta = {
@@ -44,8 +44,10 @@ const RAW_SCRIPT = fs.readFileSync(path.join(__dirname, "lib", "workflow-script.
44
44
 
45
45
  // ===== parsers 注册表(运行时注入,实现插件化)=====
46
46
  const parsers = require("./parsers");
47
- const promptImpl = require("./parsers/_prompt");
48
47
  const schemas = require("./schemas");
48
+ const { buildParserBundle } = require("./lib/parser-bundle");
49
+ const { normalizeWorkflowOptions } = require("./lib/options");
50
+ const quality = require("./lib/quality");
49
51
  const parserRegistry = parsers.registry;
50
52
 
51
53
  /**
@@ -60,12 +62,6 @@ const parserRegistry = parsers.registry;
60
62
  * 保持单一真相,不再和脚本里的副本各自漂移。
61
63
  */
62
64
  function buildSelfContainedScript() {
63
- const parserSource = (name) =>
64
- parserRegistry.parsers[name].buildPrompt
65
- .toString()
66
- // buildPrompt 闭包引用模块级 prompt(parsers/_prompt),内联后改指 __prompt
67
- .replace(/\bprompt\.buildFetchPrompt\b/g, "__prompt.buildFetchPrompt");
68
-
69
65
  const parserNames = Object.keys(parserRegistry.parsers);
70
66
  // kind 的合法取值跟着解析器表走(含自定义类型),不再写死四个内置类型。
71
67
  const fetchSchema = JSON.parse(JSON.stringify(schemas.fetchResultSchema));
@@ -74,12 +70,7 @@ function buildSelfContainedScript() {
74
70
  }
75
71
 
76
72
  const impl = [
77
- "const __prompt = { buildFetchPrompt: " + promptImpl.buildFetchPrompt.toString() + " };",
78
- "const __parsers = {",
79
- parserNames
80
- .map((name) => " " + JSON.stringify(name) + ": { buildPrompt: " + parserSource(name) + " }")
81
- .join(",\n"),
82
- "};",
73
+ buildParserBundle(parserRegistry),
83
74
  "const fetchSchema = " + JSON.stringify(fetchSchema) + ";"
84
75
  ].join("\n");
85
76
 
@@ -87,9 +78,12 @@ function buildSelfContainedScript() {
87
78
  if (!RAW_SCRIPT.includes(marker)) {
88
79
  throw new Error("workflow script marker not found: " + marker);
89
80
  }
90
- return RAW_SCRIPT.replace(marker, impl + "\nconst parsers = args._parsers || __parsers;");
81
+ return 'const normalizeWorkflowOptions = ' + normalizeWorkflowOptions.toString() + ';\n' +
82
+ 'const __quality = { checkNoteStructure: ' + quality.checkNoteStructure.toString() +
83
+ ', validateSourceCheck: ' + quality.validateSourceCheck.toString() + ' };\n' +
84
+ RAW_SCRIPT.replace(marker, impl + "\nconst parsers = args._parsers || __parsers;");
91
85
  }
92
86
 
93
87
  const script = buildSelfContainedScript();
94
88
 
95
- module.exports = { meta, script, parsers, buildSelfContainedScript };
89
+ module.exports = { meta, script, parsers, buildSelfContainedScript };