@stalfh233/omc-cli 0.6.65 → 0.6.67

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
@@ -7,7 +7,7 @@ import { createInterface } from "node:readline/promises";
7
7
  import { stdin, argv } from "node:process";
8
8
  import { createRequire } from "node:module";
9
9
  import { Command, CommanderError, Option } from "commander";
10
- import { ConfigStore, defaultPaths, removedProfileKeys } from "./config-store.js";
10
+ import { ConfigStore, defaultPaths, removedProfileKeys, resolveMainCheckout } from "./config-store.js";
11
11
  import { loadCoverageManifest, versionFamilyNotice } from "./coverage.js";
12
12
  import { redactText } from "./redact.js";
13
13
  import { readArgsFile, readStdinArgs, runToolCall, toolsByTextIntent, validateAgentPaths } from "./call.js";
@@ -613,7 +613,7 @@ async function cmdCall(store, args) {
613
613
  if (rawArgs === "-")
614
614
  parsedArgs = readStdinArgs();
615
615
  else if (argsFile)
616
- parsedArgs = readArgsFile(argsFile, resolve(process.env.OMC_CONFIG_HOME ?? process.cwd()));
616
+ parsedArgs = readArgsFile(argsFile, resolve(process.env.OMC_CONFIG_HOME ?? resolveMainCheckout(process.cwd())));
617
617
  else if (rawArgs) {
618
618
  parsedArgs = JSON.parse(rawArgs);
619
619
  if (parsedArgs === null || typeof parsedArgs !== "object" || Array.isArray(parsedArgs))
@@ -626,7 +626,9 @@ async function cmdCall(store, args) {
626
626
  // r10 F9: an out-of-root `--args-file` was reported under "--args 必须是
627
627
  // 合法 JSON", which points the reader at the wrong flag. Name the real
628
628
  // cause (and the configuration root) when the failure came from the file.
629
- const configRoot = resolve(process.env.OMC_CONFIG_HOME ?? process.cwd());
629
+ // 线上 #39-D:args-file 配置根与 .omc-envs 同源——worktree 下回退主检出
630
+ // (git 结构锚定),.scratch 参数文件不再因 worktree 被迫挪位置。
631
+ const configRoot = resolve(process.env.OMC_CONFIG_HOME ?? resolveMainCheckout(process.cwd()));
630
632
  // 1.1 of issue 2026-10-23: the old hint told the caller to write a TEMP file
631
633
  // while the validator only accepts paths under the config root — the two
632
634
  // instructions contradicted each other and neither named the root. Offer a
@@ -1,7 +1,38 @@
1
1
  import { existsSync, readFileSync, copyFileSync, chmodSync, mkdirSync, statSync } from "node:fs";
2
2
  import { dirname, join, resolve } from "node:path";
3
3
  import { homedir } from "node:os";
4
+ import { spawnSync } from "node:child_process";
4
5
  import { sync as writeFileAtomicSync } from "write-file-atomic";
6
+ /**
7
+ * 线上 #39 摩擦 D(詹记真机 2026-11-16):git worktree 下环境准入失效——`.omc-envs`
8
+ * 白名单绑定「当前目录」,同一仓库每开一个 worktree 就丢一次准入。回退解析:worktree 的
9
+ * `.git` 是指向主仓的指针文件,`git rev-parse --git-common-dir` 回主仓 `.git`,其父目录
10
+ * 即主检出。**git 结构锚定**(不是任意向上爬目录):仅当 cwd 的 .git 缺席或为指针文件、
11
+ * 且解析出的主检出 ≠ cwd 时才回退——白名单语义不变(同一 git 仓库 = 同一项目)。
12
+ */
13
+ export function resolveMainCheckout(projectDir = process.cwd()) {
14
+ const cwd = resolve(projectDir);
15
+ const dotGit = join(cwd, ".git");
16
+ if (!existsSync(dotGit))
17
+ return cwd; // 非 git 目录:不猜
18
+ try {
19
+ const stat = statSync(dotGit);
20
+ if (stat.isDirectory())
21
+ return cwd; // 主检出本身:无需回退
22
+ // .git 是文件(worktree 指针)——用 git 解析主仓
23
+ const r = spawnSync("git", ["rev-parse", "--git-common-dir"], { cwd, encoding: "utf8", timeout: 5_000 });
24
+ if (r.status === 0 && typeof r.stdout === "string") {
25
+ const commonDir = resolve(cwd, r.stdout.trim());
26
+ const mainCheckout = dirname(commonDir);
27
+ if (mainCheckout !== cwd && existsSync(join(mainCheckout, ".git")))
28
+ return mainCheckout;
29
+ }
30
+ }
31
+ catch {
32
+ // git 不可用/超时:按无回退处理
33
+ }
34
+ return cwd;
35
+ }
5
36
  /**
6
37
  * Removed governance keys. This is a development branch: seeing one of these in
7
38
  * an operator's omc.config.json is an error to be fixed, never silently ignored
@@ -160,15 +191,36 @@ export class ConfigStore {
160
191
  return [...names];
161
192
  }
162
193
  readProjectEnvBinding() {
163
- if (!existsSync(this.paths.projectEnvPath))
164
- return undefined;
165
- const name = readFileSync(this.paths.projectEnvPath, "utf8").trim();
166
- return name || undefined;
194
+ if (existsSync(this.paths.projectEnvPath)) {
195
+ const name = readFileSync(this.paths.projectEnvPath, "utf8").trim();
196
+ if (name)
197
+ return name;
198
+ }
199
+ // 线上 #39-D:worktree 下回退主检出的 .omc-env(cwd 无绑定或空时)。
200
+ const main = join(resolveMainCheckout(dirname(this.paths.projectEnvPath)), ".omc-env");
201
+ if (main !== this.paths.projectEnvPath && existsSync(main)) {
202
+ const name = readFileSync(main, "utf8").trim();
203
+ if (name)
204
+ return name;
205
+ }
206
+ return undefined;
167
207
  }
168
208
  readProjectEnvsFile() {
169
- if (!existsSync(this.paths.projectEnvsPath))
209
+ const fromCwd = this.readEnvsFrom(this.paths.projectEnvsPath);
210
+ if (fromCwd.length > 0)
211
+ return fromCwd;
212
+ // 线上 #39-D:worktree 丢环境准入——cwd 的 .omc-envs 不存在/为空时,回退同一
213
+ // git 仓库主检出的白名单(git 结构锚定,见 resolveMainCheckout)。显式本地文件
214
+ // 优先(worktree 里 omc env allow 写的是 cwd,语义保持)。
215
+ const main = join(resolveMainCheckout(dirname(this.paths.projectEnvsPath)), ".omc-envs");
216
+ if (main !== this.paths.projectEnvsPath)
217
+ return this.readEnvsFrom(main);
218
+ return [];
219
+ }
220
+ readEnvsFrom(path) {
221
+ if (!existsSync(path))
170
222
  return [];
171
- return readFileSync(this.paths.projectEnvsPath, "utf8")
223
+ return readFileSync(path, "utf8")
172
224
  .split(/\r?\n/u)
173
225
  .map((line) => line.replace(/#.*$/u, "").trim())
174
226
  .filter((line) => line !== "");
@@ -834,20 +834,21 @@ export function refuseEmptyCallerLayout(args) {
834
834
  }
835
835
  /**
836
836
  * Form-toolbar buttons are a THREE-LAYER configuration (live 2026-10-23, 1.1.25
837
- * + backend source):
838
- * 1. `bizsheet.options.customButtonJson` (a STRINGIFIED JSON array) is the
839
- * authoring face — `ModelManagementFacadeImpl.publishBizForm:1022` turns it
837
+ * + backend source; shape corrected by GitLab #38, live 8.6.26 2026-11-16):
838
+ * 1. `bizsheet.options.customButtonJson` — a JSON ARRAY with each entry's
839
+ * `actionConfig` as an OBJECT (the designer's own save shape) — is the
840
+ * authoring face; `ModelManagementFacadeImpl.publishBizForm:1022` turns it
840
841
  * into `h_biz_button` rows with `triggerType=FORM`, `triggerCode=<formCode>`
841
- * at publish time.
842
+ * at publish time. The pre-r72 CLI wrote a STRINGIFIED array (double JSON
843
+ * encoding); the platform stores that string verbatim in the JSON column
844
+ * and the form page then silently drops every button (#38: designer-shaped
845
+ * columns render, stringified ones never do — version drift vs the 1.1.25
846
+ * fastjson refusal, which is why the string form was ever written).
842
847
  * 2. Those rows are what `ActionPermissionHandler` reads
843
848
  * (`getByTriggerTypeAndCode(FORM, bizCode)`).
844
849
  * 3. Whether a button shows at a given node is filtered by the workflow
845
850
  * activity's `buttonPermission.customBtns[].enabled` (the designer's
846
851
  * 「表单操作」 checkboxes) plus `showPermCode`.
847
- *
848
- * `customButtonJson` MUST stay a string inside the options JSON — passing the
849
- * array inline makes the platform answer 50000 (fastjson
850
- * "syntax error, position at 0, name customButtonJson").
851
852
  */
852
853
  export const FORM_BUTTON_LOCATIONS = Object.freeze(["FORM", "ROW", "LIST"]);
853
854
  const FORM_BUTTON_BIND_ACTIONS = new Set([
@@ -906,6 +907,17 @@ export function validateFormButtons(buttons, tool) {
906
907
  if ((bindAction === "BUSINESS_RULE" || bindAction === "FLOW") && (typeof button.targetCode !== "string" || button.targetCode === ""))
907
908
  throw new ToolRefusalError({ status: "refused", blocker: "form-buttons-invalid", message: `${tool}: buttons[${index}] ${bindAction} 需要 targetCode` });
908
909
  }
910
+ // actionConfig rides inside options.customButtonJson as a JSON OBJECT —
911
+ // the designer's own shape (live #38, 8.6.26). The old code serialized it
912
+ // once (the h_biz_button.actionConfig WIRE column is a String), but on the
913
+ // stored-options face a stringified actionConfig inside a stringified
914
+ // customButtonJson is exactly the double encoding that made the form page
915
+ // silently drop every button. A stringified blob from a legacy readback is
916
+ // unwrapped to the object; a corrupt one refuses.
917
+ if (rawConfig !== undefined && rawConfig !== null && (Array.isArray(rawConfig) || typeof rawConfig !== "object") && typeof rawConfig !== "string")
918
+ throw new ToolRefusalError({ status: "refused", blocker: "form-buttons-invalid", message: `${tool}: buttons[${index}].actionConfig 必须是对象(或其 JSON 字符串)` });
919
+ if (rawConfig !== undefined && typeof rawConfig === "string" && rawConfig.trim() !== "" && config === undefined && scriptShorthand === undefined)
920
+ throw new ToolRefusalError({ status: "refused", blocker: "form-buttons-invalid", message: `${tool}: buttons[${index}].actionConfig 不是合法 JSON 对象(解析失败)` });
909
921
  return {
910
922
  ...button,
911
923
  code,
@@ -913,13 +925,9 @@ export function validateFormButtons(buttons, tool) {
913
925
  useLocation,
914
926
  bindAction,
915
927
  operateType,
916
- // actionConfig is a String column: serialize exactly once (double
917
- // encoding breaks the renderer). `script` merges into scriptData.
918
- ...(scriptShorthand !== undefined
919
- ? { actionConfig: JSON.stringify({ ...(config ?? {}), scriptData: scriptShorthand }) }
920
- : button.actionConfig !== undefined && typeof button.actionConfig !== "string"
921
- ? { actionConfig: JSON.stringify(button.actionConfig) }
922
- : {}),
928
+ ...(config !== undefined || scriptShorthand !== undefined
929
+ ? { actionConfig: { ...(config ?? {}), ...(scriptShorthand !== undefined ? { scriptData: scriptShorthand } : {}) } }
930
+ : {}),
923
931
  sortKey: typeof button.sortKey === "number" ? button.sortKey : index,
924
932
  };
925
933
  });
@@ -1019,28 +1027,77 @@ export function mergeFormOptionsWithButtons(existingOptions, input, tool) {
1019
1027
  else if (rawConfig !== null && typeof rawConfig === "object" && !Array.isArray(rawConfig)) {
1020
1028
  config = { ...rawConfig };
1021
1029
  }
1022
- byCode.set(patch.code, { ...current, actionConfig: JSON.stringify({ ...config, scriptData: patch.script }) });
1030
+ byCode.set(patch.code, { ...current, actionConfig: { ...config, scriptData: patch.script } });
1023
1031
  }
1024
1032
  final = [...byCode.values()].map((button, index) => ({ ...button, sortKey: typeof button.sortKey === "number" ? button.sortKey : index }));
1025
1033
  }
1026
1034
  if (removeCodes.length > 0 && mode === "replace")
1027
1035
  throw new ToolRefusalError({ status: "refused", blocker: "form-buttons-invalid", message: `${tool}: removeButtonCodes 只用于 buttonsMode:"merge"(replace 已用新列表整体替换)` });
1028
- options.customButtonJson = JSON.stringify(final);
1036
+ // #38: the column rides `options` as a JSON ARRAY (designer shape) — the
1037
+ // options column itself is serialized once for the wire, so an extra
1038
+ // JSON.stringify here is double encoding the platform stores verbatim and
1039
+ // the form page then drops every button. Legacy dirty entries (a
1040
+ // stringified actionConfig inside an ARRAY-form rewrite of a stringified
1041
+ // column) are unwrapped on the way through, so ANY button write heals the
1042
+ // whole list.
1043
+ options.customButtonJson = final.map(unwrapButtonActionConfig);
1029
1044
  return JSON.stringify(options);
1030
1045
  }
1031
- /** The caller's buttons from a READ face (parsed array, or null when absent). */
1032
- export function readFormButtons(options) {
1033
- const record = decodeOptionsColumn(options);
1034
- const raw = record.customButtonJson;
1035
- if (typeof raw !== "string" || raw === "")
1036
- return null;
1046
+ /** #38: a stored legacy button may carry a STRINGIFIED actionConfig (the old
1047
+ * CLI write shape). Unwrap it to the object form so a rewrite heals it; a
1048
+ * corrupt blob is passed through untouched for the readback lint to name. */
1049
+ function unwrapButtonActionConfig(button) {
1050
+ const rawConfig = button.actionConfig;
1051
+ if (typeof rawConfig !== "string" || rawConfig.trim() === "")
1052
+ return button;
1037
1053
  try {
1038
- const parsed = JSON.parse(raw);
1039
- return Array.isArray(parsed) ? parsed : null;
1054
+ const parsed = JSON.parse(rawConfig);
1055
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed))
1056
+ return { ...button, actionConfig: parsed };
1040
1057
  }
1041
1058
  catch {
1042
- return null;
1059
+ // corrupt blob: leave verbatim — form.get/readback shape lint names it
1060
+ }
1061
+ return button;
1062
+ }
1063
+ export function customButtonJsonStoredShape(options) {
1064
+ const record = decodeOptionsColumn(options);
1065
+ const raw = record.customButtonJson;
1066
+ if (raw === null || raw === undefined || raw === "")
1067
+ return "absent";
1068
+ if (Array.isArray(raw))
1069
+ return "array";
1070
+ if (typeof raw === "string") {
1071
+ try {
1072
+ return Array.isArray(JSON.parse(raw)) ? "string" : "absent";
1073
+ }
1074
+ catch {
1075
+ return "absent";
1076
+ }
1077
+ }
1078
+ return "absent";
1079
+ }
1080
+ export const CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING = "customButtonJson 被存为字符串(双重编码)——前端按钮不渲染,设计器形状=数组+actionConfig 对象(线上 #38);用 form.draft/form.publish 重写 buttons 即自愈";
1081
+ /** The caller's buttons from a READ face (parsed array, or null when absent).
1082
+ * #39/#38: decodes BOTH stored forms — the designer's ARRAY (authoritative;
1083
+ * the read face used to be blind to it and answered null while the store
1084
+ * held real buttons) and the legacy stringified one (dirty stores must read
1085
+ * back too, flagged by customButtonJsonStoredShape). */
1086
+ export function readFormButtons(options) {
1087
+ const record = decodeOptionsColumn(options);
1088
+ const raw = record.customButtonJson;
1089
+ let parsed = raw;
1090
+ if (typeof raw === "string") {
1091
+ if (raw === "")
1092
+ return null;
1093
+ try {
1094
+ parsed = JSON.parse(raw);
1095
+ }
1096
+ catch {
1097
+ return null;
1098
+ }
1043
1099
  }
1100
+ return Array.isArray(parsed) ? parsed : null;
1044
1101
  }
1045
1102
  export async function executeFormDraftWrite(session, args) {
1046
1103
  // 兼容别名:`fieldCodes:["items.category"]` 等价于
@@ -1430,6 +1487,9 @@ export async function executeFormDraftWrite(session, args) {
1430
1487
  readback: {
1431
1488
  hasDraft: sheet.existDraft === true || typeof sheet.draftViewJson === "string",
1432
1489
  ...(formButtons !== null ? { formButtons, formButtonCodes: formButtons.map((button) => String(button.code ?? "")) } : {}),
1490
+ // #38 shape lint: the readback must never echo "configured" while the
1491
+ // stored column is the stringified form the form page refuses to render.
1492
+ ...(customButtonJsonStoredShape(sheet.options) === "string" ? { formButtonsShapeWarning: CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING } : {}),
1433
1493
  ...(mergedOptions !== undefined ? { customButtonJsonWritten: true } : {}),
1434
1494
  ...(roundTripFaces.size > 0
1435
1495
  ? {
@@ -1666,6 +1726,8 @@ export async function executeFormPublishWrite(session, args) {
1666
1726
  formButtonNote: "按钮已写入 options.customButtonJson,本次 publish 已生成 h_biz_button(triggerType=FORM);表单页是否显示还取决于流程节点 buttonPermission.customBtns[].enabled(设计器「表单操作」勾选)",
1667
1727
  }
1668
1728
  : {}),
1729
+ // #38 shape lint — same guard as the form.draft readback.
1730
+ ...(customButtonJsonStoredShape(sheet.options) === "string" ? { formButtonsShapeWarning: CUSTOM_BUTTON_JSON_STRING_SHAPE_WARNING } : {}),
1669
1731
  },
1670
1732
  };
1671
1733
  }
@@ -734,14 +734,29 @@ function readOverviewRoute(registry, goal, index) {
734
734
  * `field.list`(读字段定义)——答的不是「谁引用了它」。r57 探针从零搭 6 个工作包,
735
735
  * `omc graph` **一次都没用过**,尽管 `omc help omc-start-here` §1b 写得很详细。
736
736
  *
737
- * 保守触发:只在**明确问引用/影响/删除前检查**时给,且不改变原有 route——
738
- * 只追加一条可核对的指路,原有路由行照旧。给不出唯一目标 code 时只给
737
+ * r72g(2026-11-17 探针)扩了两处:
738
+ * ① 触发面——盘点型关系问句(「关于 X 配了哪些规则」「哪些字段被规则用到」)
739
+ * 不带「引用/使用/影响」词面,r57 词表接不住,但答案同样一次索引查询可答;
740
+ * ② 定位——note 首句从「是本地引用索引」升级为「关系型问题第一入口」
741
+ * (探针实测:否定结论靠 9 次 rule.get 枚举拿到,索引 1 次可答)。
742
+ *
743
+ * 保守触发:只在**明确问引用/影响/删除前检查/规则盘点**时给,且不改变原有
744
+ * route——只追加一条可核对的指路,原有路由行照旧。给不出唯一目标 code 时只给
739
745
  * `status`/`search` 这类**不带 code 也能跑**的入口。
740
746
  */
741
747
  const GRAPH_INTENT_RE = /(?:谁|哪(?:个|些|里))?(?:引用|使用|用到|依赖|被用|用到了)|影响面|影响范围|爆炸半径|牵连|波及|删(?:除|掉)?(?:前|之前|了会不会|会怎样|有没有风险)|能不能删|可以删(?:吗|么)|\bimpact\b|\breferences?\b|\bwho uses\b/i;
748
+ /**
749
+ * 盘点型关系问句(r72g):只认「问规则/关联清单」的固定形状,不认裸「规则」
750
+ * (那会把规则写问句也劫来)。聚合词在场时让位——数值聚合不是关系查询,
751
+ * goalRouteInner 的聚合专项(data.list + --jq 自行计数)才是正解;词表镜像自
752
+ * 那里的 AGGREGATE_ASK(函数内常量),改词请两处同步。
753
+ */
754
+ const GRAPH_INVENTORY_RE = /有哪些规则|配了(?:哪些|什么)规则|关于.{1,12}的规则|被.{0,8}(?:规则|条件|视图)用到|跟.{1,10}(?:有关联|相关)/;
755
+ const GRAPH_AGGREGATE_RE = /(统计|分组|汇总|聚合|计数|条数(?!据)|多少条|有几条|数一下)/;
742
756
  const GRAPH_OBJECT_RE = /\b([a-z][a-z0-9]*(?:_[a-z0-9]+)+)\b/g;
743
757
  function graphHintFor(goal) {
744
- if (!GRAPH_INTENT_RE.test(goal))
758
+ // 引用/影响词面照旧;盘点型问句要过聚合闸(「统计配了哪些规则」是计数不是关系)。
759
+ if (!GRAPH_INTENT_RE.test(goal) && !(GRAPH_INVENTORY_RE.test(goal) && !GRAPH_AGGREGATE_RE.test(goal)))
745
760
  return undefined;
746
761
  const codes = [...new Set(goal.match(GRAPH_OBJECT_RE) ?? [])];
747
762
  // ⚠️ 参数面不同(2026-11-12 真机逐条验证):`status`/`references` 收 --env(仅作绑定提示),
@@ -749,7 +764,9 @@ function graphHintFor(goal) {
749
764
  // 给用户一份跑不通的命令比不给更糟,所以这里按子命令分别拼。
750
765
  const commands = codes.length === 1
751
766
  ? [
752
- `omc graph references field ${codes[0]} --env <环境名>`,
767
+ // r72g:字段 code 跨模型不唯一(rule.references 同一边界)——schema.field
768
+ // r72g 核心已落地 schema.field 解析(2026-11-17)——措辞从「将支持」改「支持」。
769
+ `omc graph references field ${codes[0]} --env <环境名> # 字段重名时消歧用 schema.field 写法(<schema>.${codes[0]})`,
753
770
  `omc graph references model ${codes[0]} --env <环境名>`,
754
771
  `omc graph impact model ${codes[0]} # 注意:impact 不收 --env`,
755
772
  ]
@@ -762,7 +779,7 @@ function graphHintFor(goal) {
762
779
  state: "unknown",
763
780
  firstCommand: "omc graph status --env <环境名>; 无索引则 omc graph pull --env <环境名>(只读,约 1 分钟)",
764
781
  commands,
765
- note: "图谱是本地的引用索引(毫秒级):一次调用答「谁引用了它」,替代逐模型 model.inspect / rule.get 枚举。索引不含规则条件叶子与流程绑定,命中后仍以 rule.get 原文为准。宿主接了 MCP 时用 omc_graph_explore(安装器自动注册)。",
782
+ note: "关系型问题第一入口:一次毫秒级答「谁用到 X / 关于 X 配了哪些规则 / 改动影响」,替代逐模型 rule.list/rule.get 枚举(r72g 探针实测 9 次 rule.get 才拿到的否定结论,索引 1 次可答)。索引含规则条件叶子(rule.condition 边),不含流程绑定,命中后仍以 rule.get 原文为准。宿主接了 MCP 时用 omc_graph_explore(安装器自动注册)。",
766
783
  };
767
784
  }
768
785
  function goalRouteInner(registry, goal) {