@stalfh233/omc-cli 0.8.15 → 0.8.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,7 +18,8 @@ import { scanPages } from "./runtime-paging.js";
18
18
  import { dataRuleSubmitContext } from "./datarule.js";
19
19
  import { decodeJsonColumn, JSON_COLUMN_NULL_COALESCE } from "../json-column.js";
20
20
  import { FIELD_PROPERTY_TYPES, SYSTEM_FIELD_CODES, familyName } from "../field-families.js";
21
- import { applicationResolutionOf, resolveApplicationScope } from "../support.js";
21
+ import { applicationResolutionOf, isUncertainWireError, resolveApplicationScope } from "../support.js";
22
+ import { refusalFromWireError } from "../wire-refusal.js";
22
23
  /** r29b F8: keep ids/itemsPreview through governedRead's compact diet. */
23
24
  const DATA_LIST_PREVIEW_LIMIT = 20;
24
25
  function dataListItemPreview(items) {
@@ -3722,6 +3723,14 @@ export function registerRuntimeDataLane(tools) {
3722
3723
  : {}),
3723
3724
  draftRuleHint: ((saveIsUpdate ? workflowUpdateHint : workflowDraftHint) ?? workflowCheckSkippedHint) ?? "草稿态(DRAFT)保存不触发业务规则——DRAFT 行跳过 Create/Update 分发(DomainServiceImpl.java:240-248);要一调完成态本调用加 submit:true(仅 data.save 有此参数;data.submit 不收);已存草稿直提形状:data.submit {schemaCode, bizObjectId: 本读回的 bizObjectId, formData}(submit 自持久化)",
3724
3725
  };
3726
+ // w132 复核:submitRefused 存在时 draftRuleHint 自相矛盾(它还教「加
3727
+ // submit:true / data.submit 直提」)。partial 回执统一省略该键——本次已经
3728
+ // 试过提交,下一步只能从 submitRefused 读,不能再教一遍相同动作。
3729
+ const partialReadback = (submitRefused) => {
3730
+ const rest = { ...plainReadback };
3731
+ delete rest.draftRuleHint;
3732
+ return { ...rest, submitRefused };
3733
+ };
3725
3734
  // r18 retro (G3): one-call COMPLETED creation — the agent goal is usually
3726
3735
  // "record AND rule effect", not "a draft". Chain the no-flow submit in
3727
3736
  // the same governed write (the same sibling execute apply_changes uses).
