mechanical-check.js 913 B

123456789101112131415161718192021222324
  1. import path from 'node:path'
  2. import { mechanicalCheck } from '../mechanical-check/index.js'
  3. /**
  4. * mechanical-check <章号> [--draft=<path>] → JSON {pass, issues, candidates}(机检,零 token)
  5. * 默认草稿 工作区/草稿-A.md。契约:纯返回 {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 draftPath =
  13. options.draft && options.draft !== true
  14. ? path.resolve(ctx.repoPath, options.draft)
  15. : path.join(ctx.repoPath, '工作区', '草稿-A.md')
  16. const r = await mechanicalCheck(ctx, { chapterNum, draftPath })
  17. if (!r.ok) return { ok: false, error: r.error }
  18. return {
  19. ok: true,
  20. output: JSON.stringify({ pass: r.pass, issues: r.issues, candidates: r.candidates }, null, 2),
  21. }
  22. }