@stalfh233/omc-cli 0.6.84 → 0.6.86

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.
Files changed (40) hide show
  1. package/README.md +6 -3
  2. package/coverage/m1-coverage-manifest-v1.json +28 -0
  3. package/dist/batch-call.js +1 -0
  4. package/dist/call.js +4 -1
  5. package/dist/capability-overview.js +4 -4
  6. package/dist/cli.js +21 -20
  7. package/dist/concurrency.js +165 -0
  8. package/dist/duration.js +73 -0
  9. package/dist/goal-routes.js +26 -1
  10. package/dist/governed-execution.js +5 -0
  11. package/dist/graph.js +5 -26
  12. package/dist/intent/capabilities/bizservice.js +178 -89
  13. package/dist/intent/capabilities/datarule.js +1 -1
  14. package/dist/intent/cli.js +1 -1
  15. package/dist/intent/compiler.js +1 -0
  16. package/dist/intent/plan-apply.js +5 -1
  17. package/dist/intent/schema.js +1 -1
  18. package/dist/journal.js +14 -1
  19. package/dist/lanes/apply-changes.js +49 -1
  20. package/dist/lanes/businessrule.js +63 -34
  21. package/dist/lanes/config-diff.js +477 -0
  22. package/dist/lanes/form.js +2 -2
  23. package/dist/lanes/runtime-data-contract.js +1 -1
  24. package/dist/lanes/runtime-data.js +43 -8
  25. package/dist/lanes/workflow-contract.js +17 -0
  26. package/dist/lanes/workflow-coverage.js +11 -0
  27. package/dist/lanes/workflow.js +47 -22
  28. package/dist/package.js +5 -2
  29. package/dist/read-shapes.js +9 -2
  30. package/dist/recipes/b2-registration.js +1 -1
  31. package/dist/rollback-spec.js +130 -32
  32. package/dist/rollback.js +67 -6
  33. package/dist/script.js +1 -0
  34. package/dist/tool-search.js +3 -0
  35. package/dist/tools.js +9 -0
  36. package/dist/write-audit.js +43 -0
  37. package/dist/write.js +10 -1
  38. package/docs/omc-introduction.md +3 -2
  39. package/package.json +3 -3
  40. package/skills/omc-capabilities.md +3 -2
package/README.md CHANGED
@@ -148,7 +148,8 @@ omc call discover_environment --env <env> --args '{}' # 环境就绪(真实
148
148
 
149
149
  - **覆盖**:`executable` 全量可用;`partial` 有取证边界(见 `omc capability <id>` 的 notes)。
150
150
  - **intent**:`partial` 表示该能力可声明式(`omc intent`)覆盖一部分——通常 create/update;
151
- `none` 表示只走 `omc call`。删除类、方法面、分类/连接池等仍走 `omc call` 逃生舱。
151
+ `none` 表示只走 `omc call`。仍走 `omc call` 逃生舱的删除/增量面:服务/方法删除、
152
+ 分类/连接池/IE,以及 listview 业务筛选/排序/按钮等前端配置。
152
153
 
153
154
  ## 近期能力(0.4.84 → 0.6.29)
154
155
 
