@stalfh233/omc-cli 0.8.31 → 0.8.33

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 (53) hide show
  1. package/dist/arg-vocabulary.js +223 -0
  2. package/dist/artifact-cmd.js +443 -0
  3. package/dist/batch-call.js +56 -3
  4. package/dist/call-command.js +70 -0
  5. package/dist/call-execute.js +228 -0
  6. package/dist/call-input.js +557 -0
  7. package/dist/call-output.js +240 -0
  8. package/dist/cli.js +23 -1360
  9. package/dist/command-transport.js +4 -1
  10. package/dist/field-add.js +2 -1
  11. package/dist/form-support.js +17 -4
  12. package/dist/intent/plan-apply.js +14 -24
  13. package/dist/lanes/datarule.js +21 -0
  14. package/dist/lanes/field.js +31 -0
  15. package/dist/lanes/list-view-shapes.js +8 -1
  16. package/dist/lanes/list-view.js +64 -2
  17. package/dist/lanes/runtime-data/aggregate-support.js +209 -0
  18. package/dist/lanes/runtime-data/aggregate.js +679 -0
  19. package/dist/lanes/runtime-data/field-options.js +52 -0
  20. package/dist/lanes/runtime-data/lane.js +4 -0
  21. package/dist/lanes/runtime-data/record-delete.js +419 -0
  22. package/dist/lanes/runtime-data/record-read.js +984 -0
  23. package/dist/lanes/runtime-data/record-write.js +562 -0
  24. package/dist/lanes/runtime-data/registration.js +22 -0
  25. package/dist/lanes/runtime-data/shapes.js +594 -0
  26. package/dist/lanes/runtime-data/submission.js +1293 -0
  27. package/dist/lanes/runtime-data/write-support.js +875 -0
  28. package/dist/lanes/runtime-data-contract.js +1 -1
  29. package/dist/lanes/runtime-data.js +10 -5556
  30. package/dist/lanes/workflow/approval-ops.js +983 -0
  31. package/dist/lanes/workflow/instance-read.js +284 -0
  32. package/dist/lanes/workflow/lifecycle-write.js +1499 -0
  33. package/dist/lanes/workflow/permissions.js +571 -0
  34. package/dist/lanes/workflow/recovery.js +361 -0
  35. package/dist/lanes/workflow/registration.js +14 -0
  36. package/dist/lanes/workflow/shapes.js +811 -0
  37. package/dist/lanes/workflow/template-fetch.js +197 -0
  38. package/dist/lanes/workflow/template-merge.js +1351 -0
  39. package/dist/lanes/workflow/template-read.js +327 -0
  40. package/dist/lanes/workflow.js +11 -6312
  41. package/dist/model-scaffold.js +3 -1
  42. package/dist/path-projection.js +27 -6
  43. package/dist/read-projection.js +442 -0
  44. package/dist/read.js +40 -335
  45. package/dist/rollback.js +17 -23
  46. package/dist/runtime-support.js +1 -1
  47. package/dist/verification.js +39 -0
  48. package/dist/write-coordinator.js +152 -0
  49. package/dist/write-outcome.js +295 -0
  50. package/dist/write.js +34 -115
  51. package/package.json +3 -3
  52. package/skills/omc-refusals.md +1 -1
  53. package/skills/omc-start-here.md +3 -3
