diff --git a/src/commands/app/create.ts b/src/commands/app/create.ts index 9d0fcb8..a2dde7b 100644 --- a/src/commands/app/create.ts +++ b/src/commands/app/create.ts @@ -70,10 +70,12 @@ export function buildAppCreateCommand(): Command { log.info(`开始创建应用: ${opts.appCode} (${opts.appName})`) log.dim(` dbName=${dbName}, force-rebuild=${!!opts.forceRebuild}, skip-db=${!!opts.skipDb}, skip-grant=${!!opts.skipGrant}`) + // === step 0 拿当前 token (developSystem 登录态, 后面切换) === // === 0. 拿当前 token (developSystem 登录态, 后面切换) === const c = await JnpfClient.fromToken() log.dim(` 当前登录: ${c.account} @ ${c.appCode} (baseUrl=${c.baseUrl})`) + // === step 1 创建系统 (幂等: 已存在则复用) === // === 1. 创建系统 (幂等: 已存在则复用) === log.info('[1/5] 创建系统...') const sysList = await c.get<{ list: AppItem[] }>('/system/System', { keyword: opts.appCode, currentPage: 1, pageSize: 50 }) @@ -106,6 +108,7 @@ export function buildAppCreateCommand(): Command { log.ok(` ✓ 系统创建: systemId=${systemId}`) } + // === step 2 创建 MySQL 数据库 (ssw-common /dblinkExt/createDatabase) === // === 2. 创建 MySQL 数据库 (ssw-common /dblinkExt/createDatabase) === let dbLinkId = '' if (!opts.skipDb) { diff --git a/src/commands/bigscreen/release.ts b/src/commands/bigscreen/release.ts index 11131e2..fc4992c 100644 --- a/src/commands/bigscreen/release.ts +++ b/src/commands/bigscreen/release.ts @@ -20,7 +20,10 @@ export function buildBigscreenReleaseCommand(): Command { .description('发布大屏 (state 0→1)') .requiredOption('--id ', '大屏 id') .action(async (opts: ReleaseOpts) => { + // === step 0 校验 --id 必填 === + // === step 1 构造 Actions/release 端点 === const c = await JnpfClient.fromToken() + // === step 2 后端API POST /extend/BigData/{id}/Actions/release === const r = await c.postJson(`/extend/BigData/${opts.id}/Actions/release`, {}) if (r.code !== 200) { const enhanced = enhanceFromBackend(r.msg || '', 'bigscreen', { entity: 'bigscreen' }) diff --git a/src/commands/bigscreen/update.ts b/src/commands/bigscreen/update.ts index 78b6683..a2a1937 100644 --- a/src/commands/bigscreen/update.ts +++ b/src/commands/bigscreen/update.ts @@ -34,8 +34,10 @@ export function buildBigscreenUpdateCommand(): Command { .option('--force', 'v0.11e+ Phase A2: 跳过 dirty check', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { + // === step 0 校验 --id + 拉原大屏 (loadVisualData.getVisualDataInfo) === const c = await JnpfClient.fromToken() await initWebapi(c) + // === step 1 dirty check (Phase A2 防 AI session 误覆盖) === const wrapper = (await loadVisualData.getVisualDataInfo?.(opts.id) || (await loadVisualData.getInfo?.(opts.id))) as { data?: Record } | Record const orig = (wrapper as { data?: Record }).data || (wrapper as Record) @@ -63,6 +65,7 @@ export function buildBigscreenUpdateCommand(): Command { log.info(`⚠ dirty check 已 --force 跳过`) } + // === step 2 PUT 后端API (loadVisualData.updateVisualData) === const body: Record = { ...orig, id: opts.id } if (opts.fullName) body.fullName = opts.fullName if (opts.enCode) body.enCode = opts.enCode diff --git a/src/commands/dict/datacreate.ts b/src/commands/dict/datacreate.ts index f9973c1..3e9a419 100644 --- a/src/commands/dict/datacreate.ts +++ b/src/commands/dict/datacreate.ts @@ -42,6 +42,7 @@ export function buildDictDataCreateCommand(): Command { process.exit(2) } + // === step 0 校验参数 + 解析 items === const c = await JnpfClient.fromToken() await initWebapi(c) let items: Array<{ enCode: string; fullName: string; sortCode?: number; parentId?: string }> @@ -68,6 +69,7 @@ export function buildDictDataCreateCommand(): Command { ] } + // === step 1 (批量调用 loadDict.createDictionaryData (后端API) === log.info(`loadDict.createDictionaryData typeId=${opts.typeId} count=${items.length}`) let ok = 0, fail = 0 diff --git a/src/commands/dict/dataupdate.ts b/src/commands/dict/dataupdate.ts index dbc6eca..3b34f21 100644 --- a/src/commands/dict/dataupdate.ts +++ b/src/commands/dict/dataupdate.ts @@ -38,6 +38,7 @@ export function buildDictDataUpdateCommand(): Command { .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() await initWebapi(c) + // === step 0 (拉原字典项 (loadDict.getDictionaryDataInfo) === // v0.11+ Phase 2: 用 webapi 镜像 (loadDict.getDictionaryDataInfo + updateDictionaryData) const orig = (await loadDict.getDictionaryDataInfo(opts.id)) as Record if (!orig) { @@ -46,6 +47,7 @@ export function buildDictDataUpdateCommand(): Command { process.exit(1) } + // === step 1 (dirty check (Phase A2, 防 AI session 误覆盖) === // v0.11e+ Phase A2: dirty check (防 AI session 误覆盖) const dirtyResult = dirtyCheck({ expectedEnCode: opts.expectedEnCode, @@ -63,6 +65,7 @@ export function buildDictDataUpdateCommand(): Command { } else if (dirtyResult.skipped) { log.info(`⚠ dirty check 已 --force 跳过`) } + // === step 2 (PUT (loadDict.updateDictionaryData, 后端API) === const body: Record = { ...orig, id: opts.id } if (opts.enCode) body.enCode = opts.enCode if (opts.fullName) body.fullName = opts.fullName diff --git a/src/commands/dict/typeupdate.ts b/src/commands/dict/typeupdate.ts index 70c57ea..ba20bc0 100644 --- a/src/commands/dict/typeupdate.ts +++ b/src/commands/dict/typeupdate.ts @@ -42,6 +42,7 @@ export function buildDictTypeUpdateCommand(): Command { .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() await initWebapi(c) + // === step 0 (拉原字典类型 (loadDict.getDictionaryTypeInfo) === // v0.11+ Phase 2: 用 webapi 镜像 (loadDict.getDictionaryTypeInfo + updateDictionaryType) const orig = (await loadDict.getDictionaryTypeInfo(opts.id)) as Record if (!orig) { @@ -49,6 +50,7 @@ export function buildDictTypeUpdateCommand(): Command { process.exit(1) } + // === step 1 (dirty check (Phase A2, 防 AI session 误覆盖) === // v0.11e+ Phase A2: dirty check (防 AI session 长时间保留误覆盖) const dirtyResult = dirtyCheck({ expectedEnCode: opts.expectedEnCode, @@ -68,6 +70,7 @@ export function buildDictTypeUpdateCommand(): Command { log.info(`⚠ dirty check 已 --force 跳过`) } + // === step 2 (PUT (loadDict.updateDictionaryType, 后端API) === const body: Record = { ...orig, id: opts.id } if (opts.fullName) body.fullName = opts.fullName if (opts.enCode) body.enCode = opts.enCode diff --git a/src/commands/form/release.ts b/src/commands/form/release.ts index 8fd158d..f3c2a61 100644 --- a/src/commands/form/release.ts +++ b/src/commands/form/release.ts @@ -25,6 +25,7 @@ export function buildFormReleaseCommand(): Command { .argument('', '表单 id') .option('--soft', '发布失败不退出 (用于 type=4)', false) .action(async (id: string, opts: { soft?: boolean }) => { + // === step 0 blindspot guard + BS-53 检测 === // P3.1: 第二层防御 — 仅接入 release 适用的 blindspot guard // - BS-8 (token expired), BS-5 (ctx 空), BS-43 (v0.6 走错端点) // - BS-37 (form 已发布未挂菜单 → 浏览器 404) — WARN, 提示后续挂菜单 @@ -35,12 +36,14 @@ export function buildFormReleaseCommand(): Command { if (guardCtx.warning) log.warn(guardCtx.warning) handleGuardResult('form release', runGuards(guardCtx.ctx, { formId: id }, 'form release')) + // === step 1 BS-53 state 检测 + 准备 release 调用 === // BS-53: 检测 state=2 并提示用户, 后端 Actions/Release 直接覆盖为 1 if (guardCtx.ctx?.modifiedAfterPublishForms?.some(f => f.startsWith(`${id}:`))) { log.info(`formId ${id} 当前 state=2 (已发布被编辑过), 将自动重新发布为 state=1`) } const c = await JnpfClient.fromToken() + // === step 2 (后端API (Actions/Release) === // v0.11+ Phase 1: 用 web 端 release (替代 c.postJson('/visualdev/Base/{id}/Actions/Release')) await initWebapi(c) const resp = await loadVisualDev.release(id) diff --git a/src/commands/form/update.ts b/src/commands/form/update.ts index a05df4b..e542231 100644 --- a/src/commands/form/update.ts +++ b/src/commands/form/update.ts @@ -13,6 +13,7 @@ import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { initWebapi, loadVisualDev } from '../../webapi/visualDev.ts' import { dirtyCheck, dirtyCheckFailAndExit } from '../_dirty_check.ts' +import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' interface Opts { id: string @@ -61,6 +62,8 @@ export function buildFormUpdateCommand(): Command { const c = await JnpfClient.fromToken() await initWebapi(c) + // === step 0 releaseOnly 分支 === + // 0. releaseOnly 模式: 仅重新发布 // 0. releaseOnly 模式: 仅重新发布 if (opts.releaseOnly) { log.info(`loadVisualDev.release (formId=${opts.id})`) @@ -75,6 +78,7 @@ export function buildFormUpdateCommand(): Command { return } + // === step 1 拉原 form / 读 current state === // 1. 拉原 form const orig = (await loadVisualDev.getInfo(opts.id)) as Record log.info(`原 form: enCode=${orig.enCode} fullName=${orig.fullName}`) @@ -113,6 +117,7 @@ export function buildFormUpdateCommand(): Command { } } + // === step 2 合并更新 / PUT 语义, 未传字段保留 === // 2. 合并更新 (PUT 语义, 未传字段保留) const body: Record = { ...orig, id: opts.id } if (opts.fullName) body.fullName = opts.fullName @@ -164,16 +169,19 @@ export function buildFormUpdateCommand(): Command { log.info(`字段合并: ${existingFields.length} → ${merged.length} (新增 ${parsed.length - (merged.length - existingFields.length)})`) } + // === step 3 PUT / 后端API === // 4. PUT log.info(`loadVisualDev.update (formId=${opts.id})`) const r = (await loadVisualDev.update(body)) as { code?: number; msg?: string; data?: unknown } if (r.code !== 200 && r.code !== undefined) { - log.error(`update 失败 (code=${r.code}): ${r.msg}`) + const enhanced = enhanceFromBackend(r.msg || '', 'form', { entity: 'form' }) + log.error(` ${formatErrorLine(enhanced, { step: 3, stepName: 'PUT 后端API' })}`) if (opts.json) printJson(r) process.exit(1) } log.ok(`✓ 表单更新成功 (id=${opts.id})`) + // === step 4 BS-53 防护 / PUT 后自动重新发布 === // 5. BS-53 防护: PUT 后自动重新发布 if (opts.autoRelease) { log.info(`PUT 后自动 Actions/Release (BS-53 防护)`) diff --git a/src/commands/menu/unrelease.ts b/src/commands/menu/unrelease.ts index d1c05a7..68cc449 100644 --- a/src/commands/menu/unrelease.ts +++ b/src/commands/menu/unrelease.ts @@ -9,6 +9,7 @@ import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log } from '../../core/log.ts' import { initWebapi, loadVisualDev } from '../../webapi/visualDev.ts' +import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' interface Opts { formId: string @@ -19,6 +20,8 @@ export function buildMenuUnreleaseCommand(): Command { .description('取消表单菜单发布 (form-driven, 走 web Actions/Module 真路径)') .requiredOption('--formId ', '表单 id') .action(async (opts: Opts) => { + // === step 0 (校验 formId (BS-37 form-driven 菜单) === + // === step 1 (构造请求体 (pc=0 app=0, 镜像 web CreateMenuModal.vue) === const c = await JnpfClient.fromToken() await initWebapi(c) const body = { @@ -31,7 +34,8 @@ export function buildMenuUnreleaseCommand(): Command { log.info(`loadVisualDev.createMenu (formId=${opts.formId}, pc=0 app=0)`) const r = (await loadVisualDev.createMenu(opts.formId, body)) as { code?: number; msg?: string } if (r.code !== 200 && r.code !== undefined) { - log.error(`unrelease 失败 code=${r.code}: ${r.msg}`) + const enhanced = enhanceFromBackend(r.msg || '', 'menu', { entity: 'menu' }) + log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) process.exit(1) } log.ok(`✓ 已取消挂菜单 (formId=${opts.formId})`) diff --git a/src/commands/portal/release.ts b/src/commands/portal/release.ts index 20c3256..e879fb3 100644 --- a/src/commands/portal/release.ts +++ b/src/commands/portal/release.ts @@ -30,7 +30,9 @@ export function buildPortalReleaseCommand(): Command { .option('--pc <0|1>', 'PC 端是否发布 (1=发布, 0=不发布, 默认 1)', '1') .option('--app <0|1>', 'App 端是否发布 (1=发布, 0=不发布, 默认 0)', '0') .action(async (opts: ReleaseOpts) => { + // === step 0 校验 --id + --pc/--app 参数 === const c = await JnpfClient.fromToken() + // === step 1 构造 pc/app/platformRelease (镜像 web ReleaseModal.vue:80) === // 关键: web 端 ReleaseModal.vue 把 {pc, app} JSON.stringify 塞进 platformRelease const pc = opts.pc === '1' ? 1 : 0 const app = opts.app === '1' ? 1 : 0 @@ -40,6 +42,7 @@ export function buildPortalReleaseCommand(): Command { app, platformRelease, } + // === step 2 PUT 后端API (/visualdev/Portal/Actions/release/{id}) === const r = await c.putJson(`/visualdev/Portal/Actions/release/${opts.id}`, body) if (r.code !== 200) { const enhanced = enhanceFromBackend(r.msg || '', 'portal', { entity: 'portal' }) diff --git a/src/commands/role/update.ts b/src/commands/role/update.ts index b16e586..6eb088e 100644 --- a/src/commands/role/update.ts +++ b/src/commands/role/update.ts @@ -39,12 +39,14 @@ export function buildRoleUpdateCommand(): Command { .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() await initWebapi(c) + // === step 0 (拉原角色 (loadRole.getInfo) === const orig = (await loadRole.getInfo(opts.id)) as Record if (!orig) { log.error(`role update 失败: 拉原角色 id=${opts.id} 失败`) process.exit(1) } + // === step 1 (dirty check (Phase A2, 防 AI session 误覆盖) === // v0.11e+ Phase A2: dirty check (防 AI session 长时间保留误覆盖) const dirtyResult = dirtyCheck({ expectedEnCode: opts.expectedEnCode, @@ -64,6 +66,7 @@ export function buildRoleUpdateCommand(): Command { log.info(`⚠ dirty check 已 --force 跳过`) } + // === step 2 (PUT (loadRole.update, 后端API) === const body: Record = { ...orig, id: opts.id } if (opts.fullName) body.fullName = opts.fullName if (opts.enCode) body.enCode = opts.enCode diff --git a/src/commands/schedule/update.ts b/src/commands/schedule/update.ts index 48d19eb..08649dc 100644 --- a/src/commands/schedule/update.ts +++ b/src/commands/schedule/update.ts @@ -44,6 +44,7 @@ export function buildScheduleUpdateCommand(): Command { .option('--force', 'v0.11e+ Phase A2: 跳过 dirty check', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { + // === step 0 拉原任务 (loadSchedule.getInfo) === const c = await JnpfClient.fromToken() await initWebapi(c) const orig = (await loadSchedule.getInfo(opts.id)) as Record @@ -53,6 +54,7 @@ export function buildScheduleUpdateCommand(): Command { process.exit(1) } + // === step 1 dirty check (Phase A2 防 AI session 误覆盖) === // v0.11e+ Phase A2: dirty check const dirtyResult = dirtyCheck({ expectedEnCode: opts.expectedEnCode, @@ -90,6 +92,7 @@ export function buildScheduleUpdateCommand(): Command { } log.info(`✓ step machine 校验通过 (${validation.steps.length}/${validation.steps.length})`) + // === step 2 PUT 后端API (loadSchedule.update) === const body: Record = { ...orig, id: opts.id } if (opts.fullName) body.fullName = opts.fullName if (opts.enCode) body.enCode = opts.enCode diff --git a/src/commands/user/update.ts b/src/commands/user/update.ts index b608dbf..a25a6a0 100644 --- a/src/commands/user/update.ts +++ b/src/commands/user/update.ts @@ -27,6 +27,7 @@ export function buildUserUpdateCommand(): Command { .option('--expected-account ', 'v0.11e+ Phase A2: 校验 account 未变 (防 AI 误覆盖)') .option('--force', 'v0.11e+ Phase A2: 跳过 dirty check', false) .action(async (opts: UpdateOpts) => { + // === step 0 (校验 --fields JSON + 必填字段) === let fields: Record try { fields = JSON.parse(opts.fields) @@ -36,6 +37,7 @@ export function buildUserUpdateCommand(): Command { } // v0.11e+ Phase A2: dirty check + // === step 1 dirty check 防 AI session 误覆盖 === const dirtyResult = dirtyCheck({ expectedEnCode: opts.expectedAccount, force: opts.force, @@ -51,6 +53,7 @@ export function buildUserUpdateCommand(): Command { log.info(`⚠ dirty check 已 --force 跳过`) } + // === step 2 PUT 后端API === const c = await JnpfClient.fromToken() const r = await c.putJson(`/permission/Users/${opts.id}`, fields) if (r.code !== 200) { diff --git a/src/commands/workflow/update.ts b/src/commands/workflow/update.ts index 3798de5..cf66fea 100644 --- a/src/commands/workflow/update.ts +++ b/src/commands/workflow/update.ts @@ -41,12 +41,14 @@ export function buildWorkflowUpdateCommand(): Command { .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() await initWebapi(c) + // === step 0 (拉原流程模板 (loadWorkflow.getInfo) === const orig = (await loadWorkflow.getInfo(opts.id)) as Record if (!orig) { log.error(`workflow update 失败: 拉原模板 id=${opts.id} 失败`) process.exit(1) } + // === step 1 (dirty check (Phase A2, 防 AI session 误覆盖) === // v0.11e+ Phase A2: dirty check (防 AI session 长时间保留误覆盖) const dirtyResult = dirtyCheck({ expectedEnCode: opts.expectedEnCode, @@ -66,6 +68,7 @@ export function buildWorkflowUpdateCommand(): Command { log.info(`⚠ dirty check 已 --force 跳过`) } + // === step 2 (PUT (loadWorkflow.update, 后端API) === const body: Record = { ...orig, id: opts.id } if (opts.fullName) body.fullName = opts.fullName if (opts.enCode) body.enCode = opts.enCode