@stalfh233/omc-cli 0.4.82 → 0.4.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.
package/README.md CHANGED
@@ -130,10 +130,11 @@ omc call discover_environment --env <env> --args '{}' # 环境就绪(真实
130
130
  - **intent**:`partial` 表示该能力可声明式(`omc intent`)覆盖一部分——通常 create/update;
131
131
  `none` 表示只走 `omc call`。删除类、方法面、分类/连接池等仍走 `omc call` 逃生舱。
132
132
 
133
- ## 近期能力(0.4.74 → 0.4.82)
133
+ ## 近期能力(0.4.74 → 0.4.83)
134
134
 
135
135
  | 版本 | 新增 / 修复 |
136
136
  |---|---|
137
+ | 0.4.83 | **r12 真机探针修正(最重要:文档纠错)**:字段计算规则(`datarule` type2)**由服务端在 `data.submit`/`data.update` 时计算并回填,且覆盖传入值**——此前 skills/describe 六处写的「API 不回填、服务端聚合需二开」是错的(旧证据只覆盖 `FORMULA(100)` 字段)。另:`omc compute` 新增 `--where "<子列> = <值>"`(编译 COUNTIF/SUMIF)并**拒绝无条件子表聚合**(`--allow-unfiltered` 显式放行);`model.delete` 把「孤儿模型」死锁变成一次明确回答——先复查读缓存,仍存在则回 `model-orphaned-record` 并给平台侧出路 |
137
138
  | 0.4.82 | **流程发起权限(40009)**:新增 `workflow.permissions` / `workflow.addPermission` / `workflow.removePermission`(`/workflow/list_permission`、`create_permission`、`delete_permission`,unitType 线上为枚举序号 1=部门 2=角色 3=用户)。`data.submit`/`data.save+workflowCode` 的 40009 现在直接回 `workflow-start-permission-denied`:带上该流程的权限行现状、两种成因(无权限行 / 发起人部门记录已失效)与可粘贴的修复命令,不再是「流程发起权限不足」五个字 |
138
139
  | 0.4.81 | **r11 真机探针修复**:`rule.save` 对 `AGGREGATION` 规则节点**写前 fail-closed**(平台会存进去、运行时 50000,真实路径是 `omc compute`/datarule type2);`omc next "统计子表行数"` 路由补 `datarule` 阶梯与 `field-compute-subtable-sum` 配方;`org.user.search` 省略关键字时**按部门树列全员**(平台 `wd` 不支持空串,此前只能枚举 0–9);`omc artifact get --jq` 无值回键清单(不再 commander 报错);`usage` 的 `faces` 纳入 `--jq/--summary/--keys/--path-only/--extract`(此前读面投影完全不记账) |
139
140
  | 0.4.80 | **省 token 与用量账本**:`omc help <topic>` 默认只回节索引(约 1KB,含每节字节数),`--all` 才读整篇;`omc artifact get` 正文 >8KB 默认只回形状(`--full` 才整包);`omc usage` 默认只回汇总(`byTool`/`redundancy`/`estimatedTokens`),`--records` 才展开;`omc script` 的**每行工具调用单独记账**(`script-call` + `parentId`);未绑定环境的目录回落 `$OMC_CONFIG_HOME/usage/<cwd-hash>.jsonl` |
@@ -71,7 +71,7 @@ const SURFACES = [
71
71
  description: "字段族全链:create→publish→表单绑定;CHILD_TABLE 子列;FORMULA 计算(子表求和回主表、子表列同行运算)。",
72
72
  operations: ["create", "update", "publish", "delete"],
73
73
  intent: { level: "partial", note: "create/update(含 CHILD_TABLE subFields、FORMULA 计算)、publish 与 delete(absent:true)已声明式。" },
74
- notes: "子表列是 schemaCode=父字段 code 上的普通字段;field.update 不接受 subFields。子列支持标量族 + WORK_SHEET 关联列(需 relativeCode + options)。**计算类已覆盖(默认走计算规则,非 FORMULA 字段)**:子表求和、子表列同行运算用「普通字段 + 计算规则」(`describe datarule.create --example field-compute-rule|field-compute-subtable-sum|field-compute-child-column`);计算由**门户前端**执行、API 不回填(写测试数据带预算值,正确性人工前台确认)。嵌套子表/MULT_WORK_SHEET/RELEVANCE_DATA 不覆盖。",
74
+ notes: "子表列是 schemaCode=父字段 code 上的普通字段;field.update 不接受 subFields。子列支持标量族 + WORK_SHEET 关联列(需 relativeCode + options)。**计算类已覆盖(默认走计算规则,非 FORMULA 字段)**:子表求和、子表列同行运算用「普通字段 + 计算规则」(`describe datarule.create --example field-compute-rule|field-compute-subtable-sum|field-compute-child-column`);计算规则由**服务端**在 data.submit/data.update 时计算并回填且覆盖传入值(真机 1.1.25 复核)。嵌套子表/MULT_WORK_SHEET/RELEVANCE_DATA 不覆盖。",
75
75
  },
