goto-chapter.js 661 B

123456789101112131415
  1. import { gotoChapter } from '../state-machine/flows/goto-chapter.js'
  2. /**
  3. * goto-chapter <章号> [--confirm] → 回到第N章(人话命令,先备份再回滚)
  4. * 不带 --confirm 只展示影响范围;带 --confirm 才真回退。
  5. * 契约:纯返回 {ok, output?, error?}(见 design §6.2)。
  6. */
  7. export async function run(args, options, ctx) {
  8. const chapterNum = parseInt(args[0], 10)
  9. if (isNaN(chapterNum)) {
  10. return { ok: false, error: '请指定要回到的章号' }
  11. }
  12. const r = await gotoChapter(ctx, { chapterNum, confirm: !!options.confirm })
  13. return r.ok ? { ok: true, output: r.message } : { ok: false, error: r.error }
  14. }