@@ -260,10 +261,12 @@ omc intent readback intent.yaml --env <env> # 解码回 intent 形状做等价
260
261
  ```
261
262
 
262
263
  - 顶层 `models[]` / `services[]`;各能力声明式覆盖程度见「能力总览」的 intent 列(`partial` = 覆盖 create/update 等一部分)。
263
- - 模型内字段级数据规则用 `models[].datarules[]` 声明(create/update:type、options、`checkType`、`childRule`),编译时自动依赖已发布字段;删除仍走 `omc call`。
264
+ - 模型内字段级数据规则用 `models[].datarules[]` 声明(create/update:type、options、`checkType`、`childRule`;delete:`absent:true`),编译时自动依赖已发布字段。
265
+ - 业务集成:`services[]` 的 `method`(单方法,name==code,随 `service.register`)与 `methods[]`(多方法,name 可不同于 code;缺失 plan `method.create`、漂移 plan `method.update`,既有服务加方法也走这里)互斥。
266
+ - 显式缺席(删除):`models[].absent:true` 删整模型、`fields[].absent:true` 删单字段、`listview.absent:true` 删列表视图、`datarules[].absent:true` 删数据规则;plan 的 `riskClass` 升为 `destructive`。
264
267
  - **plan 不可变**:apply 前 plan 被改一字节即拒(`intent-plan-tampered`),plan 后环境漂移即拒(`intent-baseline-drifted`,重跑 `intent plan`)。
265
268
  - 生产环境 apply 加 `--confirm-production`;`--dry-run` 预览,`--no-verify` 跳过最终读回等价确认。
266
- - 未声明式覆盖的操作(删除类、方法面、分类/连接池等)仍走 `omc call` 逃生舱。
269
+ - 未声明式覆盖的操作(服务/方法删除、分类/连接池/IE 等)仍走 `omc call` 逃生舱。
267
270
 
268
271
  ## 其它命令
269
272
 
@@ -1581,6 +1581,34 @@
1581
1581
  "runtime workflow admin finish instance"
1582
1582
  ],
1583
1583
  "revision_note": "r64(2026-11-14)新增:用户需求的流程运维三件套,真机全链实证(workflow_operation approval 对象形状 / adjust_workItem=加签面 / finish=正常完结语义)。定位=测试提速:运维过的实例不能用于真实流程/权限验证。"
1584
+ },
1585
+ {
1586
+ "capability": "draft-published configuration diff (config.diff)",
1587
+ "status": "executable",
1588
+ "scope": "Read-only triage diff between the draft and published faces of one configuration target. workflow: get_draft vs get_published templates diffed on the compact summary projection (activities/edges plus the three binding faces ruleBindings/nodeRuleBindings/systemRuleBindings) with a canonical raw-template deep scan for projection-external drift; form: bizsheet/get draft*Json vs published*Json parsed and control-key aligned (view/attributes/html/actions), never text-diffed. One-face-absent answered as changed:null + verdict, not an empty diff; totalKnown is the exact difference count; full diff and both face snapshots in a 0600 artifact.",
1589
+ "version_family": "8.6",
1590
+ "anchor_version": "8.6.26",
1591
+ "evidence": [
1592
+ {
1593
+ "path": "packages/omc-cli/src/lanes/config-diff.ts",
1594
+ "anchor": "diffableWorkflowSummary/canonicalFace"
1595
+ },
1596
+ {
1597
+ "path": "packages/omc-cli/test/config-diff.test.ts",
1598
+ "anchor": "config.diff receipt semantics"
1599
+ },
1600
+ {
1601
+ "path": "packages/omc-cli/src/rollback-spec.ts",
1602
+ "anchor": "deepDiff totalKnown/truncated/shapeWarnings"
1603
+ }
1604
+ ],
1605
+ "lane": "W7-S29-greenfield",
1606
+ "tools": [
1607
+ "config.diff"
1608
+ ],
1609
+ "scopes": [
1610
+ "draft published face semantic diff (workflow|form)"
1611
+ ]
1584
1612
  }
1585
1613
  ]
1586
1614
  }
@@ -95,6 +95,7 @@ export async function runBatchCall(options) {
95
95
  await runScript(lines, {
96
96
  ...(options.context !== undefined ? { context: options.context } : {}),
97
97
  ...(options.environment !== undefined ? { defaultEnv: options.environment } : {}),
98
+ ...(options.reason !== undefined ? { reason: options.reason } : {}),
98
99
  continueOnError: true,
99
100
  print: (line) => {
100
101
  let parsed = {};
package/dist/call.js CHANGED
@@ -102,7 +102,10 @@ export function toolsByTextIntent(query, registry, limit = 2) {
102
102
  }
103
103
  export async function runToolCall(toolName, options = {}) {
104
104
  const print = options.print ?? ((line) => console.log(line));
105
- const context = options.context ?? makeToolContext({ sessions: new SessionManager(new ConfigStore(defaultPaths())) });
105
+ const baseContext = options.context ?? makeToolContext({ sessions: new SessionManager(new ConfigStore(defaultPaths())) });
106
+ // R88 #3: the write reason arrives beside the args, never inside them — the
107
+ // per-call context carries it to whichever governed write journals.
108
+ const context = options.reason === undefined ? baseContext : { ...baseContext, writeAudit: { reason: options.reason } };
106
109
  const registry = buildToolRegistry();
107
110
  const tool = registry.find((definition) => definition.name === toolName);
108
111
  if (!tool) {
@@ -141,8 +141,8 @@ const SURFACES = [
141
141
  id: "workflow",
142
142
  title: "流程模板 + 组织与权限",
143
143
  lane: LANES.workflow,
144
- description: "流程模板生命周期:workflow.list(应用内流程清单)、get_draft/get_published、create、update、publish、bindRule/unbindRule(绑定与解绑)、delete、workitem.list。**含组织/部门/角色/权限范围(org.* 工具)**:部门树、角色组/角色、用户搜索、成员与管理范围(userScope)——流程参与人/可见性的候选来源。",
145
- operations: ["list", "create", "update", "publish", "bindRule", "unbindRule", "delete"],
144
+ description: "流程模板生命周期:workflow.list(应用内流程清单)、get_draft/get_published、create、update、publish、bindRule/unbindRule(绑定与解绑)、delete、workitem.list;**症状排查先 config.diff**(草稿↔发布双面差异:活动/连线/三类绑定,domain 另支持 form 表单布局双面)。**含组织/部门/角色/权限范围(org.* 工具)**:部门树、角色组/角色、用户搜索、成员与管理范围(userScope)——流程参与人/可见性的候选来源。",
145
+ operations: ["diff", "list", "create", "update", "publish", "bindRule", "unbindRule", "delete"],
146
146
  requires: ["model"],
147
147
  intent: { level: "partial", note: "声明式支持 workflow.create/update/publish 与 bindRules(事件处理器规则绑定,merge/ensure-present);runtime workitem(提交/审批)仍走 escape hatch。" },
148
148
  notes: "greenfield 首版;publish/bindRule 不得在 ValidateMessage[] 拒绝时报告成功。组织读写(org.*)挂在本能力下,别名 org/organization/organisation。r64 起含**流程运维三件套**(workflow.transfer 换审批人 / workflow.activate 跳转节点 / workflow.finish 手动结束·end 规则照常触发)——测试提速定位:运维过的实例权限语义已变,不能用于真实流程/权限验证。",
@@ -172,9 +172,9 @@ const SURFACES = [
172
172
  title: "业务集成",
173
173
  lane: LANES.b2,
174
174
  description: "业务服务与方法注册(RESTFUL/DATA_SQL/DATA_TABLE/SAP/KAFKA/SOAP)、服务清单(按分类/关键词,凭据不回显)、导入导出、设计器测试、调用日志(h_log_biz_service 读面:params/result/状态/耗时)。",
175
- operations: ["list", "register", "update", "delete", "export", "import", "check", "test", "log"],
175
+ operations: ["list", "register", "update", "method.create", "method.update", "delete", "export", "import", "check", "test", "log"],
176
176
  requires: [],
177
- intent: { level: "partial", note: "声明式支持新建 service.register(可带一个 method)与既有 service/method 的 update(结构化 config、AES 加密、patch 语义);删除、给既有服务加方法、分类/连接池/IE 仍走 escape hatch。" },
177
+ intent: { level: "partial", note: "声明式支持新建 service.register(可带一个 method 或 methods[] 多方法,后者 name 可不同于 code)与既有 service/method 的 update,含给既有服务加方法(method.create);删除、分类/连接池/IE 仍走 escape hatch。" },
178
178
  notes: "方法 configJson 走 AES-128-ECB;RESTFUL/DATA_SQL 绑定前须带适配器必需配置(否则是注册壳)。",
179
179
  },
180
180
  {
package/dist/cli.js CHANGED
@@ -30,6 +30,7 @@ import { artifactPathMissHint, nullProjectionHint, partialPathMissHint, pathMiss
30
30
  import { basename, join, resolve } from "node:path";
31
31
  import { existsSync, readFileSync, writeFileSync, chmodSync } from "node:fs";
32
32
  import { buildToolRegistry } from "./tools.js";
33
+ import { parseDurationMs } from "./duration.js";
33
34
  import { acquireWriteLock, writeLockHeldFace } from "./write-lock.js";
34
35
  import { cmdCompute } from "./compute.js";
35
36
  import { cmdRuleWhen } from "./rule-when.js";
@@ -511,6 +512,7 @@ async function cmdBatchCall(store, toolName, rawList, options) {
511
512
  argsList: entries,
512
513
  ...(options.environment !== undefined ? { environment: options.environment } : {}),
513
514
  ...(options.args.includes("--dry-run") ? { dryRun: true } : {}),
515
+ ...(options.reason !== undefined ? { reason: options.reason } : {}),
514
516
  requestId: request,
515
517
  });
516
518
  const classified = classifyResult(batched.result);
@@ -564,7 +566,7 @@ async function cmdCall(store, args) {
564
566
  return emitTransportResult({ status: "ok", ...described, helpNote: "来自 omc describe;完整面用 omc describe <tool> [--full|--param|--example]" }, { request, maxOutputBytes });
565
567
  }
566
568
  }
567
- console.error("用法:omc call <tool> [--env <环境>] [--args '<json>' | --args - (stdin) | --args-file <配置根内路径(必须位于配置根内;数组批量请改用 --args-list;跨目录临时文件用 --args -(stdin))>] [--extract <path>]... [--jq [path]] [--extract-keys] [--args-list <json数组>(最多 200 条;超出请分批或用 omc script 读文件) [--preflight]]");
569
+ console.error("用法:omc call <tool> [--env <环境>] [--args '<json>' | --args - (stdin) | --args-file <配置根内路径(必须位于配置根内;数组批量请改用 --args-list;跨目录临时文件用 --args -(stdin))>] [--extract <path>]... [--jq [path]] [--extract-keys] [--args-list <json数组>(最多 200 条;超出请分批或用 omc script 读文件) [--preflight]] [--reason <写入原因(审计)>]");
568
570
  console.error("输出预算:--max-output-bytes 默认 65536(只约束最终 stdout 信封;读面 diet ~2048 独立外置 detailArtifactId);artifact get 内联上限 8192");
569
571
  console.error("写入:由环境 writable 决定(只读环境拒写);生产环境的写必须在 args 里带 confirmProduction:true。");
570
572
  console.error("会话账号:每次回执 resultMeta.sessionAccount(token 解码:id=user_id、username=user_name、name=登录显示名;解不出回 unavailableReason)。报错里的 currentUser 是平台按 username 反查的 id,同名多账号时与 id 不同——排查 not-mine 先看这两个是否同一个人。");
@@ -572,10 +574,17 @@ async function cmdCall(store, args) {
572
574
  }
573
575
  const environment = (callEnvironment = flag("--env") ?? flag("--environment"));
574
576
  const requestValue = flag("--request-id");
577
+ // R88 #3:写审计原因(只进 artifact/journal,不是工具参数,也不是门禁)。
578
+ const writeReason = flag("--reason");
579
+ if (writeReason !== undefined && writeReason.trim().length === 0) {
580
+ const message = "--reason 不能为空:给一句话说明本次写的目的(只记审计,不影响门禁)";
581
+ writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
582
+ return CLI_EXIT_CODES.invalidInput;
583
+ }
575
584
  // Batch mode: the SAME tool N times, one process (r12: 36 field.create calls).
576
585
  const argsList = flag("--args-list");
577
586
  if (argsList !== undefined)
578
- return cmdBatchCall(store, toolName, argsList, { environment, requestValue, args, preflight: args.includes("--preflight") });
587
+ return cmdBatchCall(store, toolName, argsList, { environment, requestValue, args, preflight: args.includes("--preflight"), ...(writeReason !== undefined ? { reason: writeReason } : {}) });
579
588
  if (args.includes("--preflight")) {
580
589
  const message = "--preflight 仅用于 --args-list 批量形状;单次调用没有批量预检语义。请改用 --args-list,或移除 --preflight 后执行单次调用。";
581
590
  writeEnvelope({ ...envelope("error", {}, request, { code: "invalid-input", message, retryable: false }), resultMeta: accountMeta() });
@@ -816,6 +825,7 @@ async function cmdCall(store, args) {
816
825
  args: parsedArgs,
817
826
  ...(environment ? { environment } : {}),
818
827
  ...(requestValue !== undefined ? { requestId: requestValue } : {}),
828
+ ...(writeReason !== undefined ? { reason: writeReason } : {}),
819
829
  dryRun,
820
830
  ...(timeoutMs !== undefined ? { timeoutMs } : {}),
821
831
  print: (line) => humanSummary(line),
@@ -978,15 +988,6 @@ function resolvedDefaultEnvironment(store) {
978
988
  return "default";
979
989
  }
980
990
  }
981
- function parseDurationMs(text) {
982
- const match = /^\s*(\d+)\s*(ms|s|m|h|d|w)?\s*$/u.exec(text);
983
- if (!match)
984
- return undefined;
985
- const amount = Number(match[1]);
986
- const unit = match[2] ?? "d";
987
- const factor = unit === "ms" ? 1 : unit === "s" ? 1000 : unit === "m" ? 60_000 : unit === "h" ? 3_600_000 : unit === "d" ? 86_400_000 : 604_800_000;
988
- return amount * factor;
989
- }
990
991
  /**
991
992
  * Above this size `omc artifact get` returns the outline, not the body. The
992
993
  * transport cap (64 KB) is far too generous for a working context: one 27 KB
@@ -2939,9 +2940,9 @@ async function main() {
2939
2940
  commandExitCode = CLI_EXIT_CODES.ok;
2940
2941
  });
2941
2942
  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); });
2942
- command.command("call <tool>").option("--env <environment>", "环境名;项目白名单按当前 cwd 解析,须在含 .omc-env 的目录内运行").option("--environment <environment>").option("--args <json>").option("--args-file <path>", "从文件读参数 JSON。**必须位于配置根内**(数组批量请改用 --args-list;跨目录/系统临时文件会被拒);免落盘用 `--args -`(stdin)").option("--args-list <json-array>", '同一工具跑 N 次(JSON 数组,每条一个 args 对象,最多 200 条);超过上限请分批,或用 omc script 读文件。逐条执行、默认不中断,最后回 succeeded/failed 汇总。适合批量建字段等').option("--preflight", "与 --args-list 一起用:只跑参数校验 + 写前语义闸(零 wire、零写入),一次报全所有形状问题").option("--keys", "与 artifact get 的 --keys 同义(= --extract-keys):列出本次结果 artifact 的顶层键与体积").addOption(new Option("--extract <path>", "在本次结果的 artifact 内取一个路径的值(可重复;省掉一次 artifact get)").argParser((value, previous = []) => [...previous, value]).default([])).addOption(new Option("--jq [path]", "路径选择器(非 jq)——不是 jq 表达式,不支持管道;[] 映射如 items[].fields.planNo;裸 --jq 列顶层键。单路径命中时 result 直接是节点本体。示例:omc call model.list --env e --jq models · omc call rule.list --env e --args '{\"schemaCode\":\"m\"}' --jq rules[].code · omc call workflow.get_published --env e --args '{\"code\":\"f\"}' --jq activities[].bizActions").argParser((value, previous = []) => [...previous, value]).default([])).option("--extract-keys", "列出本次结果 artifact 的顶层键与体积(省掉一次 artifact get --keys)").option("--max-output-bytes <bytes>", "最终 stdout 信封预算;默认 65536(投影/--jq 之后再判);读面 diet(~2048) 独立外置 detailArtifactId,抬高本参数不会把已 diet 的大表重新内联;artifact get 内联上限 8192").option("--request-id <requestId>").option("--timeout-ms <milliseconds>").option("--wait <milliseconds>", "仅 `omc call` / `omc intent apply` 支持;写锁冲突时有界排队(0=立刻拒绝)").option("--dry-run").addHelpText("after", `\n${onboardingHelp()}\n`).action(async (tool, options) => {
2943
+ command.command("call <tool>").option("--env <environment>", "环境名;项目白名单按当前 cwd 解析,须在含 .omc-env 的目录内运行").option("--environment <environment>").option("--args <json>").option("--args-file <path>", "从文件读参数 JSON。**必须位于配置根内**(数组批量请改用 --args-list;跨目录/系统临时文件会被拒);免落盘用 `--args -`(stdin)").option("--args-list <json-array>", '同一工具跑 N 次(JSON 数组,每条一个 args 对象,最多 200 条);超过上限请分批,或用 omc script 读文件。逐条执行、默认不中断,最后回 succeeded/failed 汇总。适合批量建字段等').option("--preflight", "与 --args-list 一起用:只跑参数校验 + 写前语义闸(零 wire、零写入),一次报全所有形状问题").option("--keys", "与 artifact get 的 --keys 同义(= --extract-keys):列出本次结果 artifact 的顶层键与体积").addOption(new Option("--extract <path>", "在本次结果的 artifact 内取一个路径的值(可重复;省掉一次 artifact get)").argParser((value, previous = []) => [...previous, value]).default([])).addOption(new Option("--jq [path]", "路径选择器(非 jq)——不是 jq 表达式,不支持管道;[] 映射如 items[].fields.planNo;裸 --jq 列顶层键。单路径命中时 result 直接是节点本体。示例:omc call model.list --env e --jq models · omc call rule.list --env e --args '{\"schemaCode\":\"m\"}' --jq rules[].code · omc call workflow.get_published --env e --args '{\"code\":\"f\"}' --jq activities[].bizActions").argParser((value, previous = []) => [...previous, value]).default([])).option("--extract-keys", "列出本次结果 artifact 的顶层键与体积(省掉一次 artifact get --keys)").option("--max-output-bytes <bytes>", "最终 stdout 信封预算;默认 65536(投影/--jq 之后再判);读面 diet(~2048) 独立外置 detailArtifactId,抬高本参数不会把已 diet 的大表重新内联;artifact get 内联上限 8192").option("--request-id <requestId>").option("--reason <text>", "写入原因(审计面,仅写操作):记入本次写 journal 行的 reason;不是工具参数(写 schema 拒未知键),也不参与任何门禁").option("--timeout-ms <milliseconds>").option("--wait <milliseconds>", "仅 `omc call` / `omc intent apply` 支持;写锁冲突时有界排队(0=立刻拒绝)").option("--dry-run").addHelpText("after", `\n${onboardingHelp()}\n`).action(async (tool, options) => {
2943
2944
  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.argsList !== undefined ? ["--args-list", options.argsList] : []), ...(options.preflight ? ["--preflight"] : []), ...(Array.isArray(options.extract) ? options.extract.flatMap((path) => ["--extract", path]) : []), ...(options.jq === true ? ["--jq"] : Array.isArray(options.jq) ? options.jq.flatMap((path) => path === true ? ["--jq"] : ["--jq", path]) : []), ...(options.extractKeys ? ["--extract-keys"] : []),
2944
- ...(options.keys ? ["--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"] : [])];
2945
+ ...(options.keys ? ["--keys"] : []), ...(options.maxOutputBytes !== undefined ? ["--max-output-bytes", options.maxOutputBytes] : []), ...(options.requestId ? ["--request-id", options.requestId] : []), ...(options.reason !== undefined ? ["--reason", options.reason] : []), ...(options.timeoutMs !== undefined ? ["--timeout-ms", options.timeoutMs] : []), ...(options.wait !== undefined ? ["--wait", options.wait] : []), ...(options.dryRun ? ["--dry-run"] : [])];
2945
2946
  commandExitCode = await cmdCall(new ConfigStore(defaultPaths()), rest);
2946
2947
  });
2947
2948
  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) => {
@@ -3189,21 +3190,21 @@ async function main() {
3189
3190
  script: { lines: lines.length, skipped: parsed.skipped.length },
3190
3191
  }, 0);
3191
3192
  });
3192
- const rollbackCommand = command.command("rollback").description("配置回滚(git-revert 语义):list 列写时间线 / plan 预览恢复(diff+后续写覆盖警告)/ apply 执行恢复——恢复走完整写闸门并记 journal(回滚可再回滚)。apply 支持 --wait <毫秒> 有界排队;list/plan 为只读面不接写锁。接入全部配置写面(workflow/规则/数据规则/视图/表单草稿/在线JS/字典/字段/模型/应用/报表);publish 类生命周期推进不可逆(plan 会说明);journal 与 before 快照为本机边界(不跨机器)");
3193
- rollbackCommand.command("list").option("--env <environment>").option("--environment <environment>").option("--target <substr>").option("--tool <name>").option("--limit <n>").action(async (options) => {
3194
- commandExitCode = await withTransport(options, "rollback list", (transport) => cmdRollbackList({ environment: options.env ?? options.environment, target: options.target, tool: options.tool, limit: options.limit }, transport));
3193
+ const rollbackCommand = command.command("rollback").description("配置回滚(git-revert 语义):list 列写时间线 / plan 预览恢复(diff+后续写覆盖警告)/ apply 执行恢复——恢复走完整写闸门并记 journal(回滚可再回滚)。list 支持 --since <ISO|30m|2h> 收窄窗口,并回显每行的 actor(token 解码,actorSource:token-claim,不是平台 currentUser)与 reason(写入时 --reason 声明);apply 支持 --reason 与 --wait <毫秒> 有界排队。list/plan 为只读面不接写锁。journal 是**项目级**审计面(.omc/journal/<env>.ndjson,随项目目录、本机边界:不跨机器、不跨项目;故意不做第二个 omc audit 真相源)。接入全部配置写面(workflow/规则/数据规则/视图/表单草稿/在线JS/字典/字段/模型/应用/报表)+ 批量写审计行(apply_changes/intent apply,rollbackable:false 只记录);publish 类生命周期推进不可逆(plan 会说明)");
3194
+ rollbackCommand.command("list").option("--env <environment>").option("--environment <environment>").option("--target <substr>").option("--tool <name>").option("--limit <n>").option("--since <ISO|duration>", "只保留该时刻之后的写:ISO(2026-11-20T09:30Z)或带单位时长(30m、2h、7d);非法值即 invalid-input,不猜窗口").action(async (options) => {
3195
+ commandExitCode = await withTransport(options, "rollback list", (transport) => cmdRollbackList({ environment: options.env ?? options.environment, target: options.target, tool: options.tool, limit: options.limit, since: options.since }, transport));
3195
3196
  });
3196
3197
  rollbackCommand.command("plan <ref>").option("--env <environment>").option("--environment <environment>").action(async (ref, options) => {
3197
3198
  commandExitCode = await withTransport(options, "rollback plan", (transport) => cmdRollbackPlan(ref, { environment: options.env ?? options.environment }, transport));
3198
3199
  });
3199
- rollbackCommand.command("apply <ref>").option("--env <environment>").option("--environment <environment>").option("--confirm-production").option("--wait <milliseconds>", "写锁冲突时的有界排队毫秒数(默认 0=立刻拒绝)").action(async (ref, options) => {
3200
+ rollbackCommand.command("apply <ref>").option("--env <environment>").option("--environment <environment>").option("--confirm-production").option("--reason <text>", "写入原因(审计面):记入本次恢复写的 journal 行;缺省记机器可证实的出处 rollback of seq <n>").option("--wait <milliseconds>", "写锁冲突时的有界排队毫秒数(默认 0=立刻拒绝)").action(async (ref, options) => {
3200
3201
  const waitMs = options.wait === undefined ? 0 : Number(options.wait);
3201
3202
  if (!Number.isSafeInteger(waitMs) || waitMs < 0 || waitMs > 600_000) {
3202
3203
  console.error("--wait must be an integer number of milliseconds from 0 to 600000");
3203
3204
  commandExitCode = CLI_EXIT_CODES.invalidInput;
3204
3205
  return;
3205
3206
  }
3206
- commandExitCode = await withTransport(options, "rollback apply", (transport) => cmdRollbackApply(ref, { environment: options.env ?? options.environment, confirmProduction: options.confirmProduction === true, waitMs }, transport));
3207
+ commandExitCode = await withTransport(options, "rollback apply", (transport) => cmdRollbackApply(ref, { environment: options.env ?? options.environment, confirmProduction: options.confirmProduction === true, waitMs, ...(options.reason !== undefined ? { reason: options.reason } : {}) }, transport));
3207
3208
  });
3208
3209
  const artifactCommand = command.command("artifact");
3209
3210
  artifactCommand.command("prune").option("--older-than <duration>", "删除超过该时长的读回产物(如 7d/12h/30m)").option("--max-bytes <bytes>", "产物目录预算;超出时按最旧优先删除").option("--json").action((options) => {
@@ -3298,14 +3299,14 @@ async function main() {
3298
3299
  intentCommand.command("plan <file>").option("--env <environment>").option("--plan-out <file>").option("--summary", "只回变更清单(tool+reason+资源键,去 args/基线)——复核用;apply 仍需完整 plan").option("--max-output-bytes <bytes>").action(async (file, options) => {
3299
3300
  commandExitCode = await withTransport(options, request, (transport) => cmdIntentPlan(file, options.env, options.planOut, transport, options.summary === true));
3300
3301
  });
3301
- intentCommand.command("apply <file>").option("--env <environment>").option("--dry-run").option("--no-verify").option("--confirm-production").option("--wait <milliseconds>", "写锁冲突时的有界排队毫秒数(同 `omc call --wait`,默认 0=立刻拒绝)").option("--max-output-bytes <bytes>").action(async (file, options) => {
3302
+ intentCommand.command("apply <file>").option("--env <environment>").option("--dry-run").option("--no-verify").option("--confirm-production").option("--reason <text>", "写入原因(审计面):记入本次所有变更的 journal 行(批量审计行 + 各步写)").option("--wait <milliseconds>", "写锁冲突时的有界排队毫秒数(同 `omc call --wait`,默认 0=立刻拒绝)").option("--max-output-bytes <bytes>").action(async (file, options) => {
3302
3303
  const waitRaw = options.wait === undefined ? 0 : Number(options.wait);
3303
3304
  if (!Number.isSafeInteger(waitRaw) || waitRaw < 0 || waitRaw > 600_000) {
3304
3305
  console.error("--wait must be an integer number of milliseconds from 0 to 600000");
3305
3306
  commandExitCode = CLI_EXIT_CODES.invalidInput;
3306
3307
  return;
3307
3308
  }
3308
- commandExitCode = await withTransport(options, request, (transport) => cmdIntentApply(file, { env: options.env, dryRun: options.dryRun === true, verify: options.verify !== false, confirmProduction: options.confirmProduction === true, waitMs: waitRaw }, transport));
3309
+ commandExitCode = await withTransport(options, request, (transport) => cmdIntentApply(file, { env: options.env, dryRun: options.dryRun === true, verify: options.verify !== false, confirmProduction: options.confirmProduction === true, waitMs: waitRaw, ...(options.reason !== undefined ? { reason: options.reason } : {}) }, transport));
3309
3310
  });
3310
3311
  intentCommand.command("readback <file>").option("--env <environment>").option("--max-output-bytes <bytes>").action(async (file, options) => {
3311
3312
  commandExitCode = await withTransport(options, request, (transport) => cmdIntentReadback(file, options.env, transport));
@@ -0,0 +1,165 @@
1
+ import { WireError } from "./wire.js";
2
+ /**
3
+ * R88 提案 #2(扫描并发化):读面扫描共享的有界并发原语与限流退避策略。
4
+ *
5
+ * 唯一真相源是 `Semaphore`(direct handoff,自 graph.ts 抽取)——`graph pull`
6
+ * 与在线扫描(workflow.list / rule.references)用同一实现,行为不漂移。
7
+ * **写路径绝不并发**(写锁/顺序语义),本模块只服务读扫描。
8
+ *
9
+ * 与 support.ts 的 `mapBounded`(F5 worker-pool)分工:mapBounded 是 fail-fast
10
+ * 的独立读面扇出(一个失败整体失败);本模块是扫描面的 partial 语义(失败
11
+ * 收集进 failed[]、行级 readFailed)+ 限流退避 + 窗口降级 + wire 统计——
12
+ * 扫描面要的是「一次失败不变成整面错误」,别把两者合并。
13
+ */
14
+ /** 在线扫描的默认窗口(评审裁决:平台限流未知,4 起步)。 */
15
+ export const DEFAULT_SCAN_CONCURRENCY = 4;
16
+ /** 限流退避重试仍失败后的降级窗口(不整批串行、不掩盖业务错误)。 */
17
+ export const THROTTLE_DEGRADED_LIMIT = 2;
18
+ const DEFAULT_RETRY_BACKOFF_MS = 250;
19
+ /**
20
+ * Bounded semaphore with DIRECT handoff: a released slot is handed directly to
21
+ * the head waiter (capacity is never "returned to the pool"). The naive
22
+ * `free += 1; wake()` lets a task submitted in the microtask gap steal the
23
+ * slot, driving `free` negative — a waiter is then never woken, the pull
24
+ * promise never settles, and Node exits 0 SILENTLY when the event loop drains
25
+ * (no envelope, lock left behind). Tracking in-flight (instead of free) keeps
26
+ * that invariant by construction: capacity is only ever consumed by the
27
+ * releaser handing it straight to the head of the FIFO waiter queue.
28
+ */
29
+ export class Semaphore {
30
+ limit;
31
+ inFlight = 0;
32
+ waiters = [];
33
+ constructor(limit) {
34
+ this.limit = Math.max(1, Math.floor(limit));
35
+ }
36
+ async acquire() {
37
+ if (this.inFlight < this.limit) {
38
+ this.inFlight += 1;
39
+ return;
40
+ }
41
+ await new Promise((resolve) => this.waiters.push(resolve));
42
+ }
43
+ release() {
44
+ this.inFlight -= 1;
45
+ if (this.inFlight < 0) {
46
+ this.inFlight = 0;
47
+ throw new Error("semaphore over-released");
48
+ }
49
+ const waiter = this.waiters[0];
50
+ // Shrunk windows park waiters until in-flight drains below the new limit;
51
+ // the waiter stays queued (peek, not shift) unless it can be woken now.
52
+ if (waiter !== undefined && this.inFlight < this.limit) {
53
+ this.waiters.shift();
54
+ this.inFlight += 1;
55
+ waiter();
56
+ }
57
+ }
58
+ /**
59
+ * R88 限流降级:把窗口收小(只向下)。不唤醒任何 waiter——此后每次
60
+ * release 只在 in-flight 低于新限时才 direct handoff,在飞任务自然排空。
61
+ */
62
+ shrink(limit) {
63
+ const next = Math.max(1, Math.floor(limit));
64
+ if (next < this.limit)
65
+ this.limit = next;
66
+ }
67
+ }
68
+ /**
69
+ * 限流类错误特征(评审裁决的窄口径):HTTP 429/503/504(网关超时)与
70
+ * transport 面(请求超时/连接被重置)。业务错误(errcode≠0 的确定拒绝)
71
+ * 与其它 http-status(4xx/5xx 服务器错误)**不算**——重试它们只会掩盖
72
+ * 真实拒绝。
73
+ */
74
+ export function isThrottleClassError(error) {
75
+ if (error instanceof WireError) {
76
+ if (error.kind === "http-status") {
77
+ const status = error.diagnostic?.httpStatus;
78
+ return status === 429 || status === 503 || status === 504;
79
+ }
80
+ if (error.kind === "transport")
81
+ return /timed out|gateway|econnreset|econnrefused|socket hang up/i.test(error.message);
82
+ return false;
83
+ }
84
+ return error instanceof Error && /econnreset|etimedout|socket hang up/i.test(error.message);
85
+ }
86
+ /**
87
+ * Bounded-concurrency map for read scans: `items` through `fn` behind a
88
+ * direct-handoff semaphore. Errors NEVER fail-fast — each item resolves to an
89
+ * outcome (failures land in `failed[]`, indices stay aligned so callers
90
+ * reassemble receipts in input order and stay byte-identical with the serial
91
+ * baseline). The whole fn is wrapped in the same one-retry throttle policy the
92
+ * fn's internal reads may use (`scan.read`), so throwing scan bodies
93
+ * (scanModelWorkflowBindings) and swallowing scan bodies (rule.references 的
94
+ * 逐模型读) share one policy and one stats counter.
95
+ */
96
+ export async function mapWithConcurrency(items, limit, fn, options = {}) {
97
+ const isThrottle = options.isThrottle ?? isThrottleClassError;
98
+ const backoffMs = options.retryBackoffMs ?? DEFAULT_RETRY_BACKOFF_MS;
99
+ const degradedLimit = options.degradedLimit ?? THROTTLE_DEGRADED_LIMIT;
100
+ const requested = Math.max(1, Math.floor(limit));
101
+ const semaphore = new Semaphore(requested);
102
+ let retries = 0;
103
+ let degraded = false;
104
+ const degrade = () => {
105
+ if (degraded)
106
+ return;
107
+ degraded = true;
108
+ semaphore.shrink(degradedLimit);
109
+ };
110
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
111
+ const scan = {
112
+ get retries() {
113
+ return retries;
114
+ },
115
+ get degraded() {
116
+ return degraded;
117
+ },
118
+ degradedLimit,
119
+ async read(readFn) {
120
+ try {
121
+ return await readFn();
122
+ }
123
+ catch (error) {
124
+ if (!isThrottle(error))
125
+ throw error;
126
+ retries += 1;
127
+ await sleep(backoffMs * (0.5 + Math.random()));
128
+ try {
129
+ return await readFn();
130
+ }
131
+ catch (again) {
132
+ if (isThrottle(again))
133
+ degrade();
134
+ throw again;
135
+ }
136
+ }
137
+ },
138
+ };
139
+ const outcomes = new Array(items.length);
140
+ let inFlight = 0;
141
+ let maxInFlight = 0;
142
+ await Promise.all(items.map(async (item, index) => {
143
+ await semaphore.acquire();
144
+ inFlight += 1;
145
+ if (inFlight > maxInFlight)
146
+ maxInFlight = inFlight;
147
+ try {
148
+ outcomes[index] = { ok: true, value: await scan.read(() => fn(item, index, scan)) };
149
+ }
150
+ catch (error) {
151
+ outcomes[index] = { ok: false, error };
152
+ }
153
+ finally {
154
+ inFlight -= 1;
155
+ semaphore.release();
156
+ }
157
+ }));
158
+ const failed = outcomes.flatMap((outcome, index) => outcome.ok ? [] : [{ item: items[index], index, error: outcome.error }]);
159
+ return {
160
+ outcomes,
161
+ failed,
162
+ stats: { logicalCalls: items.length, retries, maxInFlight, requested, effective: degraded ? degradedLimit : requested },
163
+ };
164
+ }
165
+ //# sourceMappingURL=concurrency.js.map
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Duration / time-reference parsing — one parser for every CLI face that takes
3
+ * a human duration (`artifact prune --older-than`, `rollback list --since`).
4
+ *
5
+ * Two shapes are accepted, and nothing else is guessed:
6
+ *
7
+ * - a DURATION: `<n><unit>` where unit ∈ ms|s|m|h|d|w (`30m`, `2h`, `7d`);
8
+ * - an ISO-8601 timestamp: `2026-11-20`, `2026-11-20T09:30`,
9
+ * `2026-11-20T09:30:15Z`, `2026-11-20T09:30:15+08:00`.
10
+ *
11
+ * `parseDurationMs` keeps the historical permissive behavior artifact prune
12
+ * relied on (a bare number means DAYS). `resolveSinceRef` is the stricter
13
+ * `--since` door: a bare number there is ambiguous ("30" — minutes? days?), so
14
+ * it is refused with the accepted shapes rather than silently reinterpreted.
15
+ */
16
+ /** `<n><unit>` → milliseconds. A bare number keeps the legacy "days" reading. */
17
+ export function parseDurationMs(text) {
18
+ const match = /^\s*(\d+)\s*(ms|s|m|h|d|w)?\s*$/u.exec(text);
19
+ if (!match)
20
+ return undefined;
21
+ const amount = Number(match[1]);
22
+ const unit = match[2] ?? "d";
23
+ const factor = unit === "ms" ? 1 : unit === "s" ? 1000 : unit === "m" ? 60_000 : unit === "h" ? 3_600_000 : unit === "d" ? 86_400_000 : 604_800_000;
24
+ return amount * factor;
25
+ }
26
+ /** Duration syntax with an explicit unit (`30m`, `2h`, `7d`) — what `--since` accepts. */
27
+ const EXPLICIT_DURATION = /^\s*\d+\s*(ms|s|m|h|d|w)\s*$/u;
28
+ /** ISO-8601 date or date-time; timezone optional (absent = UTC, per ECMAScript Date.parse). */
29
+ const ISO_TIMESTAMP = /^(\d{4})-(\d{2})-(\d{2})(?:[T ](\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,9})?)?(?:Z|[+-](\d{2}):(\d{2}))?)?$/u;
30
+ /** Days in a calendar month (month is 1-based). */
31
+ function daysInMonth(year, month) {
32
+ return new Date(Date.UTC(year, month, 0)).getUTCDate();
33
+ }
34
+ /**
35
+ * Resolve a `--since` value into an absolute cutoff. Invalid input answers an
36
+ * explicit error naming the accepted shapes — never a silently guessed window.
37
+ *
38
+ * Calendar validity is checked field by field: `Date.parse("2026-02-30T…")`
39
+ * silently ROLLS OVER to March 2, which would answer a window the caller never
40
+ * asked for.
41
+ */
42
+ export function resolveSinceRef(text, now = Date.now()) {
43
+ const input = text.trim();
44
+ if (input.length === 0)
45
+ return { error: "--since 不能为空:给 ISO 时间(2026-11-20T09:30Z)或带单位的时长(30m、2h、7d)" };
46
+ if (EXPLICIT_DURATION.test(input)) {
47
+ const durationMs = parseDurationMs(input);
48
+ if (durationMs === undefined)
49
+ return { error: `--since 的时长「${text}」无法解析;可用单位 ms/s/m/h/d/w(如 30m、2h、7d)` };
50
+ return { cutoffMs: now - durationMs, mode: "duration", input };
51
+ }
52
+ const iso = ISO_TIMESTAMP.exec(input);
53
+ if (iso !== null) {
54
+ const [year, month, day] = [Number(iso[1]), Number(iso[2]), Number(iso[3])];
55
+ const hour = iso[4] === undefined ? 0 : Number(iso[4]);
56
+ const minute = iso[5] === undefined ? 0 : Number(iso[5]);
57
+ const second = iso[6] === undefined ? 0 : Number(iso[6]);
58
+ const offsetHour = iso[7] === undefined ? 0 : Number(iso[7]);
59
+ const offsetMinute = iso[8] === undefined ? 0 : Number(iso[8]);
60
+ const outOfRange = month < 1 || month > 12
61
+ || day < 1 || day > daysInMonth(year, month)
62
+ || hour > 23 || minute > 59 || second > 59
63
+ || offsetHour > 23 || offsetMinute > 59;
64
+ const parsed = Date.parse(input);
65
+ if (outOfRange || !Number.isFinite(parsed))
66
+ return { error: `--since 的 ISO 时间「${text}」不存在(月/日/时分越界?)` };
67
+ return { cutoffMs: parsed, mode: "iso", input };
68
+ }
69
+ return {
70
+ error: `--since 只认 ISO 时间(2026-11-20 或 2026-11-20T09:30Z)或带单位的时长(30m、2h、7d);收到「${text}」——裸数字有歧义(分钟?天?),请带单位`,
71
+ };
72
+ }
73
+ //# sourceMappingURL=duration.js.map
@@ -782,6 +782,28 @@ function graphHintFor(goal) {
782
782
  note: "关系型问题第一入口:一次毫秒级答「谁用到 X / 关于 X 配了哪些规则 / 改动影响」,替代逐模型 rule.list/rule.get 枚举(r72g 探针实测 9 次 rule.get 才拿到的否定结论,索引 1 次可答)。索引含规则条件叶子(rule.condition 边),不含流程绑定,命中后仍以 rule.get 原文为准。宿主接了 MCP 时用 omc_graph_explore(安装器自动注册)。",
783
783
  };
784
784
  }
785
+ /**
786
+ * R88 #1:症状排查话术 → config.diff(草稿↔发布双面差异,只读)。
787
+ *
788
+ * 保守触发:只认「部件词+没生效族」或「改/发布之后没变化族」或「草稿发布
789
+ * 不一致族」的固定形状;裸「不一致」(可能是跨环境/数据问题,config.diff
790
+ * 不做跨环境比对)不接。与 graphHint 相同的追加式语义:不改原路由。
791
+ */
792
+ const TRIAGE_PART_RE = /(?:按钮|控件|规则|节点|字段|表单|流程|配置)(?:不见了|没了|不显示|没显示|没生效|不生效|没更新|不更新|没变化|没变|没跟上)|(?:改了|配置了|改完|发布完|发布了|重新发布)(?:之后|以后|后)?[^,。;,.\n]{0,12}?(?:没生效|不生效|没更新|不更新|没变化|没变|看不到|还是老样子)|草稿.{0,8}发布.{0,8}(?:不一致|不一样|差异)|(?:不一致|不一样|差异).{0,6}(?:草稿|发布)/;
793
+ function triageHintFor(goal) {
794
+ const match = TRIAGE_PART_RE.exec(goal);
795
+ if (match === null)
796
+ return undefined;
797
+ return {
798
+ why: `症状话术命中「${match[0]}」——第一动作是定位哪一面落后,不是先改配置`,
799
+ firstCommand: 'omc call config.diff --env <环境名> --args \'{"domain":"workflow","schemaCode":"<模型code>"}\'',
800
+ commands: [
801
+ 'omc call config.diff --env <环境名> --args \'{"domain":"workflow","schemaCode":"<模型code>"}\' # 流程双面:活动/连线/三类绑定',
802
+ 'omc call config.diff --env <环境名> --args \'{"domain":"form","schemaCode":"<模型code>"}\' # 表单双面:按控件 key 对齐',
803
+ ],
804
+ note: "config.diff 只读零写:changed:null=一面缺失(看 verdict,draft-only 即草稿全未发布),不是空 diff;差异全量与双面快照在 diffArtifactId。双面一致时症状不来自草稿/发布差——再查运行面(rulelog.search / workitem.list)或节点 buttonPermission。",
805
+ };
806
+ }
785
807
  function goalRouteInner(registry, goal) {
786
808
  const index = capabilityRouteIndex(registry);
787
809
  // r49 F1(探针复现):whole-package 主推 intent 前必须确认命中能力的 intent 覆盖——
@@ -1455,10 +1477,13 @@ function capabilityOrder(capabilityId) {
1455
1477
  * `next` 的对外入口:原有路由结果原样返回,只在「引用/影响面」类提问上追加
1456
1478
  * `graphHint`(不改 route、不改 confident、不改 firstAnswer)。理由见
1457
1479
  * `graphHintFor` 注释——图谱不在能力注册表里,只能在这里补入口。
1480
+ * R88 #1:症状排查话术同理追加 `triageHint`(config.diff 指路)。
1458
1481
  */
1459
1482
  export function goalRoute(registry, goal) {
1460
1483
  const base = goalRouteInner(registry, goal);
1461
1484
  const hint = graphHintFor(goal);
1462
- return hint === undefined ? base : { ...base, graphHint: hint };
1485
+ const triage = triageHintFor(goal);
1486
+ const withGraph = hint === undefined ? base : { ...base, graphHint: hint };
1487
+ return triage === undefined ? withGraph : { ...withGraph, triageHint: triage };
1463
1488
  }
1464
1489
  //# sourceMappingURL=goal-routes.js.map
@@ -2,10 +2,14 @@ import { assertWithinCoverage, versionFamilyNotice } from "./coverage.js";
2
2
  import { planFingerprint } from "./plan.js";
3
3
  import { environmentNotice, environmentWritable, requiresProductionConfirmation } from "./environment-policy.js";
4
4
  import { refusalFromCoverage } from "./support.js";
5
+ import { normalizeWriteReason } from "./write-audit.js";
5
6
  const settled = (result) => ({ kind: "settled", result });
6
7
  /** Run the shared gate sequence; settle with a refusal or open an admission. */
7
8
  export async function admitGovernedWrite(ctx, request) {
8
9
  const claims = Array.isArray(request.coverage) ? request.coverage : [request.coverage];
10
+ // R88 #3:reason 在唯一的写入闸门处归一化一次,随后进 artifact 与 journal;
11
+ // 它不是门禁(缺省/超长都不影响写入),也不会被静默改写成别的语义。
12
+ const reason = normalizeWriteReason(request.reason);
9
13
  try {
10
14
  for (const claim of claims)
11
15
  assertWithinCoverage(ctx.manifest, claim.lane, claim.scope);
@@ -104,6 +108,7 @@ export async function admitGovernedWrite(ctx, request) {
104
108
  environmentName: session.environmentName,
105
109
  profile: resolved.profile,
106
110
  plan,
111
+ ...(reason !== undefined ? { reason } : {}),
107
112
  ...(productionConfirmed ? { productionConfirmed: true } : {}),
108
113
  ...(readOnlyEscape !== undefined ? { readOnlyEscape } : {}),
109
114
  },
package/dist/graph.js CHANGED
@@ -5,6 +5,7 @@ import { joinConfigRoot } from "./command-transport.js";
5
5
  import { decodeJsonColumn, JSON_COLUMN_NULL_COALESCE } from "./json-column.js";
6
6
  import { ENDPOINTS } from "./endpoints.js";
7
7
  import { applicationResolutionOf, flattenTreeRows, resolveApplicationScope, sha256 } from "./support.js";
8
+ import { Semaphore } from "./concurrency.js";
8
9
  import { wireCall, wireRows, WireError } from "./wire.js";
9
10
  import { walkConditionLeaves } from "./lanes/rule-graph.js";
10
11
  /**
@@ -624,32 +625,10 @@ export async function pullRuleGraph(session, concurrency = DEFAULT_PULL_CONCURRE
624
625
  let workflowCount = 0;
625
626
  let formCount = 0;
626
627
  // --- shared scheduler: bounded starts, dynamic task submission ---
627
- class Semaphore {
628
- // Handoff semantics: a released slot is handed DIRECTLY to the head
629
- // waiter (free is NOT incremented). The naive `free += 1; wake()` lets a
630
- // task submitted in the microtask gap steal the slot, driving free
631
- // negative — a waiter is then never woken, the pull promise never
632
- // settles, and Node exits 0 SILENTLY when the event loop drains (no
633
- // envelope, lock left behind). Direct handoff keeps the invariant.
634
- free = concurrency;
635
- waiters = [];
636
- async acquire() {
637
- if (this.free > 0) {
638
- this.free -= 1;
639
- return;
640
- }
641
- await new Promise((resolve) => this.waiters.push(resolve));
642
- }
643
- release() {
644
- const waiter = this.waiters.shift();
645
- if (waiter !== undefined) {
646
- waiter();
647
- return;
648
- }
649
- this.free += 1;
650
- }
651
- }
652
- const semaphore = new Semaphore();
628
+ // R88:Semaphore 抽为公共模块 src/concurrency.ts(direct-handoff 语义原样,
629
+ // 修 bug 注释见该模块)——graph pull 与在线扫描(workflow.list /
630
+ // rule.references)共用同一实现。
631
+ const semaphore = new Semaphore(concurrency);
653
632
  let inflight = 0;
654
633
  let resolveAll = () => { };
655
634
  const allDone = new Promise((resolve) => {