diff --git a/src/commands/dict/dataupdate.ts b/src/commands/dict/dataupdate.ts index 30e1601..dbc6eca 100644 --- a/src/commands/dict/dataupdate.ts +++ b/src/commands/dict/dataupdate.ts @@ -9,6 +9,7 @@ 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 { dirtyCheck, dirtyCheckFailAndExit } from '../_dirty_check.ts' import { enhanceFromBackend, formatErrorLine } from '../_error_codes.ts' interface Opts { @@ -17,18 +18,22 @@ interface Opts { fullName?: string sortCode?: string enabledMark?: string + expectedEnCode?: string + force?: boolean json?: boolean } export function buildDictDataUpdateCommand(): Command { const cmd = new Command('dataUpdate') .alias('data-update') - .description('字典项修改 (改名/排序/启用, PUT 语义, v0.11+ webapi)') + .description('字典项修改 (改名/排序/启用, PUT 语义, v0.11+ webapi + v0.11e+ dirty check)') .requiredOption('--id ', '字典项 id') .option('--enCode ', '字典项编码') .option('--fullName ', '字典项名') .option('--sortCode ', '排序', (v) => parseInt(v, 10)) .option('--enabledMark <0|1>', '启用/禁用') + .option('--expected-enCode ', 'v0.11e+ Phase A2: 校验 enCode 未变 (防 AI session 误覆盖)') + .option('--force', 'v0.11e+ Phase A2: 跳过 dirty check', false) .option('--json', '原始 JSON 输出', false) .action(async (opts: Opts) => { const c = await JnpfClient.fromToken() @@ -40,6 +45,24 @@ export function buildDictDataUpdateCommand(): Command { log.error(` ${formatErrorLine(enhanced, { step: 0, stepName: '配置拉取' })}`) process.exit(1) } + + // v0.11e+ Phase A2: dirty check (防 AI session 误覆盖) + const dirtyResult = dirtyCheck({ + expectedEnCode: opts.expectedEnCode, + 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 跳过`) + } const body: Record = { ...orig, id: opts.id } if (opts.enCode) body.enCode = opts.enCode if (opts.fullName) body.fullName = opts.fullName