@@ -3731,31 +3740,102 @@ export function registerRuntimeDataLane(tools) {
3731
3740
  // COMPLETED) — the one-call chain's ruleHint would lie. Workflow-
3732
3741
  // backed models keep the two-phase chain.
3733
3742
  if (publishedWorkflow) {
3743
+ // P1(w132 探针 J):草稿已落库、提交被确定拒收——这是 partial,不是
3744
+ // ok/DELIVERED。旧回执把 submitRefused 埋在 readback 里,顶层仍盖
3745
+ // DELIVERED,调用方只看 status 会以为已提交。保留原 blocker 名(
3746
+ // submit-model-has-workflow)在 submitRefused 里,顶层用自己的
3747
+ // blocker 说明「首段成功、复合目标未完成」。
3748
+ const submitRefused = {
3749
+ blocker: "submit-model-has-workflow",
3750
+ workflowCode: publishedWorkflow,
3751
+ // 更新行不能复用新建语义(「没有流程实例 / 重建草稿 / formData 不要带 id」
3752
+ // 都会让调用方多建一行);按 saveIsUpdate 分路。
3753
+ message: `草稿已保存(bizObjectId=${bizObjectId});${saveIsUpdate ? workflowUpdateHint : workflowDraftHint}(见 describe data.submit --example workflow-backed-data-submit)`,
3754
+ };
3755
+ const nextCommand = saveIsUpdate
3756
+ ? `omc call workitem.list --args '{"schemaCode":"${args.schemaCode}"}'`
3757
+ : `omc call data.save --env <env> --args '{"schemaCode":"${args.schemaCode}","workflowCode":"${publishedWorkflow}","formData":{...}}'`;
3734
3758
  return {
3759
+ status: "partial",
3760
+ blocker: "submit-refused-after-save",
3761
+ submitRefused,
3762
+ message: `草稿已保存(bizObjectId=${bizObjectId}),提交未完成:模型有已发布流程 ${publishedWorkflow},submit:true 被拒(submit-model-has-workflow)。` +
3763
+ `要提交请走两段式:${saveIsUpdate ? "workitem.list 找现有待办 → data.submit 三件套" : "先用 workflowCode 保存流程草稿取得 workItemId,再 data.submit 三件套"}。`,
3764
+ nextCommand,
3735
3765
  performed: { errcode: performed.errcode, bizObjectId, sheetCode, resolvedFrom, submitted: false },
3736
- readback: {
3737
- ...plainReadback,
3738
- submitRefused: {
3739
- blocker: "submit-model-has-workflow",
3740
- workflowCode: publishedWorkflow,
3741
- // 更新行不能复用新建语义(「没有流程实例 / 重建草稿 / formData 不要带 id」
3742
- // 都会让调用方多建一行);按 saveIsUpdate 分路。
3743
- message: `草稿已保存;${saveIsUpdate ? workflowUpdateHint : workflowDraftHint}(见 describe data.submit --example workflow-backed-data-submit)`,
3744
- },
3745
- },
3766
+ readback: partialReadback(submitRefused),
3746
3767
  };
3747
3768
  }
3748
3769
  const submitTool = tools.find((entry) => entry.name === "data.submit");
3749
- const submitOutcome = submitTool?.writeExecute
3750
- ? await submitTool.writeExecute(session, { schemaCode: args.schemaCode, bizObjectId, formData: args.formData })
3751
- : { status: "error", message: "data.submit 工具不可用" };
3770
+ // writeExecute 失败是**抛异常**(ToolRefusalError / WireError),不会返回
3771
+ // `{status:...}`——历史返回分支因此不可达,异常会冒到外层 wrote 管线,
3772
+ // 把「草稿已保存」的事实一起丢掉(复核驳回 P1b/P1c)。这里接住异常,
3773
+ // 统一折成 partial + 已落草稿证据;transport/uncertain 也按 partial 报
3774
+ // (submitRefused.outcome:"uncertain"),因为草稿的落库是确定的,只有
3775
+ // 提交结果未知——不回滚、不冒充全部完成。
3776
+ let submitOutcome;
3777
+ try {
3778
+ submitOutcome = submitTool?.writeExecute
3779
+ ? (await submitTool.writeExecute(session, { schemaCode: args.schemaCode, bizObjectId, formData: args.formData }))
3780
+ : { status: "error", message: "data.submit 工具不可用" };
3781
+ }
3782
+ catch (error) {
3783
+ // 本地拒绝(ToolRefusalError)永远是确定的拒绝,即便 message 里恰好
3784
+ // 出现 timeout 字样也不能被当成传输不确定。
3785
+ const uncertain = !(error instanceof ToolRefusalError) && isUncertainWireError(error);
3786
+ const failure = error instanceof ToolRefusalError
3787
+ ? { ...error.payload }
3788
+ : error instanceof WireError
3789
+ // 复用 governedWrite 的同一张 WireError 翻译表(300004 分叉、
3790
+ // 409200 隐藏字段、40000 双成因、@AdminOnly 等)——不要在这里
3791
+ // 复制一份简化文案,否则 submit-leg 会只剩平台原文。
3792
+ ? refusalFromWireError(error)
3793
+ : {
3794
+ status: uncertain ? "uncertain" : "refused",
3795
+ blocker: uncertain ? "submit-outcome-uncertain" : "submit-failed-after-save",
3796
+ message: error instanceof Error ? error.message : String(error),
3797
+ };
3798
+ // uncertain 形态(transport / 401-403)在翻译表里是 refused(那张表
3799
+ // 描述的是「写请求被拒/结果未知」的基线);submit-leg 已知首段草稿
3800
+ // 落库确定、只有提交结果未知——status 与 outcome 必须同时对齐为
3801
+ // uncertain,不能留 status:"refused" 与 outcome 自相矛盾。
3802
+ const submitRefused = uncertain ? { ...failure, status: "uncertain", outcome: "uncertain" } : failure;
3803
+ const refusalMessage = typeof submitRefused.message === "string" && submitRefused.message.length > 0
3804
+ ? submitRefused.message
3805
+ : `提交失败(${String(submitRefused.blocker ?? submitRefused.status ?? "?")})`;
3806
+ const transportLabel = error instanceof WireError && error.kind === "http-status"
3807
+ ? `服务器返回 HTTP ${error.diagnostic?.httpStatus ?? "异常"} 响应`
3808
+ : "网络传输中断";
3809
+ return {
3810
+ status: "partial",
3811
+ blocker: "submit-refused-after-save",
3812
+ submitRefused,
3813
+ // 自动化只看 status/deliveryState 仍可能把「提交结果未知」读成普通
3814
+ // 拒绝;显式再带一个顶层信号(write.ts 透传)。
3815
+ ...(uncertain ? { submitOutcome: "uncertain" } : {}),
3816
+ message: `草稿已保存(bizObjectId=${bizObjectId}),提交未完成:` +
3817
+ (uncertain ? `提交结果未知(${transportLabel})——先 data.load/workitem.list 核对草稿与待办,再决定是否重发` : refusalMessage),
3818
+ nextCommand: typeof submitRefused.nextCommand === "string"
3819
+ ? submitRefused.nextCommand
3820
+ : `omc call data.load --env <env> --args '{"schemaCode":"${args.schemaCode}","bizObjectId":"${bizObjectId}"}'`,
3821
+ performed: { errcode: performed.errcode, bizObjectId, sheetCode, resolvedFrom, submitted: false },
3822
+ readback: partialReadback(submitRefused),
3823
+ };
3824
+ }
3752
3825
  if ("status" in submitOutcome && typeof submitOutcome.status === "string" && submitOutcome.status !== "ok") {
3753
- // The save itself DELIVERED — report it honestly with the submit
3754
- // refusal attached, never as a plain refusal.
3826
+ // The save itself landed but the submit did not. This is a partial
3827
+ // composite write — never status ok/DELIVERED (P1, w132 probe J).
3755
3828
  const envelope = "envelope" in submitOutcome ? submitOutcome.envelope : submitOutcome;
3829
+ const innerMessage = typeof envelope.message === "string" && envelope.message.length > 0 ? envelope.message : `提交失败(${String(envelope.blocker ?? envelope.status ?? "?")})`;
3830
+ const innerNext = typeof envelope.nextCommand === "string" ? envelope.nextCommand : `omc call data.submit --env <env> --args '{"schemaCode":"${args.schemaCode}","bizObjectId":"${bizObjectId}"}'`;
3756
3831
  return {
3832
+ status: "partial",
3833
+ blocker: "submit-refused-after-save",
3834
+ submitRefused: envelope,
3835
+ message: `草稿已保存(bizObjectId=${bizObjectId}),提交未完成:${innerMessage}`,
3836
+ nextCommand: innerNext,
3757
3837
  performed: { errcode: performed.errcode, bizObjectId, sheetCode, resolvedFrom, submitted: false },
3758
- readback: { ...plainReadback, submitRefused: envelope },
3838
+ readback: partialReadback(envelope),
3759
3839
  };
3760
3840
  }
3761
3841
  const okOutcome = submitOutcome;
@@ -13,6 +13,7 @@ import { wireCall, wireRows, WireError } from "../wire.js";
13
13
  import { diagnoseInstanceActivity, getInstanceBaseInfo, isCanceledInstanceStatus, isFinishedInstanceStatus, listInstanceActivities, listWorkItemsByParticipant, resolveBizObjectIdByInstance, searchWorkItems, wireString } from "../workflow-support.js";
14
14
  import { readSchemaFormButtons } from "../form-support.js";
15
15
  import { WORKFLOW_EVENT_HANDLER_FIELDS, WORKFLOW_NODE_EVENT_HANDLER_FIELDS, WORKFLOW_LANE_CONTRACT, workflowTemplateArg } from "./workflow-contract.js";
16
+ import { decodeActionRow } from "./list-view-shapes.js";
16
17
  import { PLATFORM_TRIGGER_RULE_CODES } from "./rule-graph.js";
17
18
  import { executeRuleEnableWrite } from "./rule-lifecycle.js";
18
19
  import { PLATFORM_ADMIN_START_BYPASS, resolvePermissionActor } from "../identity.js";
@@ -3351,20 +3352,35 @@ export function registerWorkflowLane(tools) {
3351
3352
  actions: [],
3352
3353
  replaceActions: true,
3353
3354
  })}'`;