@@ -0,0 +1,240 @@
1
+ import { CLI_EXIT_CODES, classifyResult, envelope } from "./cli-contract.js";
2
+ import { maybeWarnMergedStreams, noteOutProjection, writeEnvelope } from "./cli-output.js";
3
+ import { sessionAccountForEnvironment } from "./session-account.js";
4
+ import { boundResult, emitTransportResult } from "./command-transport.js";
5
+ import { buildToolRegistry } from "./tools.js";
6
+ import { describeTool } from "./discovery.js";
7
+ import { containerKeyOf } from "./read.js";
8
+ import { projectResultExtract, unwrapSinglePathProjection } from "./path-projection.js";
9
+ import { locatorMetaFor } from "./read-shapes.js";
10
+ function accountMeta(context) {
11
+ return { sessionAccount: sessionAccountForEnvironment(context.store, context.environment()) };
12
+ }
13
+ export function createCallEmitter(context) {
14
+ return (status, result, exitCode, extra) => {
15
+ if (status === "uncertain" && result !== null && typeof result === "object" && !Array.isArray(result) && result.nextAction === undefined)
16
+ result = { ...result, nextAction: "read back the requestId before retrying; retry only after the outcome is established" };
17
+ // F7(0.8.17 真机 P1):`result` 可能是 --jq 单路径解包后的**叶子**(null /
18
+ // 标量 / 数组),不是工具结果。此处再 classifyResult 会走 `.status`:
19
+ // discover_environment 缓存命中 `models:null` 时 `--jq models` 直接 internal
20
+ // (Cannot read properties of null);标量叶子则把 refused 翻成 ok:true。
21
+ // 结论以**投影前**的分类为准——单路径解包时由调用方放进 extra.error。
22
+ const carriedError = extra !== undefined && Object.prototype.hasOwnProperty.call(extra, "error")
23
+ ? extra.error
24
+ : undefined;
25
+ const classifiedError = carriedError !== undefined
26
+ ? carriedError
27
+ : result !== null && typeof result === "object" && !Array.isArray(result)
28
+ ? classifyResult(result).error
29
+ : null;
30
+ // 回归(0.8.17 复核):字符串叶子仍必须受 stdout 预算约束——否则 `--jq` 取
31
+ // 一个 >64KiB 的字符串会整段内联,破「大读回不内联」。number/boolean/null
32
+ // 有界,原样返回。
33
+ const maxOutputBytes = context.maxOutputBytes();
34
+ const bounded = result !== null && typeof result === "object"
35
+ ? boundResult(result, maxOutputBytes)
36
+ : typeof result === "string"
37
+ ? boundResult(result, maxOutputBytes)
38
+ : result;
39
+ const envelopeValue = envelope(status, bounded, context.request, classifiedError);
40
+ // issue 2026-11-18 §05:单路径 --jq 解包后,`result` 是目标节点本体(可能是
41
+ // 数组/标量,装不进结果对象),路径来源等元信息放信封旁的 `resultMeta`。
42
+ // issue 07:sessionAccount 恒在 resultMeta(瘦身影封保留 resultMeta)。
43
+ writeEnvelope({
44
+ ...envelopeValue,
45
+ ...(extra !== undefined ? { ...extra, resultMeta: { sessionAccount: accountMeta(context).sessionAccount, ...(extra.resultMeta ?? {}) } } : { resultMeta: accountMeta(context) }),
46
+ });
47
+ maybeWarnMergedStreams();
48
+ return exitCode;
49
+ };
50
+ }
51
+ /**
52
+ * 解析阶段的 invalid-input 早退(还没进 wire、没有工具层载荷):stdout 回
53
+ * `{code:"invalid-input"}` 错误信封 + sessionAccount,退出码 10。
54
+ */
55
+ export function emitInvalidInput(context, message, extra = {}) {
56
+ writeEnvelope({
57
+ ...envelope("error", {}, context.request, {
58
+ code: "invalid-input",
59
+ message,
60
+ retryable: false,
61
+ ...(extra.configurationRoot !== undefined ? { configurationRoot: extra.configurationRoot } : {}),
62
+ }),
63
+ resultMeta: accountMeta(context),
64
+ });
65
+ return CLI_EXIT_CODES.invalidInput;
66
+ }
67
+ /**
68
+ * `omc call <tool> --help` / `omc call` 的帮助面。
69
+ *
70
+ * r29f F3:识别到具名工具时转发 describe 摘要,并写死输出预算默认值
71
+ * (别只回通用 call 选项)。
72
+ */
73
+ export function emitCallHelp(context, toolName, emit) {
74
+ if (toolName && toolName !== "help") {
75
+ const registry = buildToolRegistry();
76
+ const described = describeTool(registry, toolName);
77
+ if (described) {
78
+ console.error(`工具:${toolName}`);
79
+ console.error(`输出预算:--max-output-bytes 默认 65536(只约束最终 stdout 信封;读面 diet ~2048 独立外置 detailArtifactId);artifact get 内联上限 8192`);
80
+ console.error(`投影:--jq 不是 jq,仅路径选择器;--jq/--extract 相对 result(不要写 result. 前缀;误写会自动剥并标 autoStripped);先投影再判预算`);
81
+ return emitTransportResult({ status: "ok", ...described, helpNote: "来自 omc describe;完整面用 omc describe <tool> [--full|--param|--example]" }, { request: context.request, maxOutputBytes: context.maxOutputBytes() });
82
+ }
83
+ }
84
+ 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 <写入原因(审计)>]");
85
+ console.error("输出预算:--max-output-bytes 默认 65536(只约束最终 stdout 信封;读面 diet ~2048 独立外置 detailArtifactId);artifact get 内联上限 8192");
86
+ console.error("写入:由环境 writable 决定(只读环境拒写);生产环境的写必须在 args 里带 confirmProduction:true。");
87
+ console.error("会话账号:每次回执 resultMeta.sessionAccount(token 解码:id=user_id、username=user_name、name=登录显示名;解不出回 unavailableReason)。报错里的 currentUser 是平台按 username 反查的 id,同名多账号时与 id 不同——排查 not-mine 先看这两个是否同一个人。");
88
+ return emit(toolName && toolName !== "help" ? "error" : "ok", {}, toolName && toolName !== "help" ? CLI_EXIT_CODES.invalidInput : 0);
89
+ }
90
+ /**
91
+ * `omc call` 的投影面:`--jq`/`--extract`/`--keys` + 读面 unknown-key 回显 +
92
+ * 同义别名回执。
93
+ *
94
+ * 顺序是契约的一部分:容器键在**投影前**判定;ignoredArgs/aliasesApplied 放在
95
+ * 投影**之后**(否则会被窄投影吞掉),单路径解包时随 resultMeta 走。
96
+ */
97
+ export function projectCallResult(parsed, rawResult, maxOutputBytes) {
98
+ const { toolName, environment, rawArgs, parsedArgs, extractPaths, extractKeys, explainProjection, aliasesApplied, ignoredReadKeys } = parsed;
99
+ let result = rawResult;
100
+ let unwrappedBody;
101
+ let resultMeta;
102
+ // C7(0.8.4):结果容器键自描述——`items`/`models`/`rules`/`logs`/`fields` 各面
103
+ // 不同,每个工具首次使用都要先探一次键名。在**投影前**的原始结果上判定,
104
+ // 挂到信封 resultMeta(result 本体与 --jq 路径零改动)。
105
+ const container = containerKeyOf(result);
106
+ if (extractPaths.length > 0 || extractKeys) {
107
+ // F1(retro 22,ticket 138):把调用上下文交给投影层——pathMiss 能推导出
108
+ // correctPath 时,拼一条含 --env/--args/--jq 的完整可复制命令(nextCommand)。
109
+ // args 用调用方**原始** JSON(未归一化),>500B 时投影层放弃拼命令(不截断造假)。
110
+ const projected = projectResultExtract(result, extractPaths, extractKeys, {
111
+ tool: toolName,
112
+ ...(environment !== undefined && environment.length > 0 ? { environment } : {}),
113
+ argsJson: rawArgs !== undefined ? rawArgs : JSON.stringify(parsedArgs),
114
+ }, explainProjection);
115
+ if (projected !== undefined)
116
+ result = projected;
117
+ // Projected reads are represented by extract[] (and rows[] for multi-path).
118
+ // Do not also copy the single-path value to top-level content.
119
+ if (extractPaths.length > 0 && !extractKeys && typeof result === "object" && result !== null)
120
+ delete result.content;
121
+ // r40a: unsupported jq language is an input error, never an `ok:true`
122
+ // projection with a null value. Keep the path engine's detailed hint but
123
+ // make the CLI contract actionable and machine-classifiable.
124
+ if (typeof result === "object" && result !== null && Array.isArray(result.extract)) {
125
+ const extracts = result.extract;
126
+ const unsupported = extracts.filter((entry) => entry.unsupportedSyntax === true);
127
+ if (unsupported.length > 0) {
128
+ const first = unsupported[0];
129
+ const detail = typeof first?.hint === "string" ? first.hint : "投影 DSL 只做路径选择(点式 / [] 映射 / [key=value] / 切片)";
130
+ const message = `--jq 不是 jq:仅路径选择器,${detail}(${String(first?.path ?? "")})。可运行示例:--jq 'fields[].code,fields[].typeName'`;
131
+ const invalid = { status: "error", blocker: "tool-input-invalid", unsupportedSyntax: true, paths: unsupported.map((entry) => entry.path), message, nextCommand: "omc call <tool> --args '<json>' --jq 'fields[].code,fields[].typeName'" };
132
+ return { result, unwrappedBody, resultMeta, container, refusal: { status: "error", result: invalid, exitCode: CLI_EXIT_CODES.invalidInput } };
133
+ }
134
+ // issue 2026-11-18 §05:单路径命中 → 信封的 result 直接是节点本体,元信息
135
+ // 走 resultMeta(形状与不带 --jq 时的 result 同层级,只是被裁剪)。
136
+ // 未命中/不支持语法不解包:pathMiss/available/hint 留在 result 顶层才能自愈。
137
+ if (extractPaths.length === 1 && !extractKeys) {
138
+ const unwrapped = unwrapSinglePathProjection(result);
139
+ if (unwrapped !== undefined) {
140
+ unwrappedBody = unwrapped.result;
141
+ resultMeta = unwrapped.resultMeta;
142
+ }
143
+ }
144
+ for (const entry of extracts)
145
+ delete entry.autoStripped;
146
+ }
147
+ // `extract[]` is the canonical multi-path result. Do not emit the second
148
+ // row-alignment copy: callers can align the explicitly named path values.
149
+ if (typeof result === "object" && result !== null && extractPaths.length > 1)
150
+ delete result.rows;
151
+ }
152
+ // 读面未知键的非阻断回显:放在投影**之后**,否则会被 --jq 的窄投影吞掉。
153
+ // 单路径解包后 result 是节点本体(可能是数组/标量),不能再往本体上加键——
154
+ // 这类元信息跟着 resultMeta 走,确保「本体就是本体」。
155
+ if (ignoredReadKeys.length > 0 && unwrappedBody !== undefined) {
156
+ const pairs = ignoredReadKeys.map((entry) => entry.hint ? `${entry.key}(${entry.hint})` : entry.closest ? `${entry.key}→${entry.closest}` : entry.key);
157
+ resultMeta = {
158
+ ...(resultMeta ?? {}),
159
+ ignoredArgs: {
160
+ keys: ignoredReadKeys,
161
+ hint: `这些参数本工具不认识,已被忽略(没有生效):${pairs.join("、")}。若是拼写问题按 → 改;要确认完整参数表用 \`omc describe ${toolName}\``,
162
+ },
163
+ };
164
+ }
165
+ else if (ignoredReadKeys.length > 0 && typeof result === "object" && result !== null) {
166
+ const pairs = ignoredReadKeys.map((entry) => {
167
+ if (entry.hint)
168
+ return `${entry.key}(${entry.hint})`;
169
+ if (entry.closest)
170
+ return `${entry.key}→${entry.closest}`;
171
+ if (entry.absentInTool)
172
+ return `${entry.key}(本工具没有 ${entry.absentInTool} 参数)`;
173
+ return entry.key;
174
+ });
175
+ result = {
176
+ ...result,
177
+ ignoredArgs: {
178
+ keys: ignoredReadKeys,
179
+ hint: `这些参数本工具不认识,已被忽略(没有生效):${pairs.join("、")}。若是拼写问题按 → 改;要确认完整参数表用 \`omc describe ${toolName}\`。注意「过滤/排序没生效」最常见的原因就是这里拼错键。`,
180
+ },
181
+ };
182
+ }
183
+ // C1(0.8.4):同义参数换算的说明与 ignoredArgs 同层——放在投影**之后**,
184
+ // 否则被 --jq 的窄投影吞掉;单路径解包时随 resultMeta 走。
185
+ if (Object.keys(aliasesApplied).length > 0) {
186
+ if (unwrappedBody !== undefined)
187
+ resultMeta = { ...(resultMeta ?? {}), aliasesApplied };
188
+ else if (typeof result === "object" && result !== null)
189
+ result = { ...result, aliasesApplied };
190
+ }
191
+ // stdout 预算里 `--out` 投影说明走「先落盘、后回执」——此处只登记,不写 stdout。
192
+ if (extractPaths.length > 0 || extractKeys) {
193
+ const projectionValue = unwrappedBody !== undefined ? unwrappedBody : result;
194
+ const unanswered = projectionValue !== null && typeof projectionValue === "object" && !Array.isArray(projectionValue)
195
+ && projectionValue.unanswered === true;
196
+ noteOutProjection({ paths: extractPaths, value: projectionValue, hit: !unanswered, budget: maxOutputBytes });
197
+ }
198
+ return { result, unwrappedBody, resultMeta, container };
199
+ }
200
+ /**
201
+ * 最终信封:分类(结果本体)+ resultMeta.locator / containerKey + 单路径解包的
202
+ * 元信息旁置,然后 emit。
203
+ *
204
+ * 分类以**投影前/解包前**的 result 为准——`--jq` 取回的整包自带的 `status`
205
+ * 不得改写本调用的结论。
206
+ */
207
+ export function emitCallResult(input) {
208
+ const { emit, parsed, projection } = input;
209
+ const { toolName } = parsed;
210
+ const { result, unwrappedBody, resultMeta, container } = projection;
211
+ const classified = classifyResult(result);
212
+ // 单路径 --jq 命中:emit 的是节点本体(可能不是对象),元信息在信封旁。
213
+ // body 自带 `status`/`blocker` 时(如 --jq 直接取回整包),信封的 error 仍以
214
+ // **投影前**的 classified 为准——别让 payload 里的字段改写本调用的结论。
215
+ const emitValue = unwrappedBody !== undefined ? unwrappedBody : result;
216
+ // A2(r89 契约层):跨面键名对照(read-shapes 单一声明)挂信封 resultMeta.locator——
217
+ // 成功读回才有定位意义;result 本体与 --jq 路径零改动。
218
+ const locatorExtra = classified.status === "ok" ? locatorMetaFor(toolName) : undefined;
219
+ const containerExtra = classified.status === "ok" && container !== undefined
220
+ ? { containerKey: container.key, ...(container.path !== undefined ? { containerPath: container.path } : {}) }
221
+ : undefined;
222
+ const mergedMeta = { ...(locatorExtra ?? {}), ...(containerExtra ?? {}), ...(resultMeta ?? {}) };
223
+ const extras = unwrappedBody !== undefined
224
+ ? { error: classified.error, ...(Object.keys(mergedMeta).length > 0 ? { resultMeta: mergedMeta } : {}) }
225
+ : Object.keys(mergedMeta).length > 0 ? { resultMeta: mergedMeta } : undefined;
226
+ return emit(classified.status, emitValue, classified.exitCode, extras);
227
+ }
228
+ /**
229
+ * 写锁冲突(`write-lock-held`):结构化回执 + 退出码 12。
230
+ *
231
+ * r31b F2:receipt 自带 retryable/lockOwner/nextCommand,脚本不必自己发明重试
232
+ * 循环(help 说用 --wait,拒绝也要说)。stderr 人类行先于 stdout 信封。
233
+ */
234
+ export function emitCallLockConflict(context, receipt, stderr) {
235
+ if (stderr !== undefined)
236
+ console.error(stderr);
237
+ writeEnvelope({ ...envelope("refused", receipt, context.request, classifyResult(receipt).error), resultMeta: accountMeta(context) });
238
+ return CLI_EXIT_CODES.policyRefused;
239
+ }
240
+ //# sourceMappingURL=call-output.js.map