diff --git a/src/commands/form/create.ts b/src/commands/form/create.ts index 371597d..42905a8 100644 --- a/src/commands/form/create.ts +++ b/src/commands/form/create.ts @@ -342,6 +342,8 @@ export function buildFormCreateCommand(): Command { .option('--enCode-strict', '强制要求 --enCode 显式传 (BS-新411, 防 --ai 自由命名漂移, ssw-loop §9 集成场景)', false) // dos 26 P0 修复: smartProps 自动选配组件属性 (字典/min-max/relationForm/regList) .option('--no-smart-props', '关闭 --ai smartProps 自动选配 (默认 ON, AI 选填组件属性)') + .option('--preview', 'P0-6: AI 生成后先渲染字段表格供 review, 确认再提交 (TTY 交互 y/N; 非 TTY 仅预览不创建)', false) + .option('--yes', '--preview 时跳过交互确认直接创建 (自动化场景)', false) .option('--no-verify', '跳过浏览器层验证') .option('--verify ', '失败模式: warn (默认, v0.12+ jxcj) | block', 'warn') .option('--verify-timeout ', '浏览器验证超时 (默认 60s)', '60000') @@ -1495,6 +1497,40 @@ export function buildFormCreateCommand(): Command { } } + // P0-6 (2026-07-27): User-in-the-Loop 预览 — AI 生成 + smartProps + repair 后, + // 提交前渲染字段表格供用户 review (借鉴 web AiFieldModal.vue)。 + // 预览走 stderr, 不污染 --json stdout 契约。 + if ((opts as any).preview) { + const { renderFormPreview, confirmApply, collectPreviewRows } = await import('./_preview.ts') + const table = renderFormPreview(formData, { + fullName: opts.fullName, + enCode: opts.enCode, + webType: String(webType), + autoRelease: !!opts.autoRelease, + }) + process.stderr.write('\n' + table + '\n\n') + const apply = (opts as any).yes ? true : await confirmApply() + if (!apply) { + const fieldCount = Array.isArray(formData.fields) ? formData.fields.length : 0 + if (!process.stdin.isTTY && !(opts as any).yes) { + log.warn('--preview: 非交互环境, 仅预览未创建。加 --yes 直接创建, 或去掉 --preview。') + } else { + log.warn('--preview: 已取消 (未创建)。') + } + const previewPayload = { + preview: true, + created: false, + enCode: opts.enCode, + fullName: opts.fullName, + fields: fieldCount, + fieldList: collectPreviewRows(formData), + } + if (opts.json) printJson(previewPayload) + return ctx.success(previewPayload) + } + log.info('--preview: 已确认, 继续创建') + } + const body: Record = { fullName: opts.fullName, enCode: opts.enCode,