3355
+ // F8(0.8.16 探针 J):`workflow.delete` 已支持 `unbindListviews:true`——它
3356
+ // 只解本流程的视图绑定,不动视图其它动作。旧的 beforeWorkflowDelete 只
3357
+ // 指向 listview.configure `actions:[] + replaceActions:true`,那会把
3358
+ // add/delete/import/export/editowner 等其它动作一起清掉。首选 unbindListviews。
3359
+ const workflowDeleteCommand = `omc call workflow.delete --env <env> --args '${JSON.stringify({
3360
+ schemaCode: args.schemaCode,
3361
+ code: args.code,
3362
+ unbindListviews: true,
3363
+ })}'`;
3354
3364
  const listviewBinding = {
3355
3365
  bound: addBindings.bound.map(({ code, actionCode }) => ({ code, actionCode })),
3356
3366
  ...(firstPublish ? {} : { firstPublish: false }),
3357
3367
  note: addBindings.bound.length > 0
3358
3368
  ? firstPublish
3359
- ? "首次发布已把本模型各列表视图的 add 动作绑到本流程;删流程前先 listview.configure 清 actions 或用 workflow.delete 的 nextCommand"
3360
- : "列表视图的 add 动作已绑定本流程(本次不是首次发布,绑定沿用既有配置);删流程前先 listview.configure 清 actions 或用 workflow.delete 的 nextCommand"
3369
+ ? "首次发布已把本模型各列表视图的 add 动作绑到本流程;删流程前用 workflow.delete 的 nextCommand(unbindListviews:true)解绑"
3370
+ : "列表视图的 add 动作已绑定本流程(本次不是首次发布,绑定沿用既有配置);删流程前用 workflow.delete 的 nextCommand(unbindListviews:true)解绑"
3361
3371
  : addBindings.readable
3362
3372
  ? "无隐式绑定"
3363
3373
  : "列表视图读取失败,未能确认 add 绑定;删流程前先 listview.get 复核",
3364
3374
  ...(addBindings.bound.length > 0
3365
3375
  ? {
3366
- beforeWorkflowDelete: "删流程前先解绑:用 listview.configure 清掉该视图 add 动作(actions:[] + replaceActions:true),否则 workflow.delete 会撞 workflow-bound-to-listview(303024,列表还绑着流程);多个视图绑定时逐视图处理。",
3367
- ...(unbindCommand !== undefined ? { unbindCommand } : {}),
3376
+ beforeWorkflowDelete: "删流程前先解绑:首选 nextCommand —— workflow.delete 带 unbindListviews:true,本工具会先逐个视图解绑(只清本流程的绑定,不动视图其它动作),再删流程;否则会撞 workflow-bound-to-listview(303024,列表还绑着流程)。多个视图绑定时由 unbindListviews 逐视图处理。",
3377
+ ...(unbindCommand !== undefined
3378
+ ? {
3379
+ unbindCommand,
3380
+ unbindCommandNote: "次选(只在你想手工改视图时用):listview.configure 清 actions:[] + replaceActions:true 会**顺带清掉该视图的其它动作**(add/delete/import/export/editowner 等),不是只解本流程绑定;只想解本流程绑定请用 nextCommand。",
3381
+ }
3382
+ : {}),
3383
+ nextCommand: workflowDeleteCommand,
3368
3384
  }
3369
3385
  : {}),
3370
3386
  };
@@ -3924,7 +3940,7 @@ export function registerWorkflowLane(tools) {
3924
3940
  unbindListviews: z
3925
3941
  .boolean()
3926
3942
  .optional()
3927
- .describe("先解绑列表视图再删流程:true 时对本模型每个绑定了本流程的列表视图执行 listview.configure(actions:[] + replaceActions:true,保留原列 fieldCodes),成功后才删流程;任一步解绑失败即停、不删流程。**会改动视图配置(移除该视图 add 动作的平台关联),必须显式确认才做。** 默认 false 只删流程,遇 303024 仍拒绝并给 nextCommand"),
3943
+ .describe("先解绑列表视图再删流程:true 时对每个绑定了本流程的列表视图,只移除其 add 动作里指向本流程的那一条(保留 delete/import/export/editowner 等其它动作),再删流程;任一步解绑失败即停、不删流程。**会改动视图配置(移除该视图 add 动作的平台关联),必须显式确认才做。** 默认 false 只删流程,遇 303024 仍拒绝并给 nextCommand"),
3928
3944
  },
3929
3945
  // F7(0.8.8):dry-run 与真写共用同一份只读扫描——预览列出会被解绑的视图,
3930
3946
  // 真写在任何写 wire 之前也先跑这里。两者都不写。
@@ -3955,7 +3971,7 @@ export function registerWorkflowLane(tools) {
3955
3971
  code,
3956
3972
  name,
3957
3973
  ...(fieldCodes.length > 0 ? { fieldCodes } : {}),
3958
- action: "listview.configure actions:[] + replaceActions:true",
3974
+ action: "移除指向本流程的 add 绑定(其余动作原样保留)",
3959
3975
  })),
3960
3976
  }
3961
3977
  : {}),
@@ -3984,14 +4000,20 @@ export function registerWorkflowLane(tools) {
3984
4000
  workflowCode: args.code,
3985
4001
  message: "workflow.delete 需要 listview.configure 来解绑视图,但它未注册写执行;零写入停止",
3986
4002
  });
