@stalfh233/omc-cli 0.6.83 → 0.6.84

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.
@@ -2529,6 +2529,81 @@ async function ensureWorkflowRulesEnabled(session, schemaCode, codes, byCode) {
2529
2529
  }
2530
2530
  return { enabledRuleCodes, alreadyEnabledRuleCodes };
2531
2531
  }
2532
+ /** 该 target(flow 级 handler / node 级事件)在模板上的 handler 对象。 */
2533
+ function bindTargetHandlerOf(template, target) {
2534
+ if (target.scope === "workflow")
2535
+ return (template?.[target.field] ?? {}) ?? {};
2536
+ return (findTemplateActivity(template, target.activityCode)?.[target.field] ?? {}) ?? {};
2537
+ }
2538
+ /**
2539
+ * unbindRule 的读回+校验上下文——execute 与 dryRunPayload **共用这一个函数**
2540
+ * (同 rule.node.update 的 loadRuleNodePatchGraph 模式),保证 dry-run 与真写
2541
+ * 对「不存在流程 / 不存在活动 / absent code」给出完全相同的 refusal:此前
2542
+ * dry-run 走 write.ts 的泛型 plan 信封,打错 ruleCode 也回 wouldChange:true,
2543
+ * 真写才拒 absent。本函数只读草稿 + 本地校验(含模板渲染检查),零写入。
2544
+ */
2545
+ async function unbindRuleContext(session, args) {
2546
+ const target = resolveBindTarget(args.handler, args.nodeEvent, args.activityCode);
2547
+ const codes = (args.ruleCodes ?? [args.ruleCode]).map(String);
2548
+ const shouldPublish = args.publish !== false;
2549
+ const draft = (await getWorkflowDraftOrNull(session, args.workflowCode)) ?? {};
2550
+ if (Object.keys(draft).length === 0) {
2551
+ throw new ToolRefusalError({
2552
+ status: "refused",
2553
+ blocker: "workflow-not-found",
2554
+ workflowCode: args.workflowCode,
2555
+ message: `流程 ${args.workflowCode} 不存在(get_draft 401001 缺席)——先 workflow.create,再 unbindRule`,
2556
+ });
2557
+ }
2558
+ if (target.scope === "activity" && !findTemplateActivity(draft, target.activityCode)) {
2559
+ throw new ToolRefusalError({
2560
+ status: "refused",
2561
+ blocker: "workflow-activity-not-found",
2562
+ workflowCode: args.workflowCode,
2563
+ activityCode: target.activityCode,
2564
+ activities: templateActivityCodes(draft),
2565
+ message: `流程 ${args.workflowCode} 的草稿里没有活动 ${target.activityCode}——节点级事件必须指向已存在的活动。可用活动:${templateActivityCodes(draft).join("、") || "(无)"}(先用 workflow.get_draft 看 code,别用节点名)`,
2566
+ });
2567
+ }
2568
+ const existing = bindTargetHandlerOf(draft, target);
2569
+ const priorActions = Array.isArray(existing.bizActions)
2570
+ ? existing.bizActions.filter((value) => typeof value === "string")
2571
+ : [];
2572
+ // Fail closed BEFORE any wire call when the caller names codes the handler
2573
+ // does not carry — a typo'd ruleCode must not report a phantom success,
2574
+ // and the existing codes are the fix's raw material.
2575
+ const absent = codes.filter((code) => !priorActions.includes(code));
2576
+ if (absent.length > 0) {
2577
+ throw new ToolRefusalError({
2578
+ status: "refused",
2579
+ blocker: "workflow-unbind-rule-absent",
2580
+ workflowCode: args.workflowCode,
2581
+ absentRuleCodes: absent,
2582
+ bizActions: priorActions,
2583
+ ...(target.scope === "activity" ? { activityCode: target.activityCode, nodeEvent: target.key } : { handler: target.key }),
2584
+ message: `该处理器当前没有绑定 ${absent.join("、")}——现有绑定:${priorActions.join("、") || "(无)"}。解绑只对已绑定的 code 生效;要换目标先看 workflow.get_draft 的 ruleBindings/nodeRuleBindings`,
2585
+ });
2586
+ }
2587
+ const nextActions = priorActions.filter((code) => !codes.includes(code));
2588
+ // 移空后的写回形状按平台 canonical 未绑态:handler 对象保留、bizActions 与
2589
+ // bizActionType 置 null(WorkflowTemplateController 的模板示例即此形状;平台
2590
+ // 判空走 CollectionUtils.isEmpty,null 与 [] 等价,null 是平台自己的存量拼写)。
2591
+ const mergedHandler = nextActions.length > 0
2592
+ ? { ...(typeof existing === "object" && existing ? existing : {}), bizActions: nextActions, bizActionType: "BIZ_RULE" }
2593
+ : { ...(typeof existing === "object" && existing ? existing : {}), bizActions: null, bizActionType: null };
2594
+ let nextTemplate;
2595
+ if (target.scope === "workflow") {
2596
+ nextTemplate = { ...draft, [target.field]: mergedHandler, workflowCode: args.workflowCode, schemaCode: args.schemaCode };
2597
+ }
2598
+ else {
2599
+ // Keep the draft's activities container shape (array or index-keyed
2600
+ // object) — only the selected row's handler field changes.
2601
+ nextTemplate = mapTemplateActivity(draft, target.activityCode, (row) => ({ ...row, [target.field]: mergedHandler })).template;
2602
+ nextTemplate = { ...nextTemplate, workflowCode: args.workflowCode, schemaCode: args.schemaCode };
2603
+ }
2604
+ validateWorkflowRender(nextTemplate, "workflow.unbindRule");
2605
+ return { target, codes, shouldPublish, nextTemplate, priorActions, nextActions };
2606
+ }
2532
2607
  export function registerWorkflowLane(tools) {
2533
2608
  // Sibling registry for the high-level `configure_workflow` (reuses each atomic
2534
2609
  // tool's own writeExecute so every gate + readback is identical).
@@ -3278,70 +3353,9 @@ export function registerWorkflowLane(tools) {
3278
3353
  publish: z.boolean().optional(),
3279
3354
  },
3280
3355
  execute: async (session, args) => {
3281
- const target = resolveBindTarget(args.handler, args.nodeEvent, args.activityCode);
3282
- const codes = (args.ruleCodes ?? [args.ruleCode]).map(String);
3283
- const shouldPublish = args.publish !== false;
3284
- const draft = (await getWorkflowDraftOrNull(session, args.workflowCode)) ?? {};
3285
- if (Object.keys(draft).length === 0) {
3286
- throw new ToolRefusalError({
3287
- status: "refused",
3288
- blocker: "workflow-not-found",
3289
- workflowCode: args.workflowCode,
3290
- message: `流程 ${args.workflowCode} 不存在(get_draft 401001 缺席)——先 workflow.create,再 unbindRule`,
3291
- });
3292
- }
3293
- if (target.scope === "activity" && !findTemplateActivity(draft, target.activityCode)) {
3294
- throw new ToolRefusalError({
3295
- status: "refused",
3296
- blocker: "workflow-activity-not-found",
3297
- workflowCode: args.workflowCode,
3298
- activityCode: target.activityCode,
3299
- activities: templateActivityCodes(draft),
3300
- message: `流程 ${args.workflowCode} 的草稿里没有活动 ${target.activityCode}——节点级事件必须指向已存在的活动。可用活动:${templateActivityCodes(draft).join("、") || "(无)"}(先用 workflow.get_draft 看 code,别用节点名)`,
3301
- });
3302
- }
3303
- const handlerOf = (template) => {
3304
- if (target.scope === "workflow")
3305
- return (template?.[target.field] ?? {}) ?? {};
3306
- return (findTemplateActivity(template, target.activityCode)?.[target.field] ?? {}) ?? {};
3307
- };
3308
- const existing = handlerOf(draft);
3309
- const priorActions = Array.isArray(existing.bizActions)
3310
- ? existing.bizActions.filter((value) => typeof value === "string")
3311
- : [];
3312
- // Fail closed BEFORE any wire call when the caller names codes the handler
3313
- // does not carry — a typo'd ruleCode must not report a phantom success,
3314
- // and the existing codes are the fix's raw material.
3315
- const absent = codes.filter((code) => !priorActions.includes(code));
3316
- if (absent.length > 0) {
3317
- throw new ToolRefusalError({
3318
- status: "refused",
3319
- blocker: "workflow-unbind-rule-absent",
3320
- workflowCode: args.workflowCode,
3321
- absentRuleCodes: absent,
3322
- bizActions: priorActions,
3323
- ...(target.scope === "activity" ? { activityCode: target.activityCode, nodeEvent: target.key } : { handler: target.key }),
3324
- message: `该处理器当前没有绑定 ${absent.join("、")}——现有绑定:${priorActions.join("、") || "(无)"}。解绑只对已绑定的 code 生效;要换目标先看 workflow.get_draft 的 ruleBindings/nodeRuleBindings`,
3325
- });
3326
- }
3327
- const nextActions = priorActions.filter((code) => !codes.includes(code));
3328
- // 移空后的写回形状按平台 canonical 未绑态:handler 对象保留、bizActions 与
3329
- // bizActionType 置 null(WorkflowTemplateController 的模板示例即此形状;平台
3330
- // 判空走 CollectionUtils.isEmpty,null 与 [] 等价,null 是平台自己的存量拼写)。
3331
- const mergedHandler = nextActions.length > 0
3332
- ? { ...(typeof existing === "object" && existing ? existing : {}), bizActions: nextActions, bizActionType: "BIZ_RULE" }
3333
- : { ...(typeof existing === "object" && existing ? existing : {}), bizActions: null, bizActionType: null };
3334
- let nextTemplate;
3335
- if (target.scope === "workflow") {
3336
- nextTemplate = { ...draft, [target.field]: mergedHandler, workflowCode: args.workflowCode, schemaCode: args.schemaCode };
3337
- }
3338
- else {
3339
- // Keep the draft's activities container shape (array or index-keyed
3340
- // object) — only the selected row's handler field changes.
3341
- nextTemplate = mapTemplateActivity(draft, target.activityCode, (row) => ({ ...row, [target.field]: mergedHandler })).template;
3342
- nextTemplate = { ...nextTemplate, workflowCode: args.workflowCode, schemaCode: args.schemaCode };
3343
- }
3344
- validateWorkflowRender(nextTemplate, "workflow.unbindRule");
3356
+ // 读回+校验与 dry-run 共用 unbindRuleContext(同 refusal、同答案)。
3357
+ const { target, codes, shouldPublish, nextTemplate } = await unbindRuleContext(session, args);
3358
+ const handlerOf = (template) => bindTargetHandlerOf(template, target);
3345
3359
  const performed = await wireCall(session, {
3346
3360
  path: ENDPOINTS.workflowUpdate,
3347
3361
  method: "POST",
@@ -3409,6 +3423,29 @@ export function registerWorkflowLane(tools) {
3409
3423
  throw new ToolRefusalError({ status: "refused", blocker: "workflow-bindrule-codes-invalid", message: "ruleCodes 必须是非空、去重的规则 code 数组" });
3410
3424
  }
3411
3425
  },
3426
+ // dry-run 与真写同答案:读回+校验走 execute 同一个 unbindRuleContext——
3427
+ // 不存在流程 / 不存在活动 / absent code 在 dry-run 就拿到与真写完全相同的
3428
+ // refusal(打错 ruleCode 不再先亮 wouldChange:true);全过则回预览载荷。
3429
+ dryRunPayload: async (session, args) => {
3430
+ const ctx = await unbindRuleContext(session, args);
3431
+ const targetShape = ctx.target.scope === "workflow"
3432
+ ? { handler: ctx.target.key, handlerField: ctx.target.field }
3433
+ : { activityCode: ctx.target.activityCode, nodeEvent: ctx.target.key, nodeEventField: ctx.target.field };
3434
+ return {
3435
+ workflowCode: args.workflowCode,
3436
+ scope: ctx.target.scope,
3437
+ ...targetShape,
3438
+ removedRuleCodes: ctx.codes,
3439
+ currentBizActions: ctx.priorActions,
3440
+ remainingBizActions: ctx.nextActions,
3441
+ handlerWillBeCleared: ctx.nextActions.length === 0,
3442
+ publish: ctx.shouldPublish,
3443
+ ruleEnableUntouched: true,
3444
+ summary: writeSummary("workflow.unbindRule", args, undefined, "plan"),
3445
+ };
3446
+ },
3447
+ lintScope: "full",
3448
+ lintUnchecked: ["platform-side-validation", "post-write-readback"],
3412
3449
  rollback: workflowRollbackSpec("workflow.unbindRule"),
3413
3450
  });
3414
3451
  /**
@@ -517,11 +517,38 @@ export function nullProjectionHint(nullEntries, total) {
517
517
  * 这类只在 result 层有的键;`--jq modelsCount` 却去 artifact 副本里找,
518
518
  * 于是 pathMiss,且 `available` 列的是 artifact 的键——调用方看到"键明明打印过
519
519
  * 却说没有"。这里把事实补回去:该路径在 result 层存在时明确指路。
520
+ *
521
+ * retro issue 19 第三变体:result 层的同名键也可能是回执的**摘要投影**(如
522
+ * workflow.get_published 外置后的顶层 activities——形状与 artifact 正文完全
523
+ * 不同,元素常缺深层键),再无条件教「不带 --jq 直接读回执」会把人导向摘要面。
524
+ * 两头说清:正文里能解析同名键(pathMissCopyablePaths 已验证)就给可复制
525
+ * 命令;解析不了就说明形状差异并给结构性探索建议;只有正文**完全无同名键**
526
+ * (modelsCount 这类纯回执派生键)才保留「直接读回执」的旧指路。
520
527
  */
521
- function resultLayerNote(result, path) {
528
+ function resultLayerNote(result, path, artifactSource, at) {
522
529
  const head = path.replace(/^\$\.?/, "").split(/[.\[]/)[0];
523
530
  if (head === "" || !(head in result))
524
531
  return undefined;
532
+ // 与 pathMissCopyableHint 同一解析器:只在候选路径**能解析**时才输出,
533
+ // 绝不给出解析不了的假路径(issue 19 的语义门)。
534
+ const copyable = pathMissCopyablePaths(artifactSource, path, at, 1);
535
+ if (copyable.length > 0) {
536
+ return {
537
+ existsOnResult: head,
538
+ summaryProjection: true,
539
+ resultLayerHint: `result 顶层的「${head}」是摘要投影(形状与 artifact 正文不同,深层键常缺席),不要按它取值;正文里的真实路径:--jq '${copyable[0].replace(/'/g, "'\\''")}'`,
540
+ };
541
+ }
542
+ // 正文里有同名键但完整路径解析不了(如该流程无绑定、元素缺深层键):
543
+ // 说清差异 + 指向正文实际结构,不编造路径。
544
+ const bodyKey = collectKeyPaths(artifactSource, head).find((candidate) => candidate !== head);
545
+ if (bodyKey !== undefined) {
546
+ return {
547
+ existsOnResult: head,
548
+ summaryProjection: true,
549
+ resultLayerHint: `result 顶层的「${head}」是摘要投影(形状与 artifact 正文不同,深层键常缺席);正文同名键在 ${bodyKey},但该路径在正文里也不可解析(深层键缺席)。先用 artifact get --shape ${bodyKey} 看正文实际结构再定位`,
550
+ };
551
+ }
525
552
  return {
526
553
  existsOnResult: head,
527
554
  resultLayerHint: `「${head}」在 result 顶层(只是不在 artifact 副本里)。取它请不带 --jq 直接读回执,或改取 artifact 内的键(见 available)`,
@@ -759,7 +786,7 @@ export function projectResultExtract(result, paths, keysOnly) {
759
786
  ...(fan.availableTruncated !== undefined ? { availableTruncated: fan.availableTruncated } : {}),
760
787
  missedEntries: fan.missedEntries,
761
788
  ...(didYouMean !== undefined ? { didYouMean } : {}),
762
- ...(readFromArtifact ? resultLayerNote(result, path) ?? {} : {}),
789
+ ...(readFromArtifact ? resultLayerNote(result, path, projectionSource, fan.at) ?? {} : {}),
763
790
  hint: missHintFor(path, fan.at, fan.available, fan.availableAll),
764
791
  };
765
792
  }
@@ -796,7 +823,7 @@ export function projectResultExtract(result, paths, keysOnly) {
796
823
  available: single.available,
797
824
  ...(single.availableTruncated !== undefined ? { availableTruncated: single.availableTruncated } : {}),
798
825
  ...(didYouMean !== undefined ? { didYouMean } : {}),
799
- ...(readFromArtifact ? resultLayerNote(result, path) ?? {} : {}),
826
+ ...(readFromArtifact ? resultLayerNote(result, path, projectionSource, single.at) ?? {} : {}),
800
827
  hint: missHintFor(path, single.at, single.available, single.availableAll),
801
828
  };
802
829
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stalfh233/omc-cli",
3
- "version": "0.6.83",
3
+ "version": "0.6.84",
4
4
  "description": "CloudPivot 8.6 configuration capability CLI — governed, fail-closed, coverage-manifest bounded.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "commander": "14.0.3",
59
- "omc-core": "0.6.83",
59
+ "omc-core": "0.6.84",
60
60
  "proper-lockfile": "4.1.2",
61
61
  "write-file-atomic": "6.0.0",
62
62
  "zod": "^3.23.8",
@@ -74,6 +74,6 @@
74
74
  "directory": "packages/omc-cli"
75
75
  },
76
76
  "optionalDependencies": {
77
- "@stalfh233/omc-fake-platform": "0.6.83"
77
+ "@stalfh233/omc-fake-platform": "0.6.84"
78
78
  }
79
79
  }