@stalfh233/omc-cli 0.6.84 → 0.6.85

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.
@@ -0,0 +1,43 @@
1
+ import { sessionAccountForEnvironment } from "./session-account.js";
2
+ /**
3
+ * Write-audit context for the journal (R88 #3).
4
+ *
5
+ * Two questions the journal could not answer before: WHO wrote a config change
6
+ * and WHY. Both are recorded on every journal line, but neither may be invented:
7
+ *
8
+ * - actor comes from the locally cached login token (`session-account.ts`):
9
+ * zero extra wire, and `actorSource:"token-claim"` says exactly what it is —
10
+ * the JWT claim of the session that wrote, NOT the platform's `currentUser`.
11
+ * An undecodable token records `actorUnavailableReason` instead.
12
+ * - reason is the caller's own statement (`omc call --reason`,
13
+ * `omc intent apply --reason`, `omc rollback apply --reason`). It is audit
14
+ * metadata only: it never gates, delays, or refuses a write.
15
+ *
16
+ * The reason is NOT a tool input-schema field on purpose: adding it to ~170
17
+ * write tools would grow the tools/list payload for a field no schema validates.
18
+ * It rides the per-invocation `ToolContext.writeAudit`, which every governed
19
+ * entry point (call / batch / intent apply / rollback replay) can set.
20
+ */
21
+ /** Longest reason persisted to the journal (long prose belongs in the plan/summary). */
22
+ export const WRITE_REASON_MAX_LENGTH = 500;
23
+ /** Trim + bound a caller-declared reason; empty / non-string → undefined (absent, not ""). */
24
+ export function normalizeWriteReason(reason) {
25
+ if (typeof reason !== "string")
26
+ return undefined;
27
+ const trimmed = reason.trim();
28
+ if (trimmed.length === 0)
29
+ return undefined;
30
+ return trimmed.length > WRITE_REASON_MAX_LENGTH ? `${trimmed.slice(0, WRITE_REASON_MAX_LENGTH)}…` : trimmed;
31
+ }
32
+ /**
33
+ * Resolve the journal audit columns for one write. Never throws: an unreadable
34
+ * token cache / unresolved environment degrades to `actorUnavailableReason`,
35
+ * because a missing actor must not fail the write the line is describing.
36
+ */
37
+ export function journalAudit(store, environment, reason) {
38
+ const account = sessionAccountForEnvironment(store, environment);
39
+ const identity = "id" in account ? { actor: { ...account }, actorSource: "token-claim" } : { actorUnavailableReason: account.unavailableReason };
40
+ const normalized = normalizeWriteReason(reason);
41
+ return { ...identity, ...(normalized !== undefined ? { reason: normalized } : {}) };
42
+ }
43
+ //# sourceMappingURL=write-audit.js.map
package/dist/write.js CHANGED
@@ -17,6 +17,7 @@ import { writeSummary } from "./human-summary.js";
17
17
  import { planFor } from "./plan.js";
18
18
  import { isUncertainWireError, sha256, wireErrorKind, writeArtifact } from "./support.js";
19
19
  import { appendJournalEntry } from "./journal.js";
20
+ import { journalAudit } from "./write-audit.js";
20
21
  import { capabilityArg, confirmProductionArg, environmentArg, WRITE_PROTOCOL } from "./args.js";
21
22
  import { plannableArgsRaw } from "./plan.js";
22
23
  import { defineTool, ToolRefusalError } from "./tool-types.js";
@@ -49,6 +50,9 @@ lintDeclaration = { lintScope: "partial", lintUnchecked: [] }) {
49
50
  dryRun: args.dryRun,
50
51
  capability: args.capability,
51
52
  args,
53
+ // R88 #3:写入原因来自本次调用的审计上下文(omc call --reason 等),
54
+ // 不是工具入参 schema 的字段——工具面零增长。
55
+ ...(ctx.writeAudit?.reason !== undefined ? { reason: ctx.writeAudit.reason } : {}),
52
56
  ...(readOnlyEscape !== undefined ? { readOnlyEscape } : {}),
53
57
  coverage: { lane: args.capability ?? tool.lane, scope: tool.scope ?? "" },
54
58
  plan: (session) => planFor(ctx, args.environment, tool.name, args),
@@ -84,7 +88,7 @@ lintDeclaration = { lintScope: "partial", lintUnchecked: [] }) {
84
88
  });