3987
- for (const view of scan.bound) {
4003
+ const boundViews = new Map();
4004
+ for (const view of scan.bound)
4005
+ if (!boundViews.has(view.code))
4006
+ boundViews.set(view.code, view);
4007
+ for (const view of boundViews.values()) {
3988
4008
  const fieldCodes = view.fieldCodes.length > 0 ? view.fieldCodes : ["createdTime", "creater", "name", "sequenceNo"];
4009
+ // F8(0.8.16):只移除指向本流程的 add 行,其余动作原样回写。
4010
+ const remainingActions = actionsWithoutWorkflowBinding(view.actions, args.code, args.schemaCode);
3989
4011
  try {
3990
4012
  const outcome = await configure.writeExecute(session, {
3991
4013
  schemaCode: args.schemaCode,
3992
4014
  code: view.code,
3993
4015
  fieldCodes,
3994
- actions: [],
4016
+ actions: remainingActions,
3995
4017
  replaceActions: true,
3996
4018
  });
3997
4019
  if ("status" in outcome)
@@ -4007,8 +4029,16 @@ export function registerWorkflowLane(tools) {
4007
4029
  status: "ok",
4008
4030
  viewCode: view.code,
4009
4031
  viewName: view.name,
4010
- actions: "cleared",
4032
+ actions: "selective-unbind",
4033
+ removedActions: view.actions
4034
+ .filter((action) => isWorkflowAddBinding(action, args.code, args.schemaCode))
4035
+ .map((action) => ({
4036
+ actionCode: action.actionCode ?? null,
4037
+ associationCode: action.associationCode ?? null,
4038
+ })),
4039
+ keptActions: remainingActions.map((action) => action.actionCode),
4011
4040
  replaceActions: true,
4041
+ note: "add 动作已移除,平台读面不会自动补回(也不会重新绑定本流程);需要恢复新增按钮时用 listview.configure defaultActions:true 重建内置动作。",
4012
4042
  readback: outcome.readback,
4013
4043
  });
4014
4044
  }
@@ -4021,7 +4051,7 @@ export function registerWorkflowLane(tools) {
4021
4051
  schemaCode: args.schemaCode,
4022
4052
  viewCode: view.code,
4023
4053
  steps,
4024
- nextCommand: `omc call listview.configure --env <env> --args '${JSON.stringify({ schemaCode: args.schemaCode, code: view.code, fieldCodes, actions: [], replaceActions: true })}'`,
4054
+ nextCommand: `omc call listview.configure --env <env> --args '${JSON.stringify({ schemaCode: args.schemaCode, code: view.code, fieldCodes, actions: remainingActions, replaceActions: true })}'`,
4025
4055
  message: `解绑列表视图 ${view.code} 失败,已停止:**流程 ${args.code} 未删除**(不半删)。原因:${cause}。` +
4026
4056
  `按 nextCommand 修好该视图后重发 workflow.delete(仍带 unbindListviews:true);已成功解绑的视图在 steps 里。`,
4027
4057
  });
@@ -4073,6 +4103,14 @@ export function registerWorkflowLane(tools) {
4073
4103
  replaceActions: true,
4074
4104
  };
4075
4105
  const detachExample = `omc call listview.configure --env <env> --args '${JSON.stringify(detachArgs)}'`;
4106
+ // F8(0.8.16 复核):安全路径优先——workflow.delete 带 unbindListviews
4107
+ // 只移除本流程的 add 绑定,保留 delete/import/export/editowner 等其它
4108
+ // 动作;listview.configure actions:[] 是全清次选,必须标明代价。
4109
+ const safeUnbindDeleteCommand = `omc call workflow.delete --env <env> --args '${JSON.stringify({
4110
+ schemaCode: args.schemaCode,
4111
+ code: args.code,
4112
+ unbindListviews: true,
4113
+ })}'`;
4076
4114
  throw new ToolRefusalError({
4077
4115
  status: "refused",
4078
4116
  blocker: "workflow-bound-to-listview",
@@ -4086,15 +4124,18 @@ export function registerWorkflowLane(tools) {
4086
4124
  associationCode,
4087
4125
  ...(cols.length > 0 ? { fieldCodes: cols } : {}),
4088
4126
  })),
4089
- nextCommand: detachExample,
4127
+ nextCommand: safeUnbindDeleteCommand,
4128
+ unbindCommand: detachExample,
4129
+ unbindCommandNote: "次选(只在你想手工改视图时用):listview.configure 清 actions:[] + replaceActions:true 会**顺带清掉该视图的其它动作**(add/delete/import/export/editowner 等),不是只解本流程绑定;只想解本流程绑定请用 nextCommand(workflow.delete 带 unbindListviews:true)。",
4090
4130
  message: `流程 ${args.code} 仍被列表视图绑定(303024「列表绑定了流程」)。` +
4091
4131
  (bound.length > 0
4092
4132
  ? `绑在:${bound.map((view) => `${view.code}(${view.name})action=${view.actionCode ?? "?"}`).join("、")}。`
4093
4133
  : `默认视图多半是 ${args.schemaCode}(workflow.create 会自动绑)。`) +
4094
- `先解绑再删:粘贴 nextCommand(listview.configure:actions:[] + replaceActions:true + 现有 fieldCodes),再重试 workflow.delete。` +
4134
+ `先解绑再删:nextCommand 是 workflow.delete 带 unbindListviews:true(只移除本流程的 add 绑定,保留 delete/import/export/editowner 等其它动作)。` +
4135
+ `次选 unbindCommand(listview.configure actions:[] + replaceActions:true + 现有 fieldCodes)会**清掉该视图其它动作**,只在你想手工改视图时用。` +
4095
4136
  (args.unbindListviews === true
4096
- ? `本次已带 unbindListviews:true,但仍有绑定未被清掉(见 boundListviews / unreadableViews);按 nextCommand 处理后重试。`
4097
- : `也可以重发 workflow.delete 并带 unbindListviews:true,让本工具先逐个视图解绑再删。`) +
4137
+ ? `本次已带 unbindListviews:true,但仍有绑定未被清掉(见 boundListviews / unreadableViews);可重发 nextCommand,若仍 303024 用 unbindCommand 逐视图手工处理。`
4138
+ : "") +
4098
4139
  `整体清理也可用 omc model-purge --code ${args.schemaCode}(级联带走流程模板与视图)。`,
4099
4140
  });
4100
4141
  }
