next.js 1001 B

12345678910111213141516171819202122232425
  1. import { determineNextState } from '../state-machine/index.js'
  2. /**
  3. * next(「继续」单入口):跑状态机判定下一步。缺省打印中文摘要;--json 输出完整 DTO(F1)。
  4. * 空工作目录(无当前书)也可跑 → 状态机报序1 建书引导。
  5. * 契约:纯返回 {ok, output?, error?}(见 design §6.2)。
  6. */
  7. export const allowNoBook = true
  8. export async function run(args, options, ctx) {
  9. const r = await determineNextState(ctx)
  10. if (options.json) {
  11. return { ok: true, output: JSON.stringify(r, null, 2) }
  12. }
  13. const lines = []
  14. if (r.gitHealth.fixed.length) {
  15. lines.push('【git 已自动处理】', ...r.gitHealth.fixed.map((s) => ' · ' + s))
  16. }
  17. if (r.gitHealth.guidance.length) {
  18. lines.push('【需你留意】', ...r.gitHealth.guidance.map((s) => ' · ' + s))
  19. }
  20. lines.push(`【当前状态】序${r.序} ${r.state}${r.needsAI ? '(需 AI)' : ''}`)
  21. lines.push(r.message)
  22. return { ok: true, output: lines.join('\n') }
  23. }