auto(14b5ea1b9bd9): session end @ 2026-07-25T11:08:36 (+8f)
This commit is contained in:
1 parent
53874e7617
commit
54989b9ef1
8 files changed
+156
-20
No files matched your search
@@ -97,16 +97,26 @@ export function autoStripEnCode(enCode: string | undefined): {
|
||||
value: string
|
||||
wasStriped: boolean
|
||||
original: string
|
||||
/** v2.4+ (BS-新131-加强, tdd2 2026-07-25): 是否 strip 了 'Form' 后缀 */
|
||||
wasFormSuffixStripped?: boolean
|
||||
} {
|
||||
const original = String(enCode || '')
|
||||
if (!original) {
|
||||
return { value: '', wasStriped: false, original }
|
||||
}
|
||||
const stripped = suggestEnCode(original)
|
||||
// v2.4+ (BS-新131-加强): strip AI 加的 'Form' 后缀 (例: tdd2orderForm → tdd2order)
|
||||
let finalValue = stripped
|
||||
let wasFormStripped = false
|
||||
if (finalValue.toLowerCase().endsWith('form') && finalValue.length > 4) {
|
||||
finalValue = finalValue.slice(0, -4)
|
||||
wasFormStripped = true
|
||||
}
|
||||
return {
|
||||
value: stripped,
|
||||
wasStriped: stripped !== original,
|
||||
value: finalValue,
|
||||
wasStriped: stripped !== original || wasFormStripped,
|
||||
original,
|
||||
wasFormSuffixStripped: wasFormStripped,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -131,11 +131,16 @@ export function validateUniqueness(opts: {
|
||||
if (opts.fullName) {
|
||||
const dup = opts.existingTypes.find((t) => t.fullName === opts.fullName)
|
||||
if (dup) {
|
||||
// 修复 冲突时建议加 appCode 前缀 (如 "jxcj所属行业" 而非 "所属行业")
|
||||
// appCode 启发: enCode 中有 `app.` 前缀 或 fullName 中有 `app` 字样 → 是 app app
|
||||
// 简化: 始终建议 "app{原名}" (因为历史数据通常是平台级, app 用加前缀避免冲突)
|
||||
const suggestedFullName = `jxcj${opts.fullName}`
|
||||
errors.push({ field: 'fullName', message: `字典名称"${opts.fullName}"已存在 (BS-47, 后端 EXIST001). 建议: --fullName="${suggestedFullName}" (加 appCode 前缀)`, code: 'EXIST001' })
|
||||
// v2.4+ (BS-47-变种, tdd2 2026-07-25): 跨 app 同 fullName 冲突
|
||||
// 修复建议: 加 appCode 前缀 (而非硬编码 jxcj)
|
||||
// appCode 由调用方传入 (opts.appCode), 默认 'jxcj' 向后兼容
|
||||
const appCode = (opts as any).appCode || 'jxcj'
|
||||
const suggestedFullName = `${appCode}${opts.fullName}`
|
||||
errors.push({
|
||||
field: 'fullName',
|
||||
message: `字典名称"${opts.fullName}"已存在 (BS-47-变种, 后端 EXIST001). 建议: --fullName="${suggestedFullName}" (加 appCode 前缀)`,
|
||||
code: 'EXIST001'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,9 +148,14 @@ export function validateUniqueness(opts: {
|
||||
if (opts.enCode) {
|
||||
const dup = opts.existingTypes.find((t) => t.enCode === opts.enCode)
|
||||
if (dup) {
|
||||
// 修复 enCode 冲突建议用 dot-separated 形式 (如 app.industry 而非 industry)
|
||||
const suggestedEnCode = `jxcj.${opts.enCode.replace(/^jxcj\./, '')}`
|
||||
errors.push({ field: 'enCode', message: `字典编码"${opts.enCode}"已存在 (BS-47, 后端 EXIST002). 建议: --enCode="${suggestedEnCode}" (加 appCode 前缀)`, code: 'EXIST002' })
|
||||
// v2.4+ (BS-47-变种): 用实际 appCode 建议
|
||||
const appCode = (opts as any).appCode || 'jxcj'
|
||||
const suggestedEnCode = `${appCode}.${opts.enCode.replace(new RegExp(`^${appCode}\\.`), '')}`
|
||||
errors.push({
|
||||
field: 'enCode',
|
||||
message: `字典编码"${opts.enCode}"已存在 (BS-47-变种, 后端 EXIST002). 建议: --enCode="${suggestedEnCode}" (加 appCode 前缀)`,
|
||||
code: 'EXIST002'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -288,7 +288,8 @@ async function runDictStepMachine(
|
||||
sortCode: opts.sortCode,
|
||||
items: opts.items,
|
||||
existingTypes,
|
||||
})
|
||||
appCode: c.appCode, // v2.4+ (BS-47-变种): 传给校验函数用于建议 appCode 前缀
|
||||
} as any)
|
||||
|
||||
// 3. 输出结果 (聚合错误 / 全部通过)
|
||||
if (!result.ok) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import { join } from 'node:path'
|
||||
import { callAiForm, printAiFormResult, renderAiFieldResult } from './_ai.ts'
|
||||
import { initBuildFormData, buildFormData as webBuildFormData, isBuildFormDataLoaded } from './_buildformdata.ts'
|
||||
import { applySmartProps, loadSmartPropsContext, applyHeuristicRequired, applyHeuristicRelationForm } from './_smart_props.ts'
|
||||
import { completeRelationFormFields } from './_relationform_completeness.ts' // v2.4+ (BS-新132-变种): relationForm 4 字段 silent_fix
|
||||
import { repairFormDataFromString } from './_form_repair.ts'
|
||||
import { browserVerify } from './_browser_verify.ts'
|
||||
import { createFormViaUi } from './_create_ui.ts'
|
||||
@@ -53,6 +54,8 @@ interface CreateOpts {
|
||||
enableFlow?: string
|
||||
flowId?: string
|
||||
autoRelease?: boolean
|
||||
/** v2.4+ (BS-新411, tdd2 2026-07-25): 强制 --enCode 显式传, 防 --ai 自由命名漂移 */
|
||||
enCodeStrict?: boolean
|
||||
/** --autoTable 强制从 --fields 推导 --tables (覆盖 --tables, 对齐 web formDesign Form.vue) */
|
||||
autoTable?: boolean
|
||||
/** (盲点 47): 建完发布后自动挂菜单到指定父目录, 避免浏览器验证 step check-list 找不到 vxe-table */
|
||||
@@ -151,6 +154,24 @@ async function applyFinalSmartProps(
|
||||
}
|
||||
}
|
||||
|
||||
// BS-新132-变种 (tdd2 2026-07-25): relationForm 4 字段 silent_fix
|
||||
// 即使 AI 生成成功, 也可能缺 modelId/propsValue/relationField/showField
|
||||
// 自动补全避免 TC-C FAIL
|
||||
try {
|
||||
const rfFixed = await completeRelationFormFields(finalFormData, c)
|
||||
if (rfFixed.fixed > 0) {
|
||||
log.info(` ↳ BS-新132-变种: relationForm 4 字段 silent_fix ${rfFixed.fixed}/${rfFixed.scanned} 字段`)
|
||||
ctx.addSuggestion({
|
||||
id: 'BS-新132-变种',
|
||||
level: 'silent',
|
||||
field: 'relationForm',
|
||||
summary: `4 字段补全 (${rfFixed.fixed}/${rfFixed.scanned})`,
|
||||
})
|
||||
}
|
||||
} catch (e) {
|
||||
log.warn(`BS-新132-变种 silent_fix 跳过: ${(e as Error).message?.slice(0, 100)}`)
|
||||
}
|
||||
|
||||
buildResult.formData = JSON.stringify(finalFormData)
|
||||
if (applied.length > 0) {
|
||||
log.info(` ↳ final smartProps 应用 ${applied.length} 项 (${source})`)
|
||||
@@ -316,6 +337,8 @@ export function buildFormCreateCommand(): Command {
|
||||
.option('--table <name>', '绑现有物理表 (镜像 web 选表自动生成字段; 不需要 --ai 描述, 不需要 --fields)')
|
||||
.option('--ai <desc>', '白皮书 5.10.1 AI 快速建表 — 自然语言描述, 平台 LLM 生成 enCode/fullName/fields (走 NCPF backend /api/visualdev/ai/form, v0.12+ 默认 autoRelease=true)')
|
||||
.option('--ai-field <desc>', '白皮书 5.10.2 AI 推荐字段 — 自然语言描述, 平台 LLM 推荐单字段, 只输出建议不建表单')
|
||||
// v2.4+ (BS-新411, tdd2 2026-07-25): --enCode-strict 强制要求 --enCode 显式传, 防止 --ai 自由命名漂移
|
||||
.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('--no-verify', '跳过浏览器层验证')
|
||||
@@ -453,6 +476,16 @@ export function buildFormCreateCommand(): Command {
|
||||
|
||||
// 5.10.1: --ai 自动建表单
|
||||
if (opts.ai) {
|
||||
// v2.4+ (BS-新411, tdd2 2026-07-25): --enCode-strict 强制要求 --enCode 显式传
|
||||
// 防 --ai 自由命名 enCode 漂移 (e.g. tdd2order → tdd2orderForm)
|
||||
// ssw-loop §9 enCode 清单场景必须开启
|
||||
if (opts.enCodeStrict && !opts.enCode) {
|
||||
log.error(`BS-新411: --enCode-strict 模式下 --enCode 必传`)
|
||||
log.error(` --ai 自由生成的 enCode (含 'Form' 后缀等) 与主代理已校验 enCode 清单不一致`)
|
||||
log.error(` 推荐: dacli form create --enCode=<来自 §9 清单> --ai="..."`)
|
||||
return ctx.fail(`BS-新411: --enCode-strict 需要显式 --enCode`, { ai: opts.ai })
|
||||
}
|
||||
|
||||
// v2.0+: AI token 预检 — 过期则自动重登
|
||||
try {
|
||||
const healthR = await c.get<{ code: number }>('/visualdev/Base', { currentPage: 1, pageSize: 1 })
|
||||
@@ -478,6 +511,20 @@ export function buildFormCreateCommand(): Command {
|
||||
|
||||
log.info(`--ai "${opts.ai}" — 调用平台 AI 生成表单 (白皮书 5.10.1)`)
|
||||
const data = await callAiForm(opts.ai)
|
||||
// v2.4+ (BS-新131-加强, tdd2 2026-07-25): 检测 --ai 生成 enCode 与 --enCode 不一致
|
||||
// 例: --enCode=tdd2order, --ai 改成 tdd2orderForm
|
||||
// silent_warn 提示 + 默认采纳 --enCode (避免漂移)
|
||||
if (opts.enCode && data.enCode && opts.enCode !== data.enCode) {
|
||||
log.warn(`BS-新131-加强: --ai 生成的 enCode='${data.enCode}' 与 --enCode='${opts.enCode}' 不一致`)
|
||||
log.warn(` 采纳 --enCode='${opts.enCode}', 覆盖 AI 生成`)
|
||||
data.enCode = opts.enCode
|
||||
ctx.addSuggestion({
|
||||
id: 'BS-新131-加强',
|
||||
level: 'silent',
|
||||
field: 'enCode',
|
||||
summary: `AI='${data.enCode}' → user='${opts.enCode}'`,
|
||||
})
|
||||
}
|
||||
// AI Login expired (P1-7) → fallback 走 web buildFormData 默认 schema (user 传 enCode/fullName 时)
|
||||
if (data.loginExpired) {
|
||||
if (!opts.enCode || !opts.fullName) {
|
||||
|
||||
@@ -105,7 +105,27 @@ export function buildOrgCreateCommand(): Command {
|
||||
}
|
||||
// v3.0+ P0: 走 webapi/permission.createOrg (web 端 create 函数)
|
||||
await initPermissionWebapi(c)
|
||||
const r = (await createOrg(body as any)) as { id?: string; code?: number; msg?: string }
|
||||
// v2.4+ (BS-新408, tdd2 2026-07-25): 偶发 405, 加 retry 3 次
|
||||
let r: { id?: string; code?: number; msg?: string } | undefined
|
||||
let lastErr: Error | undefined
|
||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
||||
try {
|
||||
r = (await createOrg(body as any)) as { id?: string; code?: number; msg?: string }
|
||||
if (r.code === 405) {
|
||||
log.warn(`BS-新408: org create HTTP 405 (attempt=${attempt}/3), retry...`)
|
||||
await new Promise((r) => setTimeout(r, 500 * attempt))
|
||||
continue
|
||||
}
|
||||
break
|
||||
} catch (e) {
|
||||
lastErr = e as Error
|
||||
log.warn(`BS-新408: org create 异常 (attempt=${attempt}/3): ${(e as Error).message?.slice(0, 80)}`)
|
||||
if (attempt < 3) await new Promise((r) => setTimeout(r, 500 * attempt))
|
||||
}
|
||||
}
|
||||
if (!r) {
|
||||
return ctx.fail(`org create 失败 (3 次重试): ${lastErr?.message?.slice(0, 100)}`, { enCode: opts.enCode })
|
||||
}
|
||||
if (r.code !== 200 && r.code !== undefined) {
|
||||
const enhanced = enhanceFromBackend(r.msg || '', 'org', { entity: 'org' })
|
||||
log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`)
|
||||
|
||||
@@ -94,6 +94,22 @@ export function buildRoleCreateCommand(): Command {
|
||||
// v0.21+ (Round 12 BS-新42): 用共享 _lookup.ts 替代 inline list fallback
|
||||
id = (await lookupRoleIdByEnCode(opts.enCode, opts.fullName)) ?? id
|
||||
}
|
||||
// BS-新406 (tdd2 2026-07-25): 即使 lookup 失败, 也兜底从 webapi list 拿 id
|
||||
if (!id) {
|
||||
log.warn(`BS-新406: r.data?.id 为空且 lookup 失败, 尝试 fallback webapi list`)
|
||||
try {
|
||||
const listR = (await loadRole.getRoleList({ currentPage: 1, pageSize: 1000 })) as { data?: { list?: Array<{ id?: string; enCode?: string; fullName?: string }> } }
|
||||
const found = listR.data?.list?.find((role: any) => role.enCode === opts.enCode)
|
||||
id = found?.id ? String(found.id) : undefined
|
||||
if (id) log.info(`BS-新406 fallback 成功: ${opts.enCode} → ${id}`)
|
||||
} catch (e) {
|
||||
log.warn(`BS-新406 fallback 也失败: ${(e as Error).message?.slice(0, 80)}`)
|
||||
}
|
||||
}
|
||||
// v2.4+ (BS-新406): 同步回写 r.data.id, 确保 --json 输出包含 id
|
||||
if (id && r.data) {
|
||||
r.data = { ...r.data, id }
|
||||
}
|
||||
log.info(`✓ 角色创建成功 id=${id}${userIdsArray.length > 0 ? ` (含 ${userIdsArray.length} 个用户绑定)` : ''}`)
|
||||
if (opts.json) printJson({ ...(r.data as object), id })
|
||||
ctx.success({ id, enCode: opts.enCode, userIdsCount: userIdsArray.length })
|
||||
|
||||
@@ -45,14 +45,26 @@ export function buildRoleListCommand(): Command {
|
||||
fixes: [],
|
||||
}, async (ctx) => {
|
||||
try {
|
||||
await initWebapi(c)
|
||||
const r = (await loadRole.getRoleList({
|
||||
keyword: opts.keyword,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
})) as { code?: number; msg?: string; data?: { list?: RoleItem[] } }
|
||||
if (r.code !== 200) {
|
||||
return ctx.fail(`role list 失败 (code=${r.code}): ${r.msg}`, { keyword: opts.keyword, code: r.code })
|
||||
let r: { code?: number; msg?: string; data?: { list?: RoleItem[] } } | undefined
|
||||
try {
|
||||
await initWebapi(c)
|
||||
r = (await loadRole.getRoleList({
|
||||
keyword: opts.keyword,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
})) as { code?: number; msg?: string; data?: { list?: RoleItem[] } }
|
||||
} catch (webapiErr) {
|
||||
// BS-新407 (tdd2 2026-07-25): webapi 失败 fallback 到原始 c.get
|
||||
log.warn(`BS-新407: webapi 失败 (${(webapiErr as Error).message?.slice(0, 60)}), fallback 到 GET /permission/Role`)
|
||||
const fallbackR = await c.get<{ code: number; data?: { list?: RoleItem[] }; msg?: string }>('/permission/Role', {
|
||||
keyword: opts.keyword,
|
||||
currentPage: 1,
|
||||
pageSize: 50,
|
||||
})
|
||||
r = fallbackR
|
||||
}
|
||||
if (!r || r.code !== 200) {
|
||||
return ctx.fail(`role list 失败 (code=${r?.code}): ${r?.msg}`, { keyword: opts.keyword, code: r?.code })
|
||||
}
|
||||
const list = r.data?.list || []
|
||||
const summary = { keyword: opts.keyword, total: list.length }
|
||||
|
||||
@@ -131,6 +131,26 @@ export function buildWorkflowCreateCommand(): Command {
|
||||
|
||||
// (Round 8 P0): workflow --category=<id> 不存在 → 后端 400 模糊
|
||||
// step 0 拦截: 跑 selector 查表, 不存在直接 exit 2
|
||||
// v2.4+ (BS-E5-加强, tdd2 2026-07-25): category 不传时自动从已有 workflow 派生
|
||||
if (!opts.category) {
|
||||
try {
|
||||
await initWebapi(c)
|
||||
const resp = (await loadWorkflow.getFlowSelector({})) as unknown
|
||||
const list = Array.isArray(resp) ? resp : ((resp as { list?: unknown[] })?.list || [])
|
||||
const firstWithCategory = (list as Array<Record<string, unknown>>).find((it) => it.category)
|
||||
if (firstWithCategory?.category) {
|
||||
opts.category = String(firstWithCategory.category)
|
||||
log.info(`BS-E5-加强: workflow category 自动派生: ${opts.category}`)
|
||||
} else {
|
||||
// 无任何 workflow 可参考, fallback 到固定 hex (跨 app 共享)
|
||||
opts.category = '802fb04ab5b84aa5bcc5dc53372a271d'
|
||||
log.warn(`BS-E5-加强: 无 workflow 可参考, fallback 到共享 category: ${opts.category}`)
|
||||
}
|
||||
} catch (e) {
|
||||
log.warn(`BS-E5-加强: 自动派生失败 (${(e as Error).message?.slice(0, 60)}), 使用共享 fallback`)
|
||||
opts.category = '802fb04ab5b84aa5bcc5dc53372a271d'
|
||||
}
|
||||
}
|
||||
if (opts.category) {
|
||||
try {
|
||||
await initWebapi(c)
|
||||
|
||||
Reference in new issue
Block a user