@@ -4115,6 +4156,7 @@ export function registerWorkflowLane(tools) {
4115
4156
  listviewUnbind: {
4116
4157
  requested: true,
4117
4158
  unboundViews: steps.filter((step) => step.step === "listview.configure").map((step) => step.viewCode),
4159
+ note: "只移除了指向本流程的 add 绑定;平台读面不会自动补回。需要恢复新增按钮时用 listview.configure defaultActions:true 重建内置动作。",
4118
4160
  },
4119
4161
  }
4120
4162
  : {}),
@@ -4541,6 +4583,11 @@ export function registerWorkflowLane(tools) {
4541
4583
  * (F7 0.8.8). Bindings are only ever created on the `add` action by
4542
4584
  * workflow.publish → updateBizQueryAddAction (8.6.26
4543
4585
  * WorkflowTemplateController.java:791,818-846; 2.1.5 :695-711,741-761).
4586
+ *
4587
+ * 0.8.16 F8: `actions` carries the view's decoded action rows (the same
4588
+ * `query/get` response), so workflow.delete can remove ONLY the workflow-bound
4589
+ * `add` row and write the remaining set back — delete/import/export/editowner
4590
+ * and caller-authored actions survive the unbind.
4544
4591
  */
4545
4592
  async function scanListviewsBoundToWorkflow(session, schemaCode, workflowCode) {
4546
4593
  const bound = [];
@@ -4565,6 +4612,7 @@ export function registerWorkflowLane(tools) {
4565
4612
  const fieldCodes = (Array.isArray(model.queryColumns) ? model.queryColumns : [])
4566
4613
  .map((column) => String(column.propertyCode ?? ""))
4567
4614
  .filter(Boolean);
4615
+ const decodedActions = actions.map(decodeActionRow);
4568
4616
  for (const action of actions) {
4569
4617
  const association = action.associationType ?? action.queryActionRelativeType;
4570
4618
  const associationCode = String(action.associationCode ?? action.relativeCode ?? "");
@@ -4582,6 +4630,7 @@ export function registerWorkflowLane(tools) {
4582
4630
  actionCode: action.actionCode === undefined || action.actionCode === null ? null : String(action.actionCode),
4583
4631
  associationCode: associationCode || null,
4584
4632
  fieldCodes,
4633
+ actions: decodedActions,
4585
4634
  });
4586
4635
  }
4587
4636
  }
