persist-outline.js 775 B

1234567891011121314151617
  1. import { persistDraftOutline } from '../state-machine/persist.js'
  2. import { readJsonInput } from '../util/json-input.js'
  3. /**
  4. * persist-outline --file=<json>:序6 细纲产物回流({细纲} → 工作区/细纲.md)。
  5. * 契约:纯返回 {ok, output?, error?}。
  6. */
  7. export async function run(args, options, ctx) {
  8. const spec = await readJsonInput(ctx, options.file, 'file')
  9. if (!spec.ok) return { ok: false, error: spec.error }
  10. const { 细纲 } = spec.data
  11. if (typeof 细纲 !== 'string' || !细纲.trim()) {
  12. return { ok: false, error: 'JSON 需含非空字符串字段「细纲」' }
  13. }
  14. const r = await persistDraftOutline(ctx, { 细纲 })
  15. return r.ok ? { ok: true, output: `已写出 ${r.written.join('、')}` } : { ok: false, error: r.error }
  16. }