@stalfh233/omc-cli 0.6.82 → 0.6.83

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.
@@ -1162,7 +1162,10 @@ export function registerRuntimeDataLane(tools) {
1162
1162
  fields: z.array(z.string().min(1)).optional().describe("列投影别名(=displayFields;与 data.load/data.save/data.update 的 fields 同语义)"),
1163
1163
  // r73 #4(GitLab #40 P1):只读查询的排序 fallback 首选曾是写操作(listview.configure
1164
1164
  // 会改线上视图、影响所有用户)。顺序反转——本地排序第一,视图级写操作殿后并注明代价。
1165
- orders: z.array(z.object({ field: z.string().min(1), dir: z.enum(["ASC", "DESC"]) })).optional().describe("query/list 不支持服务端排序。首选本地排(items[].fields.<字段>;--jq 只投影);listview.configure 的 sorts 是写操作(改线上视图、影响所有用户),仅确需时用"),
1165
+ // r86(retro issue 16):wire 侧其实有服务端排序(QueryDataVO.orders,真机 1.1.25
1166
+ // 实证生效)——orderBy 映射为 orders:[{propertyCode,dir:ASC|DESC}];教学进
1167
+ // contract/notes(tools/list 只留这句)。
1168
+ orderBy: z.array(z.object({ field: z.string().min(1), direction: z.enum(["asc", "desc"]) })).optional().describe("服务端排序 [{field,direction:asc|desc}](wire=orders,dir 发送时转大写);多键按数组序优先;可排面=已发布字段+系统列(createdTime/modifiedTime 等);子表 schema 面被平台忽略"),
1166
1169
  mobile: z.boolean().optional(),
1167
1170
  // r63(b-F12):draftPolicy 此前只能从结果反推——探针无法控制也无法预知
1168
1171
  // 草稿口径。显式开关:false 注入 sequenceStatus≠DRAFT(真机验证可过滤,
@@ -1189,17 +1192,14 @@ export function registerRuntimeDataLane(tools) {
1189
1192
  tool: "data.list",
1190
1193
  message: '没有 `query` 参数——过滤用 `filter: {"op":"eq","field":"<字段>","value":"<值>"}`(或 `filters` 数组=AND、`filterGroup` 嵌套)。r31 真机:`query:{...}` 被静默忽略、total 不变,极易误判为"无数据/已过滤"。',
1191
1194
  });
1192
- if (args.orders !== undefined)
1193
- throw new ToolInputError({
1194
- status: "error",
1195
- blocker: "invalid-input",
1196
- tool: "data.list",
1197
- // r73 #4(GitLab #40 P1):旧文案把写操作(listview.configure 改线上视图)放在
1198
- // 首位、nextCommand 直接指向它——只读查询的 fallback 不该默认引向写。本地排序
1199
- // 第一(并说清怎么排),视图级写操作放末尾并注明影响所有用户。
1200
- message: "运行面 query/list 不支持服务端排序。排序请先在本地做:用本工具取回数据(全量 all:true 或逐页翻页),再按 items[].fields.<字段> 在本地排序(--jq 只能投影不能排序,需用客户端脚本/管道排)。只有确实要改**视图级**默认排序时才用 listview.configure 的 sorts(写操作:会改线上视图排序、影响所有用户,谨慎)。",
1201
- nextCommand: `omc call data.list --env <env> --args '${JSON.stringify({ schemaCode: args.schemaCode, all: true })}'(取回全量后本地排序)`,
1202
- });
1195
+ // r86(retro issue 16):orderBy 参数面 → wire orders(QueryDataVO.orders,
1196
+ // 真机 1.1.25 实证:dir 枚举 ASC|DESC 大小写敏感、未知列 40000、多键数组序
1197
+ // 优先、orders 优先于视图 sorts、无则平台默认 createdTime DESC)。
1198
+ const orderBy = args.orderBy;
1199
+ // r86(retro issue 15):子表拒绝只看**调用方显式给的**过滤面。includeDrafts:false
1200
+ // 注入的 sequenceStatus≠DRAFT 是默认属性(平台子表分支自建同款 parent-scope
1201
+ // notDraftFilter),按父模型解析也成立,不该被新门误伤。
1202
+ const userFilterRequested = args.rawCondition !== undefined || args.filter !== undefined || (args.filters?.length ?? 0) > 0 || args.filterGroup !== undefined;
1203
1203
  let condition;
1204
1204
  let fromDsl = false;