@@ -4597,6 +4646,40 @@ export function registerWorkflowLane(tools) {
4597
4646
  async function findListviewsBoundToWorkflow(session, schemaCode, workflowCode) {
4598
4647
  return (await scanListviewsBoundToWorkflow(session, schemaCode, workflowCode)).bound;
4599
4648
  }
4649
+ /**
4650
+ * F8(0.8.16): is this the workflow-bound `add` row? The platform only ever
4651
+ * binds the `add` action to a workflow (publish → updateBizQueryAddAction),
4652
+ * so that single row is what must go; every other action stays untouched.
4653
+ */
4654
+ const isWorkflowAddBinding = (action, workflowCode, schemaCode) => {
4655
+ if (String(action.actionCode ?? "") !== "add")
4656
+ return false;
4657
+ if (String(action.associationType ?? "").toUpperCase() !== "WORKFLOW")
4658
+ return false;
4659
+ const associationCode = String(action.associationCode ?? "");
4660
+ return associationCode === workflowCode || associationCode === schemaCode || associationCode === "";
4661
+ };
4662
+ /**
4663
+ * Build the configure `actions` payload that keeps every action except the
4664
+ * workflow-bound `add` row. Decoded read rows are converted back to the
4665
+ * configure arg shape (nulls dropped — optional zod fields reject null) and
4666
+ * renumbered, because query/update assigns `sortKey` by array position.
4667
+ */
4668
+ const actionsWithoutWorkflowBinding = (actions, workflowCode, schemaCode) => actions
4669
+ .filter((action) => !isWorkflowAddBinding(action, workflowCode, schemaCode))
4670
+ .map((action, index) => {
4671
+ const row = {
4672
+ actionCode: String(action.actionCode ?? ""),
4673
+ queryActionType: String(action.queryActionType ?? ""),
4674
+ sortKey: index + 1,
4675
+ };
4676
+ for (const key of ["name", "icon", "systemAction", "serviceCode", "serviceMethod", "customService", "associationCode", "associationType"]) {
4677
+ const value = action[key];
4678
+ if (value !== null && value !== undefined)
4679
+ row[key] = value;
4680
+ }
4681
+ return row;
4682
+ });
4600
4683
  // `list_permission` echoes the PERMISSION row id plus the unit's display name
4601
4684
  // and code — never the unitId (WorkflowTemplateController.getPermissionMap).
4602
4685
  // So identity for readback/removal is resolved from the unit's own face.
@@ -28,7 +28,7 @@ import { writeEnvelope } from "./cli-output.js";
28
28
  import { ENDPOINTS } from "./endpoints.js";
29
29
  import { wireCall, wireRows } from "./wire.js";
30
30
  import { readModelRecord } from "./model-record.js";
31
- import { deletionOrderFromSteps, inboundModelReferences, inboundReferenceRefusal, modelPurgeUnbindCommand } from "./lanes/model-references.js";
31
+ import { deletionOrderFromSteps, deletionStepLabel, inboundModelReferences, inboundReferenceRefusal, modelPurgeCommand, modelPurgeUnbindCommand } from "./lanes/model-references.js";
32
32
  import { resolveModelTreeNode } from "./lanes/model.js";
33
33
  import { SessionManager } from "./session-manager.js";
34
34
  import { ConfigStore, defaultPaths } from "./config-store.js";
@@ -49,6 +49,13 @@ export function unbindDeletionSteps(steps) {
49
49
  export function unbindPurgeCommand(schemaCode, options = {}) {
50
50
  return modelPurgeUnbindCommand(schemaCode, options);
51
51
  }
52
+ /**
53
+ * 0.8.16 F7: plain `--apply` — it still tears down self references
54
+ * automatically and only refuses on cross-model references.
55
+ */
56
+ export function purgeApplyCommand(schemaCode, options = {}) {
57
+ return modelPurgeCommand(schemaCode, options);
58
+ }
52
59
  async function sessionFor(environment) {
53
60
  const store = new ConfigStore(defaultPaths());
54
61
  const sessions = new SessionManager(store);
@@ -188,35 +195,59 @@ export async function planPurge(options, injected) {
188
195
  if (references.length > 0) {
189
196
  const refusal = inboundReferenceRefusal(options.schemaCode, references);
190
197
  const unbindEnabled = options.unbindReferences === true;
191
- const unbindSteps = unbindDeletionSteps(refusal.deletionSteps);
192
- const nextCommand = unbindPurgeCommand(options.schemaCode, { purgeInstances: instanceCount > 0 && !options.purgeInstances });
198
+ const allUnbindSteps = unbindDeletionSteps(refusal.deletionSteps);
199
+ const allLabels = allUnbindSteps.map(deletionStepLabel);
200
+ // 0.8.16 F7: split the unlink plan by reference kind. A self reference
201
+ // (the target's own child-table column resolves back to it) is internal
202
+ // to the model being deleted — purge tears it down automatically. A
203
+ // cross-model reference belongs to another model and still needs the
204
+ // explicit destructive flag. Self owners are always the target itself,
205
+ // so the two label sets are disjoint; filtering the full ordered list
206
+ // keeps the execution order the refusal already established.
207
+ const selfLabelSet = new Set(unbindDeletionSteps(inboundReferenceRefusal(options.schemaCode, references.filter((reference) => reference.selfReference)).deletionSteps).map(deletionStepLabel));
208
+ const crossLabelSet = new Set(unbindDeletionSteps(inboundReferenceRefusal(options.schemaCode, references.filter((reference) => !reference.selfReference)).deletionSteps).map(deletionStepLabel));
209
+ const selfLabels = allLabels.filter((label) => selfLabelSet.has(label));
210
+ const crossLabels = allLabels.filter((label) => crossLabelSet.has(label));
211
+ const nextCommand = crossLabels.length > 0
212
+ ? unbindPurgeCommand(options.schemaCode, { purgeInstances: instanceCount > 0 && !options.purgeInstances })
213
+ : purgeApplyCommand(options.schemaCode, { purgeInstances: instanceCount > 0 && !options.purgeInstances });
193
214
  referencePreview = {
194
215
  inboundReferences: references,
195
216
  deletionSteps: refusal.deletionSteps,
196
217
  deletionOrder: purgeDeletionOrder(refusal.deletionSteps),
197
218
  nextCommand,
219
+ // Self-reference steps are always part of the executable plan; the
220
+ // cross-model subset is the only thing the flag gates.
221
+ ...(selfLabels.length > 0 ? { selfUnbindSteps: selfLabels } : {}),
222
+ ...(crossLabels.length > 0 ? { crossModelUnbindSteps: crossLabels } : {}),
198
223
  // F4(0.8.12,探针 G):dry-run 是「看完整计划」的面,不是执行面。
199
224
  // 入站引用(含自建子表关联列)是删模型必然要拆的内部列,dry-run 直接
200
- // 预置 unbindSteps 并说明 apply 要加的 flag,而不是逼调用方先加破坏性
201
- // 开关才能看到计划。--apply 未带 flag 的行为不变(model.delete 零写入
202
- // 拒绝,引导见 dry-run 的 note)。
225
+ // 预置 unbindSteps;0.8.16 F7 起 wouldRequireFlags 只在真有跨模型引用
226
+ // 时出现(自引用 apply 自动拆,不需要 flag)。
203
227
  ...(unbindEnabled
204
- ? { unbindReferences: true, unbindSteps: purgeDeletionOrder(unbindSteps) }
228
+ ? { unbindReferences: true, unbindSteps: allLabels }
205
229
  : options.apply
206
230
  ? {}
207
- : { unbindSteps: purgeDeletionOrder(unbindSteps), wouldRequireFlags: ["--unbind-references"] }),
231
+ : { unbindSteps: allLabels, ...(crossLabels.length > 0 ? { wouldRequireFlags: ["--unbind-references"] } : {}) }),
208
232
  referenceNotice: `${options.schemaCode} 有入站引用(${refusal.referencingModels.map((model) => model.schemaCode).join("、")};` +
209
233
  `子表列经 parentCode 解析回本模型时属于自引用)。` +
210
234
  (unbindEnabled
211
- ? `已开启 --unbind-references:本命令会先按 deletionSteps 执行拆引用(${unbindSteps.map((step) => step.tool).join(" → ")};` +
235
+ ? `已开启 --unbind-references:本命令会先按 deletionSteps 执行拆引用(${allLabels.join(" → ")};` +
212
236
  `**破坏性:会删除引用列/子表关联列,列数据不可恢复**),全部成功后再让 model.delete 级联;任一步失败即停,不会删模型。`
213
- : `--apply 未带 --unbind-references 时 model.delete 会零写入拒绝;unbindSteps 是本命令会执行的拆引用步骤(` +
214
- `${unbindSteps.map((step) => step.tool).join(" → ")};**破坏性:会删除引用列/子表关联列,列数据不可恢复**),` +
215
- `nextCommand 就是带上 --unbind-references 的同一条命令;也可以自己按 deletionSteps 逐条执行。`),
237
+ : `${selfLabels.length > 0 && crossLabels.length > 0
238
+ ? `检测到自引用 + 跨模型引用:--apply 不带 flag 时**不会自动拆任何引用**(避免半拆,列数据不可恢复),model.delete 会零写入拒绝;nextCommand 带 --unbind-references 一次处理。`
239
+ : selfLabels.length > 0
240
+ ? `--apply 会自动拆自引用列(${selfLabels.join(" → ")};**破坏性:删除列数据不可恢复**),无需 --unbind-references;跨模型引用:无。`
241
+ : `--apply 不会自动拆(只有跨模型引用:${crossLabels.join(" → ")});model.delete 会零写入拒绝,nextCommand 带 --unbind-references。`}` +
242
+ `也可以自己按 deletionSteps 逐条执行。`),
216
243
  };
217
244
  steps.push(unbindEnabled
218
- ? `🔧 拆引用(--unbind-references):${unbindSteps.map((step) => step.command).join(" → ")} → 再删模型`
219
- : `🔗 入站引用(apply 前先拆;--unbind-references 一条命令,或按 deletionSteps 首步 ${refusal.deletionSteps[0]?.command ?? ""})→ 再删模型`);
245
+ ? `🔧 拆引用(--unbind-references):${allUnbindSteps.map((step) => step.command).join(" → ")} → 再删模型`
246
+ : selfLabels.length > 0 && crossLabels.length > 0
247
+ ? `🔗 入站引用(自引用 + 跨模型引用:不带 flag 不自动拆,避免半拆;需 --unbind-references)→ 再删模型`
248
+ : selfLabels.length > 0
249
+ ? `🔗 入站引用(自引用自动拆:${selfLabels.join(" → ")})→ 再删模型`
250
+ : `🔗 入站引用(跨模型引用需 --unbind-references:${crossLabels.join(" → ")})→ 再删模型`);
220
251
  }
221
252
  }
