@stalfh233/omc-cli 0.6.79 → 0.6.80
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.
- package/dist/lanes/app-contract.js +2 -2
- package/dist/lanes/b2-registration-contract.js +4 -4
- package/dist/lanes/businessrule.js +402 -121
- package/dist/lanes/field-contract.js +17 -8
- package/dist/lanes/field.js +1 -1
- package/dist/lanes/folder-contract.js +1 -1
- package/dist/lanes/folder.js +1 -1
- package/dist/lanes/form-contract.js +3 -3
- package/dist/lanes/form.js +1 -1
- package/dist/lanes/list-view-contract.js +2 -2
- package/dist/lanes/list-view.js +1 -1
- package/dist/lanes/organization.js +7 -7
- package/dist/lanes/report-contract.js +1 -1
- package/dist/lanes/report.js +1 -1
- package/dist/lanes/workflow-contract.js +4 -1
- package/dist/lanes/workflow.js +1 -1
- package/dist/read-shapes.js +6 -4
- package/dist/read.js +37 -1
- package/dist/recipes/field.js +2 -1
- package/dist/recipes/list-view.js +3 -2
- package/dist/tool-search.js +5 -2
- package/dist/tool-types.js +45 -14
- package/package.json +3 -3
- package/skills/omc-capabilities.md +1 -0
|
@@ -6,7 +6,7 @@ import { writeTool } from "../write.js";
|
|
|
6
6
|
import { decodeJsonColumn, JSON_COLUMN_NULL_COALESCE } from "../json-column.js";
|
|
7
7
|
import { applicationResolutionOf, applicationScopeHint, flattenTreeRows, resolveApplicationScope, suggestModelNames } from "../support.js";
|
|
8
8
|
import { assertRuleNamePlatformAcceptable, executeRuleSaveWrite, lintRuleGraphForWrite, lintRuleSaveWrite, ruleNodeGraphArg } from "../rule-support.js";
|
|
9
|
-
import { defineTool, ToolInputError, ToolRefusalError } from "../tool-types.js";
|
|
9
|
+
import { defineTool, isRequiredAlternativePlaceholder, ToolInputError, ToolRefusalError } from "../tool-types.js";
|
|
10
10
|
import { resolveRuleRowId } from "../identity.js";
|
|
11
11
|
import { wireCall, wireCallWith404Fallback, wireRows } from "../wire.js";
|
|
12
12
|
import { readModelRecord } from "../model-record.js";
|
|
@@ -224,32 +224,110 @@ function ruleSummaryBody(record, graph, roundTrip) {
|
|
|
224
224
|
...(roundTrip ? { roundTrip } : {}),
|
|
225
225
|
};
|
|
226
226
|
}
|
|
227
|
+
/** 规则行的 JSON 字符串列(node/route/schedulerSetting):非串 null 化,坏串原样透传。 */
|
|
228
|
+
const parseRuleColumn = (value) => decodeJsonColumn(value, JSON_COLUMN_NULL_COALESCE);
|
|
227
229
|
/**
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
230
|
+
* r83(R79 二期):BIZ_ACTION 映射的**摘要级**投影——只留定位与方法/入出参计数。
|
|
231
|
+
*
|
|
232
|
+
* `methodMapping` 完整正文(inputMappings/outputMappings)可达 600B+/节点,
|
|
233
|
+
* `rule.list --withMappings` 是清单面,整包内联会把清单变成整图转储;摘要
|
|
234
|
+
* 回答「哪条规则调了哪个服务方法、几个入参几个出参」,取形状仍走 `rule.get`。
|
|
233
235
|
*/
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
236
|
+
function ruleMappingDigests(nodes) {
|
|
237
|
+
if (!Array.isArray(nodes))
|
|
238
|
+
return [];
|
|
239
|
+
const digests = [];
|
|
240
|
+
for (const entry of nodes) {
|
|
241
|
+
if (entry === null || typeof entry !== "object" || Array.isArray(entry))
|
|
242
|
+
continue;
|
|
243
|
+
const node = entry;
|
|
244
|
+
const mapping = node.methodMapping;
|
|
245
|
+
if (mapping === null || typeof mapping !== "object" || Array.isArray(mapping))
|
|
246
|
+
continue;
|
|
247
|
+
const m = mapping;
|
|
248
|
+
digests.push({
|
|
249
|
+
nodeCode: node.nodeCode ?? null,
|
|
250
|
+
serviceCode: m.serviceCode ?? null,
|
|
251
|
+
serviceMethodCode: m.serviceMethodCode ?? null,
|
|
252
|
+
inputCount: Array.isArray(m.inputMappings) ? m.inputMappings.length : 0,
|
|
253
|
+
outputCount: Array.isArray(m.outputMappings) ? m.outputMappings.length : 0,
|
|
242
254
|
});
|
|
243
|
-
|
|
255
|
+
}
|
|
256
|
+
return digests;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* r83:`rule.list --withMappings` 的映射读取。list 行自带 node 时零额外 wire
|
|
260
|
+
* (8.6.26 list 面是完整 BusinessRuleModel);行缺 node 才按 id 回落
|
|
261
|
+
* `businessrule/get`(+1 wire/条),仍读不到则该行标 `mappingsUnavailable`,
|
|
262
|
+
* 绝不把「没读到」写成「没有映射」。
|
|
263
|
+
*/
|
|
264
|
+
async function readRuleListMappings(session, rows) {
|
|
265
|
+
const byCode = new Map();
|
|
266
|
+
let fallbackReads = 0;
|
|
267
|
+
for (const row of rows) {
|
|
268
|
+
const code = typeof row.code === "string" ? row.code : "";
|
|
269
|
+
if (code === "")
|
|
270
|
+
continue;
|
|
271
|
+
if (typeof row.node === "string") {
|
|
272
|
+
byCode.set(code, ruleMappingDigests(parseRuleColumn(row.node)));
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
const id = typeof row.id === "string" && row.id !== "" ? row.id : "";
|
|
276
|
+
if (id === "") {
|
|
277
|
+
byCode.set(code, null);
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
fallbackReads += 1;
|
|
281
|
+
try {
|
|
282
|
+
const fetched = (await wireCall(session, { path: ENDPOINTS.businessRuleGet, query: { id } })).data;
|
|
283
|
+
byCode.set(code, fetched && typeof fetched.node === "string" ? ruleMappingDigests(parseRuleColumn(fetched.node)) : null);
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
byCode.set(code, null);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return { byCode, fallbackReads };
|
|
290
|
+
}
|
|
291
|
+
/** r83:跨模型批量的模型数上限(逐模型 1 探针 + 1 list;超出拒绝并给分批指引)。 */
|
|
292
|
+
const RULE_BATCH_MAX_MODELS = 20;
|
|
293
|
+
/** r83:`schemaCodes[]` 归一(去重/去空)+ 上限门。 */
|
|
294
|
+
function ruleSchemaCodesOf(raw, tool) {
|
|
295
|
+
const unique = [...new Set(raw.map((code) => code.trim()).filter((code) => code !== ""))];
|
|
296
|
+
if (unique.length === 0)
|
|
297
|
+
throw new ToolInputError({ status: "error", blocker: "tool-input-invalid", tool, message: "schemaCodes 为空——至少给一个模型 code" });
|
|
298
|
+
if (unique.length > RULE_BATCH_MAX_MODELS) {
|
|
299
|
+
const chunk = unique.slice(0, RULE_BATCH_MAX_MODELS);
|
|
244
300
|
throw new ToolInputError({
|
|
245
301
|
status: "error",
|
|
246
|
-
blocker: "rule-batch-
|
|
247
|
-
tool
|
|
248
|
-
message:
|
|
249
|
-
nextCommand:
|
|
302
|
+
blocker: "rule-schema-batch-too-large",
|
|
303
|
+
tool,
|
|
304
|
+
message: `schemaCodes 最多 ${RULE_BATCH_MAX_MODELS} 个模型(本次 ${unique.length});超出请分批——回执只覆盖本次传入的模型,不会静默截断`,
|
|
305
|
+
nextCommand: tool === "rule.get"
|
|
306
|
+
? `omc call rule.get --env <env> --args '{"schemaCodes":${JSON.stringify(chunk)},"ruleCodes":["<ruleCode>"],"summary":true}'(再按余下 ${unique.length - RULE_BATCH_MAX_MODELS} 个模型发下一批)`
|
|
307
|
+
: `omc call rule.list --env <env> --args '{"schemaCodes":${JSON.stringify(chunk)}}'(再按余下 ${unique.length - RULE_BATCH_MAX_MODELS} 个模型发下一批)`,
|
|
308
|
+
batching: { limit: RULE_BATCH_MAX_MODELS, given: unique.length, chunks: Math.ceil(unique.length / RULE_BATCH_MAX_MODELS) },
|
|
250
309
|
});
|
|
251
|
-
|
|
252
|
-
|
|
310
|
+
}
|
|
311
|
+
return unique;
|
|
312
|
+
}
|
|
313
|
+
/** r83:`ruleCodes` 批量的 summary 门(单模型/跨模型同一句话)。 */
|
|
314
|
+
function requireRuleBatchSummary(summary, nextCommand) {
|
|
315
|
+
if (summary === true)
|
|
316
|
+
return;
|
|
317
|
+
throw new ToolInputError({
|
|
318
|
+
status: "error",
|
|
319
|
+
blocker: "rule-batch-requires-summary",
|
|
320
|
+
tool: "rule.get",
|
|
321
|
+
message: "ruleCodes 批量读必须同时传 summary:true——逐条内联整图(每条约 13KB)的批量正是本工具要消灭的形状",
|
|
322
|
+
nextCommand,
|
|
323
|
+
});
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* r83:把一个模型的 list 行解析成摘要体(同模型 ruleCodes 批量的内核)。
|
|
327
|
+
* 拆出来是为了让单模型 `readRuleBatch` 与跨模型 `schemaCodes[]` 共用同一套
|
|
328
|
+
* 「缺 node 回落 get / 单条缺失不连坐」的读取语义,而不是两份实现。
|
|
329
|
+
*/
|
|
330
|
+
async function summarizeRuleRows(session, rows, ruleCodes) {
|
|
253
331
|
const byCode = new Map();
|
|
254
332
|
for (const row of rows)
|
|
255
333
|
if (typeof row.code === "string" && row.code !== "")
|
|
@@ -257,16 +335,16 @@ async function readRuleBatch(session, args) {
|
|
|
257
335
|
const rules = [];
|
|
258
336
|
const failed = [];
|
|
259
337
|
let fallbackReads = 0;
|
|
260
|
-
for (const code of
|
|
338
|
+
for (const code of ruleCodes) {
|
|
261
339
|
let record = byCode.get(code);
|
|
262
340
|
// 部分 code 不存在:其余照常,failed 逐条点名(不把「没有这条规则」读成「没有方法映射」)。
|
|
263
341
|
if (!record) {
|
|
264
342
|
failed.push({ code, reason: "rule-absent" });
|
|
265
343
|
continue;
|
|
266
344
|
}
|
|
267
|
-
let nodes =
|
|
268
|
-
let routes =
|
|
269
|
-
let schedulerSetting =
|
|
345
|
+
let nodes = parseRuleColumn(record.node);
|
|
346
|
+
let routes = parseRuleColumn(record.route);
|
|
347
|
+
let schedulerSetting = parseRuleColumn(record.schedulerSetting);
|
|
270
348
|
if (typeof record.node !== "string") {
|
|
271
349
|
// 运行时逐行校验:该版本/该行 list 面没带 node 时回落 get(+1 wire),
|
|
272
350
|
// 回执 wireNote 会点名;仍读不到图才进 failed。
|
|
@@ -282,13 +360,37 @@ async function readRuleBatch(session, args) {
|
|
|
282
360
|
continue;
|
|
283
361
|
}
|
|
284
362
|
record = fetched;
|
|
285
|
-
nodes =
|
|
286
|
-
routes =
|
|
287
|
-
schedulerSetting =
|
|
363
|
+
nodes = parseRuleColumn(fetched.node);
|
|
364
|
+
routes = parseRuleColumn(fetched.route);
|
|
365
|
+
schedulerSetting = parseRuleColumn(fetched.schedulerSetting);
|
|
288
366
|
}
|
|
289
367
|
const lint = await lintRuleGraphFace(record, { nodes, routes, schedulerSetting });
|
|
290
368
|
rules.push(ruleSummaryBody(record, { nodes, routes, schedulerSetting }, ruleSummaryRoundTrip(lint.roundTrip)));
|
|
291
369
|
}
|
|
370
|
+
return { rules, failed, fallbackReads };
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* r79-w2b(issue 06):`ruleCodes[]` 同模型批量摘要。一次
|
|
374
|
+
* `list_by_schemacode` 解析全部 id 与 node(8.6.26 的 list 面是完整
|
|
375
|
+
* BusinessRuleModel,含 node/route——BusinessRule.getModel():128-156),
|
|
376
|
+
* 个别行缺 node 时才对该规则回落一 次 `businessrule/get`。
|
|
377
|
+
* 诚实口径:wire 字节没少(list 面把 N 张图一起搬回),少的是往返次数与信封体积。
|
|
378
|
+
*
|
|
379
|
+
* r83(R79 二期):`schemaCodes[]` 跨模型走 `readRuleBatchAcrossModels`;
|
|
380
|
+
* 单模型路径(本函数)输出形状逐字节不变。
|
|
381
|
+
*/
|
|
382
|
+
async function readRuleBatch(session, args) {
|
|
383
|
+
const schemaCode = args.schemaCode;
|
|
384
|
+
if (!schemaCode)
|
|
385
|
+
throw new ToolInputError({
|
|
386
|
+
status: "error",
|
|
387
|
+
blocker: "tool-input-invalid",
|
|
388
|
+
tool: "rule.get",
|
|
389
|
+
message: "ruleCodes 批量缺 schemaCode——单模型用 schemaCode,跨模型用 schemaCodes[]",
|
|
390
|
+
});
|
|
391
|
+
requireRuleBatchSummary(args.summary, `omc call rule.get --env <env> --args '{"schemaCode":"${schemaCode}","ruleCodes":[${args.ruleCodes.map((code) => JSON.stringify(code)).join(",")}],"summary":true}'`);
|
|
392
|
+
const rows = wireRows((await wireCall(session, { path: ENDPOINTS.businessRuleListBySchemaCode, query: { schemaCode } })).data);
|
|
393
|
+
const { rules, failed, fallbackReads } = await summarizeRuleRows(session, rows, args.ruleCodes);
|
|
292
394
|
// 全部失败/全部不存在 → fail closed(空 ok 会被读成「这些规则没有方法映射」)。
|
|
293
395
|
if (rules.length === 0)
|
|
294
396
|
return {
|
|
@@ -317,6 +419,206 @@ async function readRuleBatch(session, args) {
|
|
|
317
419
|
failed,
|
|
318
420
|
};
|
|
319
421
|
}
|
|
422
|
+
/**
|
|
423
|
+
* r83(R79 二期,issue 06 的跨模型一半):`schemaCodes[]` 逐模型批量摘要。
|
|
424
|
+
*
|
|
425
|
+
* - 逐模型先探模型存在:`list_by_schemacode` 对任意 schemaCode 会补建 7 条
|
|
426
|
+
* 预置规则并 publish(r28g F35)——幻影 schema 的预置行 API 删不掉,所以
|
|
427
|
+
* 模型不存在按 601003 口径回 `modelPresent:false` 且**不发 list**。
|
|
428
|
+
* - **部分失败不整单失败**:某模型 list 读失败/规则缺失只进 `failed[]`
|
|
429
|
+
* (`{schemaCode, code, message}`),其余模型照常回;全空才 refused。
|
|
430
|
+
*/
|
|
431
|
+
async function readRuleBatchAcrossModels(session, args) {
|
|
432
|
+
const models = [];
|
|
433
|
+
const rules = [];
|
|
434
|
+
const failed = [];
|
|
435
|
+
let listReads = 0;
|
|
436
|
+
let fallbackReads = 0;
|
|
437
|
+
for (const schemaCode of args.schemaCodes) {
|
|
438
|
+
let present;
|
|
439
|
+
try {
|
|
440
|
+
present = (await readModelRecord(session, schemaCode)) !== null;
|
|
441
|
+
}
|
|
442
|
+
catch (error) {
|
|
443
|
+
failed.push({ schemaCode, code: null, reason: "model-probe-failed", message: `模型探针失败:${error.message}` });
|
|
444
|
+
models.push({ schemaCode, modelPresent: null, rulesCount: 0, failedCount: args.ruleCodes.length });
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (!present) {
|
|
448
|
+
for (const code of args.ruleCodes)
|
|
449
|
+
failed.push({ schemaCode, code, reason: "model-absent", message: `模型 ${schemaCode} 不存在(601003 口径 modelPresent:false)——未发规则面请求` });
|
|
450
|
+
models.push({ schemaCode, modelPresent: false, rulesCount: 0, failedCount: args.ruleCodes.length });
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
let rows;
|
|
454
|
+
try {
|
|
455
|
+
listReads += 1;
|
|
456
|
+
rows = wireRows((await wireCall(session, { path: ENDPOINTS.businessRuleListBySchemaCode, query: { schemaCode } })).data);
|
|
457
|
+
}
|
|
458
|
+
catch (error) {
|
|
459
|
+
for (const code of args.ruleCodes)
|
|
460
|
+
failed.push({ schemaCode, code, reason: "list-failed", message: `模型 ${schemaCode} 的规则清单读失败:${error.message}` });
|
|
461
|
+
models.push({ schemaCode, modelPresent: true, rulesCount: 0, failedCount: args.ruleCodes.length });
|
|
462
|
+
continue;
|
|
463
|
+
}
|
|
464
|
+
const summarized = await summarizeRuleRows(session, rows, args.ruleCodes);
|
|
465
|
+
fallbackReads += summarized.fallbackReads;
|
|
466
|
+
for (const rule of summarized.rules)
|
|
467
|
+
rules.push(rule);
|
|
468
|
+
for (const failure of summarized.failed)
|
|
469
|
+
failed.push({
|
|
470
|
+
schemaCode,
|
|
471
|
+
code: failure.code,
|
|
472
|
+
reason: failure.reason,
|
|
473
|
+
message: failure.reason === "rule-absent" ? `${schemaCode}.${failure.code} 在 list 面不存在` : `${schemaCode}.${failure.code} 的规则图读不到(list 行缺 node 且 get 无图)`,
|
|
474
|
+
});
|
|
475
|
+
models.push({ schemaCode, modelPresent: true, rulesCount: summarized.rules.length, failedCount: summarized.failed.length });
|
|
476
|
+
}
|
|
477
|
+
const body = {
|
|
478
|
+
schemaCodes: args.schemaCodes,
|
|
479
|
+
requestedCount: args.schemaCodes.length * args.ruleCodes.length,
|
|
480
|
+
rulesCount: rules.length,
|
|
481
|
+
partial: failed.length > 0,
|
|
482
|
+
source: "draft-list",
|
|
483
|
+
wireNote: `跨模型批量:${args.schemaCodes.length} 次模型探针 + ${listReads} 次 list_by_schemacode${fallbackReads > 0 ? `;${fallbackReads} 条 list 行缺 node 已回落 businessrule/get(+${fallbackReads} wire)` : ";无回落 get"}`,
|
|
484
|
+
models,
|
|
485
|
+
rules,
|
|
486
|
+
failed,
|
|
487
|
+
};
|
|
488
|
+
if (rules.length === 0)
|
|
489
|
+
return {
|
|
490
|
+
status: "refused",
|
|
491
|
+
blocker: "rule-batch-empty",
|
|
492
|
+
...body,
|
|
493
|
+
partial: true,
|
|
494
|
+
nextCommand: `omc call rule.list --env <env> --args '{"schemaCodes":${JSON.stringify(args.schemaCodes)}}'`,
|
|
495
|
+
message: "没有一个 ruleCode 读到规则图——空结果不等于「没有方法映射」;先用 rule.list 核对模型与规则 code",
|
|
496
|
+
};
|
|
497
|
+
return body;
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* r83:单个模型的规则清单体——单模型路径与 `schemaCodes[]` 跨模型路径共用。
|
|
501
|
+
*
|
|
502
|
+
* 回执形状与 r79 的 rule.list 逐字节一致:`withMappings:false`(默认)时连
|
|
503
|
+
* 键都不出现;true 时每行多一条摘要级 `mappings[]`(服务/方法/入出参计数),
|
|
504
|
+
* 正文(inputMappings/outputMappings)仍在 `rule.get`,超阈值照旧外置 artifact
|
|
505
|
+
* (governedRead 的 2048B 读门)。
|
|
506
|
+
*/
|
|
507
|
+
async function readRuleListBody(session, schemaCode, options) {
|
|
508
|
+
// r28g F35/F36:list_by_schemacode 对任意 schemaCode 会补建 7 条预置并
|
|
509
|
+
// publish。从未存在的模型一旦被 list,就留下 API 删不掉的预置行。
|
|
510
|
+
// 写前 gate(assertRuleSchemaExists)已拦;读面也必须先探,不存在则
|
|
511
|
+
// 直接回 modelPresent:false + rules:[],**不发 list 请求**。
|
|
512
|
+
const modelRecord = await readModelRecord(session, schemaCode);
|
|
513
|
+
if (modelRecord === null) {
|
|
514
|
+
// r62b-F2(P1-5):带近名候选 + 可转发问句(plan 面 needs-decision 的
|
|
515
|
+
// call 面同款)——探针此前得自己翻 model.list 编问句。
|
|
516
|
+
const suggested = await suggestModelNames(session, schemaCode);
|
|
517
|
+
return {
|
|
518
|
+
schemaCode,
|
|
519
|
+
modelPresent: false,
|
|
520
|
+
rules: [],
|
|
521
|
+
rulesCount: 0,
|
|
522
|
+
...(suggested !== null
|
|
523
|
+
? {
|
|
524
|
+
suggestedModels: suggested,
|
|
525
|
+
needsDecision: `未找到「${schemaCode}」,是否指 ${suggested.map((model) => `${model.code}(${model.name ?? model.code})`).join(" / ")}?`,
|
|
526
|
+
}
|
|
527
|
+
: {}),
|
|
528
|
+
hint: "模型不存在(bizmodels/get_all 空)——未发 rule.list 请求(避免补建 7 条不可删预置);判定模型面用 model.inspect",
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
// 版本族备选(2026-11-03 issue A1):8.6 锚点走 runtime 面;8.1 族
|
|
532
|
+
// runtime 端点缺席(404)时下探 app 面 `businessrule/list_by_schemacode`。
|
|
533
|
+
// 仅 404 下探,401/500/业务码拒绝原样上抛。rule.save / rule.enable 的
|
|
534
|
+
// 读回本就走 app 面,两族都可用。下探发生时在结果里标注命中的端点族,
|
|
535
|
+
// 让调用方能看见自己不在锚点路径上(排查兼容问题时的关键信号)。
|
|
536
|
+
let endpointFamily = null;
|
|
537
|
+
const rows = wireRows((await wireCallWith404Fallback(session, [
|
|
538
|
+
{ path: ENDPOINTS.runtimeBusinessRuleListBySchemaCode, query: { schemaCode } },
|
|
539
|
+
{ path: ENDPOINTS.businessRuleListBySchemaCode, query: { schemaCode } },
|
|
540
|
+
], (failed, next) => { endpointFamily = { used: next.path, reason: `${failed.path} HTTP 404(端点在本版本族缺席,已下探)` }; })).data);
|
|
541
|
+
// N2 (r10 noise pass): the default row is the inventory face —
|
|
542
|
+
// code/name/state/publish-version/is-preset. The audit columns
|
|
543
|
+
// (id/createdTime/creator/developmentMode/templateType/…) only ride
|
|
544
|
+
// with full:true (the old 14-key row). rule.get resolves by business
|
|
545
|
+
// key (schemaCode+ruleCode), so the row id is rarely needed.
|
|
546
|
+
const fullRows = options.full;
|
|
547
|
+
const visible = options.onlyCustom ? rows.filter((row) => row.defaultRule !== true) : rows;
|
|
548
|
+
const statusLag = visible.some((row) => row.enabled === true && String(row.status ?? "") !== "ENABLED");
|
|
549
|
+
// r83:withMappings 只在显式开启时读;默认路径零额外 wire、零新增键。
|
|
550
|
+
const mappingFace = options.withMappings ? await readRuleListMappings(session, visible) : undefined;
|
|
551
|
+
const mappingOf = (row) => {
|
|
552
|
+
if (mappingFace === undefined)
|
|
553
|
+
return {};
|
|
554
|
+
const found = mappingFace.byCode.get(typeof row.code === "string" ? row.code : "");
|
|
555
|
+
// 读不到 ≠ 没有映射:显式标注不可用,避免把读取失败当成空映射。
|
|
556
|
+
if (found === undefined || found === null)
|
|
557
|
+
return { mappingsUnavailable: true };
|
|
558
|
+
return { mappings: found };
|
|
559
|
+
};
|
|
560
|
+
return {
|
|
561
|
+
schemaCode,
|
|
562
|
+
modelPresent: true,
|
|
563
|
+
// r83:rulesCount 在 handler 层回(此前只有 compact 投影从 rules 派生,导致
|
|
564
|
+
// schemaCodes[] 跨模型面的 models[] 元素缺该键,与 read-shapes「同形」承诺不符)。
|
|
565
|
+
rulesCount: visible.length,
|
|
566
|
+
// r28g F18:list 投影的是 PUBLISH 行;运行时可执行性以 rule.get / rule.enable.verified 为准。
|
|
567
|
+
source: "published-list",
|
|
568
|
+
executableHint: "rules[].enabled/status 来自 PUBLISH 投影;运行时判定读 DRAFT(rule.get 的 enabled+ruleStatus,或 rule.enable 回执的 executable/verified)。不要仅凭本面判定可 rule.run。",
|
|
569
|
+
...(statusLag
|
|
570
|
+
? {
|
|
571
|
+
statusLag: true,
|
|
572
|
+
statusNote: "本面 status 是 PUBLISH 投影列,与 rule.get 的 ruleStatus 可不同;检测到 enabled=true 而 status 非 ENABLED 的滞后行——enabled=true 才是分发真相,运行时以 rule.get/enable 复核",
|
|
573
|
+
}
|
|
574
|
+
: {
|
|
575
|
+
// r35a-F7(真机 2026-11-06):`status` 与 rule.get 的 `ruleStatus` 是
|
|
576
|
+
// **不同 wire 列**,可一个 ENABLED 一个 DISABLED(探针实测
|
|
577
|
+
// list status=ENABLED/ruleVersion=1 vs get ruleStatus=DISABLED/0)。
|
|
578
|
+
// 常态化给一句短注(~90B/次),避免把本面 status 当运行时真相。
|
|
579
|
+
statusNote: "本面 status 是 PUBLISH 投影列,与 rule.get 的 ruleStatus 可不同;运行时是否生效以 rule.get/enable 为准",
|
|
580
|
+
}),
|
|
581
|
+
...(options.onlyCustom ? { filtered: { onlyCustom: true, total: rows.length, returned: visible.length } } : {}),
|
|
582
|
+
// r60c-F7(真机复现):默认面把 7 条平台预置触发行一起返回——任何模型都
|
|
583
|
+
// 「有规则」,「哪些模型配了业务规则」会误判成全都有。默认面带上
|
|
584
|
+
// customCount + 一句判定口径;判定自建规则直接 onlyCustom:true。
|
|
585
|
+
...(options.onlyCustom
|
|
586
|
+
? {}
|
|
587
|
+
: {
|
|
588
|
+
customCount: rows.filter((row) => row.defaultRule !== true).length,
|
|
589
|
+
presetHint: "默认含平台预置触发行(preset:true,如 Available/Cancel/Create/Delete/GetList/Load/Update);判定「有没有人写过规则」看 customCount(=0 即全是预置),或直接 onlyCustom:true",
|
|
590
|
+
}),
|
|
591
|
+
...(endpointFamily ? { endpointFamily } : {}),
|
|
592
|
+
...(mappingFace
|
|
593
|
+
? { mappingsWireNote: `mappings 来自规则行 node(摘要:服务/方法/入出参计数;正文在 rule.get)${mappingFace.fallbackReads > 0 ? `;${mappingFace.fallbackReads} 条 list 行缺 node 已回落 businessrule/get(+${mappingFace.fallbackReads} wire)` : ";无回落 get"}` }
|
|
594
|
+
: {}),
|
|
595
|
+
rules: visible.map((row) => ({
|
|
596
|
+
code: row.code,
|
|
597
|
+
name: row.name,
|
|
598
|
+
enabled: row.enabled,
|
|
599
|
+
status: row.status,
|
|
600
|
+
...(row.enabled === true && String(row.status ?? "") !== "ENABLED" ? { statusLag: true } : {}),
|
|
601
|
+
...(row.ruleVersion !== undefined ? { ruleVersion: row.ruleVersion } : {}),
|
|
602
|
+
...(row.defaultRule !== undefined ? { defaultRule: row.defaultRule, preset: row.defaultRule === true } : {}),
|
|
603
|
+
// ticket-80's update-mode readback teaches following the same-code
|
|
604
|
+
// latestPublished row — keep the flag on the default face (5 B).
|
|
605
|
+
...(row.latestPublished !== undefined ? { latestPublished: row.latestPublished } : {}),
|
|
606
|
+
...(fullRows
|
|
607
|
+
? {
|
|
608
|
+
id: row.id,
|
|
609
|
+
schemaCode: row.schemaCode,
|
|
610
|
+
bizRuleType: row.bizRuleType,
|
|
611
|
+
developmentMode: row.developmentMode,
|
|
612
|
+
latestPublished: row.latestPublished,
|
|
613
|
+
templateType: row.templateType,
|
|
614
|
+
createdTime: row.createdTime,
|
|
615
|
+
creator: row.creater ?? row.creator,
|
|
616
|
+
}
|
|
617
|
+
: {}),
|
|
618
|
+
...mappingOf(row),
|
|
619
|
+
})),
|
|
620
|
+
};
|
|
621
|
+
}
|
|
320
622
|
export function registerBusinessRuleLane(tools) {
|
|
321
623
|
tools.push(defineTool({
|
|
322
624
|
name: "rule.list",
|
|
@@ -329,107 +631,68 @@ export function registerBusinessRuleLane(tools) {
|
|
|
329
631
|
inputSchema: {
|
|
330
632
|
environment: environmentArg,
|
|
331
633
|
schemaCode: z.string().min(1),
|
|
634
|
+
schemaCodes: z.array(z.string()).optional().describe("跨模型清单(≤20;失败回 partial+failed)"),
|
|
332
635
|
onlyCustom: z.boolean().optional().describe("只回自建规则(defaultRule!==true),滤掉平台预置触发行——读面收窄,省 token"),
|
|
333
636
|
full: z.boolean().optional().describe("行内联完整字段(id/createdTime/creator/…,并跳过 detailFile 外置);默认行只有 code/name/enabled/status/ruleVersion/defaultRule/latestPublished"),
|
|
637
|
+
withMappings: z.boolean().optional().describe("true=规则附 mappings 摘要(服务/方法/入出参计数)"),
|
|
334
638
|
capability: capabilityArg,
|
|
335
639
|
},
|
|
336
640
|
handler: async (ctx, args, self) => governedRead(ctx, self, args, async (session) => {
|
|
337
|
-
//
|
|
338
|
-
//
|
|
339
|
-
//
|
|
340
|
-
//
|
|
341
|
-
const
|
|
342
|
-
if (
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
const
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
641
|
+
// r83(R79 二期):跨模型清单。逐模型读、部分失败不整单失败;模型不存在
|
|
642
|
+
// 按 601003 口径回 modelPresent:false(readRuleListBody 的探针保证不发 list)。
|
|
643
|
+
// schemaCode 的必填面靠 tool-types 的 required-alternatives 占位保持稳定:
|
|
644
|
+
// 只传 schemaCodes[] 时占位值出现,这里把它当「没传 schemaCode」。
|
|
645
|
+
const singleSchemaCode = isRequiredAlternativePlaceholder(args.schemaCode) ? undefined : args.schemaCode;
|
|
646
|
+
if (args.schemaCodes !== undefined) {
|
|
647
|
+
if (singleSchemaCode !== undefined)
|
|
648
|
+
throw new ToolInputError({ status: "error", blocker: "tool-input-invalid", tool: "rule.list", message: "schemaCode 与 schemaCodes 互斥——单模型用 schemaCode,跨模型用 schemaCodes[]" });
|
|
649
|
+
const schemaCodes = ruleSchemaCodesOf(args.schemaCodes, "rule.list");
|
|
650
|
+
const models = [];
|
|
651
|
+
const failed = [];
|
|
652
|
+
const options = { onlyCustom: args.onlyCustom === true, full: args.full === true, withMappings: args.withMappings === true };
|
|
653
|
+
let firstError;
|
|
654
|
+
let rulesCount = 0;
|
|
655
|
+
// r83:三句提示(executableHint/statusNote/presetHint)逐模型逐字相同,
|
|
656
|
+
// 跨模型面把它们抬到顶层一次(crossModelNotes),否则 3 模型就顶破 2048
|
|
657
|
+
// 内联上限、整面被 compact(models 退码表)。statusLag 旗标仍逐模型保留。
|
|
658
|
+
const hoisted = {};
|
|
659
|
+
const HOIST_KEYS = ["executableHint", "statusNote", "presetHint"];
|
|
660
|
+
for (const schemaCode of schemaCodes) {
|
|
661
|
+
try {
|
|
662
|
+
const body = await readRuleListBody(session, schemaCode, options);
|
|
663
|
+
for (const key of HOIST_KEYS) {
|
|
664
|
+
if (body[key] !== undefined) {
|
|
665
|
+
hoisted[key] = body[key];
|
|
666
|
+
delete body[key];
|
|
667
|
+
}
|
|
355
668
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
};
|
|
359
|
-
}
|
|
360
|
-
// 版本族备选(2026-11-03 issue A1):8.6 锚点走 runtime 面;8.1 族
|
|
361
|
-
// runtime 端点缺席(404)时下探 app 面 `businessrule/list_by_schemacode`。
|
|
362
|
-
// 仅 404 下探,401/500/业务码拒绝原样上抛。rule.save / rule.enable 的
|
|
363
|
-
// 读回本就走 app 面,两族都可用。下探发生时在结果里标注命中的端点族,
|
|
364
|
-
// 让调用方能看见自己不在锚点路径上(排查兼容问题时的关键信号)。
|
|
365
|
-
let endpointFamily = null;
|
|
366
|
-
const rows = wireRows((await wireCallWith404Fallback(session, [
|
|
367
|
-
{ path: ENDPOINTS.runtimeBusinessRuleListBySchemaCode, query: { schemaCode: args.schemaCode } },
|
|
368
|
-
{ path: ENDPOINTS.businessRuleListBySchemaCode, query: { schemaCode: args.schemaCode } },
|
|
369
|
-
], (failed, next) => { endpointFamily = { used: next.path, reason: `${failed.path} HTTP 404(端点在本版本族缺席,已下探)` }; })).data);
|
|
370
|
-
// N2 (r10 noise pass): the default row is the inventory face —
|
|
371
|
-
// code/name/state/publish-version/is-preset. The audit columns
|
|
372
|
-
// (id/createdTime/creator/developmentMode/templateType/…) only ride
|
|
373
|
-
// with full:true (the old 14-key row). rule.get resolves by business
|
|
374
|
-
// key (schemaCode+ruleCode), so the row id is rarely needed.
|
|
375
|
-
const fullRows = args.full === true;
|
|
376
|
-
const visible = args.onlyCustom === true ? rows.filter((row) => row.defaultRule !== true) : rows;
|
|
377
|
-
const statusLag = visible.some((row) => row.enabled === true && String(row.status ?? "") !== "ENABLED");
|
|
378
|
-
return {
|
|
379
|
-
schemaCode: args.schemaCode,
|
|
380
|
-
modelPresent: true,
|
|
381
|
-
// r28g F18:list 投影的是 PUBLISH 行;运行时可执行性以 rule.get / rule.enable.verified 为准。
|
|
382
|
-
source: "published-list",
|
|
383
|
-
executableHint: "rules[].enabled/status 来自 PUBLISH 投影;运行时判定读 DRAFT(rule.get 的 enabled+ruleStatus,或 rule.enable 回执的 executable/verified)。不要仅凭本面判定可 rule.run。",
|
|
384
|
-
...(statusLag
|
|
385
|
-
? {
|
|
386
|
-
statusLag: true,
|
|
387
|
-
statusNote: "本面 status 是 PUBLISH 投影列,与 rule.get 的 ruleStatus 可不同;检测到 enabled=true 而 status 非 ENABLED 的滞后行——enabled=true 才是分发真相,运行时以 rule.get/enable 复核",
|
|
669
|
+
models.push(body);
|
|
670
|
+
rulesCount += Array.isArray(body.rules) ? body.rules.length : 0;
|
|
388
671
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
// list status=ENABLED/ruleVersion=1 vs get ruleStatus=DISABLED/0)。
|
|
393
|
-
// 常态化给一句短注(~90B/次),避免把本面 status 当运行时真相。
|
|
394
|
-
statusNote: "本面 status 是 PUBLISH 投影列,与 rule.get 的 ruleStatus 可不同;运行时是否生效以 rule.get/enable 为准",
|
|
395
|
-
}),
|
|
396
|
-
...(args.onlyCustom === true ? { filtered: { onlyCustom: true, total: rows.length, returned: visible.length } } : {}),
|
|
397
|
-
// r60c-F7(真机复现):默认面把 7 条平台预置触发行一起返回——任何模型都
|
|
398
|
-
// 「有规则」,「哪些模型配了业务规则」会误判成全都有。默认面带上
|
|
399
|
-
// customCount + 一句判定口径;判定自建规则直接 onlyCustom:true。
|
|
400
|
-
...(args.onlyCustom !== true
|
|
401
|
-
? {
|
|
402
|
-
customCount: rows.filter((row) => row.defaultRule !== true).length,
|
|
403
|
-
presetHint: "默认含平台预置触发行(preset:true,如 Available/Cancel/Create/Delete/GetList/Load/Update);判定「有没有人写过规则」看 customCount(=0 即全是预置),或直接 onlyCustom:true",
|
|
672
|
+
catch (error) {
|
|
673
|
+
firstError ??= error;
|
|
674
|
+
failed.push({ schemaCode, code: null, message: error.message });
|
|
404
675
|
}
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
...(
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
templateType: row.templateType,
|
|
426
|
-
createdTime: row.createdTime,
|
|
427
|
-
creator: row.creater ?? row.creator,
|
|
428
|
-
}
|
|
429
|
-
: {}),
|
|
430
|
-
})),
|
|
431
|
-
};
|
|
432
|
-
}, { full: args.full === true, target: `rule.list:${args.schemaCode}` }),
|
|
676
|
+
}
|
|
677
|
+
// 全部模型都读失败 → 上抛首个错误:auth/网络问题不能被读成「部分成功」。
|
|
678
|
+
if (models.length === 0 && firstError !== undefined)
|
|
679
|
+
throw firstError;
|
|
680
|
+
const absentModels = models.filter((model) => model.modelPresent === false).map((model) => String(model.schemaCode));
|
|
681
|
+
return {
|
|
682
|
+
schemaCodes,
|
|
683
|
+
modelsCount: models.length,
|
|
684
|
+
rulesCount,
|
|
685
|
+
...(Object.keys(hoisted).length > 0 ? { crossModelNotes: hoisted } : {}),
|
|
686
|
+
partial: failed.length > 0,
|
|
687
|
+
...(absentModels.length > 0 ? { absentModels } : {}),
|
|
688
|
+
models,
|
|
689
|
+
failed,
|
|
690
|
+
};
|
|
691
|
+
}
|
|
692
|
+
if (singleSchemaCode === undefined)
|
|
693
|
+
throw new ToolInputError({ status: "error", blocker: "tool-input-invalid", tool: "rule.list", message: "需要 schemaCode(单个模型)或 schemaCodes(跨模型清单)" });
|
|
694
|
+
return readRuleListBody(session, singleSchemaCode, { onlyCustom: args.onlyCustom === true, full: args.full === true, withMappings: args.withMappings === true });
|
|
695
|
+
}, { full: args.full === true, target: `rule.list:${args.schemaCodes !== undefined ? `schemaCodes:${args.schemaCodes.join(",")}` : args.schemaCode}` }),
|
|
433
696
|
}));
|
|
434
697
|
tools.push(defineTool({
|
|
435
698
|
name: "rule.references",
|
|
@@ -645,10 +908,28 @@ export function registerBusinessRuleLane(tools) {
|
|
|
645
908
|
keys: z.array(z.string().min(1)).min(1).optional().describe("工具经济(A6):只返回列出的顶层键(identity 键 id/code/schemaCode 恒在)。例 ['schedulerSetting'] 只看调度配置,不内联整图——对照生产规则形状时用"),
|
|
646
909
|
summary: z.boolean().optional().describe("工具经济(A6):身份+体量摘要(含 nodeDigests 节点/方法摘要、methodMappingCount、bytesOmitted),不含 nodes/routes 正文——节点摘要在 nodeDigests,不是 nodes"),
|
|
647
910
|
ruleCodes: z.array(z.string().min(1)).min(1).max(50).optional().describe("同 schemaCode 批量摘要(≤50;必须同时 summary:true):1 次 list 解析全部 id 与 node,回 rules[] + partial/failed[];全读不到 → refused rule-batch-empty"),
|
|
911
|
+
schemaCodes: z.array(z.string()).optional().describe("跨模型批量(配 ruleCodes+summary,≤20;失败回 partial+failed)"),
|
|
648
912
|
withRuntime: z.boolean().optional().describe("opt-in 聚合运行态:合并规则存在性、可执行性、源码版本与最近日志;默认不增加 wire 读取"),
|
|
649
913
|
capability: capabilityArg,
|
|
650
914
|
},
|
|
651
915
|
handler: async (ctx, args, self) => governedRead(ctx, self, args, async (session) => {
|
|
916
|
+
// r83(R79 二期):`schemaCodes[]` 跨模型批量——与 rule.references 的
|
|
917
|
+
// 扫描范围同形(模型 code 数组),必须配 ruleCodes[] + summary:true。
|
|
918
|
+
if (args.schemaCodes !== undefined) {
|
|
919
|
+
if (args.schemaCode !== undefined || args.ruleCode !== undefined || args.id !== undefined)
|
|
920
|
+
throw new ToolInputError({ status: "error", blocker: "tool-input-invalid", tool: "rule.get", message: "schemaCodes 与 schemaCode/ruleCode/id 互斥——跨模型批量只认 schemaCodes+ruleCodes" });
|
|
921
|
+
if (args.ruleCodes === undefined)
|
|
922
|
+
throw new ToolInputError({
|
|
923
|
+
status: "error",
|
|
924
|
+
blocker: "tool-input-invalid",
|
|
925
|
+
tool: "rule.get",
|
|
926
|
+
message: "schemaCodes 跨模型批量必须同时传 ruleCodes[](逐模型一次 list 解析全部图);只要模型清单用 rule.list {schemaCodes}",
|
|
927
|
+
nextCommand: `omc call rule.get --env <env> --args '{"schemaCodes":["<模型code>",...],"ruleCodes":["Create","Update"],"summary":true}'`,
|
|
928
|
+
});
|
|
929
|
+
const schemaCodes = ruleSchemaCodesOf(args.schemaCodes, "rule.get");
|
|
930
|
+
requireRuleBatchSummary(args.summary, `omc call rule.get --env <env> --args '{"schemaCodes":${JSON.stringify(schemaCodes)},"ruleCodes":[${args.ruleCodes.map((code) => JSON.stringify(code)).join(",")}],"summary":true}'`);
|
|
931
|
+
return readRuleBatchAcrossModels(session, { schemaCodes, ruleCodes: args.ruleCodes });
|
|
932
|
+
}
|
|
652
933
|
// r79-w2b(issue 06):同工具多主键(ruleCodes[])——不改身份/判定逻辑,
|
|
653
934
|
// 只把「一个主键」换成「同一 schemaCode 下的一批主键」。
|
|
654
935
|
if (args.ruleCodes !== undefined) {
|