@stalfh233/omc-cli 0.4.47 → 0.4.48

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/cli.js CHANGED
@@ -19,6 +19,7 @@ import { CLI_DEFAULT_OUTPUT_BYTES, assertSafeOutputPath } from "./artifacts.js";
19
19
  import { resolve } from "node:path";
20
20
  import { buildToolRegistry } from "./tools.js";
21
21
  import { acquireWriteLock } from "./write-lock.js";
22
+ import { cmdCompute } from "./compute.js";
22
23
  import { commandIndex, commandInventory, describeContract, describeContractFull, describeContractTool, describeExample, describeParam, describeSchemaOnly, describeTool, describeToolFull } from "./discovery.js";
23
24
  import { buildCapabilityOverview, capabilityDetail, compactCapabilities, executableCapabilityBundle, resolveCapabilityId, DISCOVERY_AUTHORITY } from "./capability-overview.js";
24
25
  import { goalRoute } from "./goal-routes.js";
@@ -936,9 +937,13 @@ async function main() {
936
937
  });
937
938
  command.command("doctor").option("--environment <environment>").option("--env <environment>").option("--service <serviceCode>", "可选:体检单个业务集成服务的鉴权参数形状(掩码/占位/全 0 检出,WARN 非致命)").action(async (options) => { commandExitCode = await cmdDoctor(new ConfigStore(defaultPaths()), options.environment ?? options.env, options.service); });
938
939
  command.command("call <tool>").option("--env <environment>").option("--environment <environment>").option("--args <json>").option("--args-file <path>").option("--max-output-bytes <bytes>").option("--request-id <requestId>").option("--timeout-ms <milliseconds>").option("--wait <milliseconds>").option("--dry-run").addHelpText("after", `\n${onboardingHelp()}\n`).action(async (tool, options) => {
939
- 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] : []), ...(options.maxOutputBytes !== undefined ? ["--max-output-bytes", options.maxOutputBytes] : []), ...(options.requestId ? ["--request-id", options.requestId] : []), ...(options.timeoutMs ? ["--timeout-ms", options.timeoutMs] : []), ...(options.wait !== undefined ? ["--wait", options.wait] : []), ...(options.dryRun ? ["--dry-run"] : [])];
940
+ 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] : []), ...(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"] : [])];
940
941
  commandExitCode = await cmdCall(new ConfigStore(defaultPaths()), rest);
941
942
  });