222
253
  catch {
@@ -325,7 +356,7 @@ export async function cmdModelPurge(args, injected) {
325
356
  "用法:omc model-purge --code <模型code> [--purge-instances] [--unbind-references] [--env <环境>] [--apply]",
326
357
  " 一条命令按依赖倒序清掉:列表视图 → 自建业务规则 → 流程实例 → 流程 → 模型(字段/表单/计算规则/预置规则随模型级联)。",
327
358
  " 默认 dry-run(只列计划,不写;入站引用的 unbindSteps 已在 dry-run 预置)。--purge-instances 才删流程实例(workflow.delete 遇到实例会 402508)。",
328
- " --unbind-references 才会先按 deletionSteps 拆入站引用(field.delete 引用列 + field.publish 所属模型,**破坏性:列数据不可恢复**),再删模型;不带它 --apply 不会自动拆引用。",
359
+ " --unbind-references 才会拆**跨模型**入站引用(引用方模型的关联列;field.delete + field.publish,**破坏性:列数据不可恢复**);自引用列属于被删模型自身,--apply 会自动拆(仅当没有跨模型引用时;混合引用需该 flag 一次处理,避免半拆)。",
329
360
  " 每步回读确认;某步失败即停并说明已完成到哪一步(幂等,可修好后重跑)。",
330
361
  ].join("\n");
331
362
  const invalid = (message) => {
@@ -364,9 +395,11 @@ export async function cmdModelPurge(args, injected) {
364
395
  (referenced
365
396
  ? unbindEnabled
366
397
  ? `已开启 --unbind-references:--apply 会先执行 unbindSteps(${(plan.unbindSteps ?? []).join(" → ")};**破坏性:会删除引用列/子表关联列,列数据不可恢复**),再把 model.delete 交给主流程级联。`
367
- : `入站引用已预扫(与 model.delete 同一份 gate):--apply 未带 --unbind-references 时 model.delete 会零写入拒绝。` +
368
- `unbindSteps 是本命令会执行的拆引用步骤(${(plan.unbindSteps ?? []).join(" → ")};**破坏性:会删除引用列/子表关联列,列数据不可恢复**);` +
369
- `nextCommand 是同一条命令加上 ${(plan.wouldRequireFlags ?? ["--unbind-references"]).join(" ")} --apply,也可以自己按 deletionSteps 逐条拆。`
398
+ : (plan.selfUnbindSteps?.length ?? 0) > 0 && (plan.crossModelUnbindSteps?.length ?? 0) > 0
399
+ ? `检测到自引用 + 跨模型引用:--apply 不带 flag 时**不会自动拆任何引用**(避免半拆,列数据不可恢复),model.delete 会零写入拒绝;nextCommand 带 --unbind-references 一次处理。`
400
+ : (plan.selfUnbindSteps?.length ?? 0) > 0
401
+ ? `0.8.16 F7:--apply 会**自动**拆自引用列(${(plan.selfUnbindSteps ?? []).join(" → ")};**破坏性:删除列数据不可恢复**),无需 --unbind-references;跨模型引用:无。`
402
+ : `--apply 不会自动拆(只有跨模型引用:${(plan.crossModelUnbindSteps ?? []).join(" → ")});model.delete 会零写入拒绝,nextCommand 带 --unbind-references。`
370
403
  : ""),
371
404
  }),
372
405
  }, request));
