@stalfh233/omc-cli 0.6.95 → 0.6.96

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.
@@ -12,7 +12,8 @@ import { extractDataRuleEdges, extractReferenceEdges } from "../graph.js";
12
12
  import { DEFAULT_SCAN_CONCURRENCY, mapWithConcurrency } from "../concurrency.js";
13
13
  import { readFormButtons, readFormOrNull } from "../form-support.js";
14
14
  import { scanModelWorkflowBindings } from "./workflow.js";
15
- import { readCustomScriptSource } from "./online-js.js";
15
+ import { listOtherScriptSources, readCustomScriptSource } from "./online-js.js";
16
+ import { decodeButtonScript } from "./list-view.js";
16
17
  import { wireCall, wireCallWith404Fallback, wireRows } from "../wire.js";
17
18
  import { readModelRecord } from "../model-record.js";
18
19
  import { BUSINESSRULE_LANE_CONTRACT } from "./businessrule-contract.js";
@@ -799,8 +800,39 @@ const ONLINEJS_TRIGGER_PATTERNS = [
799
800
  { kind: "fetch", test: /fetch\(/ },
800
801
  { kind: "/api/", test: /\/api\// },
801
802
  ];
802
- function onlineJsTriggerHits(script) {
803
+ /**
804
+ * sites 模式每个脚本源的命中行上限。read.ts 的 smallRowSet 只按 triggers **行数**
805
+ * ≤30 放行、不看字节——不设上限时一条 onlinejs 行能把整个回执顶出 2048B 折叠门
806
+ * 直接全量内联(评审必改 3)。hitCount 仍是真实总数。
807
+ */
808
+ const ONLINEJS_HITS_CAP = 20;
809
+ /**
810
+ * 命中行的「打到哪个接口」抽取:只做**同行字面量**,不做语法分析。
811
+ * - `axios.post('/x')` → `POST /x`;`fetch('/x')` → `/x`(fetch 默认 GET,不编造 method)
812
+ * - 模板串含 `${…}`、变量拼接、`axios({url:…})` 配置式 → 抽不到目标,标 `targetUnresolved`
813
+ * 注释行仍可能命中(scanMode:"text" 的既有局限)。
814
+ */
815
+ const ONLINEJS_TARGET_PATTERNS = [
816
+ {
817
+ test: /axios\s*\.\s*(post|get|put|delete|patch)\s*\(\s*(["'`])([^"'`]*)\2/,
818
+ build: (match) => match[3].includes("${") ? { target: `${match[1].toUpperCase()} ${match[3]}`, targetUnresolved: true } : { target: `${match[1].toUpperCase()} ${match[3]}` },
819
+ },
820
+ {
821
+ test: /fetch\s*\(\s*(["'`])([^"'`]*)\1/,
822
+ build: (match) => (match[2].includes("${") ? { target: match[2], targetUnresolved: true } : { target: match[2] }),
823
+ },
824
+ ];
825
+ function onlineJsHitTarget(line) {
826
+ for (const pattern of ONLINEJS_TARGET_PATTERNS) {
827
+ const match = pattern.test.exec(line);
828
+ if (match !== null)
829
+ return pattern.build(match);
830
+ }
831
+ return { targetUnresolved: true };
832
+ }
833
+ function onlineJsTriggerSites(script) {
803
834
  const hits = [];
835
+ let hitCount = 0;
804
836
  script.split("\n").forEach((raw, index) => {
805
837
  const line = raw.trim();
806
838
  if (line === "")
@@ -808,10 +840,13 @@ function onlineJsTriggerHits(script) {
808
840
  const matched = ONLINEJS_TRIGGER_PATTERNS.find((pattern) => pattern.test.test(line));
809
841
  if (matched === undefined)
810
842
  return;
843
+ hitCount += 1;
844
+ if (hits.length >= ONLINEJS_HITS_CAP)
845
+ return;
811
846
  // excerpt ≤120 字(含截断省略号本身)。
812
- hits.push({ line: index + 1, excerpt: line.length > 120 ? `${line.slice(0, 119)}…` : line, kind: matched.kind });
847
+ hits.push({ line: index + 1, excerpt: line.length > 120 ? `${line.slice(0, 119)}…` : line, kind: matched.kind, ...onlineJsHitTarget(line) });
813
848
  });
814
- return hits;
849
+ return { hits, hitCount };
815
850
  }
816
851
  /**
817
852
  * `action:"create"|"update"|"delete"` 的「绑定到该事件的自定义规则」反推:
@@ -880,6 +915,14 @@ async function scanSchemaTriggers(session, args) {
880
915
  let scannedButtons = 0;
881
916
  let onlinejsBytes = 0;
882
917
  let script = null;
918
+ // 评审必改 1(2026-11-23):SCRIPT 按钮的脚本与表单 customScript 同属「在线 JS
919
+ // 触发面」——数据已在同一次 bizsheet/get 里(options.customButtonJson),零额外
920
+ // wire。actionConfig 可能是对象也可能是 legacy JSON 字符串,解码走
921
+ // decodeButtonScript(与 form.get buttonScripts 同一实现)。
922
+ let scriptButtonCount = 0;
923
+ let buttonScriptBytes = 0;
924
+ const scriptButtonSources = [];
925
+ const unreadableScriptButtons = [];
883
926
  const buttonRows = [];
884
927
  if (activityCodeFilter !== undefined) {
885
928
  notScanned.push("activityCode 过滤:表单按钮/规则/预置事件/在线 JS 未扫描(只看该流程节点的绑定)");
@@ -894,9 +937,25 @@ async function scanSchemaTriggers(session, args) {
894
937
  const buttons = readFormButtons(sheet.options) ?? [];
895
938
  scannedButtons = buttons.length;
896
939
  for (const button of buttons) {
897
- // 只有 BUSINESS_RULE 绑定是触发点;其它按钮(SCRIPT/流程动作等)只计数。
898
- if (button.bindAction !== "BUSINESS_RULE")
940
+ // BUSINESS_RULE 绑定是规则触发点;SCRIPT 按钮的脚本走文本匹配(下方
941
+ // onlineRows,source:"button");其它按钮(流程动作/页面等)只计数。
942
+ if (button.bindAction !== "BUSINESS_RULE") {
943
+ if (button.bindAction !== "SCRIPT")
944
+ continue;
945
+ const code = typeof button.code === "string" ? button.code : null;
946
+ const decoded = decodeButtonScript(button);
947
+ const source = typeof decoded.scriptData === "string" ? decoded.scriptData : null;
948
+ if (source === null || source.trim() === "") {
949
+ // 聚合点名(不逐个 push):notScanned 有 2000B 内联上限。
950
+ unreadableScriptButtons.push(code ?? "(无 code)");
951
+ continue;
952
+ }
953
+ // 只计「实际完成文本扫描」的按钮;不可读的由 notScanned 点名。
954
+ scriptButtonCount += 1;
955
+ buttonScriptBytes += Buffer.byteLength(source, "utf8");
956
+ scriptButtonSources.push({ code, name: typeof button.name === "string" ? button.name : null, script: source });
899
957
  continue;
958
+ }
900
959
  buttonRows.push({
901
960
  via: "button",
902
961
  sheetCode,
@@ -906,9 +965,30 @@ async function scanSchemaTriggers(session, args) {
906
965
  targetCode: typeof button.targetCode === "string" ? button.targetCode : null,
907
966
  });
908
967
  }
909
- script = readCustomScriptSource(typeof sheet.publishedHtmlJson === "string" ? sheet.publishedHtmlJson : null).script;
968
+ if (unreadableScriptButtons.length > 0) {
969
+ // 真机 notScanned 已 ~1.3KB/2.0KB 内联上限(超了会被 compact 折成
970
+ // {count,sha256,omitted},0.6.93 的坑)——按钮名最多点 8 个,其余只报数。
971
+ const named = unreadableScriptButtons.slice(0, 8).join("、");
972
+ const rest = unreadableScriptButtons.length > 8 ? ` 等 ${unreadableScriptButtons.length} 个` : "";
973
+ notScanned.push(`SCRIPT 按钮的脚本不可读(${named}${rest}):actionConfig 缺失/不是合法 JSON 或 scriptData 为空——这些按钮的脚本未扫描`);
974
+ }
975
+ if (scriptButtonCount > 0) {
976
+ // 评审必改 2:读的是授权面(options),运行面用的是发布时物化的
977
+ // h_biz_button(ModelManagementFacadeImpl.publishBizForm)。不声明就会把
978
+ // 「草稿里刚改的脚本」报成现状。
979
+ notScanned.push("按钮脚本读的是表单 options 授权面(发布时才物化为 h_biz_button):草稿里未发布的脚本改动会被当作现状,运行面实际执行上一次发布的版本");
980
+ if (sheet.published !== true)
981
+ notScanned.push(`表单 ${sheetCode} 的 published 旗标=${String(sheet.published)}(部分构建该旗标滞后):运行面是否已有这些按钮以发布态为准`);
982
+ }
983
+ const publishedHtmlJson = typeof sheet.publishedHtmlJson === "string" ? sheet.publishedHtmlJson : null;
984
+ script = readCustomScriptSource(publishedHtmlJson).script;
910
985
  if (script === null)
911
- notScanned.push(`在线 JS:表单 ${sheetCode} 的发布面无 customScript 脚本(未扫描)`);
986
+ notScanned.push(`在线 JS:表单 ${sheetCode} 的发布面无 customScript 脚本(表单级在线 JS 未扫描;SCRIPT 按钮的脚本单独扫,见 triggers 里 source:"button" 的行)`);
987
+ // 评审必改 5:把「before/after 恒空」从经验断言变成自校验——真出现非空
988
+ // 的其它 script 元素就点名(而不是静默漏扫)。
989
+ const strayScripts = listOtherScriptSources(publishedHtmlJson);
990
+ if (strayScripts.length > 0)
991
+ notScanned.push(`布局里除 customScript 外还有非空 script 元素(${strayScripts.map((item) => `${item.id ?? "(无 id)"} ${item.bytes}B`).join("、")})未扫描——8.6.x 实测 before/after 恒空,出现即异常形态`);
912
992
  }
913
993
  }
914
994
  catch (error) {
@@ -986,17 +1066,34 @@ async function scanSchemaTriggers(session, args) {
986
1066
  }
987
1067
  }
988
1068
  }
989
- // 5. 在线 JS 文本匹配(零 wire;无脚本时第 3 步已记 notScanned)。
990
- const hits = script === null ? [] : onlineJsTriggerHits(script);
991
- onlinejsBytes = script === null ? 0 : Buffer.byteLength(script, "utf8");
992
- const onlineRows = hits.length === 0
993
- ? []
994
- : [{ via: "onlinejs", sheetCode, scanMode: "text", hitCount: hits.length, ...(mode === "sites" ? { hits } : {}) }];
1069
+ // 5. 在线 JS 文本匹配(零 wire;表单 customScript + SCRIPT 按钮脚本。无脚本时
1070
+ // 第 3 步已记 notScanned)。
1071
+ const onlineRows = [];
1072
+ const pushOnlineRow = (input) => {
1073
+ const sites = onlineJsTriggerSites(input.script);
1074
+ if (sites.hitCount === 0)
1075
+ return;
1076
+ onlineRows.push({
1077
+ via: "onlinejs",
1078
+ source: input.source,
1079
+ sheetCode,
1080
+ ...(input.source === "button" ? { buttonCode: input.buttonCode ?? null, buttonName: input.buttonName ?? null } : {}),
1081
+ scanMode: "text",
1082
+ hitCount: sites.hitCount,
1083
+ ...(mode === "sites" ? { hits: sites.hits, ...(sites.hitCount > sites.hits.length ? { hitsTruncated: true } : {}) } : {}),
1084
+ });
1085
+ };
1086
+ if (script !== null) {
1087
+ onlinejsBytes = Buffer.byteLength(script, "utf8");
1088
+ pushOnlineRow({ source: "form", script });
1089
+ }
1090
+ for (const button of scriptButtonSources)
1091
+ pushOnlineRow({ source: "button", buttonCode: button.code, buttonName: button.name, script: button.script });
995
1092
  // P4(2026-11-22,F6b):**覆盖面自述**。F6b 转录:任务说「别漏」时,agent 拿到
996
1093
  // 触发视图后仍逐面交叉核对 datarule/programming/视图——因为回执只说了"扫了什么",
997
1094
  // 没说"哪些面本来就不在这里"。把未覆盖面按入口点名列出来,省掉这轮盲目核对;
998
1095
  // 视图/权限不是动作触发点,单独说明"不适用",避免继续查。
999
- notScanned.push(`数据规则(datarule)不在本视图:按字段/记录条件触发的数据规则走 omc call datarule.list --args '{"schemaCode":"${schemaCode}"}'`, `后端在线开发(programming)不在本视图:程序源码走 omc call programming.sources --args '{"schemaCode":"${schemaCode}"}'`, "视图(listview)/字段权限/流程权限不是动作触发点(只影响显示与可达性),无需扫描", "只扫当前应用;跨应用流程与规则需显式换应用(workflow.list --applicationCode)");
1096
+ notScanned.push(`数据规则(datarule)不在本视图:按字段/记录条件触发的数据规则走 omc call datarule.list --args '{"schemaCode":"${schemaCode}"}'`, `后端在线开发(programming)是规则/方法的**动作实现**,不是触发点:要看实现走 omc call programming.sources --args '{"schemaCode":"${schemaCode}"}'`, "自定义页面(custompage)是页面级配置、不挂模型(schemaCode),不在模型触发视图范围", `多表单模型只扫一个槽位(本次 ${sheetCode};省略 sheetCode 时=模型码):其它槽位的按钮与在线 JS 未扫——用 omc call form.list --args '{"schemaCode":"${schemaCode}"}' 列槽位后按 sheetCode 逐个查`, "视图(listview)/字段权限/流程权限不是动作触发点(只影响显示与可达性),无需扫描", "只扫当前应用;跨应用流程与规则需显式换应用(workflow.list --applicationCode)");
1000
1097
  // 6. 并集 + action/activityCode 过滤(分组顺序:workflow → button → rule → preset → onlinejs)。
1001
1098
  let triggers;
1002
1099
  if (activityCodeFilter !== undefined) {
@@ -1026,10 +1123,10 @@ async function scanSchemaTriggers(session, args) {
1026
1123
  action: action ?? null,
1027
1124
  mode,
1028
1125
  triggers,
1029
- scanned: { workflows, rules: scannedRules, buttons: scannedButtons, onlinejsBytes, schedulerReads, schedulerReadFailed },
1126
+ scanned: { workflows, rules: scannedRules, buttons: scannedButtons, buttonScripts: scriptButtonCount, onlinejsBytes, buttonScriptBytes, schedulerReads, schedulerReadFailed },
1030
1127
  notScanned,
1031
1128
  scanMode: "source",
1032
- note: "零命中=本次扫描未命中触发点,不代表没有触发;在线 JS 是文本匹配,可能漏动态拼 URL" + schedulerNote + filterNote,
1129
+ note: "零命中=本次扫描未命中触发点,不代表没有触发;在线 JS(表单 customScript + SCRIPT 按钮脚本)是文本匹配,可能漏动态拼 URL、可能命中注释(命中行带 target;抽不到字面量目标标 targetUnresolved)" + schedulerNote + filterNote,
1033
1130
  ...(activityCodeFilter !== undefined ? { activityCode: activityCodeFilter } : {}),
1034
1131
  applicationResolution: { ...applicationResolutionOf(scope), mode: "trigger", models: 1 },
1035
1132
  };
@@ -1125,7 +1222,7 @@ export function registerBusinessRuleLane(tools) {
1125
1222
  action: z.enum(["create", "update", "delete", "flow"]).optional().describe("仅 kind=trigger:动作过滤,省略=全量"),
1126
1223
  activityCode: z.string().min(1).optional().describe("仅 kind=trigger:只看该流程节点的绑定(与 action 互斥)"),
1127
1224
  sheetCode: z.string().min(1).optional().describe("仅 kind=trigger:多表单模型指定槽位;省略=默认槽位"),
1128
- mode: z.enum(["summary", "sites"]).optional().describe("仅 kind=trigger:summary=默认,在线 JS 只回计数;sites=回命中行"),
1225
+ mode: z.enum(["summary", "sites"]).optional().describe("仅 kind=trigger:summary=默认,在线 JS(表单 customScript + SCRIPT 按钮脚本)只回计数;sites=回命中行(带 target)"),
1129
1226
  capability: capabilityArg,
1130
1227
  },
1131
1228
  handler: async (ctx, args, self) => governedRead(ctx, self, args, async (session) => {
@@ -55,6 +55,17 @@ export function readCustomScriptSource(rawHtml) {
55
55
  ? { present: true, script, sha256: createHash("sha256").update(script, "utf8").digest("hex"), elementCount: elements.length }
56
56
  : { present: false, script: null, sha256: "", elementCount: elements.length, notCollected: true, notCollectedReason: "customScript 不存在,无法计算脚本哈希" };
57
57
  }
58
+ /**
59
+ * 2026-11-23(评审必改 5):把「脚本骨架固定 6 元素、before/after 恒空」从经验
60
+ * 断言变成**自校验**——列出布局里除 customScript 外非空的 script 元素。调用方
61
+ * 非空即在 notScanned 点名,避免把「没见过的形态」静默当成「没有脚本」。
62
+ */
63
+ export function listOtherScriptSources(rawHtml) {
64
+ return parseLayoutElements(rawHtml)
65
+ .filter((element) => element.tagName === "script" && element.id !== "customScript")
66
+ .filter((element) => typeof element.innerHTML === "string" && element.innerHTML.trim() !== "")
67
+ .map((element) => ({ id: typeof element.id === "string" ? element.id : null, bytes: Buffer.byteLength(String(element.innerHTML), "utf8") }));
68
+ }
58
69
  /**
59
70
  * R75-B(2026-11-18):compose 的两道门都是「读面可判、但在 execute 里」——
60
71
  * dry-run 绿灯、真写拒(investigate-B E2 实证)。抽成共享函数,dry-run 与真写
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stalfh233/omc-cli",
3
- "version": "0.6.95",
3
+ "version": "0.6.96",
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.95",
59
+ "omc-core": "0.6.96",
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.95"
77
+ "@stalfh233/omc-fake-platform": "0.6.96"
78
78
  }
79
79
  }