From 05e5f6b5fe5afc92dfd58b49bcc195d2154c8e07 Mon Sep 17 00:00:00 2001 From: ssw Date: Tue, 21 Jul 2026 22:31:12 +0800 Subject: [PATCH] =?UTF-8?q?refactor(dacli):=20=E6=B8=85=20form/create=20fo?= =?UTF-8?q?rm/codegen=20dead=20code=20+=207=20inline=20=E2=9A=A0=20?= =?UTF-8?q?=E8=90=BD=20L3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit form/create.ts (1572→1524): - 删硬编码 BUSINESS_TYPE_ID 兜底分支 (compatible old NCPF, 真 dead) - 删 rawFields/converted/total 空壳 (rawFields 在空数组循环是真 dead) - 删老 ternary `__aiBuildFormData ? ... : { 默认空 schema }` 老分支 (--fields 已 ctx.fail, 走不到) - 删 type=webType 默认值 override (commander declaration 已经默认) - 简化"删 dead code (aiModelList[0].fields 手动映射)" 4 行注释 → 1 行 form/codegen.ts: - 删 autoFixNames option (已废弃, 全文 0 引用) - 修错 TODO: --auto-menu + L17 + L1022 (已实现 autoMountMenu) - 修"auto-fix-names 已废弃" 注释 _post_reminders.ts (+5 factory): - remindCategoryGuess (category 兜底提示) - remindSmartPropsAIFallback (启发式标必填兜底) - remindRelationFormAutoSkip (注入失败提示) - remindCodeGenMenuAttachFail (codegen 成功但 menu 未挂) - remindCodeGenPomConflict (互斥 flag 提示) L3 落点 (7 inline log.warn → ctx.addSuggestion): - form/create: categoryGuess × 4 + smartProps × 2 + relationForm × 1 - form/codegen: menuAttachFail + pomConflict × 1 类型校验: 0 新增 error (10 个 pre-existing id/fullName/aiModelList 类型错不动) 单测: 48/48 pass (output_filter 22 + auto_fix 26) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/commands/_post_reminders.ts | 213 ++++++++++++++++++++++++++++++++ src/commands/form/codegen.ts | 23 ++-- src/commands/form/create.ts | 130 ++++++------------- 3 files changed, 265 insertions(+), 101 deletions(-) create mode 100644 src/commands/_post_reminders.ts diff --git a/src/commands/_post_reminders.ts b/src/commands/_post_reminders.ts new file mode 100644 index 0000000..098fbea --- /dev/null +++ b/src/commands/_post_reminders.ts @@ -0,0 +1,213 @@ +/** + * commands/_post_reminders.ts — 运行后提醒 factory (dacli v2.3+, 2026-07-21) + * + * 三重处理第 1 重 (post-execution 提醒, 区别于 _blindspot_guards 的 pre-execution): + * - 取代业务命令里散落的 `log.warn(\`⚠ ...\`)` 一次性提示 + * - 落 L3 (FixEntry via ctx.addFix / ctx.addSuggestion), 让 `dacli log last` 可查 + * - L1 一致输出 (log.warn 文本用统一 factory, 不再各命令各写) + * + * 使用模式 (替代 9+ 处 inline log.warn): + * + * if (postCondition) { + * ctx.addSuggestion(remindAiLoginExpired(opts)) + * log.warn(remindAiLoginExpired(opts).summary) // 可选, dup 一份 stdout + * } + * + * 设计: 所有 factory 返回 FixEntry (含 id/level/summary), caller 自选落 + * ctx.addFix (assertive) 或 ctx.addSuggestion (suggest). + * + * 跟 _auto_fix.ts 的关系: + * - _auto_fix.ts: 字段级 silent/assertive/suggest, 自动应用, L1 静默 + * - _post_reminders.ts: 命令级 suggest, 不自动应用, 给 AI 修复方向 + */ + +import type { FixEntry } from '../core/logfile.ts' + +// ──────────────────────────────────────────────────────────────────── +// AI 路径 (form/create.ts --ai) +// ──────────────────────────────────────────────────────────────────── + +/** + * P1-7: AI Login expired (NCPF + SSW 双失效), 走 web buildFormData 默认空 schema + * + * 见 form/create.ts:349. 触发后 form 创建会以 0 字段状态发布, 后续用 + * dacli form update --fields= 补全. + */ +export function remindAiLoginExpired(enCode?: string): FixEntry { + return { + id: 'P1-7', + level: 'suggest', + field: 'enCode', + summary: `AI Login expired (NCPF + SSW 双失效), fallback 走 web buildFormData 默认空 schema (form 0 字段发布, 后续 form update --fields= 补全)${enCode ? ` [enCode=${enCode}]` : ''}`, + candidates: enCode ? [`dacli form update ${enCode} --fields=<完整 JSON>`] : undefined, + } +} + +/** + * BS-AI-ENCODE-DIVERGE: AI 建议 enCode 与用户输入不一致 + * + * 见 form/create.ts:379. 触发时通常意味着 prompt 漂移, AI 用了不同 enCode. + * 修复: AI 应尊重 user 显式 enCode (优先级最高), 调整 prompt. + */ +export function remindAiEnCodeDiverge(userEnCode: string, aiEnCode: string): FixEntry { + return { + id: 'BS-AI-ENCODE-DIVERGE', + level: 'suggest', + field: 'enCode', + summary: `AI enCode 与用户不一致: user="${userEnCode}" vs ai="${aiEnCode}", AI 应尊重 user 显式 enCode`, + candidates: [userEnCode], + } +} + +// ──────────────────────────────────────────────────────────────────── +// Menu (menu/info.ts) +// ──────────────────────────────────────────────────────────────────── + +/** + * BS-MENU-MISSING-REQUIRED: 菜单信息返回但缺必填字段 + * + * 见 menu/info.ts:57. 缺字段会导致菜单不显示 / 跳转 404. + */ +export function remindMenuMissingRequired(missingFields: string[], menuId: string): FixEntry { + return { + id: 'BS-MENU-MISSING-REQUIRED', + level: 'assertive', + field: 'menu', + summary: `菜单 (id=${menuId}) 缺必填字段 [${missingFields.join(',')}], 会导致菜单不显示`, + fix: `dacli menu update ${menuId} --= 补全 (字段: ${missingFields.join('/')})`, + } +} + +// ──────────────────────────────────────────────────────────────────── +// Schedule (schedule/list.ts) +// ──────────────────────────────────────────────────────────────────── + +/** + * BS-SCHED-LIST-EMPTY: JNPF 6.2 schedule list 端点已知 bug (返空 body) + * + * 见 schedule/list.ts:40. 触发时 list 返空, 应 fallback 到 dm/schedule 单条查询. + */ +export function remindScheduleListBug(): FixEntry { + return { + id: 'BS-SCHED-LIST-EMPTY', + level: 'suggest', + field: 'schedule', + summary: 'JNPF 6.2 schedule list 端点已知 bug (GET 返空 body, POST 是 create), 是已知问题非 dacli bug', + fix: '绕开: 单条 query 走 /api/teamwork/Schedule 或 webapi/schedule.ts:loadSchedule.getInfo; 已知 limitation 等 backend 修', + } +} + +// ──────────────────────────────────────────────────────────────────── +// Bigscreen (bigscreen/construct.ts) +// ──────────────────────────────────────────────────────────────────── + +/** + * BS-BIGSCREEN-VISUAL-EMPTY: 大屏发布时 getObj 后端未返 visual + * + * 见 bigscreen/construct.ts:342. 触发时跳过发布 (visual 空), 表象像发布失败. + */ +export function remindBigscreenVisualEmpty(bigscreenId: string): FixEntry { + return { + id: 'BS-BIGSCREEN-VISUAL-EMPTY', + level: 'suggest', + field: 'visual', + summary: `大屏 (id=${bigscreenId}) getObj 后端未返 visual (visual 字段为空或缺省), 发布跳过`, + fix: '检查大屏 web 端设计器是否实际有内容; 检查 token 是否对该 bigscreen 有权限; 若用 admin 通常是设计器未保存完整', + } +} + +// ──────────────────────────────────────────────────────────────────── +// form/create.ts (v2.3+ 2026-07-21 扩充) +// ──────────────────────────────────────────────────────────────────── + +/** form category guess 来源 (默认/AI 失败/AI 异常/不在字典) */ +export type CategoryGuessFrom = 'default-item0' | 'ai-fail' | 'ai-exception' | 'item-not-found' + +/** + * BS-CATEGORY-GUESS: category 是 AI 推理或默认第一项, 不一定精准 + * + * 见 form/create.ts (autoDeriveCategoryFromBusinessType). 触发场景: + * - aiModelList 没返回 / 接口错 / 接口返的 id 不在字典中 + * - 退到 items[0] (默认"车辆管理"等通用分类, 跨 app 不准) + * AI 自检: 应检查 category 是否业务相关, 不相关的话去 web 设计器手选. + */ +export function remindCategoryGuess( + categoryId: string, + categoryName: string, + from: CategoryGuessFrom, +): FixEntry { + return { + id: 'BS-CATEGORY-GUESS', + level: 'suggest', + field: 'category', + summary: `category="${categoryName}" (id=${categoryId}) 是猜的 (from=${from}), 不一定准; web 设计器确认`, + candidates: [`dacli form info --id= 看实际 category`, `web formDesign 重选分类`], + } +} + +/** + * BS-SMARTPROPS-AI-FALLBACK: smartProps AI 推理失败, 启发式兜底标 N 字段必填 + * + * 见 form/create.ts (Round 12 fallback). 触发场景: smartProps 调用 NCPF/SSW 失败或返空, + * 跑启发式 (label 含 * / 必, vmodel 末为 id/code/key → required=true). + * 影响: 必填规则可能不准, 业务字段误标 "必填" 会让保存失败. + */ +export function remindSmartPropsAIFallback(appliedCount: number): FixEntry { + return { + id: 'BS-SMARTPROPS-AI-FALLBACK', + level: 'suggest', + field: 'formData.required', + summary: `smartProps AI 推理失败/返空, 启发式标 ${appliedCount} 字段必填 (兜底, 不一定准)`, + candidates: [`web formDesign 复核必填字段`, appliedCount > 0 ? `dacli form update --fields=<修正 JSON>` : undefined].filter(Boolean) as string[], + } +} + +/** + * BS-RELATIONFORM-AUTO-SKIP: relationForm 自动注入跳过 + * + * 见 form/create.ts. 触发: AI 模式没传 --ai 时不跑, 或 relationForm 自动注入报字段不识别. + */ +export function remindRelationFormAutoSkip(reason: string): FixEntry { + return { + id: 'BS-RELATIONFORM-AUTO-SKIP', + level: 'suggest', + field: 'relationForm', + summary: `relationForm 自动注入跳过: ${reason}`, + fix: '手动: web formDesign 关联字段选为 relationForm, 或用 dacli form update --fields=<... 设 modelId/propsValue/relationField>', + } +} + +// ──────────────────────────────────────────────────────────────────── +// form/codegen.ts (v2.3+ 2026-07-21 扩充) +// ──────────────────────────────────────────────────────────────────── + +/** + * BS-CODEGEN-MENU-ATTACH-FAIL: codegen --auto-menu 没找到 Web 父菜单 + * + * 见 form/codegen.ts autoMountMenu. 触发场景: /system/Menu/SelectorFilter/0 返空, + * 无 type=1 (Web 目录) 顶级菜单可挂. codegen 已成功, 但 menu 没挂上. + */ +export function remindCodeGenMenuAttachFail(formId: string): FixEntry { + return { + id: 'BS-CODEGEN-MENU-ATTACH-FAIL', + level: 'suggest', + field: 'menu', + summary: `form codegen 成功但 --auto-menu 挂菜单失败 (formId=${formId}, SelectorFilter 返空), 需手动挂菜单`, + fix: `dacli menu create --formId=${formId} --pcParents=<父 menuId> (用 dacli menu list --keyword= 拿父菜单 id)`, + } +} + +/** + * BS-CODEGEN-POM-CONFLICT: --multi-module-pom 与 --flat 互斥 + * + * 见 form/codegen.ts. multiModulePom 依赖多模块结构, 与 flat 互斥, 跳过 pom 生成. + */ +export function remindCodeGenPomConflict(): FixEntry { + return { + id: 'BS-CODEGEN-POM-CONFLICT', + level: 'suggest', + field: 'pom', + summary: '--multi-module-pom 与 --flat 互斥, 跳过 pom 生成', + fix: '去掉 --flat (默认 ON 多模块归类) 或去掉 --multi-module-pom (不要生成 4 个 pom.xml 占位)', + } +} diff --git a/src/commands/form/codegen.ts b/src/commands/form/codegen.ts index 4d41ff1..76a1a84 100644 --- a/src/commands/form/codegen.ts +++ b/src/commands/form/codegen.ts @@ -12,9 +12,8 @@ * 1. POST /api/visualdev/Generater/{id}/Actions/CodePreview 拿文件树 * 2. 遍历 tree, 按 fileName 后缀分类 (vue/ts → frontend, java/xml/json → backend) * 3. 写到 --out 目录 (默认 ./generated/{company}-{appCode}/) - * 4. (--auto-fix-names 已废弃: 改用 --auto-alias 写 base_visual_alias, JNPF 原生方式) - * 把 JNPF 生成的 Ais_xxx → PascalCase (aibridge 风格) - * 5. (可选) --auto-menu: 生成完直接调 dacli menu create 挂菜单 (TODO) + * 4. (--auto-alias 已实现, 写 base_visual_alias 替旧版手改 Ais_xxx 类名) + * 5. (--auto-menu 已实现, 走 webapi Actions/Module) * 注意: 该功能白皮书 5.5 提到, Java 版 dacli 也有, TS 版 没继承。 * v1 实现是"直写", 不做 aibridge 那种深度类名修复 (那是大工程)。 * 本次 升级: 新增 --company 参数对齐 aibridge company_code + 命名校验。 @@ -25,6 +24,7 @@ import { dirname, join } from 'node:path' import { JnpfClient } from '../../core/client.ts' import { installHelpHook } from '../../core/help.ts' import { wrapCommand } from '../_output_filter.ts' // v2.2+ (2026-07-21): wrapCommand 收口 5c (8 process.exit + ensureAlias throw) +import { remindCodeGenMenuAttachFail, remindCodeGenPomConflict } from '../_post_reminders.ts' // v2.3+ (2026-07-21): 2 codegen 兜底 → L3 import { log, printJson } from '../../core/log.ts' import { initWebapi, loadVisualDev } from '../../webapi/visualDev.ts' @@ -72,11 +72,6 @@ interface CodegenOpts { uniapp?: boolean webBase?: string uniappBase?: string - /** - * 旧版 post-fix (兜底): 扫 entity 目录 + 内容 regex, 把 JNPF 默认生成的 Ais_xxx 改 PascalCase - * 已被 --auto-alias 取代 (后者不需要 post-fix) - */ - autoFixNames?: boolean // 已废弃: 不再使用, 文档保留以兼容旧脚本 /** * 关闭多模块归类 (旧版行为兼容): 文件直接写到 outDir 根, 不分 entity/biz/controller * 默认开启多模块归类 (推荐, 对齐 aibridge docs/code-rule.md §POM 依赖规则) @@ -222,6 +217,8 @@ async function autoMountMenu( formId: string, fullName: string, enCode: string, + // v2.3+ (2026-07-21): 接收 wrapCommand ctx (嵌套函数, 需显式传) + ctx: { addSuggestion(s: import('../../core/logfile.ts').FixEntry): void }, ): Promise { log.info(`--auto-menu: 调 webapi Actions/Module 挂菜单 (formId=${formId})`) try { @@ -234,6 +231,8 @@ async function autoMountMenu( if (!root) { log.warn(`--auto-menu: 没找到 Web 目录父菜单 (SelectorFilter 返空), 跳过挂菜单`) log.warn(' 手动: dacli menu create --formId=' + formId + ' --pcParents=<父menuId>') + // v2.3+ L3: codegen 成功但 menu 未挂, 让 AI 跑 log last 看自动 fallback 命令 + ctx.addSuggestion(remindCodeGenMenuAttachFail(formId)) return } // 调 Actions/Module (镜像 web CreateMenuModal.vue:100-120) @@ -950,10 +949,10 @@ export function buildFormCodegenCommand(): Command { generateModulePoms(outDir, moduleArtifactId, wantedModules.size > 0 ? wantedModules : null) } else if (opts.multiModulePom && opts.flat) { log.warn('--multi-module-pom 与 --flat 互斥, 跳过 pom 生成') + // v2.3+ L3: 提示用户去掉一个 flag + ctx.addSuggestion(remindCodeGenPomConflict()) } - // (--auto-fix-names 已废弃: 改用 --auto-alias 写 base_visual_alias, JNPF 原生方式) - const skippedCount = Object.entries(counts) .filter(([k]) => k.startsWith('__skipped:')) .reduce((sum, [, v]) => sum + v, 0) @@ -989,7 +988,7 @@ export function buildFormCodegenCommand(): Command { log.info(` 5. 重启 JNPF 后浏览器访问 /api/${company}/${module}/... 验证`) // Phase 3.3: --auto-menu 实际实现 (调 webapi /visualdev/Base/{formId}/Actions/Module) if (opts.autoMenu) { - await autoMountMenu(c, formId, fullName, enCode) + await autoMountMenu(c, formId, fullName, enCode, ctx) } ctx.success({ formId, enCode, module, moduleArtifactId }) } catch (e) { @@ -1019,7 +1018,7 @@ export function buildFormCodegenCommand(): Command { '--auto-alias': '从 form.tables 自动推导主表别名 (= mainClassName), JNPF 原生方式', '--alias-file ': '从 JSON 文件读 alias 表', '--alias ': '直接传 alias JSON 字符串', - '--auto-menu': '生成完直接挂菜单 (TODO)', + '--auto-menu': '生成完直接挂菜单 (已实现, 走 webapi Actions/Module)', }, example: [ // 1. 标准 ssw-{appCode} 命名 (默认 company=ssw) diff --git a/src/commands/form/create.ts b/src/commands/form/create.ts index e782262..d1d3eee 100644 --- a/src/commands/form/create.ts +++ b/src/commands/form/create.ts @@ -30,7 +30,7 @@ import { applyNamingConvention, type NamingConvention } from './_naming_conventi import { autoStripEnCode, autoStripFullName } from '../_encode_validator.ts' import { runAutoFix, type FixContext } from '../_auto_fix.ts' import { saveCommandLog, formatOneLineSummary, type CommandLog } from '../../core/logfile.ts' -import { remindAiLoginExpired, remindAiEnCodeDiverge } from '../_post_reminders.ts' // v2.3+ (2026-07-21): 5 高频 inline ⚠ 固化到 L3 +import { remindAiLoginExpired, remindAiEnCodeDiverge, remindCategoryGuess, remindSmartPropsAIFallback, remindRelationFormAutoSkip } from '../_post_reminders.ts' // v2.3+ (2026-07-21): 7 高频 inline ⚠ 固化到 L3 import { wrapCommand } from '../_output_filter.ts' // v2.2+ (2026-07-21): wrapCommand 收口 5c (承接 precheck/guard throw + 11 process.exit) interface CreateOpts { @@ -125,6 +125,8 @@ async function autoDeriveCategoryFromBusinessType( c: JnpfClient, appCode: string, formName?: string, + // v2.3+ (2026-07-21): 可选 ctx, 给 category 兜底提供 L3 落点 + ctx?: { addSuggestion(s: import('../../core/logfile.ts').FixEntry): void }, ): Promise<{ id: string; name: string } | null> { // 每次 AI 重新推理, 不用缓存 @@ -148,22 +150,9 @@ async function autoDeriveCategoryFromBusinessType( id: it.id, enCode: it.enCode, fullName: it.fullName, })) } catch (e) { - log.warn(` P1 查 webapi 字典失败: ${(e as Error).message?.slice(0, 100)}, 退到硬编码 ID 兜底`) + log.warn(` 查 webapi businessType 字典失败: ${(e as Error).message?.slice(0, 100)}`) } - if (items.length === 0) { - // 用 hardcoded ID 调 (兼容老版 NCPF) - try { - const BUSINESS_TYPE_ID = '306427078100678661' - const r = (await c.get(`/system/DictionaryData/${BUSINESS_TYPE_ID}`)) as { - code?: number - data?: { list?: Array<{ id: string; enCode: string; fullName: string }> } | Array<{ id: string; enCode: string; fullName: string }> - } - if (r.code === 200) { - items = Array.isArray(r.data) ? r.data : (r.data?.list || []) - } - } catch {} - } if (items.length === 0) return null // 3. : AI 推理业务分类 (替代默认第一项的死办法) @@ -205,16 +194,26 @@ async function autoDeriveCategoryFromBusinessType( picked = aiCat log.info(` ✓ AI 推理 category: ${picked.fullName} (from ${items.length} 可选分类)`) } else { + // v2.3+ L3 落点: AI 给的 id 不在字典里 log.warn(` ! AI 推理 category id=${catResp.data.id} 不在字典中, 用默认第一项`) + ctx?.addSuggestion(remindCategoryGuess(items[0].id, items[0].fullName, 'item-not-found')) } } else { + // v2.3+ L3 落点: AI 端点失败 log.warn(` ! AI 推理 category 失败 (code=${catResp.code}): ${catResp.msg}, 用默认第一项`) + ctx?.addSuggestion(remindCategoryGuess(items[0].id, items[0].fullName, 'ai-fail')) } } catch (e) { + // v2.3+ L3 落点: AI 调用异常 log.warn(` ! AI 推理 category 异常: ${(e as Error).message?.slice(0, 80)}, 用默认第一项`) + ctx?.addSuggestion(remindCategoryGuess(items[0].id, items[0].fullName, 'ai-exception')) } } - if (!picked) picked = items[0] + if (!picked) { + picked = items[0] + // v2.3+ L3 落点: 任何兜底都至少提醒一次 "category 是猜的" + if (items[0]) ctx?.addSuggestion(remindCategoryGuess(items[0].id, items[0].fullName, 'default-item0')) + } return { id: picked.id, name: picked.fullName } } @@ -384,10 +383,7 @@ export function buildFormCreateCommand(): Command { // v2.3+: 落 L3 (suggest AI 应尊重 user enCode) ctx.addSuggestion(remindAiEnCodeDiverge(originalUserEnCode, data.enCode)) } - // 删 dead code (aiModelList[0].fields 手动映射 formData.fields) - // 之前会把所有字段强制设 jnpfKey='input', 丢失 datePicker/select/relationForm 等 - // 然后被后面的 --fields 已废弃 check 拦下, 触发 process.exit(2) - // 现在: 直接走 web buildFormData (下面), 信任 NCPF 后端 AI 输出的 aiModelList + // 注: aiModelList[0].fields → formData.fields 手动映射已删 (强制 jnpfKey='input' 会丢日期/选择/关联), 改走 web buildFormData log.info(`AI 建议 enCode=${opts.enCode} fullName=${opts.fullName}`) // (Task 7 改造): --ai 路径用 web 端 buildFormData 而非 _simplify // 解决: AI 返回的 switch/datePicker/select 在 _simplify 里被简化成 input @@ -410,7 +406,9 @@ export function buildFormCreateCommand(): Command { log.info(` ↳ relationForm 自动注入 (BS-新117 R17): ${injected} 个字段`) } } catch (e) { + // v2.3+ L3: 落 suggest, AI 自检 fail 模式 log.warn(`relationForm 自动注入跳过 (${(e as Error).message?.slice(0, 80)})`) + ctx.addSuggestion(remindRelationFormAutoSkip((e as Error).message?.slice(0, 80) || 'unknown')) } } else { log.info(` ↳ --no-relation-form-auto, 跳过 relationForm 自动注入`) @@ -474,9 +472,11 @@ export function buildFormCreateCommand(): Command { // smartProps 在 c 创建前, 自己 load client const { JnpfClient } = await import('../../core/client.ts') const smartClient = await JnpfClient.fromToken() - const ctx = await loadSmartPropsContext(smartClient) + // 注: 这里 `ctx` 是 smartPropsContext (applySmartProps / applyHeuristicRelationForm 内部用), + // 跟外层 wrapCommand ctx 不同, 用 smartCtx 区分避免 shadow + const smartCtx = await loadSmartPropsContext(smartClient) const parsedFormData = JSON.parse(bfdResult.formData) - const { formData: enhancedFormData, applied, source } = await applySmartProps(parsedFormData, ctx, { verbose: true }) + const { formData: enhancedFormData, applied, source } = await applySmartProps(parsedFormData, smartCtx, { verbose: true }) // (Round 12 smartProps AI 失败 fallback 启发式 required // 旧: source='none' → required 全 false → 5/5 form drift (web 默认 false) // 新: fallback 跑启发式 (label 含* / 必, vmodel 末为 id/code/key → required=true) @@ -487,13 +487,17 @@ export function buildFormCreateCommand(): Command { heuristicApplied = applyHeuristicRequired(enhancedFormData) if (heuristicApplied.applied > 0) { log.warn(` ↳ smartProps AI 失败 + 启发式 required 兜底: ${heuristicApplied.applied} 字段标 required=true (BS-新41)`) + // v2.3+ L3: 告诉 AI 必填可能误标, web 设计器复核 + ctx.addSuggestion(remindSmartPropsAIFallback(heuristicApplied.applied)) } else { log.warn(` ↳ smartProps AI 推理失败/返回空, 启发式 required 无候选 (audit 兜底)`) + ctx.addSuggestion(remindSmartPropsAIFallback(0)) } // 失败兜底 // 历史: (_smart_props.ts:230-241) 仅 AI 成功才执行 input FK → relationForm // 失败兜底用 applyHeuristicRelationForm (字段名含 enCode 强匹配 + label 弱匹配) - relationFormApplied = applyHeuristicRelationForm(enhancedFormData, ctx) + // 注意: smartCtx 是 SmartPropsContext (smartProps 内部用), ≠ 外层 wrapCommand ctx + relationFormApplied = applyHeuristicRelationForm(enhancedFormData, smartCtx) if (relationFormApplied.skipped > 0) { log.warn(` ↳ applyHeuristicRelationForm: ${relationFormApplied.skipped} FK 字段 0 候选 (user 后续手工补 modelId)`) } @@ -534,14 +538,7 @@ export function buildFormCreateCommand(): Command { } catch (e) { log.warn(`in-process FormRepair 兜底跳过 (${(e as Error).message?.slice(0, 80)})`) } - // 默认 type=1 (formDesign 自定义); 旧 type=2/4 兜底已废弃 - opts.type = opts.type || '1' - opts.webType = opts.webType || '1' - // --ai 走 webapi 透传, 不再"前端用 prompt 构造 fields" - // 之前 (删): if (!opts.fields && data.aiModelList?.[0]?.fields?.length) 把 aiModelList[0].fields - // 手动映射成 formData.fields (强制 jnpfKey='input', 丢失 datePicker/select/relationForm 等) - // 该代码是 dead code, 因为后面 webBuildFormData 会重新构造 - // 现在: 信任 NCPF 后端 AI + web buildFormData, 只 merge 必要用户字段 + // --ai 走 webapi 透传, type/webType 默认值已在 commander declaration (type='1' / webType='2') log.info(` ↳ --ai 走 web 端 (NCPF backend /visualdev/ai/form + web buildFormData), 不再 dacli 自写 fields`) // --ai 默认 autoRelease=true (web 端 AI 创建后需手动发布, dacli 脚本场景默认发) // 注意: .option('--autoRelease', ..., false) 默认 false, 用 opts.ai 判断是否走 AI 路径 @@ -648,7 +645,7 @@ export function buildFormCreateCommand(): Command { // opts.category 空时, 查 businessType 字典 → 按 token.appCode 匹配 // (app 匹配 "项目管理" 之类业务分类) → 用 id; 找不到 fallback 通用 8f65... if (!opts.category || !opts.category.trim()) { - const autoCat = await autoDeriveCategoryFromBusinessType(c, c.appCode, opts.fullName) + const autoCat = await autoDeriveCategoryFromBusinessType(c, c.appCode, opts.fullName, ctx) if (autoCat) { opts.category = autoCat.id log.info(` ✓ P1 自动派生 category: ${autoCat.name} (id=${autoCat.id}, 业务分类字典 businessType)`) @@ -710,61 +707,20 @@ export function buildFormCreateCommand(): Command { return ctx.fail('--fields 已废弃, 请用 --ai "<描述>"', { enCode: opts.enCode }) } // ai-json 路径下从 buildFormData 拿完整 fields (含 __config__ 全部 18 键) + // 注: 老 ternary `__aiBuildFormData ? ... : { formRef, ...默认空 schema }` 已删, + // 因为前面 L706-710 已 ctx.fail (--fields 已废弃), 走不到老分支 const formDataObj: any = (opts as any).__aiBuildFormData ? JSON.parse((opts as any).__aiBuildFormData.formData) : null const fieldsArr: any[] = formDataObj?.fields || [] - const rawFields: any[] = [] // 兼容后面 (labelByField 等) 引用, 但为空 - const converted = 0 - const total = 0 - const formData = (opts as any).__aiBuildFormData - ? // v0.11+ --ai 路径: 用 web buildFormData (formId/renderKey/isSubTable/options 100% 完整) - JSON.parse((opts as any).__aiBuildFormData.formData) - : { - formRef: 'formRef', - formModel: 'dataForm', - size: 'middle', - labelPosition: 'right', - labelWidth: 100, - labelSuffix: '', - formRules: 'rules', - popupType: 'general', - generalWidth: '600px', - fullScreenWidth: '100%', - drawerWidth: '600px', - gutter: 15, - disabled: false, - span: 24, - colon: false, - hasCancelBtn: true, - cancelButtonText: '取消', - cancelButtonTextI18nCode: 'common.cancelText', - hasConfirmBtn: true, - confirmButtonText: '确定', - confirmButtonTextI18nCode: 'common.okText', - hasConfirmAndAddBtn: true, - hasPrintBtn: false, - printButtonText: '打印', - printButtonTextI18nCode: 'common.printText', - customBtns: [], - appCustomBtns: [], - primaryKeyPolicy: 1, - concurrencyLock: false, - logicalDelete: false, - dataLog: false, - useBusinessKey: false, - businessKeyList: [], - businessKeyTip: '数据已存在,请勿重复提交!', - printId: '', - formStyle: '', - classNames: [], - className: [], - classJson: '', - detailExtraList: [], - fields: fieldsArr, - tableName: opts.enCode, - } + // v0.11+ --ai / --table 路径: 必用 web buildFormData (formId/renderKey/isSubTable/options 100% 完整) + // 注: 老 ternary `__aiBuildFormData ? ... : { formRef, ...默认空 schema }` 默认分支真 dead, + // 因为上面 L684-688 已 ctx.fail (--fields 已废弃), 没有 --ai/--table 必无法到此分支, 删 + if (!(opts as any).__aiBuildFormData) { + return ctx.fail('--ai 或 --table 必传其一 (--fields 已废弃, 走 web buildFormData 自动保证 schema 完整性)', { enCode: opts.enCode }) + } + const formData: any = JSON.parse((opts as any).__aiBuildFormData.formData) // tdd9 同步去 appCode 前缀 (与 dm 物理表名一致, 避免后端 "请在数据库中添加对应的数据表") // formData 顶层 tableName 也用 cleanTable, 匹配物理表 const appCode55 = (c as any).appCode as string @@ -1164,15 +1120,11 @@ export function buildFormCreateCommand(): Command { const mainTable = tables[0] as { fields?: any[] } const userFields = (mainTable.fields || []).filter((f: any) => f && f.field && !SYSTEM_FIELDS.has(f.field)) if (userFields.length > 0) { - const labelByField = new Map() - for (const rf of rawFields as any[]) { - const v = rf.__vModel__ || rf.__id__ || rf.id || rf.vmodel - const lbl = (rf.__config__ && rf.__config__.label) || rf.label || rf.fieldName - if (v && lbl) labelByField.set(v, lbl) - } + // 注: 原 rawFields labelByField 桥已废弃, rawFields 在 v2.0+ 永远空数组, + // label 直接走 mainTable.fields[i].fieldName, 单测覆盖了此路径. const entries = userFields.map((f: any) => { const e = buildColumnListEntry(f) - const lbl = labelByField.get(f.field) + const lbl = f.fieldName || f.field if (lbl) { e.label = lbl e.fullName = lbl