1205
1205
  try {
@@ -1266,6 +1266,22 @@ export function registerRuntimeDataLane(tools) {
1266
1266
  publishedTypes = new Map((await publishedFields()).map((row) => [row.code, row.type]));
1267
1267
  return publishedTypes;
1268
1268
  };
1269
+ /**
1270
+ * r86(retro issue 15):子表 schema 判别——bizmodels/get_all 的 parentCode
1271
+ * (BizSchemaModel.parentCode,QueryRuntimeController.list 同源判别)。
1272
+ * 非子表/读不到(8.0/8.1 不挂载该路径、模型不存在)都返回 undefined,
1273
+ * 调用方按「不能预判」处理(发 wire,50000 时再映射)。
1274
+ */
1275
+ const subtableParentCodeOf = async (session, schemaCode) => {
1276
+ try {
1277
+ const record = (await wireCall(session, { path: ENDPOINTS.modelGet, query: { schemaCode } })).data;
1278
+ const parent = record?.parentCode;
1279
+ return typeof parent === "string" && parent.trim().length > 0 ? parent : undefined;
1280
+ }
1281
+ catch {
1282
+ return undefined;
1283
+ }
1284
+ };
1269
1285
  if (fromDsl) {
1270
1286
  const typeByCode = await publishedTypeByCode();
1271
1287
  const injected = injectPropertyTypes(condition, (code) => {
@@ -1353,6 +1369,58 @@ export function registerRuntimeDataLane(tools) {
1353
1369
  message: `这些字段是子表(propertyType=${CHILD_TABLE_PROPERTY_TYPE},值是行数组):运行面 query/list 只支持标量过滤,按子表字段过滤会回 errcode 50000 且无明细。改法:用 data.load 读主表记录(子表行随主记录返回),或在本地按子表字段筛选。`,
1354
1370
  nextCommand: `omc call data.load --env <env> --args '{"schemaCode":"${args.schemaCode}","bizObjectId":"<主表 bizObjectId>"}'`,
1355
1371
  };
1372
+ // r86(retro issue 15,真机 1.1.25 实证):schemaCode 本身是子表 schema
1373
+ // (get_all parentCode 非空)时,queryCondition 的裸叶子被平台按**父模型**
1374
+ // 元数据解析(ChildBizObjectAssembler.buildFilter(父code) + 无点号→
1375
+ // schema=parentCode)——子表自身字段(含 parentId)→ 50000 服务异常。
1376
+ // DSL 叶子按子表自身 field.list 注入 propertyType 后必然是裸子表字段,
1377
+ // 全部是错误形状,写前整批拒绝(+1 wire 读 get_all 换拒绝面)。
1378
+ const parentCode = await subtableParentCodeOf(session, args.schemaCode);
1379
+ if (parentCode !== undefined && userFilterRequested)
1380
+ return {
1381
+ status: "refused",
1382
+ blocker: "unsupported-filter-on-subtable",
1383
+ schemaCode: args.schemaCode,
1384
+ parentSchema: parentCode,
1385
+ fields: collectConditionLeafFields(condition),
1386
+ message: `${args.schemaCode} 是子表模型(父模型 ${parentCode}):运行面 query/list 的过滤叶子按**父模型**解析——裸子表字段(含 parentId)会回 errcode 50000「服务异常」(真机实证),不是平台故障。` +
1387
+ `读子表行的正路:data.load 父模型记录(子表行随主记录返回),或本工具不带 filter 全量拉子表后本地筛。要点号「<子表code>.<字段>」形状请走 rawCondition。`,
1388
+ nextCommand: `omc call data.load --env <env> --args '{"schemaCode":"${parentCode}","bizObjectId":"<主表 bizObjectId>"}' --jq 'data.${args.schemaCode}'`,
1389
+ };
1390
+ }
1391
+ // r86(retro issue 16):orderBy 参数面 → wire orders。可排面 = 已发布字段 +
1392
+ // 系统列(平台默认排序本身用 createdTime,8.6.26 resolveSorts;真机 1.1.25
1393
+ // 实证 createdTime/modifiedTime/业务列均可排)。不在可排面的列写前拒——
1394
+ // 平台会回 40000「调用数据库发生异常」(真机),与真故障难分。
1395
+ let wireOrders;
1396
+ if (orderBy !== undefined && orderBy.length > 0) {
1397
+ // r86(retro issue 16):可排面 = 已发布业务字段 + **全部**默认属性列
1398
+ // (DefaultPropertyType.codes:id/name/creater/createdDeptId/owner/
1399
+ // ownerDeptId/createdTime/modifier/modifiedTime/workflowInstanceId/
1400
+ // sequenceNo/sequenceStatus/ownerDeptQueryCode/version)——真机 1.1.25
1401
+ // 逐列实证 createdTime/name/id/sequenceNo 均可排;它们都是物理列,不是
1402
+ // 元数据特例。只放 createdTime/modifiedTime 会把合法排序误拒。
1403
+ const ORDERABLE_SYSTEM_FIELDS = new Set([
1404
+ "id", "name", "creater", "createdDeptId", "owner", "ownerDeptId", "createdTime",
1405
+ "modifier", "modifiedTime", "workflowInstanceId", "sequenceNo", "sequenceStatus",
1406
+ "ownerDeptQueryCode", "version",
1407
+ ]);
1408
+ const catalog = await publishedFields();
1409
+ const codes = catalog.map((row) => row.code);
1410
+ const missing = [...new Set(orderBy.map((entry) => entry.field))].filter((field) => !ORDERABLE_SYSTEM_FIELDS.has(field) && !codes.includes(field));
1411
+ if (missing.length > 0)
1412
+ return {
1413
+ status: "refused",
1414
+ blocker: "unsupported-order-field",
1415
+ schemaCode: args.schemaCode,
1416
+ fields: missing,
1417
+ ...(catalog.length > 0 && catalog.length <= FILTER_FIELD_SAMPLE_LIMIT ? { acceptedValues: { "orderBy.field": [...ORDERABLE_SYSTEM_FIELDS, ...codes] } } : {}),
1418
+ message: `排序字段不在可排面:${missing.join("、")}(可排 = 已发布字段 + 系统列,如 createdTime/modifiedTime/name/id/sequenceNo)。` +
1419
+ `平台对未知排序列回 40000「调用数据库发生异常」(真机实证:no_such_col DESC → 40000),与数据库真故障同码——写前拒绝免歧义。` +
1420
+ `排序形状:orderBy:[{"field":"modifiedTime","direction":"desc"}],多键按数组序优先。`,
1421
+ ...(catalog.length > 0 ? { nextCommand: `omc call field.list --env <env> --args '{"schemaCode":"${args.schemaCode}","published":true}'` } : {}),
1422
+ };
1423
+ wireOrders = orderBy.map((entry) => ({ propertyCode: entry.field, dir: entry.direction === "desc" ? "DESC" : "ASC" }));
1356
1424
  }
1357
1425
  // r29b F9: fields 是 displayFields/columns 的同义别名(与 data.load 对齐)。
1358
1426
  const requestedFields = args.displayFields ?? args.columns ?? args.fields;
@@ -1367,6 +1435,7 @@ export function registerRuntimeDataLane(tools) {
1367
1435
  queryVersion: 1,
1368
1436
  showTotal: args.showTotal !== false,
1369
1437
  ...(condition !== undefined ? { queryCondition: condition } : {}),
1438
+ ...(wireOrders !== undefined ? { orders: wireOrders } : {}),
1370
1439
  };
1371
1440
  // An empty model answers with a business error (301005) on this face;
1372
1441
  // that is "no data yet", not a query failure.
@@ -1524,7 +1593,25 @@ export function registerRuntimeDataLane(tools) {
1524
1593
  // 不改判定的排查提示——子表/子表 schema 的过滤与系统字段过滤是这个面
1525
1594
  // 最常见的"服务异常"来源(live: 子表 schema 加 parentId 过滤 → 50000,
1526
1595
  // 去掉 filter 就正常)。只加 hint,不猜 blocker。
1596
+ // r86(retro issue 15):rawCondition 路径无法写前预判(点号形状合法),
1597
+ // 50000 后补读一次 get_all parentCode——确认是子表 schema 就把该形状
1598
+ // 重写为结构化 blocker(平台原文进 detail,不吞),否则维持原样抛出。
1527
1599
  if (error instanceof WireError && error.kind === "business" && error.errcode === 50000) {
1600
+ if (condition !== undefined) {
1601
+ const parentCodeOn50000 = await subtableParentCodeOf(session, args.schemaCode);
1602
+ if (parentCodeOn50000 !== undefined)
1603
+ return {
1604
+ status: "refused",
1605
+ blocker: "unsupported-filter-on-subtable",
1606
+ schemaCode: args.schemaCode,
1607
+ parentSchema: parentCodeOn50000,
1608
+ rawCondition: true,
1609
+ detail: `平台原文:errcode 50000 ${error.message}`,
1610
+ message: `${args.schemaCode} 是子表模型(父模型 ${parentCodeOn50000}),本次查询带了 rawCondition——运行面 query/list 的过滤叶子按**父模型**解析,裸子表字段(含 parentId)会回 50000「服务异常」。` +
1611
+ `合法 wire 形状只有点号「<子表code>.<字段>」(真机实证 errcode 0);或改 data.load 读父模型记录后看子表数组。若 rawCondition 里已经全是点号字段仍 50000,按真服务异常排查(平台原文见 detail)。`,
1612
+ nextCommand: `omc call data.load --env <env> --args '{"schemaCode":"${parentCodeOn50000}","bizObjectId":"<主表 bizObjectId>"}' --jq 'data.${args.schemaCode}'`,
1613
+ };
1614
+ }
1528
1615
  throw new WireError(error.kind, error.message, error.errcode, error.diagnostic, `若 filter/filters 里含子表字段或子表自身 schema 的 parentId 等系统字段:运行面 query/list 的标量过滤不适用于子表,去掉 filter 后按主表 id 用 data.load 读子表行。其余情况按真服务异常处理(同一 schemaCode 去掉 filter 可读即说明是过滤形状问题)。`);
1529
1616
  }
1530
1617
  throw error;
@@ -312,8 +312,13 @@ export const PATH_MISS_HINT = `路径未命中(这一层没有该段)。${RE
312
312
  * `artifact get` 面:产物内容的投影。区别只在开头——它已经把 miss 落在哪一段
313
313
  * (`missedAt`)和可用的键/范围一并返回,所以不必重复「这一层没有该段」。
314
314
  */
315
- export function artifactPathMissHint(at) {
316
- return `路径未命中${at !== undefined ? `段 "${at}"` : "(这一层没有该段)"}——available 是该层真实存在的键/范围;方括号下标(a[0])与点式(a.0)等价;想一次拿全部顶层键:--keys(或裸 --jq)。${JQ_PATH_SYNTAX}${JQ_PATH_RULES}${JQ_PATH_HELP_POINTER}`;
315
+ export function artifactPathMissHint(at, copyable) {
316
+ const lead = `路径未命中${at !== undefined ? `段 "${at}"` : "(这一层没有该段)"}`;
317
+ // issue 19:命中同名键时先给可整段复制的完整路径(相对产物正文)。
318
+ if (copyable !== undefined) {
319
+ return `${lead}。${copyable}。想一次拿全部顶层键:--keys(或裸 --jq)。${JQ_PATH_SYNTAX}${JQ_PATH_RULES}${JQ_PATH_HELP_POINTER}`;
320
+ }
321
+ return `${lead}——available 是该层真实存在的键/范围;方括号下标(a[0])与点式(a.0)等价;想一次拿全部顶层键:--keys(或裸 --jq)。${JQ_PATH_SYNTAX}${JQ_PATH_RULES}${JQ_PATH_HELP_POINTER}`;
317
322
  }
318
323
  /** 逗号多路径里只有部分 miss:给出定位方式 + 同一套语法。 */
319
324
  export function partialPathMissHint() {
@@ -376,6 +381,106 @@ export function pathMissDidYouMean(at, available, availableAll) {
376
381
  const alias = PATH_KEY_ALIASES[leaf.toLowerCase()];
377
382
  return alias !== undefined && keys.includes(alias) ? alias : undefined;
378
383
  }
384
+ /**
385
+ * Issue 19(retro 2026-11-19):`workflow.get_published` 的 activities 在
386
+ * `data.activities`,但 pathMiss hint 只会说「这一层没有该段 / 它在 result
387
+ * 顶层(只是不在 artifact 副本里)」——描述性指引让人再猜 2–3 次。
388
+ *
389
+ * 这里在**真实结果树**里找同名的键,拼出可整段复制的完整路径:
390
+ * `activities[].bizActions` → `data.activities[].bizActions`。多个位置就列
391
+ * 全部(≤3 条)让调用方自己选;找不到/都解析不通就返回 undefined,由原
392
+ * hint 兜底(不编造路径)。
393
+ */
394
+ const COPYABLE_SCAN_MAX_NODES = 4000;
395
+ const COPYABLE_MAX_CANDIDATES = 24;
396
+ function escapeRegExp(text) {
397
+ return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
398
+ }
399
+ /** 收集 source 里键名恰为 leaf 的所有路径;数组层记作 `[]`(与 DSL 同形)。 */
400
+ function collectKeyPaths(source, leaf) {
401
+ const found = [];
402
+ let visited = 0;
403
+ const walk = (node, prefix, depth) => {
404
+ if (found.length >= COPYABLE_MAX_CANDIDATES || visited > COPYABLE_SCAN_MAX_NODES || depth > 8)
405
+ return;
406
+ if (Array.isArray(node)) {
407
+ const arrayPrefix = prefix === "" ? "" : `${prefix}[]`;
408
+ for (const entry of node.slice(0, 25)) {
409
+ visited += 1;
410
+ walk(entry, arrayPrefix, depth + 1);
411
+ if (found.length >= COPYABLE_MAX_CANDIDATES)
412
+ return;
413
+ }
414
+ return;
415
+ }
416
+ if (node === null || typeof node !== "object")
417
+ return;
418
+ for (const [key, child] of Object.entries(node)) {
419
+ visited += 1;
420
+ const next = prefix === "" ? key : `${prefix}.${key}`;
421
+ if (key === leaf)
422
+ found.push(next);
423
+ walk(child, next, depth + 1);
424
+ if (found.length >= COPYABLE_MAX_CANDIDATES)
425
+ return;
426
+ }
427
+ };
428
+ walk(source, "", 0);
429
+ return found;
430
+ }
431
+ /** path 里 leaf 之后的部分(含 `[]` / `.` 分隔符)。 */
432
+ function suffixAfterLeaf(path, leaf) {
433
+ const matcher = new RegExp(`(?:^|[.\\[])${escapeRegExp(leaf)}(?=$|[.\\[\\]])`, "gu");
434
+ let last;
435
+ let match;
436
+ while ((match = matcher.exec(path)) !== null)
437
+ last = match;
438
+ if (last === undefined)
439
+ return undefined;
440
+ return path.slice(last.index + last[0].length);
441
+ }
442
+ function copyableCandidateResolves(source, candidate) {
443
+ return candidate.includes("[]")
444
+ ? !projectJsonPathFanout(source, candidate).missed
445
+ : !projectJsonPath(source, candidate).missed;
446
+ }
447
+ /** 可复制的完整路径(已验证在 source 上命中;去重,≤limit 条)。 */
448
+ export function pathMissCopyablePaths(source, path, at, limit = 3) {
449
+ if (at === undefined || at.length === 0)
450
+ return [];
451
+ const cleanPath = path.replace(/^\$\.?/, "").replace(/^[.\/]+/, "");
452
+ const leaf = at.replace(/^[.\/]+/, "").split(/[./\[]/).filter(Boolean).pop();
453
+ if (leaf === undefined || leaf.length === 0)
454
+ return [];
455
+ const suffix = suffixAfterLeaf(cleanPath, leaf);
456
+ if (suffix === undefined)
457
+ return [];
458
+ const candidates = [];
459
+ for (const prefix of collectKeyPaths(source, leaf)) {
460
+ const candidate = `${prefix}${suffix}`;
461
+ if (candidate === cleanPath || candidates.includes(candidate))
462
+ continue;
463
+ if (!copyableCandidateResolves(source, candidate))
464
+ continue;
465
+ candidates.push(candidate);
466
+ if (candidates.length >= limit)
467
+ break;
468
+ }
469
+ return candidates;
470
+ }
471
+ /**
472
+ * pathMiss hint 的「可复制路径」句。有命中就**先给命令**(而不是描述它在
473
+ * 哪);多个位置列前 3 条;没有命中返回 undefined(原 hint 原样兜底)。
474
+ */
475
+ export function pathMissCopyableHint(source, path, at, limit = 3) {
476
+ const shown = pathMissCopyablePaths(source, path, at, limit);
477
+ if (shown.length === 0)
478
+ return undefined;
479
+ const quoted = shown.map((candidate) => `--jq '${candidate.replace(/'/g, "'\\''")}'`).join(";");
480
+ if (shown.length === 1)
481
+ return `这段的完整路径是 ${shown[0]}——可直接复制:${quoted}`;
482
+ return `这段有多个位置——可直接复制其一:${quoted}`;
483
+ }
379
484
  /**
380
485
  * 多路径一次投影时的**唯一一份**语法说明(放结果顶层,不再逐条复制)。
381
486
  * 只给最要紧的三条:位置语义、映射写法、help 指针。
@@ -594,25 +699,32 @@ export function projectResultExtract(result, paths, keysOnly) {
594
699
  const missHintFor = (path, at, available, availableAll) => {
595
700
  const fallback = multiPath ? pathMissEntryHint(at, available) : PATH_MISS_HINT;
596
701
  const candidate = pathMissDidYouMean(at, available, availableAll);
597
- if (candidate === undefined || at === undefined)
598
- return fallback;
599
- // Replace only the missed segment, retaining array mapping and suffixes.
600
- const leaf = at.split(/[./\[]/).filter(Boolean).pop();
601
- if (leaf === undefined)
602
- return fallback;
603
- let replaced = false;
604
- const corrected = path.replace(/[^.[\]/]+/g, (segment, offset) => {
605
- const prefix = path.slice(0, offset + segment.length).replace(/^[.$/]+/, "");
606
- if (replaced || segment !== leaf || (at !== leaf && prefix !== at))
607
- return segment;
608
- replaced = true;
609
- return candidate;
610
- });
611
- // A similar key is useful only if the complete proposed path resolves.
612
- if (corrected === path || projectPathOnSource(projectionSource, corrected).projected.missed)
613
- return fallback;
614
- const quoted = corrected.replace(/'/g, "'\\''");
615
- return `路径未命中:在 "${at}" 断开;最接近的是 ${candidate}。可试:--jq '${quoted}'`;
702
+ if (candidate !== undefined && at !== undefined) {
703
+ // Replace only the missed segment, retaining array mapping and suffixes.
704
+ const leaf = at.split(/[./\[]/).filter(Boolean).pop();
705
+ if (leaf !== undefined) {
706
+ let replaced = false;
707
+ const corrected = path.replace(/[^.[\]/]+/g, (segment, offset) => {
708
+ const prefix = path.slice(0, offset + segment.length).replace(/^[.$/]+/, "");
709
+ if (replaced || segment !== leaf || (at !== leaf && prefix !== at))
710
+ return segment;
711
+ replaced = true;
712
+ return candidate;
713
+ });
714
+ // A similar key is useful only if the complete proposed path resolves.
715
+ if (corrected !== path && !projectPathOnSource(projectionSource, corrected).projected.missed) {
716
+ const quoted = corrected.replace(/'/g, "'\\''");
717
+ return `路径未命中:在 "${at}" 断开;最接近的是 ${candidate}。可试:--jq '${quoted}'`;
718
+ }
719
+ }
720
+ }
721
+ // issue 19:没有拼写近似时,在真实结果树里找同名键,直接给可复制的完整
722
+ // 路径(如 data.activities[].bizActions)——不再只描述「它在哪一层」。
723
+ const copyable = pathMissCopyableHint(projectionSource, path, at);
724
+ if (copyable !== undefined) {
725
+ return multiPath ? `${copyable}。${pathMissEntryHint(at, available)}` : `${copyable}。${RESULT_RELATIVE_PATH_NOTE}`;
726
+ }
727
+ return fallback;
616
728
  };
617
729
  out.extract = paths.map((path) => {
618
730
  // r28f F2:对象构造 / 函数调用不是 pathMiss——先识别,别伪装成键缺失。
@@ -12,11 +12,12 @@
12
12
  const READ_SHAPES = {
13
13
  // r28k 治理面形状钉:截断≠空表;指纹有用途;doctor/get_status 分流。
14
14
  "discover_environment": {
15
- keys: ["applications:array<{code,name,groupId?,portalHidden?}>", "applicationsCount", "groups", "groupsCount", "foldersAndModels?", "foldersAndModelsCount?", "foldersAndModelsOmitted?", "models?", "modelsCount?", "modelsOmitted?", "tablesHint?", "applicationCode", "applicationResolution", "readiness", "detectedVersion", "inAnchorFamily", "versionSource", "versionFamily", "anchorVersion", "versionNotice?", "environmentFingerprint", "fingerprintHint?", "detailArtifactId?"],
15
+ keys: ["applications:array<{code,name,groupId?,portalHidden?}>", "applicationsCount", "groups", "groupsCount", "foldersAndModels?", "foldersAndModelsCount?", "foldersAndModelsOmitted?", "models?", "modelsCount?", "modelsOmitted?", "tablesHint?", "applicationCode", "applicationResolution", "readiness", "detectedVersion", "inAnchorFamily", "versionSource", "versionFamily", "anchorVersion", "versionNotice?", "environmentFingerprint", "fingerprintHint?", "platform:{productVersion,buildTime?,licenseType?,licenseExpiration?,source,licenseFaceUnavailable?,extensionBuildShaUnavailable?}|{versionUnavailable}", "detailArtifactId?"],
16
16
  notes: [
17
17
  "applications/groups 内联;foldersAndModels/models 外置时是 null + *Omitted:true(不是 [])",
18
18
  "environmentFingerprint 用途见 fingerprintHint(写前漂移/计划绑定/读缓存键,非审批令牌)",
19
19
  "detectedVersion/inAnchorFamily/versionSource 与 doctor/fingerprint 同源",
20
+ "platform.productVersion 是原始版本串(如 AI-Platform-v1.1.25);buildTime 只有平台回传才有(8.6.26 info() 从不赋值)、扩展 build sha 无端点(extensionBuildShaUnavailable)",
20
21
  ],
21
22
  },
22
23
  "environment.fingerprint": {
@@ -115,7 +115,7 @@ const FIX_FIRST_GATES = Object.freeze({
115
115
  "workflow-start-permission-denied": "40009 有三个独立同码原因:① 发起人角色没挂该流程的发起权限(ouScope ∩ 发起人部门链,全空会静默回退发起人);② 流程未启用/未发布;③ 模型未绑定流程。先 omc call workflow.permissions / workflow.get_published 核对;管理员发起成功带 bypassReason 时不证明白名单生效——换非管理员环境验证。不要反复换参数重试 data.submit",
116
116
  "workflow-bound-to-listview": "303024 列表绑定了流程:直接粘贴回执 nextCommand(listview.configure:actions:[] + replaceActions:true + 现成 fieldCodes)解绑,再 workflow.delete;整体清理用 model-purge",
117
117
  "workflow-start-permission-empty": "发起权限表为空:除平台管理员外无人能发起。用 workflow.addPermission 授给部门/角色/用户;管理员 data.submit 成功不证明白名单生效",
118
- "environment-write-disabled": "当前环境 profile 不可写:换可写环境,或让维护者在配置里开 writable——CLI 侧没有绕过开关",
118
+ "environment-write-disabled": "当前环境 profile 不可写:换可写环境;临时改一次配置用 `omc env writable <env> --ttl 10m --reason \"...\"`(有审计、到期自动恢复只读),`omc env writable <env> --close` 立即恢复——窗口只解除 writable 门,生产写仍需每笔 confirmProduction:true(两道门并存)",
119
119
  "production-confirmation-required": "生产环境的写需要显式 confirmProduction:true——确认这次写入真的要落生产再加该参数,不要靠重试",
120
120
  "app-not-published": "目标应用未发布:先 workflow/form/field 各面发布(或 app 级发布),再重试运行面操作",
121
121
  "submit-workitem-not-mine": "该 workItem 不在当前登录人的待办里:用 omc call workitem.list --args '{\"status\":\"PENDING\"}' 拿**自己的** workItemId,不要用别人的 id 提交",
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import { wireCall, wireRows, WireError } from "./wire.js";
2
+ import { wireCall, wireCallWith404Fallback, wireRows, WireError } from "./wire.js";
3
3
  import { ENDPOINTS } from "./endpoints.js";
4
4
  import { readModelRecord } from "./model-record.js";
5
5
  import { ToolRefusalError } from "./tool-types.js";
@@ -1408,6 +1408,73 @@ export async function lintRuleSaveWrite(session, args) {
1408
1408
  ...(mappingPreflight.absent !== undefined ? { absentMappingFields: mappingPreflight.absent } : {}),
1409
1409
  };
1410
1410
  }
1411
+ async function verifyRulePublish(session, schemaCode, ruleCode, publishResponse) {
1412
+ const verifyWire = "发布后经 runtime/business_rule/list_by_schemacode 读回验证(+1 wire,替换原先读不到发布事实的 app/DRAFT 面读回——app 面只投影 DRAFT 行,读它验证不了发布)";
1413
+ const responseVersion = publishResponse !== null && typeof publishResponse.ruleVersion === "number" ? publishResponse.ruleVersion : undefined;
1414
+ let rows;
1415
+ try {
1416
+ rows = wireRows((await wireCallWith404Fallback(session, [
1417
+ { path: ENDPOINTS.runtimeBusinessRuleListBySchemaCode, query: { schemaCode } },
1418
+ { path: ENDPOINTS.businessRuleListBySchemaCode, query: { schemaCode } },
1419
+ ])).data);
1420
+ }
1421
+ catch (error) {
1422
+ // 读回异常:发布请求本身已成功(wireCall errcode 0 才走到这里),验证失败 ≠ 未发布。
1423
+ return {
1424
+ publishedVerified: false,
1425
+ latestPublished: false,
1426
+ detail: {
1427
+ verifyWire,
1428
+ verifyFailed: "read-error",
1429
+ verifyError: error instanceof Error ? error.message.slice(0, 200) : String(error).slice(0, 200),
1430
+ verifyNote: "发布请求已成功(performed.errcode 0),但发布后读回验证读失败——不要据此重复 save(会造新记录);用 rule.list 复核 latestPublished/ruleVersion",
1431
+ nextCommand: `omc call rule.list --args '${JSON.stringify({ schemaCode })}' --env <env>(读 latestPublished/ruleVersion 复核发布)`,
1432
+ },
1433
+ };
1434
+ }
1435
+ const publishedRow = rows.find((row) => row.code === ruleCode && row.latestPublished === true);
1436
+ if (publishedRow !== undefined) {
1437
+ const listedVersion = typeof publishedRow.ruleVersion === "number" ? publishedRow.ruleVersion : undefined;
1438
+ const version = listedVersion ?? responseVersion ?? null;
1439
+ return {
1440
+ publishedVerified: true,
1441
+ verifiedBy: "published-list",
1442
+ ruleVersion: version,
1443
+ latestPublished: true,
1444
+ detail: {
1445
+ verifyWire,
1446
+ ...(listedVersion !== undefined && responseVersion !== undefined && listedVersion !== responseVersion
1447
+ ? { versionMismatchNote: `列表验证版本 ${listedVersion} ≠ 发布响应版本 ${responseVersion}(以列表为准——发布响应是 DRAFT 行模型 + facade 回填的版本号)` }
1448
+ : {}),
1449
+ },
1450
+ };
1451
+ }
1452
+ if (responseVersion !== undefined) {
1453
+ // 列表读不到但发布响应带了新版本号:runtime 面按 DRAFT 行 enabled 过滤
1454
+ // (草稿未启用则 PUBLISH 行不出现),或 8.1 族 runtime 面缺席下探到的 app 面
1455
+ // 只回 DRAFT 行——发布本身有服务端同步证据。
1456
+ return {
1457
+ publishedVerified: true,
1458
+ verifiedBy: "publish-response",
1459
+ ruleVersion: responseVersion,
1460
+ latestPublished: false,
1461
+ detail: {
1462
+ verifyWire,
1463
+ latestPublishedUncheckedNote: "发布响应已带新 ruleVersion(facade 同步铸 PUBLISH 行的证据),但列表面读不到 latestPublished 行——runtime 面按 DRAFT 行 enabled 过滤(未启用则不显示)或本版本族走的是 app/DRAFT 面。latestPublished 未经列表证实,故不给该键",
1464
+ },
1465
+ };
1466
+ }
1467
+ return {
1468
+ publishedVerified: false,
1469
+ latestPublished: false,
1470
+ detail: {
1471
+ verifyWire,
1472
+ verifyFailed: "not-visible",
1473
+ verifyNote: "发布请求已发出,但列表面与发布响应都没给出可验证的版本证据(可能仍在传播或该版本族的发布响应不带 ruleVersion)——不要据此重复 save;用 rule.list 复核",
1474
+ nextCommand: `omc call rule.list --args '${JSON.stringify({ schemaCode })}' --env <env>(读 latestPublished/ruleVersion 复核发布)`,
1475
+ },
1476
+ };
1477
+ }
1411
1478
  export async function executeRuleSaveWrite(session, args) {
1412
1479
  // 与 dry-run 同源:同一套只读门先跑,然后才写。
1413
1480
  const { lintWarnings, lintHazards, bizMethodChecks, existing, customTriggerApplied, isPresetRule, bizRuleType, nodeJson, routeJson, schedulerField, schedulerSetting, nodes, routesSource, emptyMappings, preservedDesignerText, designerTextOverwritten, mappingFieldChecks, absentMappingFields, } = await lintRuleSaveWrite(session, args);
@@ -1461,6 +1528,14 @@ export async function executeRuleSaveWrite(session, args) {
1461
1528
  const currentLintWarnings = lintWarnings.filter((warning) => warning.nodeCode === undefined || graphNodeCodes.has(warning.nodeCode) || warning.code === "rule-graph-system-node-tool-owned");
1462
1529
  if (args.publish === true) {
1463
1530
  const row = await currentRow();
1531
+ // Publish-response evidence (r86 issue 14): the platform's publish answer is
1532
+ // itself synchronous proof — the facade mints the PUBLISH row inside a lock
1533
+ // (templateType=PUBLISH, latestPublished=TRUE, ruleVersion=max+1, status
1534
+ // ENABLED) and RETURNS the model with the minted ruleVersion
1535
+ // (BusinessRuleFacadeImpl.publishBusinessRule:337-352 →
1536
+ // BusinessRuleServiceImpl.publish:483-536). Keep the body; verification
1537
+ // falls back to it when the list face cannot show the row.
1538
+ let publishResponse = null;
1464
1539
  if (row?.id) {
1465
1540
  // Publish the FULL model, not the list-projection row: `list_by_schemacode`
1466
1541
  // omits `node`/`route`/`schedulerSetting`, so publishing it drops the
@@ -1468,7 +1543,8 @@ export async function executeRuleSaveWrite(session, args) {
1468
1543
  // the authoritative `businessrule/get?id` model (same as rule.get/enable).
1469
1544
  const full = (await wireCall(session, { path: ENDPOINTS.businessRuleGet, query: { id: String(row.id) } })).data;
1470
1545
  try {
1471
- await wireCall(session, { path: ENDPOINTS.businessRulePublish, method: "POST", body: full ?? row });
1546
+ const publishedCall = await wireCall(session, { path: ENDPOINTS.businessRulePublish, method: "POST", body: full ?? row });
1547
+ publishResponse = (publishedCall.data ?? null);
1472
1548
  }
1473
1549
  catch (error) {
1474
1550
  if (error instanceof WireError && error.errcode === RULE_SELF_CHECK_ERRCODE) {
@@ -1485,15 +1561,20 @@ export async function executeRuleSaveWrite(session, args) {
1485
1561
  throw error;
1486
1562
  }
1487
1563
  }
1488
- const effective = await currentRow();
1489
- // Live 8.6.26 (2026-09-17): businessrule/publish mints a version but does
1490
- // NOT flip a publish marker that this readback can see — the working row
1491
- // keeps templateType DRAFT and the list projection reports
1492
- // latestPublished:false even for the platform's own ENABLED presets. So
1493
- // `published` must be DERIVED from the effective row, never assumed; a
1494
- // hardcoded true made a draft rule look live and a workflow end-event
1495
- // binding on it was silently dead. Liveness itself is `rule.enable`.
1496
- const published = effective?.status === "ENABLED" || effective?.latestPublished === true || effective?.templateType === "PUBLISH";
1564
+ // r86(retro issue 14):发布后必须用「能看见 PUBLISH 行的面」验证。旧的
1565
+ // currentRow() 走 app 面 list_by_schemacode,而平台用 **DRAFT 行**服务它
1566
+ // (BusinessRuleController.list → listViewsBySchemaCode →
1567
+ // listDraftBySchemaCode,BusinessRuleFacadeImpl.java:143-150 /
1568
+ // BusinessRuleServiceImpl.java:175-177)——DRAFT 行结构上不可能携带
1569
+ // latestPublished,于是发布成功后回执仍报 latestPublished:false /
1570
+ // ruleVersion:null(retro 实证:紧接着 rule.list 却读到 latestPublished:true、
1571
+ // ruleVersion:4),agent 以为没发布成功而重复 save,每次都铸造新规则记录 ID。
1572
+ // runtime 面 list_by_schemacode 才投影 PUBLISH 行
1573
+ // (BusinessRuleRuntimeController.java:71-77 → listLatestRulesBySchemaCode),
1574
+ // 与 rule.list 同源;发布后经它读回验证(+1 wire),列表读不到时回落发布
1575
+ // 响应体的 ruleVersion。绝不把「验证不了」谎报成 latestPublished:false。
1576
+ const verification = await verifyRulePublish(session, args.schemaCode, args.ruleCode, publishResponse);
1577
+ const published = verification.publishedVerified;
1497
1578
  const effectiveNow = published && enabled;
1498
1579
  const effectiveBasis = effectiveNow ? "本次图已发布且规则 enabled:true,当前运行面可用" : "本次图未同时满足 publish + enabled;仍需 rule.enable 才是当前运行图";
1499
1580
  const previousRuleVersion = existing?.ruleVersion;
@@ -1502,8 +1583,16 @@ export async function executeRuleSaveWrite(session, args) {
1502
1583
  readback: {
1503
1584
  rulePresent: true,
1504
1585
  published,
1586
+ // r86 issue 14:publishedVerified/verifiedBy 是发布成败的判定键;ruleVersion
1587
+ // 只报验证过的版本(列表验证值优先,回落发布响应值)。latestPublished 仅在
1588
+ // 列表验证成立时出现,否则 latestPublishedUnchecked——不再谎报 false。
1589
+ publishedVerified: verification.publishedVerified,
1590
+ ...(verification.verifiedBy !== undefined ? { verifiedBy: verification.verifiedBy } : {}),
1591
+ ...(verification.ruleVersion !== undefined ? { ruleVersion: verification.ruleVersion } : {}),
1592
+ ...(verification.latestPublished === true ? { latestPublished: true } : { latestPublishedUnchecked: true }),
1593
+ ...verification.detail,
1505
1594
  enabled,
1506
- status: effective?.status,
1595
+ status: row?.status,
1507
1596
  ...(currentLintWarnings.length > 0 ? { lintWarnings: currentLintWarnings } : {}),
1508
1597
  ...(lintHazards.length > 0 ? { lintHazards } : {}),
1509
1598
  customTrigger: customTriggerApplied,
@@ -1516,15 +1605,16 @@ export async function executeRuleSaveWrite(session, args) {
1516
1605
  executableRequires: "rule.enable",
1517
1606
  executableHint: "publish 只写 PUBLISH 行,不等于可执行:运行时按 DRAFT 行的 enabled + status 判定(BusinessRuleTableImpl#getExecutableBySchemaCodeAndCode),而 list 面显示的是 PUBLISH 行。用 rule.run / domain_service_runtime 前先 rule.enable(它 publish 后再调平台 /enable,把 DRAFT 行 status 置 ENABLED)。",
1518
1607
  ...(customTriggerApplied ? {} : { customTriggerHint: "图中没有 CUSTOM_NODE 触发节点:门户按钮/流程按钮调用该规则时会按各自的触发面执行;rule.run 也能执行(它不要求 CUSTOM_NODE),执行时以 BUTTON 触发类型跑同一张图" }),
1519
- id: effective?.id ?? undefined,
1520
- ruleVersion: effective?.ruleVersion,
1608
+ id: row?.id ?? undefined,
1521
1609
  previousRuleVersion,
1522
1610
  effectiveNow,
1523
1611
  effectiveBasis,
1524
- latestPublished: effective?.latestPublished,
1525
1612
  ...r85Readback,
1526
1613
  ...(await modelWorkflowDispatchWarning(session, args.schemaCode)),
1527
1614
  ...(existing?.id ? { versionNote } : {}),
1615
+ // r86 issue 14:防重复保存警示——看错 latestPublished 而重复 save 的代价是
1616
+ // 每次都铸造新规则记录 ID(同 code 旧行仍可读,见 versionNote)。
1617
+ repeatSaveWarning: `发布是否成功看 publishedVerified(本次 ${verification.publishedVerified ? `verifiedBy:${verification.verifiedBy}` : "未验证通过"});同一 ruleCode 每次保存都会造新规则记录 ID,不要因 latestPublished 缺席/未验证而重复 save`,
1528
1618
  ...(enabled ? {} : { nextAction: "rule.enable(businessrule/publish + businessrule/enable 两步)后规则才会分发并对流程/按钮可见;publish:true 只写入版本" }),
1529
1619
  },
1530
1620
  };
package/dist/session.js CHANGED
@@ -21,6 +21,8 @@ export class CloudPivotSession {
21
21
  tokenCache;
22
22
  loginResult;
23
23
  version;
24
+ /** r86(retro issue 17):原始版本串("AI-Platform-v1.1.25" 这类含产品线前缀的完整值)。 */
25
+ rawVersion;
24
26
  /**
25
27
  * Non-fatal login caveats (e.g. the `client` blob in system/config was
26
28
  * absent or unreadable, so the token request carried no client_secret).
@@ -67,6 +69,8 @@ export class CloudPivotSession {
67
69
  };
68
70
  if (cached.version !== undefined) {
69
71
  this.version = cached.version;
72
+ if (cached.rawVersion !== undefined)
73
+ this.rawVersion = cached.rawVersion;
70
74
  }
71
75
  else {
72
76
  // Legacy cache written while version evidence was unavailable: probe the
@@ -77,6 +81,7 @@ export class CloudPivotSession {
77
81
  .fetchCloudPivotSystemConfig(this.profile.baseUrl, undefined, fetch, core.cloudPivotTenantHeaders(this.profile.engineCode))
78
82
  .catch(() => undefined);
79
83
  this.version = detectVersion(systemConfig);
84
+ this.rawVersion = detectRawVersion(systemConfig);
80
85
  if (this.version !== undefined) {
81
86
  this.tokenCache?.save({
82
87
  token: cached.token,
@@ -84,6 +89,7 @@ export class CloudPivotSession {
84
89
  administrator: cached.administrator,
85
90
  ...(cached.accountIdentity !== undefined ? { accountIdentity: cached.accountIdentity } : {}),
86
91
  version: this.version,
92
+ ...(this.rawVersion !== undefined ? { rawVersion: this.rawVersion } : {}),
87
93
  });
88
94
  }
89
95
  }
@@ -110,12 +116,14 @@ export class CloudPivotSession {
110
116
  });
111
117
  this.loginNotesValue = authenticator.loginNotes();
112
118
  this.version = detectVersion(systemConfig);
119
+ this.rawVersion = detectRawVersion(systemConfig);
113
120
  this.tokenCache?.save({
114
121
  token: this.loginResult.token,
115
122
  enterpriseId: this.loginResult.enterpriseId,
116
123
  administrator: this.loginResult.administrator,
117
124
  ...(this.loginResult.accountIdentity !== undefined ? { accountIdentity: this.loginResult.accountIdentity } : {}),
118
125
  ...(this.version !== undefined ? { version: this.version } : {}),
126
+ ...(this.rawVersion !== undefined ? { rawVersion: this.rawVersion } : {}),
119
127
  });
120
128
  return this.loginResult;
121
129
  }
@@ -123,6 +131,10 @@ export class CloudPivotSession {
123
131
  detectedVersion() {
124
132
  return this.version;
125
133
  }
134
+ /** r86(retro issue 17):原始版本串(含产品线前缀);无证据返回 undefined。 */
135
+ rawSystemVersion() {
136
+ return this.rawVersion;
137
+ }
126
138
  /** Non-fatal login caveats; empty when the login was fully nominal. */
127
139
  loginNotes() {
128
140
  return this.loginNotesValue;
@@ -176,6 +188,7 @@ export class CloudPivotSession {
176
188
  return first;
177
189
  this.loginResult = undefined;
178
190
  this.version = undefined;
191
+ this.rawVersion = undefined;
179
192
  // The invalidated token must not be re-loaded by the re-login below.
180
193
  this.tokenCache?.clear();
181
194
  return this.send(input);
@@ -226,6 +239,20 @@ function detectVersion(systemConfig) {
226
239
  }
227
240
  return undefined;
228
241
  }
242
+ /**
243
+ * r86(retro issue 17):原始版本键值(如 "AI-Platform-v1.1.25")——detectVersion
244
+ * 只留点号数字段,产品线前缀被丢弃;productVersion 面需要原串(同一 key 优先序)。
245
+ */
246
+ function detectRawVersion(systemConfig) {
247
+ if (!systemConfig)
248
+ return undefined;
249
+ for (const key of ["version", "sysVersion", "systemVersion", "productVersion", "serverVersion"]) {
250
+ const value = systemConfig[key];
251
+ if (typeof value === "string" && value.trim().length > 0)
252
+ return value.trim();
253
+ }
254
+ return undefined;
255
+ }
229
256
  /**
230
257
  * A request that produced no response within the timeout. Without this, a
231
258
  * stalled CloudPivot (e.g. mid-restart) would leave a write hanging forever and