persist-volume-review.js 1.2 KB

12345678910111213141516171819202122
  1. import { persistVolumeReview } from '../state-machine/persist.js'
  2. import { readJsonInput } from '../util/json-input.js'
  3. /**
  4. * persist-volume-review --file=<json>:序4 卷复盘产物回流
  5. * ({卷号, 卷摘要, 下卷卷纲?, 伏笔条目?} → 卷摘要/下卷卷纲/伏笔条目落盘)。
  6. * 契约:纯返回 {ok, output?, error?}。
  7. */
  8. export async function run(args, options, ctx) {
  9. const spec = await readJsonInput(ctx, options.file, 'file')
  10. if (!spec.ok) return { ok: false, error: spec.error }
  11. const { 卷号, 卷摘要, 下卷卷纲, 伏笔条目 } = spec.data
  12. if (!Number.isInteger(卷号) || 卷号 < 1) return { ok: false, error: 'JSON 需含正整数字段「卷号」' }
  13. if (typeof 卷摘要 !== 'string' || !卷摘要.trim()) {
  14. return { ok: false, error: 'JSON 需含非空字符串字段「卷摘要」' }
  15. }
  16. if (伏笔条目 !== undefined && !Array.isArray(伏笔条目)) {
  17. return { ok: false, error: '「伏笔条目」需是数组(每项 {id, frontMatter, body})' }
  18. }
  19. const r = await persistVolumeReview(ctx, { 卷号, 卷摘要, 下卷卷纲, 伏笔条目: 伏笔条目 || [] })
  20. return r.ok ? { ok: true, output: `已写出 ${r.written.join('、')}` } : { ok: false, error: r.error }
  21. }