76
76
  {
77
77
  id: "form",
package/dist/cli.js CHANGED
@@ -1146,8 +1146,8 @@ async function main() {
1146
1146
  const rest = [tool, ...(options.env ? ["--env", options.env] : []), ...(options.environment ? ["--environment", options.environment] : []), ...(options.args !== undefined ? ["--args", options.args] : []), ...(options.argsFile !== undefined ? ["--args-file", options.argsFile] : []), ...(Array.isArray(options.extract) ? options.extract.flatMap((path) => ["--extract", path]) : []), ...(options.extractKeys ? ["--extract-keys"] : []), ...(options.maxOutputBytes !== undefined ? ["--max-output-bytes", options.maxOutputBytes] : []), ...(options.requestId ? ["--request-id", options.requestId] : []), ...(options.timeoutMs !== undefined ? ["--timeout-ms", options.timeoutMs] : []), ...(options.wait !== undefined ? ["--wait", options.wait] : []), ...(options.dryRun ? ["--dry-run"] : [])];
1147
1147
  commandExitCode = await cmdCall(new ConfigStore(defaultPaths()), rest);
1148
1148
  });
1149
- command.command("compute").option("--schema <schemaCode>").option("--schema-code <schemaCode>").option("--target <propertyCode>").option("--property <propertyCode>").option("--formula <formula>").option("--name <name>").option("--env <environment>").option("--environment <environment>").option("--apply").addHelpText("after", "\n字段计算规则拼装器:公式 {字段} 引用 → datarule type2 完整形状(editorText/editorMark 自动生成)。默认 dry-run,--apply 写入。复杂场景(条件分支/跨模型)走 omc next 的 recipe 路径。\n").action(async (options) => {
1150
- const rest = ["compute", ...(options.schema ? ["--schema", options.schema] : []), ...(options.schemaCode ? ["--schema-code", options.schemaCode] : []), ...(options.target ? ["--target", options.target] : []), ...(options.property ? ["--property", options.property] : []), ...(options.formula !== undefined ? ["--formula", options.formula] : []), ...(options.name ? ["--name", options.name] : []), ...(options.env ? ["--env", options.env] : []), ...(options.environment ? ["--environment", options.environment] : []), ...(options.apply ? ["--apply"] : [])];
1149
+ command.command("compute").option("--schema <schemaCode>").option("--schema-code <schemaCode>").option("--target <propertyCode>").option("--property <propertyCode>").option("--formula <formula>").option("--where <condition>", "条件聚合:\"<子列code> = <值>\",与 --formula \"{<子表code>.<子列code>}\" 配合编译为 COUNTIF/SUMIF").option("--aggregate <count|sum>", "条件聚合用哪种:count(默认,→COUNTIF)/ sum(→SUMIF)").option("--allow-unfiltered", "显式接受「对整个子表列无条件聚合」;不给则拒绝(会把不符合条件的行也算进去)").option("--name <name>").option("--env <environment>").option("--environment <environment>").option("--apply").addHelpText("after", "\n字段计算规则拼装器:公式 {字段} 引用 → datarule type2 完整形状(editorText/editorMark 自动生成)。默认 dry-run,--apply 写入。条件聚合用 --formula \"{子表.子列}\" --where \"子列 = 值\"。复杂场景(条件分支/跨模型)走 omc next 的 recipe 路径。\n").action(async (options) => {
1150
+ const rest = ["compute", ...(options.schema ? ["--schema", options.schema] : []), ...(options.schemaCode ? ["--schema-code", options.schemaCode] : []), ...(options.target ? ["--target", options.target] : []), ...(options.property ? ["--property", options.property] : []), ...(options.formula !== undefined ? ["--formula", options.formula] : []), ...(options.where !== undefined ? ["--where", options.where] : []), ...(options.aggregate !== undefined ? ["--aggregate", options.aggregate] : []), ...(options.allowUnfiltered ? ["--allow-unfiltered"] : []), ...(options.name ? ["--name", options.name] : []), ...(options.env ? ["--env", options.env] : []), ...(options.environment ? ["--environment", options.environment] : []), ...(options.apply ? ["--apply"] : [])];
1151
1151
  commandExitCode = await cmdCompute(rest);
1152
1152
  });
1153
1153
  // Commander 14 needs a real variadic Option; the old `{variadic:true}` cast
package/dist/compute.js CHANGED
@@ -17,23 +17,90 @@ import { runToolCall } from "./call.js";
17
17
  import { envelope, requestId, classifyResult, CLI_EXIT_CODES } from "./cli-contract.js";
18
18
  import { writeEnvelope } from "./cli-output.js";
19
19
  import { argvValue } from "./args.js";
20
+ /**
21
+ * The offending aggregate call when a formula aggregates a whole child column
22
+ * with no filter function, else undefined. COUNTIF/SUMIF/IF-wrapped calls are
23
+ * filtered by construction and pass.
24
+ */
25
+ export function childAggregateWithoutFilter(formula) {
26
+ const upper = formula.toUpperCase();
27
+ if (upper.includes("COUNTIF") || upper.includes("SUMIF"))
28
+ return undefined;
29
+ // An IF(...) around the aggregate is the hand-written filtered form.
30
+ if (upper.trimStart().startsWith("IF("))
31
+ return undefined;
32
+ for (const fn of CHILD_AGGREGATES) {
33
+ const pattern = new RegExp(`${fn}\\(\\s*\\{([^{}]+\\.[^{}]+)\\}\\s*\\)`, "i");
34
+ const match = pattern.exec(formula);
35
+ if (match)
36
+ return `${fn}(${match[1]})`;
37
+ }
38
+ return undefined;
39
+ }
20
40
  /** 编译 formula → editorText:每个 {token} 引用包成 <field-mark>裸token</field-mark>。 */
21
41
  export function compileEditorText(formula, editorMark) {
22
42
  return formula.replace(/\{([^{}]+)\}/g, (_match, token) => `<${editorMark}>${token.trim()}</${editorMark}>`);
23
43
  }
44
+ /** Aggregation functions that consume a whole child column. */
45
+ const CHILD_AGGREGATES = ["SUM", "COUNT", "MAX", "MIN", "AVG", "UNION"];
46
+ /**
47
+ * Compile `--where "<子列> = <值>"` into the platform's conditional aggregate.
48
+ *
49
+ * Shape: `COUNTIF({<child>.<column>}, "<value>")` / `SUMIF({<child>.<column>}, "<value>")`.
50
+ * Only equality is supported: the platform's aggregator takes a value, not a
51
+ * predicate, and inventing operator support would silently emit a formula the
52
+ * engine reads differently.
53
+ */
54
+ export function compileConditionalAggregate(options) {
55
+ const source = options.formula.trim();
56
+ const where = options.where.trim();
57
+ const requested = (options.aggregate ?? "count").toLowerCase();
58
+ // The formula must already be a bare child-column reference: `{child.column}`.
59
+ const reference = /^\{([^{}]+)\}$/.exec(source);
60
+ if (!reference)
61
+ throw new Error(`--where 需要 --formula 是单个子表列引用,如 --formula "{<子表code>.<子列code>}"(当前:"${source}")`);
62
+ const token = reference[1].trim();
63
+ if (!token.includes("."))
64
+ throw new Error(`--where 的 --formula 必须是「子表code.子列code」形式(当前:"${token}")`);
65
+ const columnCode = token.split(".").pop().trim();
66
+ const condition = /^([^=<>!]+?)\s*=\s*(.+)$/.exec(where);
67
+ if (!condition)
68
+ throw new Error(`--where 只支持「<子列code> = <值>」(平台聚合器接受的是值,不是谓词;当前:"${where}")`);
69
+ const whereColumn = condition[1].trim().split(".").pop().trim();
70
+ const expected = condition[2].trim().replace(/^["']|["']$/g, "");
71
+ if (whereColumn !== columnCode)
72
+ throw new Error(`--where 的列(${whereColumn})与 --formula 引用列(${columnCode})不一致;条件聚合只作用于同一列,如 --formula "{items.checkResult}" --where "checkResult = 异常"`);
73
+ if (requested !== "count" && requested !== "sum")
74
+ throw new Error(`--aggregate 只支持 count/sum(条件聚合映射为 COUNTIF/SUMIF,当前 "${String(options.aggregate)}")`);
75
+ return `${requested === "sum" ? "SUMIF" : "COUNTIF"}({${token}},${JSON.stringify(expected)})`;
76
+ }
24
77
  /** 组装 datarule.create 的完整 args(导出供测试直接断言形状)。 */
25
78
  export function composeComputeArgs(options) {
26
79
  const editorMark = "field-omc0001";
27
- const editorText = compileEditorText(options.formula, editorMark);
28
- if (!/\{[^{}]+\}/.test(options.formula))
80
+ // Conditional aggregation REPLACES the formula: the caller describes the
81
+ // intent ("count where X = Y") and the composer emits the platform's IF form.
82
+ const effectiveFormula = options.where !== undefined ? compileConditionalAggregate(options) : options.formula;
83
+ const editorText = compileEditorText(effectiveFormula, editorMark);
84
+ if (!/\{[^{}]+\}/.test(effectiveFormula))
29
85
  throw new Error("--formula 至少含一个字段引用(如 {amount});纯常量没有计算规则意义");
30
86
  if (editorText.includes("{") || editorText.includes("}"))
31
87
  throw new Error("公式内出现嵌套花括号({{...}}),拼装器暂不支持;请展开为简单引用");
88
+ // r12: an unfiltered COUNT/SUM over a child column dry-runs clean and then
89
+ // counts EVERY row. That is occasionally what you want, but "统计子表中满足
90
+ // 条件的行数" is the common ask, and silently aggregating everything is the
91
+ // wrong answer written to the platform. Refuse instead of warning: `--apply`
92
+ // makes this a data defect, not a hint.
93
+ const unfilteredChild = childAggregateWithoutFilter(effectiveFormula);
94
+ if (unfilteredChild !== undefined && options.where === undefined && options.allowUnfiltered !== true)
95
+ throw new Error(`公式 ${unfilteredChild} 对整个子表列聚合,没有任何过滤条件——会把不符合条件的行也算进去。` +
96
+ `若要「统计满足条件的行数」,用 --where:omc compute --schema ${options.schema} --target ${options.target} ` +
97
+ `--formula "{<子表code>.<子列code>}" --where "<子列code> = <值>"(编译为 COUNTIF / SUMIF)。` +
98
+ `确实要无条件聚合时,加 --allow-unfiltered 显式确认。`);
32
99
  return {
33
100
  schemaCode: options.schema,
34
101
  propertyCode: options.target,
35
102
  dataRuleType: 2,
36
- options: { shortTextStitch: JSON.stringify({ formula: options.formula, editorText, editorMark }) },
103
+ options: { shortTextStitch: JSON.stringify({ formula: effectiveFormula, editorText, editorMark }) },
37
104
  name: options.name ?? `${options.target} 计算规则`,
38
105
  ...(options.environment ? { environment: options.environment } : {}),
39
106
  dryRun: !options.apply,
@@ -48,7 +115,15 @@ export async function cmdCompute(args) {
48
115
  const name = flag("--name");
49
116
  const environment = flag("--env") ?? flag("--environment");
50
117
  const apply = args.includes("--apply");
51
- const usage = "用法:omc compute --schema <模型code> --target <目标字段> --formula \"<公式,{字段} 引用>\" [--name 规则名] [--env 环境] [--apply]\n公式语法:同类字段 {字段code};子表列 {子表code.子列code};聚合 SUM({子表.子列})。默认 dry-run,--apply 才写入。";
118
+ const where = flag("--where");
119
+ const aggregateFlag = flag("--aggregate");
120
+ const allowUnfiltered = args.includes("--allow-unfiltered");
121
+ const usage = [
122
+ "用法:omc compute --schema <模型code> --target <目标字段> --formula \"<公式,{字段} 引用>\" [--name 规则名] [--env 环境] [--apply]",
123
+ "条件聚合:--formula \"{<子表code>.<子列code>}\" --where \"<子列code> = <值>\" [--aggregate count|sum] → 编译为 COUNTIF / SUMIF",
124
+ "公式语法:同类字段 {字段code};子表列 {子表code.子列code};无条件聚合 SUM/COUNT/MAX/MIN/AVG({子表.子列}) 需加 --allow-unfiltered 显式确认。",
125
+ "默认 dry-run,--apply 才写入。",
126
+ ].join("\n");
52
127
  const invalid = (message) => {
53
128
  writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message: `${message}\n${usage}`, retryable: false }));
54
129
  return CLI_EXIT_CODES.invalidInput;
@@ -57,7 +132,14 @@ export async function cmdCompute(args) {
57
132
  return invalid("--schema/--target/--formula 均必填");
58
133
  let createArgs;
59
134
  try {
60
- createArgs = composeComputeArgs({ schema, target, formula, name, environment, apply });
135
+ if (aggregateFlag !== undefined && !["count", "sum"].includes(aggregateFlag))
136
+ return invalid(`--aggregate 只支持 count 或 sum(当前 "${aggregateFlag}")`);
137
+ createArgs = composeComputeArgs({
138
+ schema, target, formula, name, environment, apply,
139
+ ...(where !== undefined ? { where } : {}),
140
+ ...(aggregateFlag !== undefined ? { aggregate: aggregateFlag } : {}),
141
+ ...(allowUnfiltered ? { allowUnfiltered: true } : {}),
142
+ });
61
143
  }
62
144
  catch (error) {
63
145
  return invalid(error instanceof Error ? error.message : String(error));
@@ -171,7 +171,7 @@ export const fieldOptionsArg = z
171
171
  searchFormula: jsonString().optional().describe("WORK_SHEET / MULT_WORK_SHEET data restriction range JSON"),
172
172
  conditions: jsonString().optional().describe("WORK_SHEET / MULT_WORK_SHEET query conditions JSON"),
173
173
  optionsSet: optionsSetArg.optional().describe("selection source: custom, dictionary, or businessModel"),
174
- formulaConfig: z.string().optional().describe('FORMULA(计算公式)字段 required: nested JSON string. **计算类需求默认不要建本字段类型**,改用普通字段(数值/单行文本)+计算规则(datarule.create dataRuleType 2, 裸 {字段} 引用)。本字段类型用于明确的「计算公式」列。形状 {"resultType":0|2,"resultFormat":""|"percentile","formulaType":"EXPRESSION","expression":"<JSON string {formula,editorText,editorMark}>"};计算由门户前端执行、API 不回填。'),
174
+ formulaConfig: z.string().optional().describe('FORMULA(计算公式)字段 required: nested JSON string. **计算类需求默认不要建本字段类型**,改用普通字段(数值/单行文本)+计算规则(datarule.create dataRuleType 2, 裸 {字段} 引用)。本字段类型用于明确的「计算公式」列。形状 {"resultType":0|2,"resultFormat":""|"percentile","formulaType":"EXPRESSION","expression":"<JSON string {formula,editorText,editorMark}>"};本类型字段由门户前端计算、API 不回填(计算规则 datarule type2 则是服务端回填)。'),
175
175
  persistent: z.boolean().optional().describe("FORMULA(100): must be true; persistent=false is outside the evidenced contract"),
176
176
  relevanceField: z.string().optional().describe("RELEVANCE_DATA(16) required: local WORK_SHEET field code the reference resolves through"),
177
177
  referenceField: z.string().optional().describe("RELEVANCE_DATA(16) required: referenced field code on the related model"),
@@ -90,9 +90,9 @@ export const FIELD_FORMULA_WIRE = Object.freeze({
90
90
  outerOptions: '{"formulaConfig":"<JSON string>","persistent":true[, "format":""|"percentile" — readback-only mirror, fwb §100]}',
91
91
  innerConfig: '{"resultType":0|2,"resultFormat":""|"percentile","formulaType":"EXPRESSION","expression":"<JSON string {formula,editorText,editorMark}>"}',
92
92
  expressionFormula: '<fieldCode> placeholders, e.g. {omc_a} + {omc_b}',
93
- aggregationConfig: 'AGGREGATION nested {schemaCode,dataItemCode,calculateType,formula,queryConditions} = 表单「计算」控件的「聚合计算」(UI 实测 2026-10-07:跨模型聚合,求和/最大/最小/…). FormulaProcessor.executeMainAggregation 用 queryConditions 查该 schema、对匹配行的 dataItemCode 求值 formula. shape-validated & allowed. **计算类需求默认不用 FORMULA 字段**:子表求和回主表、子表列同行运算一律「普通字段 + 计算规则」(`datarule.create` dataRuleType:2,recipes `field-compute-subtable-sum` / `field-compute-child-column`,前台真机算得 7.00/350);FORMULA 字段仅作已存量读取。计算由**门户前端**执行、API 不回填(写测试数据带预算值;正确性人工前台确认)。',
93
+ aggregationConfig: 'AGGREGATION nested {schemaCode,dataItemCode,calculateType,formula,queryConditions} = 表单「计算」控件的「聚合计算」(UI 实测 2026-10-07:跨模型聚合,求和/最大/最小/…). FormulaProcessor.executeMainAggregation 用 queryConditions 查该 schema、对匹配行的 dataItemCode 求值 formula. shape-validated & allowed. **计算类需求默认不用 FORMULA 字段**:子表求和回主表、子表列同行运算一律「普通字段 + 计算规则」(`datarule.create` dataRuleType:2,recipes `field-compute-subtable-sum` / `field-compute-child-column`,前台真机算得 7.00/350);FORMULA 字段仅作已存量读取。计算规则(`datarule.create` dataRuleType:2)**由服务端在 data.submit/data.update 时计算并回填,且覆盖传入值**(真机 1.1.25 复核 2026-10-24);本 FORMULA 类型字段才是仅前端计算、API 不回填。',
94
94
  legacyRejected: "resultType/expression top-level keys are not read by the platform and are refused",
95
- runtimeVerification: "FORMULA 字段视为「配置好即在前台会算」:计算由门户**前端**执行,API save/update/submit 不回填/重算(真机 2026-09-25/2026-10-07)。写测试数据时显式带上预算好的计算值;**公式正确性由人工在前台(配表单→填表)确认**,不要用 API 回读断言。带子表计算字段的模型 API data.save/update 可能 50000(服务端重算 NPE),前台正常。",
95
+ runtimeVerification: "本 FORMULA(100) 字段类型:计算由门户**前端**执行,API save/update/submit 不回填/重算(真机 2026-09-25/2026-10-07,仅覆盖该字段类型)。**不要**把这条套到字段计算规则(datarule dataRuleType:2)上——后者由服务端在 data.submit/data.update 时计算并回填,且覆盖传入值(真机 1.1.25 复核 2026-10-24,含删除规则后传入值生效的对照组)。带子表计算字段的模型 API data.save/update 可能 50000(服务端重算 NPE),前台正常。",
96
96
  });
97
97
  /** RELEVANCE_DATA(16) options wire (8.6.26 RelevanceDataOptions + admin field serializer). */
98
98
  export const FIELD_RELEVANCE_WIRE = Object.freeze({
@@ -364,7 +364,11 @@ export function registerModelLane(tools) {
364
364
  blocker: "model-create-duplicate-orphan",
365
365
  schemaCode: args.code,
366
366
  applicationCode: args.applicationCode ?? null,
367
- message: `模型 ${args.code} 在册(bizmodels/get_all 可读)但不在应用树中——疑似挂载孤儿(h_app_function.parentId 无效)。请修 parentId 为目录行 id,不要 create;否则会再建一条孤儿`,
367
+ nextCommand: `omc call model.delete --env <env> --args '{"schemaCode":"${args.code}"}'`,
368
+ message: `模型 ${args.code} 在册(bizmodels/get_all 可读)但不在应用树中。**先跑一次 model.delete**——它现在会把两种成因分开:` +
369
+ `① 读缓存滞后(记录其实已删)→ 回 already-absent/stale-record-cache,随后可直接 create;` +
370
+ `② 真孤儿(删除级联中断留下的残骸)→ 回 model-orphaned-record 并给平台侧出路(回收站物理删除 / 换 code),因为 8.6 平台无法删除没有 AppFunction 行的业务模型。` +
371
+ `不要重复 create(会再造一条孤儿),也不要只信这一条拒绝信息。`,
368
372
  });
369
373
  }
370
374
  }
@@ -500,11 +504,51 @@ export function registerModelLane(tools) {
500
504
  if (!node) {
501
505
  if (record === null)
502
506
  return { performed: { skipped: "already-absent" }, readback: { absent: true } };
507
+ // r12 (2026-10-24): "record readable but no tree node" has TWO causes and
508
+ // the caller could not tell them apart — create said "go fix parentId",
509
+ // model.move said "there is no node", model.delete said "no node means
510
+ // no delete": a closed loop with no exit.
511
+ //
512
+ // Cause A: a stale read face. `bizmodels/get_all` is served through a
513
+ // cache, so a record already removed by a previous delete (or by an
514
+ // interrupted cascade) keeps answering for a while. Re-read after a
515
+ // short wait before declaring anything.
516
+ // ~7s total: long enough to clear a warm read cache, short enough that
517
+ // a genuine orphan is reported without a long stall. Tests can shrink it
518
+ // with OMC_MODEL_ORPHAN_RECHECK_MS.
519
+ const recheckDelay = Number(process.env.OMC_MODEL_ORPHAN_RECHECK_MS ?? 1000);
520
+ let stillPresent = record;
521
+ for (let attempt = 0; attempt < 4 && stillPresent !== null; attempt += 1) {
522
+ await new Promise((resolve) => setTimeout(resolve, Number.isFinite(recheckDelay) ? recheckDelay : 1000));
523
+ stillPresent = await readRecord();
524
+ }
525
+ if (stillPresent === null) {
526
+ return {
527
+ performed: { skipped: "stale-record-cache" },
528
+ readback: {
529
+ absent: true,
530
+ note: "业务模型记录读取面(bizmodels/get_all)先前仍返回该 code,复查后已消失——这是读缓存滞后的残留,模型实际已删除。若刚跑过 model.create 又被拒「已在册」,现在可以重试。",
531
+ },
532
+ };
533
+ }
534
+ // Cause B: a genuine orphan. The platform has no path: physically_delete
535
+ // resolves the id through AppFunction and `removeBizModel` throws
536
+ // APP_FUNCTION_MODEL_NOTEXIST when the row is gone
537
+ // (AppIntegrationFacadeImpl:1905-1910), so no id can satisfy it.
503
538
  throw new ToolRefusalError({
504
539
  status: "refused",
505
- blocker: "model-application-unresolved",
540
+ blocker: "model-orphaned-record",
506
541
  schemaCode: args.schemaCode,
507
- message: `${args.schemaCode} 的业务模型记录仍存在,但在任何应用树中都找不到它的节点(AppFunction)——不能删:physically_delete 需要 AppFunction id,传入业务模型记录 id 会被平台以 601003 业务模型不存在拒绝(不猜测 id)。请显式传 applicationCode(模型所属应用),或用 discover_environment 确认该模型的归属应用后再删。`,
542
+ retryable: false,
543
+ platformLimitation: "removeBizModel(AppIntegrationFacadeImpl:1905) 先 getAppFunction(id),找不到即抛 APP_FUNCTION_MODEL_NOTEXIST——没有 AppFunction 行的业务模型记录在 8.6 平台上无法通过 physically_delete 删除。",
544
+ message: `${args.schemaCode} 的业务模型记录仍在(bizmodels/get_all 持续返回),但应用树里没有它的节点(AppFunction)。` +
545
+ `**这是平台侧的不可删状态**:physically_delete 用 AppFunction id 定位,而平台 removeBizModel 找不到 AppFunction 行时抛 APP_FUNCTION_MODEL_NOTEXIST——本工具不猜测 id(传业务记录 id 只会得到 601003 业务模型不存在),因此无法通过 physically_delete 删除。` +
546
+ `已连续复查 4 次、间隔约 1s,记录仍在,因此不是读缓存滞后。` +
547
+ `已知成因:删除级联被中断(逐列异步 40-60s,中途失败会留下「记录在、节点没了」的残骸)。` +
548
+ `可行出路(按代价排序):① 用平台「回收站 → 物理删除」清理该残留(apppackage/physically_deleteAll 同一路径);` +
549
+ `② 换一个未占用的 schema code 继续(r11/r12 探针均采用此法);` +
550
+ `③ 若你有平台数据库权限,删除 h_biz_schema/h_biz_property/h_biz_sheet 对应行并重启 launcher 清缓存——但这是维护者操作,不在工具权限内。` +
551
+ `**不要再重复调用 model.delete / model.move / model.create**:三方都会给出同样的答复。`,
508
552
  });
509
553
  }
510
554
  const targetId = node.id;
@@ -1237,7 +1237,7 @@ export function validateDataAction(action, nodeCode, index) {
1237
1237
  code: "rule-graph-aggregation-is-a-field-feature",
1238
1238
  nodeCode,
1239
1239
  key: `dataActions[${index}].ruleValueType`,
1240
- message: `${nodeCode}: 规则节点不支持 AGGREGATION 赋值——平台会存进去并启用,但运行期聚合结果是集合(ArrayList),标量目标收到集合即 50000「服务异常」(DecimalBizField.fillClientContent)。**子表计数/求和/取最值回主表用字段计算规则**:目标字段建成普通数值字段,然后 \`omc compute --schema <主表> --target <目标字段> --formula 'COUNTIF({<子表code>.<子列code>},"异常")'\`(默认 dry-run,--apply 写入;等价 datarule.create dataRuleType:2,配方 \`field-compute-subtable-sum\`)。规则图里只做 FIXED/DYNAMIC/EXPRESSION 的直接赋值。注意计算由门户前端执行、API data.load 不回填(平台既有行为,见 FIELD_FORMULA_WIRE.runtimeVerification):要 API 侧断言结果,请在测试数据里显式写预算值,不要用回读判定公式对错。来源:r11 巡检沙盒 2026-10-24(1.1.25)。`,
1240
+ message: `${nodeCode}: 规则节点不支持 AGGREGATION 赋值——平台会存进去并启用,但运行期聚合结果是集合(ArrayList),标量目标收到集合即 50000「服务异常」(DecimalBizField.fillClientContent)。**子表计数/求和/取最值回主表用字段计算规则**:目标字段建成普通数值字段,然后 \`omc compute --schema <主表> --target <目标字段> --formula 'COUNTIF({<子表code>.<子列code>},"异常")'\`(默认 dry-run,--apply 写入;等价 datarule.create dataRuleType:2,配方 \`field-compute-subtable-sum\`)。规则图里只做 FIXED/DYNAMIC/EXPRESSION 的直接赋值。该计算规则由**服务端**在 data.submit/data.update 时计算并回填(真机 1.1.25 复核),写完可直接 data.load 断言结果;注意它会**覆盖**你传入的同名字段值。来源:r11 巡检沙盒 2026-10-24(1.1.25)。`,
1241
1241
  }];
1242
1242
  if (!RULE_VALUE_TYPES.includes(valueType))
1243
1243
  blockers.push({ code: "rule-graph-action-value-type", nodeCode, key: "ruleValueType", message: `${where}: ruleValueType "${valueType}" 不在 ${RULE_VALUE_TYPES.join("/")}` });
@@ -54,7 +54,7 @@ const dataruleCalcRule = Object.freeze({
54
54
  },
55
55
  name: "c=a+b",
56
56
  },
57
- preconditions: ["**拼装器优先**:简单表达式/子表聚合一条 `omc compute --schema <s> --target <f> --formula '{a}*0.4+{b}*0.3'` 直接编译(默认 dry-run,--apply 写入),本配方仅用于条件分支等复杂场景。",
57
+ preconditions: ["**拼装器优先**:简单表达式用 `omc compute --formula '{a}*0.4+{b}*0.3'`;**条件聚合**用 `omc compute --formula '{<子表>.<子列>}' --where '<子列> = <值>'`(自动编译 COUNTIF/SUMIF)——两者都默认 dry-run、`--apply` 写入。本配方仅用于拼装器表达不了的条件分支等复杂场景。",
58
58
  "**计算类需求:建普通业务字段(数值优先,文本亦可)+ 本计算规则;不要用「计算公式」字段类型(FORMULA)**——平台约定是普通字段顺带配计算规则(真机 2026-10-08 复核:普通数值字段 + type2 计算规则,门户算出 7.00,设计器「计算规则」弹窗显示公式)。",
59
59
  "参与计算的字段已发布",
60
60
  ],
@@ -95,7 +95,7 @@ const dataruleSubtableSum = Object.freeze({
95
95
  },
96
96
  name: "合计=明细金额之和",
97
97
  },
98
- preconditions: ["**拼装器优先**:简单表达式/子表聚合一条 `omc compute --schema <s> --target <f> --formula '{a}*0.4+{b}*0.3'` 直接编译(默认 dry-run,--apply 写入),本配方仅用于条件分支等复杂场景。",
98
+ preconditions: ["**拼装器优先**:简单表达式用 `omc compute --formula '{a}*0.4+{b}*0.3'`;**条件聚合**用 `omc compute --formula '{<子表>.<子列>}' --where '<子列> = <值>'`(自动编译 COUNTIF/SUMIF)——两者都默认 dry-run、`--apply` 写入。本配方仅用于拼装器表达不了的条件分支等复杂场景。",
99
99
  "**目标 `total` 是普通数值字段(不是「计算公式」字段)**;`<childSchemaCode>` 是子表字段的 code(如 `prop_repair_detail` / `Sub_item_information_table`),`amount` 是其子列 code",
100
100
  "子表与其列已发布",
101
101
  ],
@@ -131,7 +131,7 @@ const dataruleChildColumn = Object.freeze({
131
131
  },
132
132
  name: "金额=数量×单价",
133
133
  },
134
- preconditions: ["**拼装器优先**:简单表达式/子表聚合一条 `omc compute --schema <s> --target <f> --formula '{a}*0.4+{b}*0.3'` 直接编译(默认 dry-run,--apply 写入),本配方仅用于条件分支等复杂场景。",
134
+ preconditions: ["**拼装器优先**:简单表达式用 `omc compute --formula '{a}*0.4+{b}*0.3'`;**条件聚合**用 `omc compute --formula '{<子表>.<子列>}' --where '<子列> = <值>'`(自动编译 COUNTIF/SUMIF)——两者都默认 dry-run、`--apply` 写入。本配方仅用于拼装器表达不了的条件分支等复杂场景。",
135
135
  "**子表列 `amount` 是普通数值字段(不是「计算公式」字段)**,且是子表内的列(schemaCode=子表字段 code)"],
136
136
  conditionalRequirements: [
137
137
  "**子表内列引用用 `{子表schemaCode.子列code}` 点号全限定**(真机 2026-10-08 设计器产出:`{prop_repair_detail.qty}*{prop_repair_detail.unit_price}`);不要写裸 `{qty}`。",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stalfh233/omc-cli",
3
- "version": "0.4.82",
3
+ "version": "0.4.83",
4
4
  "description": "CloudPivot 8.6 configuration capability CLI — governed, fail-closed, coverage-manifest bounded.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -50,9 +50,9 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@stalfh233/omc-fake-platform": "0.4.82",
53
+ "@stalfh233/omc-fake-platform": "0.4.83",
54
54
  "commander": "14.0.3",
55
- "omc-core": "0.4.82",
55
+ "omc-core": "0.4.83",
56
56
  "proper-lockfile": "4.1.2",
57
57
  "write-file-atomic": "6.0.0",
58
58
  "zod": "^3.23.8",
@@ -91,8 +91,8 @@ only the section for the capability you need —
91
91
  - **边界 / 陷阱**:
92
92
  - **计算类需求默认走「普通字段 + 计算规则」,不要建「计算公式」字段类型(FORMULA)**:建一个**数值/单行文本**业务字段,再配一条**字段级计算规则**(`datarule.create` `dataRuleType:2`,`options.shortTextStitch={"formula","editorText","editorMark"}`)。理由:平台约定用正常业务字段承载、顺带配计算规则(真机 2026-10-08 production 表单核验 + 设计器弹窗显示)。「计算公式」字段类型不是默认,仅当确需一列专用公式时才用。
93
93
  - **计算规则公式引用**:同类字段裸 `{字段code}`(`{a}+{b}`);**子表列用 `{子表字段code.子列code}`**(`{Sub_item_information_table.taxInclusiveAmount}`);子表求和 `SUM({子表.子列})`;支持 `IF(cond,a,b)`、`CASE(v,c1,r1,c2,r2)`、`VALUE()`、`AND`、比较 `=`、字符串字面量与运算符空格。recipe:`omc describe datarule.create --example field-compute-rule|field-compute-subtable-sum|field-compute-child-column`。
94
- - 计算由**门户前端**执行,API(`data.save/update`)不回填/重算——写测试数据带预算值,正确性人工前台确认。(FORMULA 字段类型仍受支持,但非默认。)
95
- - 计算由**门户前端**执行,API(`data.save/update`)不回填/重算——写测试数据带预算值,正确性人工前台确认。
94
+ - 计算规则(`dataRuleType:2`)**由服务端在 `data.submit`/`data.update` 时计算并回填,且覆盖传入值**(真机 1.1.25,2026-10-24 复核;对照组:删规则后传入值生效)。可直接 `data.load` 读回验证,无需前台人工确认。
95
+ - 只有 `FORMULA`(计算公式,`propertyType:100`)字段是**门户前端**计算、API 不回填(旧证据 2026-09-25/10-07,仅覆盖该字段类型)。
96
96
  - 子表列支持标量族 + WORK_SHEET 关联列(需 `relativeCode`+options);**嵌套子表 / MULT_WORK_SHEET / RELEVANCE_DATA 不覆盖**。
97
97
 
98
98
  ## 默认表单 `form`
@@ -45,11 +45,12 @@ Coverage status and boundaries for every capability (including 权限/子表/聚
45
45
  上线/内联/OCR) live in **`omc-capabilities`** — its 能力索引 table and
46
46
  [边界] section are the authority; read the relevant section there rather than a
47
47
  copy here. In particular, **跨模型/子表聚合、汇总、求和是配置能力**,不要当二开。
48
- 落点是**字段计算规则**:`omc compute --schema <主表> --target <目标字段> --formula 'COUNTIF({<子表code>.<子列code>},"异常")'`
48
+ 落点是**字段计算规则**:条件计数/求和用拼装器的 `--where`——
49
+ `omc compute --schema <主表> --target <目标字段> --formula '{<子表code>.<子列code>}' --where "<子列code> = <值>"`(编译为 COUNTIF/SUMIF;等价手写 `--formula 'COUNTIF({<子表code>.<子列code>},"异常")'`)
49
50
  (等价 `datarule.create` `dataRuleType:2`,配方 `field-compute-subtable-sum` / `field-compute-child-column`)。
50
51
  **不要**在规则图(`rule.save`)里用 `ruleValueType:"AGGREGATION"` —— 平台会存进去并启用,运行期聚合结果是集合,
51
52
  标量目标收到集合即 50000「服务异常」(r11 巡检沙盒 2026-10-24,1.1.25;OMC 现已写前 fail-closed)。
52
- 计算由门户前端执行、API `data.load` 不回填,属平台既有行为:要断言结果请在测试数据里写预算值。
53
+ 字段计算规则(`dataRuleType:2`)由**服务端**在 `data.submit`/`data.update` 时计算并回填(且覆盖传入值,真机 1.1.25 复核):写完直接 `data.load` 读目标字段即可验证。只有 `FORMULA`(100) 字段是前端计算、API 不回填。
53
54
 
54
55
  Cue → capability is a starting point, never a substitute for 定面. A cue that
55
56
  could name two faces is resolved by the 定面表 in the parent skill.
@@ -97,9 +97,13 @@ omc call field.publish --env local --args '{"schemaCode":"expense"}'
97
97
 
98
98
  ## 计算规则(datarule)的取值时机
99
99
 
100
- - **计算由门户前端执行,API 写入不回填**:`datarule.create` 接受 `IF({实际日期}>{需求日期},"是","否")` 这类比较式并落库,但 `data.save`/`data.submit` 不计算结果值,读回仍是 null。
101
- - 所以"计算规则是否生效"**无法用 API 判定**,必须在门户录一条看结果;验收清单要写"计算类字段前台确认"。
102
- - 需要服务端就有值(参与汇总、流程分流、超期判定)时不要依赖 datarule:改用二开接口在保存/审批时算好并回写标量。
100
+ - **字段计算规则(`datarule.create` `dataRuleType:2`)由服务端在写入时计算并回填**(真机 1.1.25 复核 2026-10-24):
101
+ `data.submit` 与 `data.update` 都会算,且**计算值覆盖调用方传入的值**。
102
+ - 实测:`COUNTIF({子表.checkResult},"异常")` → submit 4 行(3 异常)回读 `3`;update 传 `9` 回读仍是重算的 `2`;删除该规则后同一 update 传 `7` 则回读 `7`(对照组)。
103
+ - 所以「计算规则是否生效」**可以用 API 判定**:写一条带子表的数据后 `data.load` 读目标字段。
104
+ - 服务端聚合(子表计数/求和/回主表)**不需要二开**,用普通字段 + type2 计算规则即可参与流程分流、报表、后续 update。
105
+ - **区别:`FORMULA`(计算公式,`propertyType:100`)字段仍只在前端算** —— 旧证据(2026-09-25 / 2026-10-07)只覆盖该字段类型,API 写入不回填。计算类需求默认不要建 FORMULA 字段(见 `omc-capabilities` §字段)。
106
+ - ⚠️ **计算字段不要靠 `data.update` 主动赋值**:规则在时会重算并丢弃你传的值。要让某字段取特定值,先确认它没有计算规则(或删规则),再写。
103
107
 
104
108
  ## 规则与业务集成
105
109