@@ -406,9 +439,7 @@ export async function executeUnbindSteps(call, steps) {
406
439
  const executed = [];
407
440
  for (let index = 0; index < candidates.length; index += 1) {
408
441
  const step = candidates[index];
409
- const label = step.tool === "field.delete"
410
- ? `field.delete:${String(step.args.schemaCode ?? "")}.${String(step.args.code ?? "")}`
411
- : `field.publish:${String(step.args.schemaCode ?? "")}`;
442
+ const label = deletionStepLabel(step);
412
443
  const schemaCode = step.args.schemaCode;
413
444
  const code = step.args.code;
414
445
  const shapeValid = typeof schemaCode === "string" &&
@@ -482,16 +513,27 @@ export async function executePurge(plan, session, call) {
482
513
  steps.push(...instanceOutcome.steps);
483
514
  let failed = instanceOutcome.failed;
484
515
  const unremovableInstances = instanceOutcome.unremovableInstances;
485
- // F7(0.8.9,探针 D):`--unbind-references` 才执行拆引用。只跑
516
+ // F7(0.8.9,探针 D)+ 0.8.16 F7:`--unbind-references` 执行全部拆引用;
517
+ // 不带 flag 时只自动执行 `selfReference` 那部分(模型自身的子表列指回自身,
518
+ // 删模型必然带走它)。**自引用与跨模型引用同时存在时 fail-closed**:不自动
519
+ // 拆任何引用——先删自引用列再被 model.delete 拒绝就是「半拆」,而列数据不可
520
+ // 恢复。混合引用必须由用户带 --unbind-references 一次处理。只跑
486
521
  // deletionSteps 里的 field.delete/field.publish(model.delete 仍由本命令的
487
522
  // 主流程负责,绝不重复)。任一步失败即停,模型不删。
488
523
  let unbindOutcome;
489
- if (!failed && plan.unbindReferences === true && (plan.deletionSteps?.length ?? 0) > 0) {
524
+ let autoUnbindSelfReferences = false;
525
+ const selfLabels = new Set(plan.selfUnbindSteps ?? []);
526
+ const mixedReferencesWithoutFlag = plan.unbindReferences !== true && selfLabels.size > 0 && (plan.crossModelUnbindSteps?.length ?? 0) > 0;
527
+ if (!failed && !mixedReferencesWithoutFlag && (plan.deletionSteps?.length ?? 0) > 0) {
490
528
  const candidates = plan.deletionSteps ?? [];
491
- unbindOutcome = await executeUnbindSteps(call, candidates);
492
- steps.push(...unbindOutcome.steps);
493
- if (unbindOutcome.failed)
494
- failed = true;
529
+ const thatNeedRunning = plan.unbindReferences === true ? candidates : candidates.filter((step) => selfLabels.has(deletionStepLabel(step)));
530
+ if (thatNeedRunning.length > 0) {
531
+ autoUnbindSelfReferences = plan.unbindReferences !== true;
532
+ unbindOutcome = await executeUnbindSteps(call, thatNeedRunning);
533
+ steps.push(...unbindOutcome.steps);
534
+ if (unbindOutcome.failed)
535
+ failed = true;
536
+ }
495
537
  }
496
538
  // 2) the model — everything else cascades with it.
497
539
  let referrers = [];
@@ -520,18 +562,23 @@ export async function executePurge(plan, session, call) {
520
562
  }
521
563
  }
522
564
  const status = failed ? "partial" : "ok";
523
- const rerunCommand = unbindPurgeCommand(schemaCode);
565
+ const mixedReferencesAtRefusal = plan.unbindReferences !== true && selfLabels.size > 0 && (plan.crossModelUnbindSteps?.length ?? 0) > 0;
566
+ const refusalHasCrossModel = (plan.crossModelUnbindSteps?.length ?? 0) > 0 ||
567
+ (deleteRefusal?.inboundReferences ?? []).some((reference) => reference.selfReference !== true);
568
+ // Self-only refs are auto-unbound by a plain `--apply`, so pointing the retry
569
+ // at the destructive flag would be a lie.
570
+ const rerunCommand = refusalHasCrossModel ? unbindPurgeCommand(schemaCode) : purgeApplyCommand(schemaCode);
524
571
  // Pass the inner refusal through verbatim; the purge-level receipt must not
525
572
  // promise keys it dropped (F9: message named deletionSteps that were absent).
526
573
  const failureFields = unbindOutcome?.failed === true
527
574
  ? {
528
575
  nextAction: "fix-and-rerun",
529
- unbindReferences: true,
576
+ ...(plan.unbindReferences === true ? { unbindReferences: true } : { autoUnbindSelfReferences: true }),
530
577
  failedStep: unbindOutcome.failedStep,
531
578
  remainingSteps: unbindOutcome.remaining,
532
579
  modelDeletePending: true,
533
580
  nextCommand: rerunCommand,
534
- message: `${schemaCode} 未删除:拆引用在 ${unbindOutcome.failedStep ?? "某一步"} 失败,已停在该步;` +
581
+ message: `${schemaCode} 未删除:${autoUnbindSelfReferences ? "自动拆自引用" : "拆引用"}在 ${unbindOutcome.failedStep ?? "某一步"} 失败,已停在该步;` +
535
582
  `**未调用 model.delete,模型仍存在**。原因:${unbindOutcome.failureMessage ?? "平台拒绝"}。` +
536
583
  `已成功的拆引用步骤不回滚(幂等,重跑不会重复破坏);修复后重跑本命令(nextCommand)继续。`,
537
584
  }
@@ -543,9 +590,13 @@ export async function executePurge(plan, session, call) {
543
590
  deletionOrder: purgeDeletionOrder(deleteRefusal.deletionSteps),
544
591
  nextCommand: rerunCommand,
545
592
  ...(referrers.length > 0 ? { blockedBy: referrers } : {}),
546
- message: `${schemaCode} 未删除(零写入拒绝,未启动平台删除任务)。${deleteRefusal.message} ` +
547
- `两条路:① 一条命令自动拆引用:nextCommand(--unbind-references;**破坏性:会删除指向本模型的引用列/子表关联列,列数据不可恢复**),` +
548
- `拆完引用后由 model.delete 级联;② 自己按 deletionSteps 逐条执行。不要在未拆引用时重试 --apply(不带 --unbind-references 仍会零写入拒绝)。`,
593
+ message: (mixedReferencesAtRefusal
594
+ ? `${schemaCode} 未删除:检测到自引用 + 跨模型引用。为避免半拆,本次零写入(未删除任何列、未发布模型、未启动平台删除任务)。按 deletionSteps 逐条执行,或 nextCommand(带 --unbind-references)一次处理。 `
595
+ : `${schemaCode} 未删除(零写入拒绝,未启动平台删除任务)。`) +
596
+ `${deleteRefusal.message} ` +
597
+ `两条路:① 一条命令自动拆引用:nextCommand(${refusalHasCrossModel ? "--unbind-references;" : ""}**破坏性:会删除指向本模型的引用列/子表关联列,列数据不可恢复**),` +
598
+ `拆完引用后由 model.delete 级联;② 自己按 deletionSteps 逐条执行。` +
599
+ (refusalHasCrossModel ? "不要在未拆引用时重试 --apply(不带 --unbind-references 仍会零写入拒绝)。" : ""),
549
600
  }
550
601
  : {
551
602
  nextAction: "fix-and-rerun",
@@ -560,7 +611,11 @@ export async function executePurge(plan, session, call) {
560
611
  schemaCode,
561
612
  verdict: plan.modelExists && !failed ? "cascading" : "clean",
562
613
  ...(plan.workflowCode !== undefined ? { workflowCode: plan.workflowCode } : {}),
563
- ...(plan.unbindReferences === true ? { unbindReferences: true } : {}),
614
+ ...(plan.unbindReferences === true
615
+ ? { unbindReferences: true }
616
+ : autoUnbindSelfReferences
617
+ ? { autoUnbindSelfReferences: true }
618
+ : {}),
564
619
  ...(unbindOutcome !== undefined ? { unboundSteps: unbindOutcome.executed, unbindFailed: unbindOutcome.failed } : {}),
565
620
  deletedInstances: steps.filter((step) => step.step.startsWith("workflow.delete_instance:") && step.status === "ok").length,
566
621
  ...(unremovableInstances.length > 0 ? { unremovableInstances } : {}),