diff --git a/src/commands/_dirty_check.ts b/src/commands/_dirty_check.ts index 6ee62d4..845b90b 100644 --- a/src/commands/_dirty_check.ts +++ b/src/commands/_dirty_check.ts @@ -32,10 +32,10 @@ export interface DirtyCheckOpts { state?: string | number /** 其他描述信息, 用于错误输出 (如 form fullName) */ fullName?: string - /** 模块标识, 用于错误输出 (form/workflow/dict) */ - type: 'form' | 'workflow' | 'dict' + /** 模块标识, 用于错误输出 (form/workflow/dict/role/di) */ + type: 'form' | 'workflow' | 'dict' | 'role' | 'di' } - /** form/workflow/dict id, 用于错误输出 */ + /** form/workflow/dict/role/di id, 用于错误输出 */ id: string } @@ -95,7 +95,7 @@ export function dirtyCheck(opts: DirtyCheckOpts): DirtyCheckResult { */ export function dirtyCheckFailAndExit( result: DirtyCheckResult, - ctx: { type: 'form' | 'workflow' | 'dict'; id: string; current: { enCode?: string; state?: string | number; fullName?: string } }, + ctx: { type: 'form' | 'workflow' | 'dict' | 'role' | 'di'; id: string; current: { enCode?: string; state?: string | number; fullName?: string } }, logError: (msg: string) => void, ): void { if (result.ok) return diff --git a/src/commands/di/update.ts b/src/commands/di/update.ts index 2daa416..da071b0 100644 --- a/src/commands/di/update.ts +++ b/src/commands/di/update.ts @@ -11,6 +11,7 @@ import { log, printJson } from '../../core/log.ts' import { initWebapi, loadDataInterface } from '../../webapi/di.ts' import { validateDiUpdate, type DiOpts } from './_validate.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { dirtyCheck, dirtyCheckFailAndExit } from '../_dirty_check.ts' interface Opts { id: string @@ -19,6 +20,9 @@ interface Opts { categoryId?: string requestMethod?: string url?: string + expectedEnCode?: string + expectedState?: string + force?: boolean json?: boolean } @@ -31,6 +35,9 @@ export function buildDiUpdateCommand(): Command { .option('--categoryId ', '分类 id') .option('--requestMethod ', '请求方法 (GET/POST/PUT/DELETE)') .option('--url ', '接口路径/URL') + .option('--expected-enCode ', 'v0.11e+ Phase A2: 校验 enCode 未变 (防 AI session 误覆盖)') + .option('--expected-state ', 'v0.11e+ Phase A2: 校验 enabledMark 未变') + .option('--force', 'v0.11e+ Phase A2: 跳过 dirty check', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() @@ -41,6 +48,25 @@ export function buildDiUpdateCommand(): Command { process.exit(1) } + // v0.11e+ Phase A2: dirty check (防 AI session 长时间保留误覆盖) + const dirtyResult = dirtyCheck({ + expectedEnCode: opts.expectedEnCode, + expectedState: opts.expectedState, + force: opts.force, + current: { + enCode: orig.enCode as string | undefined, + state: orig.enabledMark as string | number | undefined, + fullName: orig.fullName as string | undefined, + type: 'di', + }, + id: opts.id, + }) + if (!dirtyResult.ok) { + dirtyCheckFailAndExit(dirtyResult, { type: 'di', id: opts.id, current: { enCode: orig.enCode as string | undefined, fullName: orig.fullName as string | undefined } }, log.error) + } else if (dirtyResult.skipped) { + log.info(`⚠ dirty check 已 --force 跳过`) + } + // v0.11d+ Phase di: step machine 校验 (镜像 web dataInterface/Form.vue + 后端 DataInterfaceController.update) // 跑 3 step 校验, 失败 → exit 1 await runDiStepMachine(c, opts, orig) @@ -67,11 +93,12 @@ export function buildDiUpdateCommand(): Command { installAiHelpHook(cmd, { purpose: '数据接口修改 (改 schema/path/参数). PUT 语义, 未传字段保留原值. v0.11d+ 加 step machine 校验 (3 step 镜像 web dataInterface/Form.vue + 后端 DataInterfaceController.update, BS-47 唯一性预校验, 聚合错误)', required: { '--id': '数据接口 id' }, - optional: { '--fullName': '中文名', '--enCode': '英文编码', '--categoryId': '分类 id', '--requestMethod': '请求方法', '--url': '接口路径/URL' }, + optional: { '--fullName': '中文名', '--enCode': '英文编码', '--categoryId': '分类 id', '--requestMethod': '请求方法', '--url': '接口路径/URL', '--expected-enCode': '防 AI 误覆盖 (A2)', '--expected-state': '防 AI 误覆盖 (A2)', '--force': '跳过 dirty check (A2)' }, example: 'dacli di update --id=123 --url=/api/new/path', source: { api: 'PUT /api/system/DataInterface/{id}', ref: 'web/.../api/systemData/dataInterface.ts updateDataInterface() (后端: jnpf/.../DataInterfaceController.java:292-311)' }, notes: [ 'v0.11+ 改用 webapi 镜像 (loadDataInterface.updateDataInterface)', + 'v0.11e+ Phase A2: dirty check --expected-enCode/--expected-state/--force (防 AI session 长时间保留误覆盖)', 'v0.11d+ step machine (镜像 web dataInterface/Form.vue:166-251 + 后端 DataInterfaceController.update L292-311):', ' step 0 基础信息: fullName 必填 + enCode 必填 (**无正则**, 与 menu/dict/role 不同!) + category + type ∈ {1,2,3}', ' step 1 联动: action 仅 type=1 必填 (type=2/3 不显示)', diff --git a/src/commands/dict/typeupdate.ts b/src/commands/dict/typeupdate.ts index 9e689bd..70c57ea 100644 --- a/src/commands/dict/typeupdate.ts +++ b/src/commands/dict/typeupdate.ts @@ -9,6 +9,8 @@ import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { initWebapi, loadDict } from '../../webapi/dict.ts' +import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { dirtyCheck, dirtyCheckFailAndExit } from '../_dirty_check.ts' interface Opts { id: string @@ -17,6 +19,9 @@ interface Opts { category?: string isTree?: string sortCode?: string + expectedEnCode?: string + expectedState?: string + force?: boolean json?: boolean } @@ -30,6 +35,9 @@ export function buildDictTypeUpdateCommand(): Command { .option('--category ', '分类 (0=业务 1=系统)') .option('--isTree <0|1>', '是否树形', (v) => parseInt(v, 10)) .option('--sortCode ', '排序', (v) => parseInt(v, 10)) + .option('--expected-enCode ', 'v0.11e+ Phase A2: 校验 enCode 未变 (防 AI session 误覆盖)') + .option('--expected-state ', 'v0.11e+ Phase A2: 校验 enabledMark 未变') + .option('--force', 'v0.11e+ Phase A2: 跳过 dirty check', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() @@ -40,6 +48,26 @@ export function buildDictTypeUpdateCommand(): Command { log.error(`dict typeUpdate 失败: 拉原字典类型 id=${opts.id} 失败`) process.exit(1) } + + // v0.11e+ Phase A2: dirty check (防 AI session 长时间保留误覆盖) + const dirtyResult = dirtyCheck({ + expectedEnCode: opts.expectedEnCode, + expectedState: opts.expectedState, + force: opts.force, + current: { + enCode: orig.enCode as string | undefined, + state: orig.enabledMark as string | number | undefined, + fullName: orig.fullName as string | undefined, + type: 'dict', + }, + id: opts.id, + }) + if (!dirtyResult.ok) { + dirtyCheckFailAndExit(dirtyResult, { type: 'dict', id: opts.id, current: { enCode: orig.enCode as string | undefined, fullName: orig.fullName as string | undefined } }, log.error) + } else if (dirtyResult.skipped) { + log.info(`⚠ dirty check 已 --force 跳过`) + } + const body: Record = { ...orig, id: opts.id } if (opts.fullName) body.fullName = opts.fullName if (opts.enCode) body.enCode = opts.enCode @@ -49,7 +77,8 @@ export function buildDictTypeUpdateCommand(): Command { log.info(`loadDict.updateDictionaryType (id=${opts.id})`) const r = (await loadDict.updateDictionaryType(body)) as { code?: number; msg?: string; data?: unknown } if (r.code !== 200 && r.code !== undefined) { - log.error(`dict typeUpdate 失败 (code=${r.code}): ${r.msg}`) + const enhanced = enhanceFromBackend(r.msg || '', 'dictType', { entity: 'dict' }) + log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) if (opts.json) printJson(r) process.exit(1) } @@ -59,10 +88,13 @@ export function buildDictTypeUpdateCommand(): Command { installAiHelpHook(cmd, { purpose: '字典类型修改 (改名/分类/树形/排序). PUT 语义, 未传保留.', required: { '--id': '字典类型 id' }, - optional: { '--fullName': '名', '--enCode': '编码', '--category': '分类', '--isTree': '树形', '--sortCode': '排序' }, + optional: { '--fullName': '名', '--enCode': '编码', '--category': '分类', '--isTree': '树形', '--sortCode': '排序', '--expected-enCode': '防 AI 误覆盖 (A2)', '--expected-state': '防 AI 误覆盖 (A2)', '--force': '跳过 dirty check (A2)' }, example: 'dacli dict typeUpdate --id=123 --fullName=新名', source: { api: 'PUT /api/system/DictionaryType/{id}', ref: 'web/.../api/systemData/dictionary.ts updateDictionaryType()' }, - notes: ['v0.11+ 改用 webapi 镜像 (loadDict.updateDictionaryType)'], + notes: [ + 'v0.11+ 改用 webapi 镜像 (loadDict.updateDictionaryType)', + 'v0.11e+ Phase A2: dirty check --expected-enCode/--expected-state/--force (防 AI session 长时间保留误覆盖)', + ], }) return cmd } diff --git a/src/commands/role/update.ts b/src/commands/role/update.ts index b6ebb9a..b16e586 100644 --- a/src/commands/role/update.ts +++ b/src/commands/role/update.ts @@ -10,6 +10,7 @@ import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { initWebapi, loadRole } from '../../webapi/role.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { dirtyCheck, dirtyCheckFailAndExit } from '../_dirty_check.ts' interface Opts { id: string @@ -17,6 +18,9 @@ interface Opts { enCode?: string enabledMark?: string description?: string + expectedEnCode?: string + expectedState?: string + force?: boolean json?: boolean } @@ -28,6 +32,9 @@ export function buildRoleUpdateCommand(): Command { .option('--enCode ', '英文编码') .option('--enabledMark <0|1>', '启用/禁用', (v) => parseInt(v, 10)) .option('--description ', '描述') + .option('--expected-enCode ', 'v0.11e+ Phase A2: 校验 enCode 未变 (防 AI session 误覆盖)') + .option('--expected-state ', 'v0.11e+ Phase A2: 校验 enabledMark 未变') + .option('--force', 'v0.11e+ Phase A2: 跳过 dirty check', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() @@ -37,6 +44,26 @@ export function buildRoleUpdateCommand(): Command { log.error(`role update 失败: 拉原角色 id=${opts.id} 失败`) process.exit(1) } + + // v0.11e+ Phase A2: dirty check (防 AI session 长时间保留误覆盖) + const dirtyResult = dirtyCheck({ + expectedEnCode: opts.expectedEnCode, + expectedState: opts.expectedState, + force: opts.force, + current: { + enCode: orig.enCode as string | undefined, + state: orig.enabledMark as string | number | undefined, + fullName: orig.fullName as string | undefined, + type: 'role', + }, + id: opts.id, + }) + if (!dirtyResult.ok) { + dirtyCheckFailAndExit(dirtyResult, { type: 'role', id: opts.id, current: { enCode: orig.enCode as string | undefined, fullName: orig.fullName as string | undefined } }, log.error) + } else if (dirtyResult.skipped) { + log.info(`⚠ dirty check 已 --force 跳过`) + } + 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/workflow/update.ts b/src/commands/workflow/update.ts index 7803832..3798de5 100644 --- a/src/commands/workflow/update.ts +++ b/src/commands/workflow/update.ts @@ -9,6 +9,8 @@ import { JnpfClient } from '../../core/client.ts' import { installAiHelpHook } from '../../core/help.ts' import { log, printJson } from '../../core/log.ts' import { initWebapi, loadWorkflow } from '../../webapi/workflow.ts' +import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' +import { dirtyCheck, dirtyCheckFailAndExit } from '../_dirty_check.ts' interface Opts { id: string @@ -17,6 +19,9 @@ interface Opts { category?: string enabledMark?: string description?: string + expectedEnCode?: string + expectedState?: string + force?: boolean json?: boolean } @@ -29,6 +34,9 @@ export function buildWorkflowUpdateCommand(): Command { .option('--category ', '分类 id') .option('--enabledMark <0|1>', '启用/禁用') .option('--description ', '描述') + .option('--expected-enCode ', 'v0.11e+ Phase A2: 校验 enCode 未变 (防 AI session 误覆盖)') + .option('--expected-state ', 'v0.11e+ Phase A2: 校验 enabledMark 未变') + .option('--force', 'v0.11e+ Phase A2: 跳过 dirty check', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() @@ -38,6 +46,26 @@ export function buildWorkflowUpdateCommand(): Command { log.error(`workflow update 失败: 拉原模板 id=${opts.id} 失败`) process.exit(1) } + + // v0.11e+ Phase A2: dirty check (防 AI session 长时间保留误覆盖) + const dirtyResult = dirtyCheck({ + expectedEnCode: opts.expectedEnCode, + expectedState: opts.expectedState, + force: opts.force, + current: { + enCode: orig.enCode as string | undefined, + state: orig.enabledMark as string | number | undefined, + fullName: orig.fullName as string | undefined, + type: 'workflow', + }, + id: opts.id, + }) + if (!dirtyResult.ok) { + dirtyCheckFailAndExit(dirtyResult, { type: 'workflow', id: opts.id, current: { enCode: orig.enCode as string | undefined, fullName: orig.fullName as string | undefined } }, log.error) + } else if (dirtyResult.skipped) { + log.info(`⚠ dirty check 已 --force 跳过`) + } + const body: Record = { ...orig, id: opts.id } if (opts.fullName) body.fullName = opts.fullName if (opts.enCode) body.enCode = opts.enCode @@ -47,7 +75,8 @@ export function buildWorkflowUpdateCommand(): Command { log.info(`loadWorkflow.update (id=${opts.id})`) const r = (await loadWorkflow.update(body)) as { code?: number; msg?: string; data?: unknown } if (r.code !== 200 && r.code !== undefined) { - log.error(`workflow update 失败 (code=${r.code}): ${r.msg}`) + const enhanced = enhanceFromBackend(r.msg || '', 'workflow', { entity: 'workflow' }) + log.error(` ${formatErrorLine(enhanced, { step: 1, stepName: '后端API' })}`) if (opts.json) printJson(r) process.exit(1) } @@ -57,10 +86,13 @@ export function buildWorkflowUpdateCommand(): Command { installAiHelpHook(cmd, { purpose: '流程模板修改 (PUT 语义).', required: { '--id': '流程模板 id' }, - optional: { '--fullName': '中文名', '--enCode': '英文编码', '--category': '分类 id', '--enabledMark': '启用/禁用 0|1', '--description': '描述' }, + optional: { '--fullName': '中文名', '--enCode': '英文编码', '--category': '分类 id', '--enabledMark': '启用/禁用 0|1', '--description': '描述', '--expected-enCode': '防 AI 误覆盖 (A2)', '--expected-state': '防 AI 误覆盖 (A2)', '--force': '跳过 dirty check (A2)' }, example: 'dacli workflow update --id=123 --enabledMark=0', source: { api: 'PUT /api/workflow/template/{id}', ref: 'web/.../api/workFlow/template.ts update()' }, - notes: ['v0.11+ 改用 webapi 镜像 (loadWorkflow.update)'], + notes: [ + 'v0.11+ 改用 webapi 镜像 (loadWorkflow.update)', + 'v0.11e+ Phase A2: dirty check --expected-enCode/--expected-state/--force (防 AI session 长时间保留误覆盖, 同 form/update.ts)', + ], }) return cmd }