85
89
  if (outcome.kind === "settled")
86
90
  return outcome.result;
87
- const { session, plan, productionConfirmed, readOnlyEscape: readOnlyEscapeNote } = outcome.admission;
91
+ const { session, plan, productionConfirmed, readOnlyEscape: readOnlyEscapeNote, reason } = outcome.admission;
88
92
  return ctx.lease.run(session.environmentName, `${tool.name}:${randomUUID().slice(0, 8)}`, async () => {
89
93
  // Rollback before-capture: the pre-write state of the declared target is
90
94
  // fetched INSIDE the lease (serialized with the write itself) and stored
@@ -204,6 +208,7 @@ lintDeclaration = { lintScope: "partial", lintUnchecked: [] }) {
204
208
  readback,
205
209
  ...(steps !== undefined ? { steps } : {}),
206
210
  ...(productionConfirmed ? { productionConfirmed: true } : {}),
211
+ ...(reason !== undefined ? { reason } : {}),
207
212
  ...(tool.rollback
208
213
  ? {
209
214
  rollback: {
@@ -238,6 +243,9 @@ lintDeclaration = { lintScope: "partial", lintUnchecked: [] }) {
238
243
  beforeSha: artifact.rollback.beforeSha,
239
244
  rollbackable: rollbackBefore !== undefined && !rollbackCaptureError,
240
245
  ...(rollbackCaptureError ? { note: `before-capture failed: ${rollbackCaptureError}` } : {}),
246
+ // R88 #3:每一行都带「谁写的」(token 解码,0 wire;解不出记原因)与
247
+ // 「为什么写」(调用方 --reason;缺省则不记,不发明理由)。
248
+ ...journalAudit(ctx.sessions.config(), session.environmentName, reason),
241
249
  artifactFile: artifactRef.detailFile,
242
250
  artifactId: basename(artifactRef.detailFile).replace(/\.artifact$/, "") || basename(artifactRef.detailFile),
243
251
  artifactSha: artifactRef.detailSha256,
@@ -259,6 +267,7 @@ lintDeclaration = { lintScope: "partial", lintUnchecked: [] }) {
259
267
  // r30a F1: first write → replay:"none"; duplicate only on true replay.
260
268
  ...(args.requestId ? { requestId: args.requestId, idempotency: idempotencyDeclaration(tool.name, "none") } : {}),
261
269
  ...(productionConfirmed ? { productionConfirmed: true } : {}),
270
+ ...(reason !== undefined ? { reason } : {}),
262
271
  ...(rollbackRef
263
272
  ? { rollback: { ...(rollbackReceipt ?? {}), seq: rollbackRef.seq, ...(rollbackReceipt ? {} : { hint: rollbackRef.hint }) } }
264
273
  : {}),
@@ -530,7 +530,7 @@ omc intent readback intent.yaml --env test # 解码回 intent 形状做等价
530
530
  - 顶层 `models[]` / `services[]`;`models[].{code,name,fields,datarules,rules,form,listview,workflow,onlinejs}`。
531
531
  - `intent apply` 既可以吃 `plan` 文件,也可以直接吃 YAML(`omc intent apply intent.yaml --env <env>`,自动编译);大 plan 会自动外置,回 `planFile`。
532
532
  - **幂等收敛**:已达标环境重跑 plan/apply → 零变更、零重复创建。
533
- - 显式缺席(删除):`models[].absent:true` 删整模型、`fields[].absent:true` 删单字段;plan 的 `riskClass` 升为 `destructive`。
533
+ - 显式缺席(删除):`models[].absent:true` 删整模型、`fields[].absent:true` 删单字段、`listview.absent:true` 删列表视图、`datarules[].absent:true` 删数据规则;plan 的 `riskClass` 升为 `destructive`,`cleanup` 逐项列出。
534
534
  - 生产 apply 加 `--confirm-production`;`--dry-run` 预览,`--no-verify` 跳过最终读回。
535
535
 
536
536
  ### 5.3 复合命令 —— 一条命令 = 一个变更包
@@ -544,7 +544,7 @@ omc intent readback intent.yaml --env test # 解码回 intent 形状做等价
544
544
  | `omc workflow-update-publish` | 显式合成最终模板(默认保留旧节点,`--confirm-replace` 才丢弃) |
545
545
  | `omc call apply_changes` | 批量提交异构变更清单 `changes:[{tool,args}]`,首败即停、逐步读回、整批时间预算 |
546
546
  | `omc script` | NDJSON 多调脚本,一个进程一次会话跑完全部 |
547
- | `omc rollback` | 配置回滚(list / plan / apply),git-revert 语义;journal 与 before 快照是本机边界(不跨机器),publish 类生命周期推进不可逆 |
547
+ | `omc rollback` | 配置回滚(list / plan / apply),git-revert 语义;journal 兼作**项目级写审计面**:每行带 `actor`(token 解码,`actorSource:token-claim`,不是平台 currentUser;解不出回 `actorUnavailableReason`)与 `reason`(写时 `--reason`),`list --since <ISO\|30m\|2h>` 收窄窗口。journal 与 before 快照是本机边界(不跨机器、不跨项目;故意不设第二个 `omc audit` 真相源),publish 类生命周期推进不可逆 |
548
548
 
549
549
  另有若干「不写环境」的辅助命令:`compute`(聚合公式编译)、`rule-when`、`approval-flow`、`form-default`、
550
550
  `bench`(跑分)、`usage`(用量账本)、`next`(目标 → 工具一步定位)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stalfh233/omc-cli",
3
- "version": "0.6.84",
3
+ "version": "0.6.85",
4
4
  "description": "CloudPivot 8.6 configuration capability CLI — governed, fail-closed, coverage-manifest bounded.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -56,7 +56,7 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "commander": "14.0.3",
59
- "omc-core": "0.6.84",
59
+ "omc-core": "0.6.85",
60
60
  "proper-lockfile": "4.1.2",
61
61
  "write-file-atomic": "6.0.0",
62
62
  "zod": "^3.23.8",
@@ -74,6 +74,6 @@
74
74
  "directory": "packages/omc-cli"
75
75
  },
76
76
  "optionalDependencies": {
77
- "@stalfh233/omc-fake-platform": "0.6.84"
77
+ "@stalfh233/omc-fake-platform": "0.6.85"
78
78
  }
79
79
  }
@@ -168,8 +168,8 @@ only the section for the capability you need —
168
168
 
169
169
  ## 流程模板 `workflow`
170
170
 
171
- - **能做哪些事**:流程模板 workflow.list(应用内流程清单,以模型为索引)、get_draft/get_published、create、update、publish、bindRule/unbindRule(事件处理器规则绑定与解绑)、delete、workitem.list、workflow.instanceActivity(实例节点状态诊断);参与人用组织对象。**流程运维三件套**(r64,测试提速定位):workflow.transfer 换审批人(回执 newWorkItems 带补查的新 workItemId)/ workflow.activate 跳转节点 / workflow.finish 手动结束(end 规则照常触发)——运维过的实例不能用于真实流程/权限验证。
172
- - **工具**:`workflow.list`、`workflow.get_draft`、`workflow.setButtons`(节点「表单操作」按钮勾选)、`workflow.get_published`、`workflow.validate`、`workflow.create`、`workflow.update`、`workflow.publish`、`workflow.bindRule`、`workflow.unbindRule`(镜像 bindRule 两形态做减法;移空按平台 canonical 未绑态写回,不自动 disable 规则)、`workflow.delete`、`workflow.permissions`、`workflow.addPermission`、`workflow.removePermission`(发起权限:发布流程不会自动建这一行,缺它一律 40009)、`configure_workflow`、`workitem.list`、`workflow.instanceActivity`、`workflow.transfer`、`workflow.activate`、`workflow.finish`、`org.role.list`、`org.department.list`、`org.user.search`、`org.role.users`、`org.role.userScope`、`org.roleGroup.create`、`org.role.create`、`org.role.update`、`org.role.addUsers`、`org.role.removeUsers`、`org.role.setUserScope`、`org.department.create`、`org.department.update`、`org.department.delete`、`org.department.users`、`org.user.create`、`org.user.update`、`org.user.delete`、`org.user.info`、`org.user.departments`、`org.role.delete`、`org.roleGroup.delete`、`org.user.transferDepartment`
171
+ - **能做哪些事**:流程模板 workflow.list(应用内流程清单,以模型为索引)、get_draft/get_published、create、update、publish、bindRule/unbindRule(事件处理器规则绑定与解绑)、delete、workitem.list、workflow.instanceActivity(实例节点状态诊断);参与人用组织对象。**症状排查先 `config.diff`**(domain 另支持 form 表单布局双面):「按钮不见了/规则没生效/表单没更新/改了没生效」先 diff 双面定位哪一面落后(活动/连线/**三类绑定分别报**:流程级 ruleBindings、节点事件 nodeRuleBindings、SYSTEM_ACTIVITY 顶层 systemRuleBindings;changed:null=一面缺失看 verdict,不是空 diff)。**流程运维三件套**(r64,测试提速定位):workflow.transfer 换审批人(回执 newWorkItems 带补查的新 workItemId)/ workflow.activate 跳转节点 / workflow.finish 手动结束(end 规则照常触发)——运维过的实例不能用于真实流程/权限验证。
172
+ - **工具**:`config.diff`(草稿↔发布双面差异,只读)、`workflow.list`、`workflow.get_draft`、`workflow.setButtons`(节点「表单操作」按钮勾选)、`workflow.get_published`、`workflow.validate`、`workflow.create`、`workflow.update`、`workflow.publish`、`workflow.bindRule`、`workflow.unbindRule`(镜像 bindRule 两形态做减法;移空按平台 canonical 未绑态写回,不自动 disable 规则)、`workflow.delete`、`workflow.permissions`、`workflow.addPermission`、`workflow.removePermission`(发起权限:发布流程不会自动建这一行,缺它一律 40009)、`configure_workflow`、`workitem.list`、`workflow.instanceActivity`、`workflow.transfer`、`workflow.activate`、`workflow.finish`、`org.role.list`、`org.department.list`、`org.user.search`、`org.role.users`、`org.role.userScope`、`org.roleGroup.create`、`org.role.create`、`org.role.update`、`org.role.addUsers`、`org.role.removeUsers`、`org.role.setUserScope`、`org.department.create`、`org.department.update`、`org.department.delete`、`org.department.users`、`org.user.create`、`org.user.update`、`org.user.delete`、`org.user.info`、`org.user.departments`、`org.role.delete`、`org.roleGroup.delete`、`org.user.transferDepartment`
173
173
  - **recipe**:`omc describe workflow.bindRule --example workflow-handler-binding`;条件两级/一级:`omc describe workflow.update --example workflow-conditional-two-level-approval`
174
174
  - **边界 / 陷阱**:greenfield 首版;`publish`/`bindRule` 不得在 `ValidateMessage[]` 拒绝时报告成功。运行时 workitem(提交/审批)走 `data.submit`;想知道实例停在哪/是否错派,用 `workflow.instanceActivity`(无 status=1=真停,参与人全是发起人=解析为空退回)。**发起权限**(`workflow.permissions` / `addPermission`)只有部门/角色/用户三种白名单,**没有「全员」选项**——缺权限行时非管理员通常不能发起(40009),想放开只能授一个够宽的部门/角色,不是「不建行=全员」。**行级数据权限 / 可见范围 / 申请人只看自己的单据不在工具覆盖内**(没有按登录人动态过滤的读面/写面);`org.role.setUserScope` 是角色成员的部门管理范围,不是单据行级可见范围。
175
175