943
+ 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) => {
944
+ 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"] : [])];
945
+ commandExitCode = await cmdCompute(rest);
946
+ });
942
947
  command.command("script [file]").option("--env <environment>", "行内无 env 时的默认环境").option("--continue", "某行失败后继续执行剩余行(默认停在首个失败)").description("NDJSON 多调脚本:每行 {\"tool\":\"<名称>\",\"args\":{...},\"env\":\"<环境>\",\"dryRun\":true}(# 注释/空行忽略;file 为 - 读 stdin);一个进程一次会话跑完全部,逐行输出 {index,tool,exitCode,result}").action(async (file, options) => {
943
948
  const { runScript, parseScript, readScriptInput } = await import("./script.js");
944
949
  let lines;
@@ -0,0 +1,72 @@
1
+ /**
2
+ * `omc compute` — 字段计算规则拼装器(v1:datarule type2 表达式)。
3
+ *
4
+ * 真机反馈(2026-10-16):agent 手拼计算规则非常卡手——options.shortTextStitch 是
5
+ * 套娃 JSON 串(formula 花括号引用 / editorText 的 <field-mark>裸token</field-mark>
6
+ * 标签 / editorMark 一致 id 三者互锁,错一点就 fail closed 或设计器标红),读形状
7
+ * 文档+手工转义烧一堆 token。本命令把 90% 简单场景压成一条平铺命令:
8
+ *
9
+ * omc compute --schema s --target total --formula "{a}*0.4+{b}*0.3" [--apply]
10
+ *
11
+ * 内部编译为 datarule.create 参数后走既有执行链(dry-run 默认、lint/治理/幂等/
12
+ * 回读全部继承;拼装结果再被 datarule-stitch-editor-mismatch lint 反向校验)。
13
+ * 子表聚合(SUM({子表.子列}))就是公式语法,同一路径覆盖。复杂场景(条件分支、
14
+ * 跨模型取值、文本拼接以外的 type 家族)仍走 recipe 手拼路径。
15
+ */
16
+ import { runToolCall } from "./call.js";
17
+ import { envelope, requestId, classifyResult, CLI_EXIT_CODES } from "./cli-contract.js";
18
+ import { writeEnvelope } from "./cli-output.js";
19
+ /** 编译 formula → editorText:每个 {token} 引用包成 <field-mark>裸token</field-mark>。 */
20
+ export function compileEditorText(formula, editorMark) {
21
+ return formula.replace(/\{([^{}]+)\}/g, (_match, token) => `<${editorMark}>${token.trim()}</${editorMark}>`);
22
+ }
23
+ /** 组装 datarule.create 的完整 args(导出供测试直接断言形状)。 */
24
+ export function composeComputeArgs(options) {
25
+ const editorMark = "field-omc0001";
26
+ const editorText = compileEditorText(options.formula, editorMark);
27
+ if (!/\{[^{}]+\}/.test(options.formula))
28
+ throw new Error("--formula 至少含一个字段引用(如 {amount});纯常量没有计算规则意义");
29
+ if (editorText.includes("{") || editorText.includes("}"))
30
+ throw new Error("公式内出现嵌套花括号({{...}}),拼装器暂不支持;请展开为简单引用");
31
+ return {
32
+ schemaCode: options.schema,
33
+ propertyCode: options.target,
34
+ dataRuleType: 2,
35
+ options: { shortTextStitch: JSON.stringify({ formula: options.formula, editorText, editorMark }) },
36
+ name: options.name ?? `${options.target} 计算规则`,
37
+ ...(options.environment ? { environment: options.environment } : {}),
38
+ dryRun: !options.apply,
39
+ };
40
+ }
41
+ export async function cmdCompute(args) {
42
+ const request = requestId();
43
+ const flag = (name) => {
44
+ const index = args.indexOf(name);
45
+ return index >= 0 ? args[index + 1] : undefined;
46
+ };
47
+ const schema = flag("--schema") ?? flag("--schema-code");
48
+ const target = flag("--target") ?? flag("--property");
49
+ const formula = flag("--formula");
50
+ const name = flag("--name");
51
+ const environment = flag("--env") ?? flag("--environment");
52
+ const apply = args.includes("--apply");
53
+ const usage = "用法:omc compute --schema <模型code> --target <目标字段> --formula \"<公式,{字段} 引用>\" [--name 规则名] [--env 环境] [--apply]\n公式语法:同类字段 {字段code};子表列 {子表code.子列code};聚合 SUM({子表.子列})。默认 dry-run,--apply 才写入。";
54
+ const invalid = (message) => {
55
+ writeEnvelope(envelope("error", {}, request, { code: "invalid-input", message: `${message}\n${usage}`, retryable: false }));
56
+ return CLI_EXIT_CODES.invalidInput;
57
+ };
58
+ if (!schema || !target || formula === undefined)
59
+ return invalid("--schema/--target/--formula 均必填");
60
+ let createArgs;
61
+ try {
62
+ createArgs = composeComputeArgs({ schema, target, formula, name, environment, apply });
63
+ }
64
+ catch (error) {
65
+ return invalid(error instanceof Error ? error.message : String(error));
66
+ }
67
+ const { result, exitCode } = await runToolCall("datarule.create", { args: createArgs, requestId: request, environment });
68
+ const classified = classifyResult(result);
69
+ writeEnvelope(envelope(classified.status, result, request, classified.error));
70
+ return exitCode;
71
+ }
72
+ //# sourceMappingURL=compute.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stalfh233/omc-cli",
3
- "version": "0.4.47",
3
+ "version": "0.4.48",
4
4
  "description": "CloudPivot 8.6 configuration capability CLI — governed, fail-closed, coverage-manifest bounded.",
5
5
  "type": "module",
6
6
  "bin": {